diff --git a/Makefile b/Makefile index 1e50a3042..ce3b6c0c3 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ update-all: python3 ./setupsrc/pl_setup/update_pdfium.py setup-all: - python3 ./setupsrc/pl_setup/craft_packages.py + python3 ./setupsrc/pl_setup/craft_wheels.py packaging: bash ./utilities/packaging.sh diff --git a/docs/devel/tasks.md b/docs/devel/tasks.md index 75d1876be..dfd22ff4d 100644 --- a/docs/devel/tasks.md +++ b/docs/devel/tasks.md @@ -20,7 +20,7 @@ Also see the issues panel and inline `TODO` marks in source code. * Consolidate and extend helper classes. ### Setup Infrastructure -* craft_packages: add means to skip platforms for which artefacts are missing. +* craft_wheels: add means to skip platforms for which artefacts are missing. * update_pdfium: only generate the bindings file once for all platforms. * update_pdfium: add option to download a custom pdfium-binaries release (i. e. not the latest). * packaging_base: use a class for `VerNamespace` so it can be flushed more easily (?) diff --git a/setupsrc/pl_setup/craft_packages.py b/setupsrc/pl_setup/craft_wheels.py similarity index 59% rename from setupsrc/pl_setup/craft_packages.py rename to setupsrc/pl_setup/craft_wheels.py index 6b233503c..61b0beb17 100644 --- a/setupsrc/pl_setup/craft_packages.py +++ b/setupsrc/pl_setup/craft_wheels.py @@ -27,6 +27,30 @@ ) +class ArtefactStash: + + # Preserve in-tree aftefacts from editable install + + def __init__(self): + + self.tmp_dir = None + self.plfile_names = [BindingsFileName, LibnameForSystem[Host.system]] + self.plfile_paths = [join(ModuleDir, fn) for fn in self.plfile_names] + + if not any(os.path.exists(fp) for fp in self.plfile_paths): + return + self.tmp_dir = tempfile.TemporaryDirectory(prefix="pypdfium2_artefact_stash_") + for fp in self.plfile_paths: + shutil.move(fp, self.tmp_dir.name) + + def pop(self): + if self.tmp_dir is None: + return + for fn in self.plfile_names: + shutil.move(join(self.tmp_dir.name, fn), ModuleDir) + self.tmp_dir.cleanup() + + def run_build(args): run_cmd([sys.executable, "-m", "build", "--skip-dependency-check", "--no-isolation"] + args, cwd=SourceTree, env=os.environ) @@ -38,18 +62,8 @@ def main(): ) args = parser.parse_args() - # Push possible in-tree artefacts from editable install to stash - tmp_dir = None - platfiles = ( - join(ModuleDir, BindingsFileName), - join(ModuleDir, LibnameForSystem[Host.system]), - ) - if any(os.path.exists(fp) for fp in platfiles): - tmp_dir = tempfile.TemporaryDirectory(prefix="pypdfium2_artefact_stash_") - for fp in platfiles: - shutil.move(fp, tmp_dir.name) + stash = ArtefactStash() - clean_artefacts() os.environ[BinaryTargetVar] = BinaryTarget_None run_build(["--sdist"]) clean_artefacts() @@ -59,11 +73,7 @@ def main(): run_build(["--wheel"]) clean_artefacts() - # Pop stash - if tmp_dir is not None: - for fn in os.listdir(tmp_dir.name): - shutil.move(join(tmp_dir.name, fn), ModuleDir) - tmp_dir.cleanup() + stash.pop() if __name__ == '__main__': diff --git a/utilities/packaging.sh b/utilities/packaging.sh index 6412b5ea5..4857d70d7 100755 --- a/utilities/packaging.sh +++ b/utilities/packaging.sh @@ -11,7 +11,7 @@ bash utilities/install.sh python3 -m pytest tests/ python3 ./setupsrc/pl_setup/update_pdfium.py -python3 ./setupsrc/pl_setup/craft_packages.py +python3 ./setupsrc/pl_setup/craft_wheels.py twine check dist/* check-wheel-contents dist/*.whl