Skip to content

Commit 69e0853

Browse files
authored
Merge pull request #1509 from mathics/dup-settings
Revise doc data for TeX
2 parents 809f8a7 + 40bb133 commit 69e0853

File tree

9 files changed

+70
-35
lines changed

9 files changed

+70
-35
lines changed

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ include Makefile
77
include requirements-dev.txt
88
include requirements-full.txt
99
recursive-include mathics *.py
10+
recursive-include mathics/data *
1011
recursive-include test *.py *.m

admin-tools/make-dist.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ if ! source ./pyenv-versions ; then
1414
exit $?
1515
fi
1616

17-
1817
cd ..
1918
source mathics/version.py
19+
cp -v ${HOME}/.local/var/mathics/doc_tex_data.pcl mathics/data/
20+
2021
echo $__version__
2122

2223
for pyversion in $PYVERSIONS; do
2324
if ! pyenv local $pyversion ; then
2425
exit $?
2526
fi
26-
# pip bdist_egg create too-general wheels. So
27-
# we narrow that by moving the generated wheel.
28-
29-
# Pick out first two number of version, e.g. 3.7.9 -> 37
30-
first_two=$(echo $pyversion | cut -d'.' -f 1-2 | sed -e 's/\.//')
3127
rm -fr build
3228
python setup.py bdist_egg
3329
python setup.py bdist_wheel
34-
python setup.py bdist_wheel --universal
35-
mv -v dist/${PACKAGE}-$VERSION-{py2.py3,py$first_two}-none-any.whl
3630
done
3731

3832
python ./setup.py sdist

mathics/doc/common_doc.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
import importlib
30+
import os.path as osp
3031
import pkgutil
3132
import re
3233

@@ -719,7 +720,7 @@ def __init__(self):
719720
self.parts = []
720721
self.parts_by_slug = {}
721722
self.pymathics_doc_loaded = False
722-
self.doc_data_file = settings.DOC_DATA_PATH
723+
self.doc_data_file = settings.get_doc_tex_data_path(should_be_readable=True)
723724
self.title = "Overview"
724725
files = listdir(self.doc_dir)
725726
files.sort()
@@ -730,7 +731,7 @@ def __init__(self):
730731
if part_title.endswith(".mdoc"):
731732
part_title = part_title[: -len(".mdoc")]
732733
part = DocPart(self, part_title)
733-
text = open(self.doc_dir + file, "rb").read().decode("utf8")
734+
text = open(osp.join(self.doc_dir, file), "rb").read().decode("utf8")
734735
text = filter_comments(text)
735736
chapters = CHAPTER_RE.findall(text)
736737
for title, text in chapters:

mathics/doc/tex/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ LATEXMK ?= latexmk
66
BASH ?= /bin/bash
77
#-quiet
88

9-
DOC_DATA_PCL ?= $(HOME)/.local/var/mathics/doc_data.pcl
9+
DOC_TEX_DATA_PCL ?= $(HOME)/.local/var/mathics/doc_tex_data.pcl
1010

1111
#: Default target: Make everything
1212
all doc texdoc: mathics.pdf
1313

14-
doc-data $(DOC_DATA_PCL):
14+
#: Create internal Document Data from .mdoc and Python builtin module docstrings
15+
doc-data $(DOC_TEX_DATA_PCL):
1516
(cd ../.. && $(PYTHON) docpipeline.py --output --keep-going)
1617

1718
#: Build mathics PDF
18-
mathics.pdf: mathics.tex documentation.tex logo-text-nodrop.pdf logo-heptatom.pdf $(DOC_DATA_PCL)
19+
mathics.pdf: mathics.tex documentation.tex logo-text-nodrop.pdf logo-heptatom.pdf $(DOC_TEX_DATA_PCL)
1920
$(LATEXMK) --verbose -f -pdf -pdflatex="$(XETEX) -halt-on-error" mathics
2021

2122
#: Build test PDF
@@ -28,7 +29,7 @@ logo-heptatom.pdf logo-text-nodrop.pdf:
2829
(cd .. && $(BASH) ./images.sh)
2930

