From 9a1dcd358dd8114c60cc3da06c42b4fe5a8498ae Mon Sep 17 00:00:00 2001 From: geisserml Date: Thu, 23 Nov 2023 15:49:54 +0100 Subject: [PATCH] Inline build version handling in craft_packages --- .github/workflows/conda.yaml | 11 +---- .github/workflows/main.yaml | 1 + .../pypdfium2_setup/autorelease_conda_raw.py | 43 ------------------- setupsrc/pypdfium2_setup/craft_packages.py | 24 +++++++++-- 4 files changed, 23 insertions(+), 56 deletions(-) delete mode 100644 setupsrc/pypdfium2_setup/autorelease_conda_raw.py diff --git a/.github/workflows/conda.yaml b/.github/workflows/conda.yaml index ad52c4e03..6d8531519 100644 --- a/.github/workflows/conda.yaml +++ b/.github/workflows/conda.yaml @@ -61,15 +61,8 @@ jobs: git config --global user.name "geisserml" python -m pip install -U -r req/setup.txt - - name: Build raw package - if: inputs.package == 'raw' - run: | - python setupsrc/pypdfium2_setup/autorelease_conda_raw.py --pdfium-ver ${{ inputs.pdfium_ver }} - ./run craft --pdfium-ver ${{ inputs.pdfium_ver }} conda_raw - - - name: Build helpers package - if: inputs.package == 'helpers' - run: ./run craft --pdfium-ver ${{ inputs.pdfium_ver }} conda_helpers + - name: Build package + run: ./run craft --pdfium-ver "${{ inputs.pdfium_ver }}" conda_${{ inputs.package }} - name: Upload artifact uses: actions/upload-artifact@v3 diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 88ff0621e..9bb7b60b4 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -244,6 +244,7 @@ jobs: - name: Trigger conda pypdfium2_helpers build uses: benc-uk/workflow-dispatch@v1 with: + # FIXME input not respected for py_version here workflow: conda.yaml inputs: | { diff --git a/setupsrc/pypdfium2_setup/autorelease_conda_raw.py b/setupsrc/pypdfium2_setup/autorelease_conda_raw.py deleted file mode 100644 index 5379de55c..000000000 --- a/setupsrc/pypdfium2_setup/autorelease_conda_raw.py +++ /dev/null @@ -1,43 +0,0 @@ -#! /usr/bin/env python3 -# SPDX-FileCopyrightText: 2023 geisserml -# SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause - -import sys -import json -import argparse -from pathlib import Path -sys.path.insert(0, str(Path(__file__).parents[1])) -from pypdfium2_setup.packaging_base import * - - -def main(): - - # FIXME we currently traverse the whole list with max() - any chance of (elegantly) avoiding this while maintaining inherent correctness? - - parser = argparse.ArgumentParser() - parser.add_argument("--pdfium-ver", default=None) - args = parser.parse_args() - is_literal_latest = args.pdfium_ver == "latest" - if not args.pdfium_ver or is_literal_latest: - args.pdfium_ver = PdfiumVer.get_latest() - else: - args.pdfium_ver = int(args.pdfium_ver) - - # parse existing releases to automatically handle arbitrary version builds - search = run_cmd(["conda", "search", "--json", "pypdfium2_raw", "--override-channels", "-c", "pypdfium2-team"], cwd=None, capture=True) - search = reversed(json.loads(search)["pypdfium2_raw"]) - - if is_literal_latest: - assert args.pdfium_ver > max([int(d["version"]) for d in search]), "Literal latest must resolve to a new version. This is done to avoid rebuilds without new version in scheduled releases. If you want to rebuild, omit --pdfium-ver or pass the resolved value." - - # determine build number - build = max([d["build_number"] for d in search if int(d["version"]) == args.pdfium_ver], default=None) - build = 0 if build is None else build+1 - print(build, file=sys.stderr) - - # store build number in a file for use in a subsequent craft_packages call - CondaRaw_BuildNumF.write_text(str(build)) - - -if __name__ == "__main__": - main() diff --git a/setupsrc/pypdfium2_setup/craft_packages.py b/setupsrc/pypdfium2_setup/craft_packages.py index e76359647..35332398a 100644 --- a/setupsrc/pypdfium2_setup/craft_packages.py +++ b/setupsrc/pypdfium2_setup/craft_packages.py @@ -3,6 +3,7 @@ import os import sys +import json import shutil import argparse import tempfile @@ -52,7 +53,8 @@ def parse_args(): ) args = root_parser.parse_args() - if not args.pdfium_ver or args.pdfium_ver == "latest": + args.is_literal_latest = args.pdfium_ver == "latest" + if not args.pdfium_ver or args.is_literal_latest: args.pdfium_ver = PdfiumVer.get_latest() else: args.pdfium_ver = int(args.pdfium_ver) @@ -164,12 +166,26 @@ def main_conda_bundle(args): _run_conda_bundle(args, Host.platform, suffix, conda_args) +def _get_build_num(args): + + # parse existing releases to automatically handle arbitrary version builds + search = run_cmd(["conda", "search", "--json", "pypdfium2_raw", "--override-channels", "-c", "pypdfium2-team"], cwd=None, capture=True) + search = reversed(json.loads(search)["pypdfium2_raw"]) + + if args.is_literal_latest: + assert args.pdfium_ver > max([int(d["version"]) for d in search]), "Literal latest must resolve to a new version. This is done to avoid rebuilds without new version in scheduled releases. If you want to rebuild, omit --pdfium-ver or pass the resolved value." + + # determine build number + build_num = max([d["build_number"] for d in search if int(d["version"]) == args.pdfium_ver], default=None) + build_num = 0 if build_num is None else build_num+1 + + return build_num + + def main_conda_raw(args): os.environ["PDFIUM_SHORT"] = str(args.pdfium_ver) os.environ["PDFIUM_FULL"] = ".".join([str(v) for v in PdfiumVer.to_full(args.pdfium_ver)]) - assert CondaRaw_BuildNumF.exists(), "build number must be given explicitly through conda/raw/build_num.txt - run autorelease_conda_raw.py to create" - build_num = int(CondaRaw_BuildNumF.read_text().strip()) - os.environ["BUILD_NUM"] = str(build_num) + os.environ["BUILD_NUM"] = str(_get_build_num(args)) emplace_func = partial(prepare_setup, ExtPlats.system, args.pdfium_ver, use_v8=None) with CondaExtPlatfiles(emplace_func): run_conda_build(CondaDir/"raw", CondaDir/"raw"/"out", args=["--override-channels", "-c", "bblanchon"])