diff --git a/setupsrc/pypdfium2_setup/craft_packages.py b/setupsrc/pypdfium2_setup/craft_packages.py index 16a62e384..821da159d 100644 --- a/setupsrc/pypdfium2_setup/craft_packages.py +++ b/setupsrc/pypdfium2_setup/craft_packages.py @@ -167,7 +167,7 @@ def main_conda_bundle(args): def main_conda_raw(args): os.environ["PDFIUM_SHORT"] = str(args.pdfium_ver) - os.environ["PDFIUM_FULL"] = PdfiumVer.to_full(args.pdfium_ver, origin="pdfium-binaries", as_str=True) + os.environ["PDFIUM_FULL"] = PdfiumVer.to_full(args.pdfium_ver, type=str) 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") diff --git a/setupsrc/pypdfium2_setup/packaging_base.py b/setupsrc/pypdfium2_setup/packaging_base.py index 736ac7299..1ec129f98 100644 --- a/setupsrc/pypdfium2_setup/packaging_base.py +++ b/setupsrc/pypdfium2_setup/packaging_base.py @@ -126,30 +126,36 @@ def get_latest(): return int( tag.split("/")[-1] ) @staticmethod - def to_full(v_short, origin, as_str=False): - - # TODO determine from chromium tags instead. This would allow us to handle system and sourcebuild properly + @functools.lru_cache(maxsize=1) + def _get_version_conv(): - if origin == "sourcebuild": - # For sourcebuild, we don't actually set the full version (retrieving from chromium not implemented yet). Also note v_short may be a commit hash if building from an untagged commit. - # FIXME as_str not implemented - v_parts = (None, None, v_short, None) + ChromiumURL = "https://chromium.googlesource.com/chromium/src" + refs_txt = run_cmd(["git", "ls-remote", "--sort", "-version:refname", "--tags", ChromiumURL, '*.*.*.0'], cwd=None, capture=True) - else: - info = url_request.urlopen(f"{ReleaseInfoURL}{v_short}").read().decode("utf-8") - info = json.loads(info) - title = info["name"] - match = re.match(rf"PDFium (\d+.\d+.{v_short}.\d+)", title) - v_string = match.group(1) - if as_str: - return v_string - v_parts = [int(v) for v in v_string.split(".")] - v_short = int(v_short) + # FIXME parses too much - we'd only need to read until we find a given v_short and then deepen on demand on further calls + to_full = {} + for ref in refs_txt.split("\n"): + ref = ref.split("\t")[-1].rsplit("/", maxsplit=1)[-1] + major, minor, build, patch = [int(v) for v in ref.split(".")] + to_full[build] = (major, minor, build, patch) + return to_full + + @staticmethod + def to_full(v_short, type=dict): # XXX origin - v_info = dict(zip(PdfiumVer.V_KEYS, v_parts)) - assert v_info["build"] == v_short + v_short = int(v_short) + ver_dict = PdfiumVer._get_version_conv() + v_parts = ver_dict[v_short] + assert v_parts[2] == v_short - return v_info + if type in (tuple, list): + return v_parts + elif type is str: + return v_parts.join(".") + elif type is dict: + return dict(zip(PdfiumVer.V_KEYS, v_parts)) + else: + assert False def read_json(fp): @@ -162,7 +168,7 @@ def write_json(fp, data, indent=2): def write_pdfium_info(dir, build, origin, flags=[], n_commits=0, hash=None): - info = dict(**PdfiumVer.to_full(build, origin), n_commits=n_commits, hash=hash, origin=origin, flags=flags) + info = dict(**PdfiumVer.to_full(build, type=dict), n_commits=n_commits, hash=hash, origin=origin, flags=flags) write_json(dir/VersionFN, info) return info