3031
#: The build of the documentation which is derived from docstrings in the Python code
31-
documentation.tex: $(DOC_DATA_PCL)
32+
documentation.tex: $(DOC_TEX_DATA_PCL)
3233
$(PYTHON) ./doc2latex.py
3334

3435
#: Same as mathics.pdf
@@ -40,6 +41,6 @@ clean:
4041
rm -f test-mathics.aux test-mathics.idx test-mathics.log test-mathics.mtc test-mathics.mtc* test-mathics.out test-mathics.toc || true
4142
rm -f mathics.fdb_latexmk mathics.ilg mathics.ind mathics.maf mathics.pre || true
4243
rm -f mathics_*.* || true
43-
rm -f mathics-*.* documentation.tex doc_data.pcl || true
44-
rm -f mathics.pdf mathics.dvi data_tex_data.pcl test-mathics.pdf test-mathics.dvi || true
44+
rm -f mathics-*.* documentation.tex $(DOC_TEX_DATA_PCL) || true
45+
rm -f mathics.pdf mathics.dvi test-mathics.pdf test-mathics.dvi || true
4546
rm -f mathics-test.pdf mathics-test.dvi || true

mathics/doc/tex/doc2latex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def extract_doc_from_source(quiet=False):
2828
if not quiet:
2929
print(f"Extracting internal doc data for {version_string}")
3030
try:
31-
return load_doc_data(settings.DOC_DATA_PATH)
31+
return load_doc_data(settings.get_doc_tex_data_path(should_be_readable=True))
3232
except KeyboardInterrupt:
3333
print("\nAborted.\n")
3434
return

mathics/docpipeline.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111

1212
import os
13+
import os.path as osp
1314
import pickle
1415
import re
1516
import sys
@@ -302,8 +303,8 @@ def open_ensure_dir(f, *args, **kwargs):
302303
try:
303304
return open(f, *args, **kwargs)
304305
except (IOError, OSError):
305-
d = os.path.dirname(f)
306-
if d and not os.path.exists(d):
306+
d = osp.dirname(f)
307+
if d and not osp.exists(d):
307308
os.makedirs(d)
308309
return open(f, *args, **kwargs)
309310

@@ -323,7 +324,11 @@ def test_all(
323324

324325
if generate_output:
325326
if texdatafolder is None:
326-
texdatafolder = settings.DOC_DATA_PATH
327+
texdatafolder = osp.dirname(
328+
settings.get_doc_tex_data_path(
329+
should_be_readable=False, create_parent=True
330+
)
331+
)
327332
try:
328333
index = 0
329334
total = failed = skipped = 0
@@ -385,14 +390,18 @@ def test_all(
385390

386391

387392
def load_doc_data():
388-
print(f"Loading internal document data from {settings.DOC_DATA_PATH}")
389-
with open_ensure_dir(settings.DOC_DATA_PATH, "rb") as doc_data_file:
393+
doc_tex_data_path = settings.get_doc_tex_data_path(should_be_readable=True)
394+
print(f"Loading internal document data from {doc_tex_data_path}")
395+
with open_ensure_dir(doc_tex_data_path, "rb") as doc_data_file:
390396
return pickle.load(doc_data_file)
391397

392398

393399
def save_doc_data(output_data):
394-
print(f"Writing internal document data to {settings.DOC_DATA_PATH}")
395-
with open_ensure_dir(settings.DOC_DATA_PATH, "wb") as output_file:
400+
doc_tex_data_path = settings.get_doc_tex_data_path(
401+
should_be_readable=False, create_parent=True
402+
)
403+
print(f"Writing internal document data to {doc_tex_data_path}")
404+
with open(settings.DOC_USER_TEX_DATA_PATH, "wb") as output_file:
396405
pickle.dump(output_data, output_file, 4)
397406

398407

mathics/settings.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import pkg_resources
55
import sys
66
import os
7-
from os import path
7+
import os.path as osp
8+
from pathlib import Path
89

910

1011
DEBUG = True
@@ -27,27 +28,53 @@
2728
if sys.platform.startswith("win"):
2829
DATA_DIR = os.environ["APPDATA"].replace(os.sep, "/") + "/Python/Mathics/"
2930
else:
30-
DATA_DIR = path.expanduser("~/.local/var/mathics/")
31-
# if not path.exists(DATA_DIR):
32-
# os.makedirs(DATA_DIR)
31+
DATA_DIR = osp.expanduser("~/.local/var/mathics/")
3332

34-
# Location of internal document data.
35-
# NOTE: Storing this in JSON if possible would be preferable and faster
36-
DOC_DATA_PATH = os.path.join(DATA_DIR, "doc_data.pcl")
33+
# Location of internal document data. Currently this is in Python
34+
# Pickle form, but storing this in JSON if possible would be preferable and faster
3735

38-
DOC_DIR = os.path.join(ROOT_DIR, "doc/documentation/")
39-
DOC_LATEX_FILE = os.path.join(ROOT_DIR, "doc/tex/documentation.tex")
36+
# We need two versions, one in the user space which is updated with
37+
# local packages installed and is user writable.
38+
DOC_USER_TEX_DATA_PATH = osp.join(DATA_DIR, "doc_tex_data.pcl")
4039

40+
# We need another version as a fallback, and that is distributed with the
41+
# package. It is note user writable and not in the user space.
42+
DOC_SYSTEM_TEX_DATA_PATH = osp.join(ROOT_DIR, "data", "doc_tex_data.pcl")
43+
44+
DOC_DIR = osp.join(ROOT_DIR, "doc", "documentation")
45+
DOC_LATEX_FILE = osp.join(ROOT_DIR, "doc", "tex", "documentation.tex")
4146

4247
# Set this True if you prefer 12 hour time to be the default
4348
TIME_12HOUR = False
4449

4550
# Leave this True unless you have specific reason for not permitting
46-
# users to access local files
51+
# users to access local files.
4752
ENABLE_FILES_MODULE = True
4853

4954
# Rocky: this is probably a hack. LoadModule[] needs to handle
5055
# whatever it is that setting this thing did.
5156
default_pymathics_modules = []
5257

5358
SYSTEM_CHARACTER_ENCODING = "UTF-8" if sys.getdefaultencoding() == "utf-8" else "ASCII"
59+
60+
61+
def get_doc_tex_data_path(should_be_readable=False, create_parent=False) -> str:
62+
"""Returns a string path where we can find Python Pickle data for LaTeX
63+
processing.
64+
65+
If `should_be_readable` is True, the we will check to see whether this file is
66+
readable (which also means it exists). If not, we'll return the `DOC_SYSTEM_DATA_PATH`.
67+
"""
68+
doc_user_tex_data_path = Path(DOC_USER_TEX_DATA_PATH)
69+
base_config_dir = doc_user_tex_data_path.parent
70+
if not base_config_dir.is_dir() and create_parent:
71+
Path("base_config_dir").mkdir(parents=True, exist_ok=True)
72+
73+
if should_be_readable:
74+
return (
75+
DOC_USER_TEX_DATA_PATH
76+
if doc_user_tex_data_path.is_file
77+
else DOC_SYSTEM_TEX_DATA_PATH
78+
)
79+
else:
80+
return DOC_USER_TEX_DATA_PATH

mathics/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
# well as importing into Python. That's why there is no
66
# space around "=" below.
77
# fmt: off
8-
__version__="3.1.1.dev0" # noqa
8+
__version__="4.0.0.dev0" # noqa

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,10 @@ def subdirs(root, file="*.*", depth=10):
158158
package_data={
159159
"mathics": [
160160
"data/*.csv",
161+
"data/*.json",
161162
"data/*.yml",
162163
"data/*.yaml",
164+
"data/*.pcl",
163165
"data/ExampleData/*",
164166
"doc/xml/data",
165167
"doc/tex/data",

0 commit comments

Comments
 (0)