|
4 | 4 | import pkg_resources |
5 | 5 | import sys |
6 | 6 | import os |
7 | | -from os import path |
| 7 | +import os.path as osp |
| 8 | +from pathlib import Path |
8 | 9 |
|
9 | 10 |
|
10 | 11 | DEBUG = True |
|
27 | 28 | if sys.platform.startswith("win"): |
28 | 29 | DATA_DIR = os.environ["APPDATA"].replace(os.sep, "/") + "/Python/Mathics/" |
29 | 30 | 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/") |
33 | 32 |
|
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. Current this is in Python |
| 34 | +# Pickle form, but storing this in JSON if possible would be preferable and faster |
37 | 35 |
|
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") |
40 | 39 |
|
| 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") |
41 | 46 |
|
42 | 47 | # Set this True if you prefer 12 hour time to be the default |
43 | 48 | TIME_12HOUR = False |
44 | 49 |
|
45 | 50 | # Leave this True unless you have specific reason for not permitting |
46 | | -# users to access local files |
| 51 | +# users to access local files. |
47 | 52 | ENABLE_FILES_MODULE = True |
48 | 53 |
|
49 | 54 | # Rocky: this is probably a hack. LoadModule[] needs to handle |
50 | 55 | # whatever it is that setting this thing did. |
51 | 56 | default_pymathics_modules = [] |
52 | 57 |
|
53 | 58 | 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 |
0 commit comments