From 334c37d26e3c2b1386c19e06347814ff6f3f7b80 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Mon, 11 Aug 2025 16:11:08 +0200 Subject: [PATCH] docs: fix conf after _build.py changes `docs/conf.py` tries to read version info from `src/__init__py` using an expression match. This breaks after e439a0fa ("setup.py src/ tests/: auto-generate pymupdf.pymupdf_version and add git info.", 2025-08-08) makes `src/__init__py` import that info from `_build.py`, which is generated during build in the build directory. Make the build process generate a copy of `_build.py` in `docs` and let `docs/conf.py` import version info from there. Alternative fixes: - pointing `docs/conf.py` at the build directory; this may no longer exist after a wheel build, though - reading from the generated wheel; oh well ;-) - installing the build and importing `_build.py` from there; this would mean intermingling build and install steps --- .gitignore | 3 ++- docs/conf.py | 12 ++---------- setup.py | 2 ++ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 23e954719..aed030c40 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ *.swp build/ demo/README.rst -docs/build \ No newline at end of file +docs/build +docs/_build.py diff --git a/docs/conf.py b/docs/conf.py index 2cd93940b..d6b49115f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -49,16 +49,8 @@ # built documents. # # The full version, including alpha/beta/rc tags. -_path = os.path.abspath(f'{__file__}/../../src/__init__.py') -with open(_path) as f: - for line in f: - match = re.search('pymupdf_version = "([0-9][.][0-9]+[.][0-9]+(rc[0-9]+)?)"', line) - if match: - release = match.group(1) - print(f'{__file__}: setting version from {_path}: {release}') - break - else: - raise Exception(f'Failed to find `VersionBind = ...` in {_path}') +from _build import pymupdf_version as release # noqa F401 +print(f'{__file__}: setting version from _build.py: {release}') # The short X.Y version version = release diff --git a/setup.py b/setup.py index 3072a795c..69d62f3c6 100755 --- a/setup.py +++ b/setup.py @@ -743,6 +743,8 @@ def add(flavour, from_, to_): text += f'pymupdf_git_diff = {diff!r}\n' text += f'pymupdf_git_branch = {branch!r}\n' add('p', text.encode(), f'{to_dir}/_build.py') + with open('docs/_build.py', 'w') as f: + f.write(text) # Add single README file. if 'p' in PYMUPDF_SETUP_FLAVOUR: