Skip to content

Commit e439a0f

Browse files
setup.py src/ tests/: auto-generate pymupdf.pymupdf_version and add git info.
setup.py:build(): add extra information to the generated _build.py file (which used to contain just mupdf_location): * PyMuPDF package version. * Information about git sha, branch and diff (if any). src/__init__.py: make _build.py's contents available as: * mupdf_location * pymupdf_git_branch * pymupdf_git_diff * pymupdf_git_sha * pymupdf_version
1 parent 13c92ad commit e439a0f

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,17 @@ def add(flavour, from_, to_):
731731
add('d', f'{header_abs}', f'{to_dir_d}/include/{header_rel}')
732732

733733
# Add a .py file containing location of MuPDF.
734-
text = f"mupdf_location='{mupdf_location}'\n"
734+
try:
735+
sha, comment, diff, branch = git_info(g_root)
736+
except Exception as e:
737+
log(f'Failed to get git information: {e}')
738+
sha, comment, diff, branch = (None, None, None, None)
739+
text = ''
740+
text += f'mupdf_location = {mupdf_location!r}\n'
741+
text += f'pymupdf_version = {version_p!r}\n'
742+
text += f'pymupdf_git_sha = {sha!r}\n'
743+
text += f'pymupdf_git_diff = {diff!r}\n'
744+
text += f'pymupdf_git_branch = {branch!r}\n'
735745
add('p', text.encode(), f'{to_dir}/_build.py')
736746

737747
# Add single README file.

src/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,18 @@ def _int_rc(text):
375375

376376
# Basic version information.
377377
#
378-
pymupdf_version = "1.26.3"
378+
# (We use `noqa F401` to avoid flake8 errors such as `F401
379+
# '._build.mupdf_location' imported but unused`.
380+
#
381+
from ._build import mupdf_location # noqa F401
382+
from ._build import pymupdf_git_branch # noqa F401
383+
from ._build import pymupdf_git_diff # noqa F401
384+
from ._build import pymupdf_git_sha # noqa F401
385+
from ._build import pymupdf_version # noqa F401
386+
379387
mupdf_version = mupdf.FZ_VERSION
388+
389+
# Removed in PyMuPDF-1.26.1.
380390
pymupdf_date = None
381391

382392
# Versions as tuples; useful when comparing versions.

tests/test_general.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,3 +1946,17 @@ def test_4496():
19461946
path = os.path.normpath(f'{__file__}/../../tests/resources/test_4496.hwpx')
19471947
with pymupdf.open(path) as document:
19481948
print(document.page_count)
1949+
1950+
1951+
def test_gitinfo():
1952+
# This doesn't really test very much, but can be useful to see the current
1953+
# values.
1954+
print('')
1955+
print(f'test_4496():')
1956+
print(f'{pymupdf.mupdf_location=}')
1957+
print(f'{pymupdf.mupdf_version=}')
1958+
print(f'{pymupdf.pymupdf_git_branch=}')
1959+
print(f'{pymupdf.pymupdf_git_sha=}')
1960+
print(f'{pymupdf.pymupdf_version=}')
1961+
print(f'pymupdf.pymupdf_git_diff:\n{textwrap.indent(pymupdf.pymupdf_git_diff, " ")}')
1962+

0 commit comments

Comments
 (0)