From 4c0aee6d230aa2f73f8441979235c24cfeec7e23 Mon Sep 17 00:00:00 2001 From: geisserml Date: Sat, 9 Dec 2023 00:14:40 +0100 Subject: [PATCH] conda: get rid of effectively dead bundling code Unbundling is the way to go with conda, so I figured it would be good to remove the effectively dead code, which is more bloated/confusing than useful. --- conda/bundle/recipe/meta.yaml | 74 --------- setupsrc/pypdfium2_setup/craft_packages.py | 180 ++++++--------------- 2 files changed, 53 insertions(+), 201 deletions(-) delete mode 100644 conda/bundle/recipe/meta.yaml diff --git a/conda/bundle/recipe/meta.yaml b/conda/bundle/recipe/meta.yaml deleted file mode 100644 index 022ef9b38..000000000 --- a/conda/bundle/recipe/meta.yaml +++ /dev/null @@ -1,74 +0,0 @@ -# SPDX-FileCopyrightText: 2023 geisserml -# SPDX-License-Identifier: CC-BY-4.0 - -# NOTE -# This is an attempt to bundle the pdfium binaries with conda packages, like we do for pypi wheels. -# However, conda does not support CPU specific but Python version independent packages, meaning we'd have to build for each Python separately, so the better solution is probably to unbundle pdfium. -# For now, let's retain this passively as a second option just in case a situation arises where bundling would be desired anyway. -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -{% set helpers_ver = environ["M_HELPERS_VER"] %} -{% set pl_spec = environ["IN_PDFIUM_PLATFORM"] %} -# {% set setup_cfg = load_file_data("setup.cfg") %} - -package: - name: pypdfium2_bundle - version: {{ helpers_ver }} - -source: - git_url: ../../.. - -build: - number: 0 - entry_points: - - pypdfium2 = pypdfium2.__main__:cli_main - script_env: - # NOTE conda neither needs nor likes env values being wrapped in quotes - - PDFIUM_PLATFORM=prepared!{{ pl_spec }} - script: - - {{ PYTHON }} conda/prepare_script.py - - {{ PYTHON }} -m pip install . -v --no-deps --no-build-isolation - -requirements: - # NOTE conda theoretically offers an additional host section, but for our purposes this is effectively the same as the build section - build: - - git - - python - - pip - - setuptools - - wheel !=0.38.0,!=0.38.1 - run: - - python - -# pass --no-test if cross-building for non-host target -# NOTE not embedding the whole helpers test suite to avoid blowing upload size -test: - requires: - - pip - - python - imports: - - pypdfium2 - - pypdfium2_raw # bundled - source_files: - - conda/raw/minitest.py - commands: - - pip check - - pypdfium2 --help - - python conda/raw/minitest.py - -about: - summary: Python bindings to PDFium (bundled helpers/binary/bindings) - license: (Apache-2.0 OR BSD-3-Clause) AND LicenseRef-PdfiumThirdParty - license_file: - - LICENSES/Apache-2.0.txt - - LICENSES/BSD-3-Clause.txt - - LICENSES/CC-BY-4.0.txt - - LICENSES/LicenseRef-PdfiumThirdParty.txt - - .reuse/dep5-wheel - dev_url: https://github.com/pypdfium2-team/pypdfium2 - doc_url: https://pypdfium2.readthedocs.io - -extra: - recipe-maintainers: - - pypdfium2-team - - mara004 diff --git a/setupsrc/pypdfium2_setup/craft_packages.py b/setupsrc/pypdfium2_setup/craft_packages.py index c6fa6e1aa..60c4aa1fd 100644 --- a/setupsrc/pypdfium2_setup/craft_packages.py +++ b/setupsrc/pypdfium2_setup/craft_packages.py @@ -1,6 +1,8 @@ # SPDX-FileCopyrightText: 2023 geisserml # SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause +# TODO split in pypi and conda? + import os import sys import shutil @@ -16,11 +18,9 @@ P_PYPI = "pypi" -P_CONDA_BUNDLE = "conda_bundle" P_CONDA_RAW = "conda_raw" P_CONDA_HELPERS = "conda_helpers" - def parse_args(): root_parser = argparse.ArgumentParser( @@ -32,24 +32,12 @@ def parse_args(): ) subparsers = root_parser.add_subparsers(dest="parser") pypi = subparsers.add_parser(P_PYPI) + pypi.add_argument( + "--use-v8", + action = "store_true", + ) conda_raw = subparsers.add_parser(P_CONDA_RAW) conda_helpers = subparsers.add_parser(P_CONDA_HELPERS) - conda_bundle = subparsers.add_parser(P_CONDA_BUNDLE) - conda_bundle.add_argument( - "--platforms", - nargs = "+", - default = [Host.platform], - ) - conda_bundle.add_argument( - "--py-variants", - nargs = "*", - ) - - for p in (pypi, conda_bundle): - p.add_argument( - "--use-v8", - action = "store_true", - ) args = root_parser.parse_args() args.is_literal_latest = args.pdfium_ver == "latest" @@ -62,114 +50,48 @@ def parse_args(): args.pdfium_ver = PdfiumVer.get_latest() else: args.pdfium_ver = int(args.pdfium_ver) - if args.parser == P_CONDA_BUNDLE: - if args.platforms and args.platforms[0] == "all": - args.platforms = list(CondaNames.keys()) - if args.py_variants and args.py_variants[0] == "all": - args.py_variants = ["3.8", "3.9", "3.10", "3.11", "3.12"] return args -def run_pypi_build(args): +def main(): + + args = parse_args() + + with ArtifactStash(): + if args.parser == P_PYPI: + main_pypi(args) + elif args.parser == P_CONDA_RAW: + main_conda_raw(args) + elif args.parser == P_CONDA_HELPERS: + helpers_info = parse_git_tag() + os.environ["M_HELPERS_VER"] = merge_tag(helpers_info, "py") + main_conda_helpers(args) + else: + assert False + + +def _run_pypi_build(args): run_cmd([sys.executable, "-m", "build", "--skip-dependency-check", "--no-isolation"] + args, cwd=ProjectDir, env=os.environ) + def main_pypi(args): os.environ[PlatSpec_EnvVar] = ExtPlats.none - run_pypi_build(["--sdist"]) + _run_pypi_build(["--sdist"]) suffix = build_pl_suffix(args.pdfium_ver, args.use_v8) for plat in ReleaseNames.keys(): os.environ[PlatSpec_EnvVar] = plat + suffix - run_pypi_build(["--wheel"]) + _run_pypi_build(["--wheel"]) clean_platfiles() -class ArtifactStash: - - # Preserve in-tree aftefacts from editable install - - def __enter__(self): - - self.tmpdir = None - - file_names = [VersionFN, BindingsFN, LibnameForSystem[Host.system]] - self.files = [fp for fp in [ModuleDir_Raw / fn for fn in file_names] if fp.exists()] - if len(self.files) == 0: - return - - self.tmpdir = tempfile.TemporaryDirectory(prefix="pypdfium2_artifact_stash_") - self.tmpdir_path = Path(self.tmpdir.name) - for fp in self.files: - shutil.move(fp, self.tmpdir_path) - - def __exit__(self, *_): - if self.tmpdir is None: - return - for fp in self.files: - shutil.move(self.tmpdir_path / fp.name, ModuleDir_Raw) - self.tmpdir.cleanup() - - def run_conda_build(recipe_dir, out_dir, args=[]): with TmpCommitCtx(): run_cmd(["conda", "build", recipe_dir, "--output-folder", out_dir, *args], cwd=ProjectDir, env=os.environ) -CondaNames = { - # NOTE looks like conda doesn't support musllinux yet ... - PlatNames.darwin_x64 : "osx-64", - PlatNames.darwin_arm64 : "osx-arm64", - PlatNames.linux_x64 : "linux-64", - PlatNames.linux_x86 : "linux-32", - PlatNames.linux_arm64 : "linux-aarch64", - PlatNames.linux_arm32 : "linux-armv7l", - PlatNames.windows_x64 : "win-64", - PlatNames.windows_x86 : "win-32", - PlatNames.windows_arm64 : "win-arm64", -} - -def _run_conda_bundle(args, pl_name, suffix, conda_args): - - os.environ["IN_"+PlatSpec_EnvVar] = pl_name + suffix - emplace_func = partial(prepare_setup, pl_name, args.pdfium_ver, args.use_v8) - - with CondaExtPlatfiles(emplace_func): - run_conda_build(CondaDir/"bundle", CondaDir/"bundle"/"out", conda_args) - - -def main_conda_bundle(args): - - helpers_ver = merge_tag(parse_git_tag(), "py") - os.environ["VERSION"] = helpers_ver - - platforms = args.platforms.copy() - with_host = Host.platform in platforms - if with_host: - platforms.remove(Host.platform) - conda_host = CondaNames[Host.platform] - host_files = None - - conda_args = [] - if args.py_variants: - conda_args += ["--variants", "{python: %s}" % (args.py_variants, )] - suffix = build_pl_suffix(args.pdfium_ver, args.use_v8) - - for pl_name in platforms: - - _run_conda_bundle(args, pl_name, suffix, [*conda_args, "--no-test"]) - if not host_files: - host_files = list((CondaDir/"bundle"/"out"/conda_host).glob(f"pypdfium2_bundle-{helpers_ver}-*.tar.bz2")) - - run_cmd(["conda", "convert", "-f", *host_files, "-p", CondaNames[pl_name], "-o", CondaDir/"bundle"/"out"], cwd=ProjectDir, env=os.environ) - for hf in host_files: - hf.unlink() - - if with_host: - _run_conda_bundle(args, Host.platform, suffix, conda_args) - - def _get_build_num(args): # parse existing releases to automatically handle arbitrary version builds @@ -207,6 +129,32 @@ def main_conda_helpers(args): run_conda_build(CondaDir/"helpers", CondaDir/"helpers"/"out", args=["--override-channels", "-c", "pypdfium2-team", "-c", "bblanchon"]) +class ArtifactStash: + + # Preserve in-tree aftefacts from editable install + + def __enter__(self): + + self.tmpdir = None + + file_names = [VersionFN, BindingsFN, LibnameForSystem[Host.system]] + self.files = [fp for fp in [ModuleDir_Raw / fn for fn in file_names] if fp.exists()] + if len(self.files) == 0: + return + + self.tmpdir = tempfile.TemporaryDirectory(prefix="pypdfium2_artifact_stash_") + self.tmpdir_path = Path(self.tmpdir.name) + for fp in self.files: + shutil.move(fp, self.tmpdir_path) + + def __exit__(self, *_): + if self.tmpdir is None: + return + for fp in self.files: + shutil.move(self.tmpdir_path / fp.name, ModuleDir_Raw) + self.tmpdir.cleanup() + + class TmpCommitCtx: # Work around local conda `git_url` not including uncommitted changes @@ -252,27 +200,5 @@ def __exit__(self, *_): fp.unlink() -def main(): - - args = parse_args() - - with ArtifactStash(): - if args.parser == P_PYPI: - main_pypi(args) - elif args.parser.startswith("conda"): - helpers_info = parse_git_tag() - os.environ["M_HELPERS_VER"] = merge_tag(helpers_info, "py") - if args.parser == P_CONDA_BUNDLE: - main_conda_bundle(args) - elif args.parser == P_CONDA_RAW: - main_conda_raw(args) - elif args.parser == P_CONDA_HELPERS: - main_conda_helpers(args) - else: - assert False - else: - assert False - - if __name__ == '__main__': main()