Skip to content

Commit

Permalink
Handle latest version separately for conda pdfium/pypdfium2_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Dec 8, 2023
1 parent 63a17ba commit c1717af
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
14 changes: 9 additions & 5 deletions setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import os
import sys
import json
import shutil
import argparse
import tempfile
Expand Down Expand Up @@ -55,7 +54,12 @@ def parse_args():
args = root_parser.parse_args()
args.is_literal_latest = args.pdfium_ver == "latest"
if not args.pdfium_ver or args.is_literal_latest:
args.pdfium_ver = PdfiumVer.get_latest()
if args.parser == P_CONDA_RAW:
args.pdfium_ver = PdfiumVer.get_latest_conda_pdfium()
elif args.parser == P_CONDA_HELPERS:
args.pdfium_ver = PdfiumVer.get_latest_conda_bindings()
else:
args.pdfium_ver = PdfiumVer.get_latest()
else:
args.pdfium_ver = int(args.pdfium_ver)
if args.parser == P_CONDA_BUNDLE:
Expand Down Expand Up @@ -166,12 +170,12 @@ def main_conda_bundle(args):
_run_conda_bundle(args, Host.platform, suffix, conda_args)


# TODO expand to pypdfium2_helpers as well, so we could rebuild with different pdfium bounds in a workflow
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"])
# TODO expand to pypdfium2_helpers as well, so we could rebuild with different pdfium bounds in a workflow

search = reversed(run_conda_search("pypdfium2_raw", "pypdfium2-team"))

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."
Expand Down
25 changes: 25 additions & 0 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ class PlatNames:
BinarySystems = list(LibnameForSystem.keys())


@functools.lru_cache(maxsize=2)
def run_conda_search(package, channel):
output = run_cmd(["conda", "search", "--json", package, "--override-channels", "-c", channel], cwd=None, capture=True)
return json.loads(output)[package]


class PdfiumVer:

scheme = namedtuple("PdfiumVer", ("major", "minor", "build", "patch"))
Expand All @@ -138,6 +144,25 @@ def get_latest():
tag = git_ls.split("\t")[-1]
return int( tag.split("/")[-1] )

@staticmethod
@functools.lru_cache(maxsize=2)
def _get_latest_conda_for(package, channel, v_func):
search = run_conda_search(package, channel)
search = sorted(search, key=lambda d: v_func(d["version"]), reverse=True)
result = v_func(search[0]["version"])
print(f"Resolved latest {channel}::{package} to {result}", file=sys.stderr)
return result

def get_latest_conda_pdfium():
return PdfiumVer._get_latest_conda_for(
"pdfium-binaries", "bblanchon", lambda v: int(v.split(".")[2])
)

def get_latest_conda_bindings():
return PdfiumVer._get_latest_conda_for(
"pypdfium2_raw", "pypdfium2-team", lambda v: int(v)
)

@classmethod
def to_full(cls, v_short):

Expand Down

0 comments on commit c1717af

Please sign in to comment.