Skip to content

Commit 3f4a9b4

Browse files
docs/conf.py: change how we look for version numbers in setup.py and scripts/test.py.
Instead of importing, we grep the .py code directly. This avoids problems with required packages not being installed.
1 parent 368054a commit 3f4a9b4

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

docs/conf.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,43 @@
5252
#
5353
# The full version, including alpha/beta/rc tags.
5454

55-
# PyMuPDF version is set in setup.py, so we import it here.
56-
sys.path.insert(0, os.path.abspath(f'{__file__}/../..'))
57-
try:
58-
import setup
59-
finally:
60-
del sys.path[0]
61-
version = setup.version_p
62-
del setup # Necessary otherwise sphinx seems to do `setup()`.
63-
64-
# Supported Python versions are set in scripts.test.py.
65-
sys.path.insert(0, os.path.abspath(f'{__file__}/../../scripts'))
66-
try:
67-
import test
68-
finally:
69-
del sys.path[0]
70-
python_versions_minor = test.python_versions_minor
71-
del test
55+
if 1:
56+
# Importing setup.py requires pipcl etc so instead of importing, we grep
57+
# for the version info in setup.py and scripts/test.py.
58+
setup_py_path = os.path.normpath(f'{__file__}/../../setup.py')
59+
with open(setup_py_path) as f:
60+
setup_py_text = f.read()
61+
regex = "\nversion_p = '([0-9.]+)'\n"
62+
m = re.search(regex, setup_py_text)
63+
assert m, f'Cannot find version number in {setup_py_path!r} with {regex=}.'
64+
version = m.group(1)
65+
66+
test_py_path = os.path.normpath(f'{__file__}/../../scripts/test.py')
67+
with open(test_py_path) as f:
68+
test_py_text = f.read()
69+
regex = '\npython_versions_minor = (.+)\n'
70+
m = re.search(regex, test_py_text)
71+
assert m, f'Cannot find python_versions_minor in {test_py_path!r} with {regex=}.'
72+
python_versions_minor = m.group(1)
73+
python_versions_minor = eval(m.group(1))
74+
else:
75+
# PyMuPDF version is set in setup.py, so we import it here.
76+
sys.path.insert(0, os.path.abspath(f'{__file__}/../..'))
77+
try:
78+
import setup
79+
finally:
80+
del sys.path[0]
81+
version = setup.version_p
82+
del setup # Necessary otherwise sphinx seems to do `setup()`.
83+
84+
# Supported Python versions are set in scripts.test.py.
85+
sys.path.insert(0, os.path.abspath(f'{__file__}/../../scripts'))
86+
try:
87+
import test
88+
finally:
89+
del sys.path[0]
90+
python_versions_minor = test.python_versions_minor
91+
del test
7292
python_versions_list = [f'3.{i}' for i in python_versions_minor]
7393
python_versions = ', '.join(python_versions_list[:-1]) + f' and {python_versions_list[-1]}'
7494
# Make `|python_versions|` available in .rst files.

0 commit comments

Comments
 (0)