Mercurial > hgrepos > Python2 > PyMuPDF
comparison src/__init__.py @ 23:3b13504f9d89
Use the official packaging.version.Version to parse version strings.
While there revert the previons change to _int_rc(): it is not needed
now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 19 Sep 2025 12:40:07 +0200 |
| parents | d77477b4e151 |
| children | 71bcc18e306f |
comparison
equal
deleted
inserted
replaced
| 22:d77477b4e151 | 23:3b13504f9d89 |
|---|---|
| 15 import io | 15 import io |
| 16 import math | 16 import math |
| 17 import os | 17 import os |
| 18 import pathlib | 18 import pathlib |
| 19 import glob | 19 import glob |
| 20 import packaging.version | |
| 20 import re | 21 import re |
| 21 import string | 22 import string |
| 22 import sys | 23 import sys |
| 23 import tarfile | 24 import tarfile |
| 24 import time | 25 import time |
| 364 mupdf.internal_check_ndebug() | 365 mupdf.internal_check_ndebug() |
| 365 mupdf.reinit_singlethreaded() | 366 mupdf.reinit_singlethreaded() |
| 366 | 367 |
| 367 def _int_rc(text): | 368 def _int_rc(text): |
| 368 ''' | 369 ''' |
| 369 Converts string to int, ignoring trailing 'rc...' and a trailing | 370 Converts string to int, ignoring trailing 'rc...'. |
| 370 local version. | 371 ''' |
| 371 ''' | |
| 372 rc = text.find('+') | |
| 373 if rc >= 0: | |
| 374 text = text[:rc] | |
| 375 rc = text.find('rc') | 372 rc = text.find('rc') |
| 376 if rc >= 0: | 373 if rc >= 0: |
| 377 text = text[:rc] | 374 text = text[:rc] |
| 378 return int(text) | 375 return int(text) |
| 379 | 376 |
| 395 # Removed in PyMuPDF-1.26.1. | 392 # Removed in PyMuPDF-1.26.1. |
| 396 pymupdf_date = None | 393 pymupdf_date = None |
| 397 | 394 |
| 398 # Versions as tuples; useful when comparing versions. | 395 # Versions as tuples; useful when comparing versions. |
| 399 # | 396 # |
| 400 pymupdf_version_tuple = tuple( [_int_rc(i) for i in pymupdf_version.split('.')]) | 397 pymupdf_version_tuple = packaging.version.Version(pymupdf_version).release |
| 401 mupdf_version_tuple = tuple( [_int_rc(i) for i in mupdf_version.split('.')]) | 398 mupdf_version_tuple = packaging.version.Version(mupdf_version).release |
| 402 | 399 |
| 403 assert mupdf_version_tuple == (mupdf.FZ_VERSION_MAJOR, mupdf.FZ_VERSION_MINOR, mupdf.FZ_VERSION_PATCH), \ | 400 assert mupdf_version_tuple == (mupdf.FZ_VERSION_MAJOR, mupdf.FZ_VERSION_MINOR, mupdf.FZ_VERSION_PATCH), \ |
| 404 f'Inconsistent MuPDF version numbers: {mupdf_version_tuple=} != {(mupdf.FZ_VERSION_MAJOR, mupdf.FZ_VERSION_MINOR, mupdf.FZ_VERSION_PATCH)=}' | 401 f'Inconsistent MuPDF version numbers: {mupdf_version_tuple=} != {(mupdf.FZ_VERSION_MAJOR, mupdf.FZ_VERSION_MINOR, mupdf.FZ_VERSION_PATCH)=}' |
| 405 | 402 |
| 406 # Legacy version information. | 403 # Legacy version information. |
