Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions doc/_extensions/dollarmath.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ def setup(app):


def test_dollar():
assert replace_dollar(u"no dollar")==u"no dollar"
assert replace_dollar(u"$only$")==u":math:`only`"
assert replace_dollar(u"$first$ is good")==u":math:`first` is good"
assert replace_dollar(u"so is $last$")==u"so is :math:`last`"
assert replace_dollar(u"and $mid$ too")==u"and :math:`mid` too"
assert replace_dollar(u"$first$, $mid$, $last$")==u":math:`first`, :math:`mid`, :math:`last`"
assert replace_dollar(u"dollar\$ escape")==u"dollar$ escape"
assert replace_dollar(u"dollar \$escape\$ too")==u"dollar $escape$ too"
assert replace_dollar(u"spaces $in the$ math")==u"spaces :math:`in the` math"
assert replace_dollar(u"emb\ $ed$\ ed")==u"emb\ :math:`ed`\ ed"
assert replace_dollar(u"$first$a")==u"$first$a"
assert replace_dollar(u"a$last$")==u"a$last$"
assert replace_dollar(u"$37")==u"$37"
assert replace_dollar(u"($37)")==u"($37)"
assert replace_dollar(u"$37 - $43")==u"$37 - $43"
assert replace_dollar(u"($37, $38)")==u"($37, $38)"
assert replace_dollar(u"a $mid$dle a")==u"a $mid$dle a"
assert replace_dollar(u"a ($in parens$) a")==u"a (:math:`in parens`) a"
assert replace_dollar(u"a (again $in parens$) a")==u"a (again :math:`in parens`) a"
assert replace_dollar("no dollar")=="no dollar"
assert replace_dollar("$only$")==":math:`only`"
assert replace_dollar("$first$ is good")==":math:`first` is good"
assert replace_dollar("so is $last$")=="so is :math:`last`"
assert replace_dollar("and $mid$ too")=="and :math:`mid` too"
assert replace_dollar("$first$, $mid$, $last$")==":math:`first`, :math:`mid`, :math:`last`"
assert replace_dollar(r"dollar\$ escape")=="dollar$ escape"
assert replace_dollar(r"dollar \$escape\$ too")=="dollar $escape$ too"
assert replace_dollar("spaces $in the$ math")=="spaces :math:`in the` math"
assert replace_dollar(r"emb\ $ed$\ ed")==r"emb\ :math:`ed`\ ed"
assert replace_dollar("$first$a")=="$first$a"
assert replace_dollar("a$last$")=="a$last$"
assert replace_dollar("$37")=="$37"
assert replace_dollar("($37)")=="($37)"
assert replace_dollar("$37 - $43")=="$37 - $43"
assert replace_dollar("($37, $38)")=="($37, $38)"
assert replace_dollar("a $mid$dle a")=="a $mid$dle a"
assert replace_dollar("a ($in parens$) a")=="a (:math:`in parens`) a"
assert replace_dollar("a (again $in parens$) a")=="a (again :math:`in parens`) a"

if __name__ == "__main__":
test_dollar()
47 changes: 23 additions & 24 deletions doc/genmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def make_figure(model_info, opts):
"""
import matplotlib.pyplot as plt

print("Build model")
# print("Build model")
model = core.build_model(model_info)

print("Set up figure")
# print("Set up figure")
fig_height = 3.0 # in
fig_left = 0.6 # in
fig_right = 0.5 # in
Expand All @@ -170,10 +170,10 @@ def make_figure(model_info, opts):
ax_width = ax_height/ratio # square axes
fig = plt.figure(figsize=aspect)
ax2d = fig.add_axes([0.5+ax_left, ax_bottom, ax_width, ax_height])
print("2D plot")
# print("2D plot")
plot_2d(model, opts, ax2d)
ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height])
print("1D plot")
# print("1D plot")
plot_1d(model, opts, ax1d)
#ax.set_aspect('square')
else:
Expand All @@ -187,14 +187,14 @@ def make_figure(model_info, opts):
aspect = (fig_width, fig_height)
fig = plt.figure(figsize=aspect)
ax1d = fig.add_axes([ax_left, ax_bottom, ax_width, ax_height])
print("1D plot")
# print("1D plot")
plot_1d(model, opts, ax1d)

if model_info.profile:
print("Profile inset")
# print("Profile inset")
plot_profile_inset(model_info, ax1d)

print("Save")
# print("Save")
# Save image in model/img
makedirs(joinpath(TARGET_DIR, 'img'), exist_ok=True)
path = joinpath(TARGET_DIR, 'img', figfile(model_info))
Expand Down Expand Up @@ -312,16 +312,17 @@ def make_figure_cached(model_info, opts):
into the cache.

Be sure to clear the cache from time to time. Even though the model
source
source hasn't changed, the supporting infrastructure may change the rendering
of the figure.
"""
import hashlib

# check if we are caching
cache_dir = os.environ.get('SASMODELS_BUILD_CACHE', None)
if cache_dir is None:
print("Nothing cashed, creating...")
# print("No figure cache directory, creating...")
make_figure(model_info, opts)
print("Made a figure")
# print("Made a figure")
return

# TODO: changing default parameters won't trigger a rebuild.
Expand Down Expand Up @@ -370,9 +371,10 @@ def process_model(py_file, force=False):

If *force* then generate the rst file regardless of time stamps.
"""
rst_file = joinpath(TARGET_DIR, basename(py_file).replace('.py', '.rst'))
model_name = basename(py_file).rsplit('.', 1)[0]
rst_file = joinpath(TARGET_DIR, f"{model_name}.rst")
if not (force or newer(py_file, rst_file) or newer(__file__, rst_file)):
#print("skipping", rst_file)
# print("skipping", rst_file)
return rst_file

# Load the model file
Expand All @@ -397,17 +399,15 @@ def process_model(py_file, force=False):
}

# Generate the RST file and the figure. Order doesn't matter.
print("generating rst", rst_file)
print("1: docs")
print(f"{model_name}: make docs in {rst_file}")
gen_docs(model_info, rst_file)
print("2: figure", end='')
print(f"{model_name}: make figure")
# TODO: Caching isn't used. Should remove it to simplify the code.
# TODO: If we don't remove it, then update the cache on forced rebuild.
if force:
print()
make_figure(model_info, PLOT_OPTS)
else:
print(" (cached)")
make_figure_cached(model_info, PLOT_OPTS)
print("Done process_model")

return rst_file

Expand All @@ -416,15 +416,15 @@ def run_sphinx(rst_files, output):
Use sphinx to build *rst_files*, storing the html in *output*.
"""

print("Building index...")
# print("Building index...")

conf_dir = dirname(realpath(__file__))
with open(joinpath(TARGET_DIR, 'index.rst'), 'w') as fid:
fid.write(".. toctree::\n\n")
for path in rst_files:
fid.write(" %s\n"%basename(path))

print("Running sphinx command...")
# print("Running sphinx command...")

command = [
sys.executable,
Expand Down Expand Up @@ -474,17 +474,16 @@ def main():
global TARGET_DIR
TARGET_DIR = os.path.expanduser(args.rst)
if not os.path.exists(TARGET_DIR) and not args.sphinx:
print("build directory %r does not exist"%TARGET_DIR)
print("Build directory %r does not exist"%TARGET_DIR)
sys.exit(1)
makedirs(TARGET_DIR, exist_ok=True)

print("** 'Normal' processing **")
# print("** Generating all .rst files and figures **")
rst_files = [process_model(py_file, args.force)
for py_file in args.files]
print("normal .rst file processing complete")

if args.sphinx:
print("running sphinx")
# print("** running sphinx **")
run_sphinx(rst_files, args.build)


Expand Down
Loading