diff --git a/docs/devel/changelog_staging.md b/docs/devel/changelog_staging.md index d03de8462..1a919c643 100644 --- a/docs/devel/changelog_staging.md +++ b/docs/devel/changelog_staging.md @@ -7,7 +7,7 @@ - `PdfTextPage.get_text_range()`: Correct the allocation in case of excluded/inserted chars, modify scope to prevent pdfium from reading beyond `range(index, index+count)` (which otherwise it does with leading excluded chars). Update docs to note the two different representations. Thanks to Nikita Rybak for the discovery ({issue}`261`). - ctypesgen fork: replaced the old library loader with a new, lean version - Setup changes (partly ported from the devel branch) - Merged `$PDFIUM_VERSION` and `$PDFIUM_USE_V8` into the existing `$PDFIUM_PLATFORM` specifier (see Readme for updated description). The relatively minor setup API breakage was considered tolerable; the core library API is not affected. + * Merged `$PDFIUM_VERSION` and `$PDFIUM_USE_V8` into the existing `$PDFIUM_PLATFORM` specifier (see Readme for updated description). The relatively minor setup API breakage was considered tolerable; the core library API is not affected. * Removed the `build` package from pyproject buildsystem requires, where it was unnecessary. Thanks to Anaconda Team. * Split in two separate modules: pypdfium2 for helpers (pure-python), pypdfium2_raw for the core bindings (data files). - Switched PyPI upload to "trusted publishing" (OIDC), which is considered safer. Further, the core maintainers have set up 2FA as requested by PyPI. diff --git a/setupsrc/pypdfium2_setup/build_pdfium.py b/setupsrc/pypdfium2_setup/build_pdfium.py index 2bf7a09e3..bce87b543 100755 --- a/setupsrc/pypdfium2_setup/build_pdfium.py +++ b/setupsrc/pypdfium2_setup/build_pdfium.py @@ -20,7 +20,7 @@ DepotToolsDir = SB_Dir / "depot_tools" PDFiumDir = SB_Dir / "pdfium" PDFiumBuildDir = PDFiumDir / "out" / "Default" -OutputDir = DataTree / PlatformNames.sourcebuild +OutputDir = DataTree / PlatNames.sourcebuild PatchesMain = [ (PatchDir/"shared_library.patch", PDFiumDir), diff --git a/setupsrc/pypdfium2_setup/emplace.py b/setupsrc/pypdfium2_setup/emplace.py index 277ef75e8..f8d25e081 100644 --- a/setupsrc/pypdfium2_setup/emplace.py +++ b/setupsrc/pypdfium2_setup/emplace.py @@ -19,9 +19,9 @@ def get_pdfium(plat_spec, force_rebuild=False): - if plat_spec == PlatformNames.sourcebuild: + if plat_spec == PlatNames.sourcebuild: # for now, require that callers ran build_pdfium.py beforehand so they are in charge of the build config - don't trigger sourcebuild in here if platform files don't exist - return PlatformNames.sourcebuild + return PlatNames.sourcebuild req_ver = None use_v8 = False @@ -35,8 +35,8 @@ def get_pdfium(plat_spec, force_rebuild=False): pl_name = Host.platform if pl_name is None: raise RuntimeError(f"No pre-built binaries available for system {Host._system_name} (libc info {Host._libc_info}) on machine {Host._machine_name}. You may place custom binaries & bindings in data/sourcebuild and install with `{PlatSpec_EnvVar}=sourcebuild`.") - elif hasattr(PlatformNames, plat_spec): - pl_name = getattr(PlatformNames, plat_spec) + elif hasattr(PlatNames, plat_spec): + pl_name = getattr(PlatNames, plat_spec) else: raise ValueError(f"Invalid binary spec '{plat_spec}'") diff --git a/setupsrc/pypdfium2_setup/packaging_base.py b/setupsrc/pypdfium2_setup/packaging_base.py index 08fdf406c..61d2b9f70 100644 --- a/setupsrc/pypdfium2_setup/packaging_base.py +++ b/setupsrc/pypdfium2_setup/packaging_base.py @@ -56,47 +56,47 @@ ReleaseInfoURL = ReleaseURL.replace("github.com/", "api.github.com/repos/").replace("download/", "tags/") -class SystemNames: +class SysNames: linux = "linux" darwin = "darwin" windows = "windows" -class PlatformNames: +class PlatNames: # - Attribute names and values are expected to match # - Platform names are expected to start with the corresponding system name - linux_x64 = SystemNames.linux + "_x64" - linux_x86 = SystemNames.linux + "_x86" - linux_arm64 = SystemNames.linux + "_arm64" - linux_arm32 = SystemNames.linux + "_arm32" - linux_musl_x64 = SystemNames.linux + "_musl_x64" - linux_musl_x86 = SystemNames.linux + "_musl_x86" - darwin_x64 = SystemNames.darwin + "_x64" - darwin_arm64 = SystemNames.darwin + "_arm64" - windows_x64 = SystemNames.windows + "_x64" - windows_x86 = SystemNames.windows + "_x86" - windows_arm64 = SystemNames.windows + "_arm64" + linux_x64 = SysNames.linux + "_x64" + linux_x86 = SysNames.linux + "_x86" + linux_arm64 = SysNames.linux + "_arm64" + linux_arm32 = SysNames.linux + "_arm32" + linux_musl_x64 = SysNames.linux + "_musl_x64" + linux_musl_x86 = SysNames.linux + "_musl_x86" + darwin_x64 = SysNames.darwin + "_x64" + darwin_arm64 = SysNames.darwin + "_arm64" + windows_x64 = SysNames.windows + "_x64" + windows_x86 = SysNames.windows + "_x86" + windows_arm64 = SysNames.windows + "_arm64" sourcebuild = "sourcebuild" ReleaseNames = { - PlatformNames.darwin_x64 : "mac-x64", - PlatformNames.darwin_arm64 : "mac-arm64", - PlatformNames.linux_x64 : "linux-x64", - PlatformNames.linux_x86 : "linux-x86", - PlatformNames.linux_arm64 : "linux-arm64", - PlatformNames.linux_arm32 : "linux-arm", - PlatformNames.linux_musl_x64 : "linux-musl-x64", - PlatformNames.linux_musl_x86 : "linux-musl-x86", - PlatformNames.windows_x64 : "win-x64", - PlatformNames.windows_x86 : "win-x86", - PlatformNames.windows_arm64 : "win-arm64", + PlatNames.darwin_x64 : "mac-x64", + PlatNames.darwin_arm64 : "mac-arm64", + PlatNames.linux_x64 : "linux-x64", + PlatNames.linux_x86 : "linux-x86", + PlatNames.linux_arm64 : "linux-arm64", + PlatNames.linux_arm32 : "linux-arm", + PlatNames.linux_musl_x64 : "linux-musl-x64", + PlatNames.linux_musl_x86 : "linux-musl-x86", + PlatNames.windows_x64 : "win-x64", + PlatNames.windows_x86 : "win-x86", + PlatNames.windows_arm64 : "win-arm64", } LibnameForSystem = { - SystemNames.linux: "libpdfium.so", - SystemNames.darwin: "libpdfium.dylib", - SystemNames.windows: "pdfium.dll", + SysNames.linux: "libpdfium.so", + SysNames.darwin: "libpdfium.dylib", + SysNames.windows: "pdfium.dll", } BinaryPlatforms = list(ReleaseNames.keys()) @@ -104,7 +104,7 @@ class PlatformNames: MainLibnames = list(LibnameForSystem.values()) def plat_to_system(pl_name): - if pl_name == PlatformNames.sourcebuild: + if pl_name == PlatNames.sourcebuild: # FIXME If doing a sourcebuild on an unknown host system, this returns None, which will cause binary detection code to fail (we need to know the platform-specific binary name) - handle this downsteam with fallback value? return Host.system result = [s for s in BinarySystems if pl_name.startswith(s)] @@ -147,23 +147,23 @@ def _get_platform(self): # some machine names are merely "qualified guesses", mistakes can't be fully excluded for platforms we don't have access to if self._is_plat("darwin", "x86_64"): - return PlatformNames.darwin_x64 + return PlatNames.darwin_x64 elif self._is_plat("darwin", "arm64"): - return PlatformNames.darwin_arm64 + return PlatNames.darwin_arm64 elif self._is_plat("linux", "x86_64"): - return PlatformNames.linux_x64 if self._is_glibc else PlatformNames.linux_musl_x64 + return PlatNames.linux_x64 if self._is_glibc else PlatNames.linux_musl_x64 elif self._is_plat("linux", "i686"): - return PlatformNames.linux_x86 if self._is_glibc else PlatformNames.linux_musl_x86 + return PlatNames.linux_x86 if self._is_glibc else PlatNames.linux_musl_x86 elif self._is_plat("linux", "armv7l"): - return PlatformNames.linux_arm32 + return PlatNames.linux_arm32 elif self._is_plat("linux", "aarch64"): - return PlatformNames.linux_arm64 + return PlatNames.linux_arm64 elif self._is_plat("windows", "amd64"): - return PlatformNames.windows_x64 + return PlatNames.windows_x64 elif self._is_plat("windows", "arm64"): - return PlatformNames.windows_arm64 + return PlatNames.windows_arm64 elif self._is_plat("windows", "x86"): - return PlatformNames.windows_x86 + return PlatNames.windows_x86 else: return None @@ -172,32 +172,32 @@ def _get_platform(self): def get_wheel_tag(pl_name): - if pl_name == PlatformNames.darwin_x64: + if pl_name == PlatNames.darwin_x64: # pdfium-binaries/steps/05-configure.sh defines `mac_deployment_target = "10.13.0"` return "macosx_10_13_x86_64" - elif pl_name == PlatformNames.darwin_arm64: + elif pl_name == PlatNames.darwin_arm64: # macOS 11 is the first version available on arm64 return "macosx_11_0_arm64" # linux glibc requirement: see BUG(203) for discussion - elif pl_name == PlatformNames.linux_x64: + elif pl_name == PlatNames.linux_x64: return "manylinux_2_17_x86_64" - elif pl_name == PlatformNames.linux_x86: + elif pl_name == PlatNames.linux_x86: return "manylinux_2_17_i686" - elif pl_name == PlatformNames.linux_arm64: + elif pl_name == PlatNames.linux_arm64: return "manylinux_2_17_aarch64" - elif pl_name == PlatformNames.linux_arm32: + elif pl_name == PlatNames.linux_arm32: return "manylinux_2_17_armv7l" - elif pl_name == PlatformNames.linux_musl_x64: + elif pl_name == PlatNames.linux_musl_x64: return "musllinux_1_1_x86_64" - elif pl_name == PlatformNames.linux_musl_x86: + elif pl_name == PlatNames.linux_musl_x86: return "musllinux_1_1_i686" - elif pl_name == PlatformNames.windows_x64: + elif pl_name == PlatNames.windows_x64: return "win_amd64" - elif pl_name == PlatformNames.windows_arm64: + elif pl_name == PlatNames.windows_arm64: return "win_arm64" - elif pl_name == PlatformNames.windows_x86: + elif pl_name == PlatNames.windows_x86: return "win32" - elif pl_name == PlatformNames.sourcebuild: + elif pl_name == PlatNames.sourcebuild: tag = sysconfig.get_platform() for char in ("-", "."): tag = tag.replace(char, "_") @@ -317,7 +317,7 @@ def call_ctypesgen(target_dir, include_dir, pl_name, use_v8xfa=False, guard_symb args += ["--no-symbol-guards"] if use_v8xfa: args += ["-D", "PDF_ENABLE_V8", "PDF_ENABLE_XFA"] - if pl_name.startswith(SystemNames.windows) and Host.system == SystemNames.windows: + if pl_name.startswith(SysNames.windows) and Host.system == SysNames.windows: args += ["-D", "_WIN32"] args += ["--headers"] + [h.name for h in sorted(include_dir.glob("*.h"))] + ["-o", bindings] @@ -365,7 +365,7 @@ def emplace_platfiles(pl_name): ver_changes = dict() ver_changes["V_LIBPDFIUM"], ver_changes["V_LIBPDFIUM_FULL"] = read_version_file(ver_file) - ver_changes["V_BUILDNAME"] = "source" if pl_name == PlatformNames.sourcebuild else "pdfium-binaries" + ver_changes["V_BUILDNAME"] = "source" if pl_name == PlatNames.sourcebuild else "pdfium-binaries" ver_changes["V_PDFIUM_IS_V8"] = (pl_dir / V8StatusFileName).exists() set_versions(ver_changes) diff --git a/setupsrc/pypdfium2_setup/update_pdfium.py b/setupsrc/pypdfium2_setup/update_pdfium.py index 7ec6ae747..826f2f76c 100755 --- a/setupsrc/pypdfium2_setup/update_pdfium.py +++ b/setupsrc/pypdfium2_setup/update_pdfium.py @@ -83,7 +83,7 @@ def generate_bindings(archives, version, full_version, use_v8, ctypesgen_kws): bin_dir = build_dir / "lib" system = plat_to_system(pl_name) - if system == SystemNames.windows: + if system == SysNames.windows: bin_dir = build_dir / "bin" libname = LibnameForSystem[system] diff --git a/tests_old/test_setup.py b/tests_old/test_setup.py index d1810de94..19408b014 100644 --- a/tests_old/test_setup.py +++ b/tests_old/test_setup.py @@ -11,7 +11,7 @@ packaging_base as pkg_base, ) from pypdfium2_setup.packaging_base import ( - PlatformNames, + PlatNames, BinaryPlatforms, ReleaseNames, ) @@ -20,7 +20,7 @@ @pytest.fixture def all_platnames(): - return list( get_members(PlatformNames) ) + return list( get_members(PlatNames) ) # module @@ -47,25 +47,25 @@ def all_platnames(): # setup_base ExpectedTags = ( - (PlatformNames.linux_x64, "manylinux_2_17_x86_64"), - (PlatformNames.linux_x86, "manylinux_2_17_i686"), - (PlatformNames.linux_arm64, "manylinux_2_17_aarch64"), - (PlatformNames.linux_arm32, "manylinux_2_17_armv7l"), - (PlatformNames.linux_musl_x64, "musllinux_1_1_x86_64"), - (PlatformNames.linux_musl_x86, "musllinux_1_1_i686"), - (PlatformNames.darwin_x64, "macosx_10_13_x86_64"), - (PlatformNames.darwin_arm64, "macosx_11_0_arm64"), - (PlatformNames.windows_x64, "win_amd64"), - (PlatformNames.windows_arm64, "win_arm64"), - (PlatformNames.windows_x86, "win32"), - (PlatformNames.sourcebuild, sysconfig.get_platform().replace('-','_').replace('.','_')), + (PlatNames.linux_x64, "manylinux_2_17_x86_64"), + (PlatNames.linux_x86, "manylinux_2_17_i686"), + (PlatNames.linux_arm64, "manylinux_2_17_aarch64"), + (PlatNames.linux_arm32, "manylinux_2_17_armv7l"), + (PlatNames.linux_musl_x64, "musllinux_1_1_x86_64"), + (PlatNames.linux_musl_x86, "musllinux_1_1_i686"), + (PlatNames.darwin_x64, "macosx_10_13_x86_64"), + (PlatNames.darwin_arm64, "macosx_11_0_arm64"), + (PlatNames.windows_x64, "win_amd64"), + (PlatNames.windows_arm64, "win_arm64"), + (PlatNames.windows_x86, "win32"), + (PlatNames.sourcebuild, sysconfig.get_platform().replace('-','_').replace('.','_')), ) def test_expected_tags(all_platnames): assert len(all_platnames) == len(ExpectedTags) for platform, tag in ExpectedTags: - assert hasattr(PlatformNames, platform) + assert hasattr(PlatNames, platform) assert isinstance(tag, str) @@ -91,10 +91,10 @@ def test_libnames(): for name in pkg_base.MainLibnames: assert "pdfium" in name -def test_platformnames(all_platnames): +def test_PlatNames(all_platnames): # make sure variable names and values are identical for name in all_platnames: - assert name == getattr(PlatformNames, name) + assert name == getattr(PlatNames, name) def test_paths(): # FIXME not much point doing this? @@ -112,7 +112,7 @@ def test_releasenames(all_platnames): assert len(ReleaseNames) == len(BinaryPlatforms) == len(all_platnames) - 1 for key, value in ReleaseNames.items(): assert key in BinaryPlatforms - assert hasattr(PlatformNames, key) + assert hasattr(PlatNames, key) system, cpu = value.replace("linux-musl", "musllinux").split("-", maxsplit=3) assert system in ("linux", "musllinux", "mac", "win") assert cpu in ("x64", "x86", "arm64", "arm")