Changeset 0d5dc05 in sasmodels for doc/genmodel.py
- Timestamp:
- Mar 31, 2019 7:33:49 AM (6 years ago)
- Branches:
- master
- Children:
- f8060c5
- Parents:
- be0942c (diff), 7050455 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Steve K <smk78@…> (03/31/19 07:33:49)
- git-committer:
- GitHub <noreply@…> (03/31/19 07:33:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/genmodel.py
rb866abf rbe0942c 7 7 import matplotlib.pyplot as plt 8 8 sys.path.insert(0, os.path.abspath('..')) 9 import sasmodels 9 10 from sasmodels import generate, core 10 11 from sasmodels.direct_model import DirectModel, call_profile … … 127 128 #print("figure saved in",path) 128 129 130 def 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 141 def 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 # Could do syntax highlighting on the model files by creating a rst file 160 # beside each source file named containing source file with 161 # 162 # src/path.rst: 163 # 164 # .. {{ path.replace('/','_') }}: 165 # 166 # .. literalinclude:: {{ src/path }} 167 # :language: {{ "python" if path.endswith('.py') else "c" }} 168 # :linenos: 169 # 170 # and link to it using 171 # 172 # colors = [":ref:`%s`"%(path.replace('/','_')) for path in sources] 173 # 174 # Probably need to dump all the rst files into an index.rst to build them. 175 176 # Link to github repo (either the tagged sasmodels version or master) 177 url = "https://github.com/SasView/sasmodels/blob/v%s"%sasmodels.__version__ 178 #url = "https://github.com/SasView/sasmodels/blob/master"%sasmodels.__version__ 179 links = ["`%s <%s/sasmodels/models/%s>`_"%(path, url, path) for path in sources] 180 181 sep = "\n$\\ \\star\\ $ " # bullet 182 body = "\n**Source**\n" 183 #body += "\n" + sep.join(links) + "\n\n" 184 body += "\n" + sep.join(downloads) + "\n\n" 185 return body 186 129 187 def gen_docs(model_info): 130 188 # type: (ModelInfo) -> None … … 150 208 match = re.search(pattern, docstr.upper()) 151 209 210 sources = link_sources(model_info) 211 212 insertion = captionstr + sources 213 152 214 if match: 153 215 docstr1 = docstr[:match.start()] 154 216 docstr2 = docstr[match.start():] 155 docstr = docstr1 + captionstr+ docstr2217 docstr = docstr1 + insertion + docstr2 156 218 else: 157 219 print('------------------------------------------------------------------') 158 220 print('References NOT FOUND for model: ', model_info.id) 159 221 print('------------------------------------------------------------------') 160 docstr += captionstr161 162 open(sys.argv[2], 'w').write(docstr)222 docstr += insertion 223 224 open(sys.argv[2], 'w').write(docstr) 163 225 164 226 def process_model(path):
Note: See TracChangeset
for help on using the changeset viewer.