Skip to content

Commit

Permalink
setup: make conda and prepared detectable
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Nov 8, 2023
1 parent f04f757 commit 0f17ee0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
14 changes: 11 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,20 @@ def main():
pl_spec = os.environ.get(PlatSpec_EnvVar, "")
modspec = os.environ.get(ModulesSpec_EnvVar, "")

# TODO embed is_prepared in version file? - in principle, it could be arbitrary caller-given files
with_prepare, pl_name, pdfium_ver, use_v8 = parse_pl_spec(pl_spec)
modnames = parse_modspec(modspec, pl_name)

if ModuleRaw in modnames and with_prepare:
prepare_setup(pl_name, pdfium_ver, use_v8)
if ModuleRaw in modnames:
if with_prepare:
prepare_setup(pl_name, pdfium_ver, use_v8)
# TODO rewrite only if not with_prepare?
pdfium_info_file = ModuleDir_Raw/VersionFN
pdfium_info = read_json(pdfium_info_file)
if with_prepare:
pdfium_info["data_source"] = "internal"
else:
pdfium_info["data_source"] = "external"
write_json(pdfium_info_file, pdfium_info)
run_setup(modnames, pl_name, pdfium_ver)


Expand Down
2 changes: 1 addition & 1 deletion setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def run_conda_build(recipe_dir, out_dir, args=[]):
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)
emplace_func = partial(prepare_setup, pl_name, args.pdfium_ver, args.use_v8, is_conda=True)

with CondaExtPlatfiles(emplace_func):
run_conda_build(CondaDir/"bundle", CondaDir/"bundle"/"out", conda_args)
Expand Down
6 changes: 4 additions & 2 deletions setupsrc/pypdfium2_setup/emplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _get_pdfium_with_cache(pl_name, req_ver, req_flags, use_v8):
build_pdfium_bindings(req_ver, flags=req_flags, compile_lds=compile_lds)


def prepare_setup(pl_name, pdfium_ver, use_v8):
def prepare_setup(pl_name, pdfium_ver, use_v8, is_conda=False):

clean_platfiles()
flags = ["V8", "XFA"] if use_v8 else []
Expand All @@ -53,8 +53,10 @@ def prepare_setup(pl_name, pdfium_ver, use_v8):
# TODO add option for caller to pass in custom run_lds and headers_dir
build_pdfium_bindings(pdfium_ver, flags=flags, guard_symbols=True, run_lds=[])
shutil.copyfile(DataDir_Bindings/BindingsFN, ModuleDir_Raw/BindingsFN)
write_pdfium_info(ModuleDir_Raw, pdfium_ver, origin="system", flags=flags)
origin = "system" + ("_conda" if is_conda else "")
write_pdfium_info(ModuleDir_Raw, pdfium_ver, origin=origin, flags=flags)
return [BindingsFN, VersionFN]

else:
platfiles = []
pl_dir = DataDir/pl_name
Expand Down
4 changes: 2 additions & 2 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,8 @@ def parse_pl_spec(pl_spec, need_prepare=True):
else:
raise ValueError(f"Invalid binary spec '{pl_spec}'")

if pl_name == ExtPlats.system:
assert req_ver, "Version must be given explicitly for system target."
if pl_name == ExtPlats.system or not need_prepare:
assert req_ver, "Version must be given explicitly for system or prepared targets."

if req_ver:
assert req_ver.isnumeric()
Expand Down
7 changes: 7 additions & 0 deletions src/pypdfium2/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def _craft_desc(self, extra=[]):
desc = ""
if local_ver:
desc += "+" + ".".join(local_ver)

return desc

@cached_property
Expand Down Expand Up @@ -111,6 +112,8 @@ def desc(self):
desc += ":{%s}" % ",".join(self.flags)
if self.origin != "pdfium-binaries":
desc += f"@{self.origin}"
if self.data_source != "internal":
desc += f"!{self.data_source}_source" # external
return desc

# TODO(future) add bindings info (e.g. ctypesgen version, reference/generated, runtime libdirs)
Expand Down Expand Up @@ -218,6 +221,10 @@ def desc(self):
- ``system``: Dynamically loaded from a standard system location using :func:`ctypes.util.find_library`.
flags (tuple[str]):
Tuple of pdfium feature flags. Empty for default build. (V8, XFA) for pdfium-binaries V8 build.
data_source (str):
Source of the bundled data files (binary/bindings/version). Possible values:\n
- ``internal`` if probably generated natively by setup code.
- ``external`` if provided by caller. Unsafe, can be arbitrary given files. This is evidence of a third-party build unless origin is system_conda (but not all third-party builds have to be external).
"""

# -----

0 comments on commit 0f17ee0

Please sign in to comment.