Skip to content

Commit

Permalink
conda_raw: handle rebuilds (#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 authored Nov 22, 2023
1 parent ecb77d2 commit 3b418eb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 10 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/conda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ on:
options:
- raw
- helpers
pdfium_ver:
default: 'latest'
type: string
test:
default: true
type: boolean
Expand All @@ -27,7 +30,7 @@ defaults:
run:
shell: bash -el {0}

# TODO it would be nice to also support building both packages in one run and testing the helpers package with the newly-built raw package, but this may be failry complicated
# TODO it would be nice to also support building both packages in one run and testing the helpers package with the newly-built raw package, but this may be fairly complicated

jobs:

Expand Down Expand Up @@ -58,8 +61,15 @@ jobs:
git config --global user.name "geisserml"
python -m pip install -U -r req/setup.txt
- name: Build package
run: ./run craft conda_${{ inputs.package }}
- 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: Upload artifact
uses: actions/upload-artifact@v3
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ jobs:
inputs: |
{
"package": "helpers",
"pdfium_ver": "latest",
"test": "true",
"publish": "${{ inputs.publish }}",
"py_version": "3.11"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/trigger_conda_raw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
inputs: |
{
"package": "raw",
"pdfium_ver": "latest",
"test": "true",
"publish": "true",
"py_version": "3.11"
Expand Down
3 changes: 2 additions & 1 deletion conda/raw/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

{% set pdfium_short = environ["PDFIUM_SHORT"] %}
{% set pdfium_full = environ["PDFIUM_FULL"] %}
{% set build_num = environ["BUILD_NUM"] %}

package:
name: pypdfium2_raw
Expand All @@ -12,7 +13,7 @@ source:
git_url: ../../..

build:
number: 0
number: {{ build_num }}
noarch: python
script_env:
- PYPDFIUM_MODULES=raw
Expand Down
2 changes: 1 addition & 1 deletion setupsrc/pypdfium2_setup/autorelease.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def log_changes(summary, prev_pdfium, new_pdfium, new_tag, beta):
def register_changes(new_tag):
run_local(["git", "checkout", "-B", "autorelease_tmp"])
run_local(["git", "add", *PlacesToRegister])
run_local(["git", "commit", "-m", "[autorelease] update changelog and version file"])
run_local(["git", "commit", "-m", f"[autorelease main] update {new_tag}"])
run_local(["git", "tag", "-a", new_tag, "-m", "Autorelease"])


Expand Down
43 changes: 43 additions & 0 deletions setupsrc/pypdfium2_setup/autorelease_conda_raw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#! /usr/bin/env python3
# SPDX-FileCopyrightText: 2023 geisserml <[email protected]>
# 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()
10 changes: 6 additions & 4 deletions setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
P_CONDA_RAW = "conda_raw"
P_CONDA_HELPERS = "conda_helpers"

CondaDir = ProjectDir / "conda"


def parse_args():

Expand All @@ -30,7 +28,6 @@ def parse_args():
)
root_parser.add_argument(
"--pdfium-ver",
type = int,
default = None,
)
subparsers = root_parser.add_subparsers(dest="parser")
Expand All @@ -55,8 +52,10 @@ def parse_args():
)

args = root_parser.parse_args()
if not args.pdfium_ver:
if not args.pdfium_ver or args.pdfium_ver == "latest":
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())
Expand Down Expand Up @@ -168,6 +167,9 @@ def main_conda_bundle(args):
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)
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"])
Expand Down
5 changes: 4 additions & 1 deletion setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@
HAVE_GIT_REPO = (ProjectDir / ".git").exists()

AutoreleaseDir = ProjectDir / "autorelease"
AR_RecordFile = AutoreleaseDir / "record.json" # TODO verify contents on before merge
AR_RecordFile = AutoreleaseDir / "record.json"
AR_ConfigFile = AutoreleaseDir / "config.json"
RefBindingsFile = AutoreleaseDir / BindingsFN

CondaDir = ProjectDir / "conda"
CondaRaw_BuildNumF = CondaDir / "raw" / "build_num.txt"

RepositoryURL = "https://github.com/pypdfium2-team/pypdfium2"
PdfiumURL = "https://pdfium.googlesource.com/pdfium"
DepotToolsURL = "https://chromium.googlesource.com/chromium/tools/depot_tools.git"
Expand Down

0 comments on commit 3b418eb

Please sign in to comment.