Changeset c1e44e5 in sasmodels for doc


Ignore:
Timestamp:
Mar 30, 2019 1:59:45 AM (6 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master
Children:
a42b091
Parents:
663d2a8
Message:

Add local link to source files. Refs #1263.

Location:
doc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/conf.py

    r30b60d2 rc1e44e5  
    3636              #'only_directives', 
    3737              #'matplotlib.sphinxext.mathmpl', 
    38               'matplotlib.sphinxext.only_directives', 
     38              #'matplotlib.sphinxext.only_directives', 
    3939              'matplotlib.sphinxext.plot_directive', 
    4040              'dollarmath', 
  • doc/genmodel.py

    rb866abf rc1e44e5  
    77import matplotlib.pyplot as plt 
    88sys.path.insert(0, os.path.abspath('..')) 
     9import sasmodels 
    910from sasmodels import generate, core 
    1011from sasmodels.direct_model import DirectModel, call_profile 
     
    127128    #print("figure saved in",path) 
    128129 
     130def copy_if_newer(src, dst): 
     131    from os.path import dirname, exists, getmtime 
     132    import shutil 
     133    if not exists(dst): 
     134        path = dirname(dst) 
     135        if not exists(path): 
     136            os.makedirs(path) 
     137        shutil.copy2(src, dst) 
     138    elif getmtime(src) > getmtime(dst): 
     139        shutil.copy2(src, dst) 
     140 
     141def link_sources(model_info): 
     142    from os.path import basename, dirname, realpath, join as joinpath 
     143 
     144    # List source files in reverse order of dependency. 
     145    model_file = basename(model_info.filename) 
     146    sources = list(reversed(model_info.source + [model_file])) 
     147 
     148    # Copy files to src dir under models directory.  Need to do this 
     149    # because sphinx can't link to an absolute path. 
     150    root = dirname(dirname(realpath(__file__))) 
     151    src = joinpath(root, "sasmodels", "models") 
     152    dst = joinpath(root, "doc", "model", "src") 
     153    for path in sources: 
     154        copy_if_newer(joinpath(src, path), joinpath(dst, path)) 
     155 
     156    # Link to local copy of the files 
     157    downloads = [":download:`%s <src/%s>`"%(path, path) for path in sources] 
     158 
     159    # Link to github repo (either the tagged sasmodels version or master) 
     160    url = "https://github.com/SasView/sasmodels/blob/v%s"%sasmodels.__version__ 
     161    #url = "https://github.com/SasView/sasmodels/blob/master"%sasmodels.__version__ 
     162    links = ["`%s <%s/sasmodels/models/%s>`_"%(path, url, path) for path in sources] 
     163 
     164    sep = u"\n\\ \u25E6 \\ "  # bullet 
     165    body = "\n**Source**\n" 
     166    #body += "\n\\ " + sep.join(links) + "\n\n" 
     167    body += "\n\\ " + sep.join(downloads) + "\n\n" 
     168    return body 
     169 
    129170def gen_docs(model_info): 
    130171    # type: (ModelInfo) -> None 
     
    150191    match = re.search(pattern, docstr.upper()) 
    151192 
     193    sources = link_sources(model_info) 
     194 
     195    insertion = captionstr + sources 
     196 
    152197    if match: 
    153198        docstr1 = docstr[:match.start()] 
    154199        docstr2 = docstr[match.start():] 
    155         docstr = docstr1 + captionstr + docstr2 
     200        docstr = docstr1 + insertion + docstr2 
    156201    else: 
    157202        print('------------------------------------------------------------------') 
    158203        print('References NOT FOUND for model: ', model_info.id) 
    159204        print('------------------------------------------------------------------') 
    160         docstr += captionstr 
     205        docstr += insertion 
    161206 
    162207    open(sys.argv[2],'w').write(docstr) 
Note: See TracChangeset for help on using the changeset viewer.