|
52 | 52 | # |
53 | 53 | # The full version, including alpha/beta/rc tags. |
54 | 54 |
|
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 |
72 | 92 | python_versions_list = [f'3.{i}' for i in python_versions_minor] |
73 | 93 | python_versions = ', '.join(python_versions_list[:-1]) + f' and {python_versions_list[-1]}' |
74 | 94 | # Make `|python_versions|` available in .rst files. |
|
0 commit comments