Skip to content

Commit

Permalink
some cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Jan 10, 2024
1 parent 2eb90a2 commit b774be5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def run_setup(modnames, pl_name, pdfium_ver):
install_requires = [],
)

if modnames == [ModuleHelpers] and pl_name != ExtPlats.none:
if modnames == [ModuleHelpers] and pl_name != ExtPlats.sdist:
# do not do this for sdist (none)
kwargs["name"] += "_helpers"
kwargs["description"] += " (helpers module)"
Expand All @@ -113,9 +113,9 @@ def run_setup(modnames, pl_name, pdfium_ver):
if ModuleRaw in modnames:
kwargs["package_dir"]["pypdfium2_raw"] = "src/pypdfium2_raw"

if ModuleRaw not in modnames or pl_name == ExtPlats.none:
if ModuleRaw not in modnames or pl_name == ExtPlats.sdist:
kwargs["exclude_package_data"] = {"pypdfium2_raw": PLATFILES_GLOB}
if pl_name == ExtPlats.none:
if pl_name == ExtPlats.sdist:
kwargs["license_files"] += LICENSES_SDIST
elif pl_name == ExtPlats.system:
kwargs["package_data"]["pypdfium2_raw"] = [VersionFN, BindingsFN]
Expand Down Expand Up @@ -145,7 +145,7 @@ def main():
with_prepare, pl_name, pdfium_ver, use_v8 = parse_pl_spec(pl_spec)
modnames = parse_modspec(modspec)

if ModuleRaw in modnames and with_prepare and pl_name != ExtPlats.none:
if ModuleRaw in modnames and with_prepare and pl_name != ExtPlats.sdist:
prepare_setup(pl_name, pdfium_ver, use_v8)
run_setup(modnames, pl_name, pdfium_ver)

Expand Down
5 changes: 3 additions & 2 deletions setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ def main():


def _run_pypi_build(args):
run_cmd([sys.executable, "-m", "build", "--skip-dependency-check", "--no-isolation"] + args, cwd=ProjectDir, env=os.environ)
# -nx: --no-isolation --skip-dependency-check
run_cmd([sys.executable, "-m", "build", "-nx"] + args, cwd=ProjectDir, env=os.environ)


def main_pypi(args):

os.environ[PlatSpec_EnvVar] = ExtPlats.none
os.environ[PlatSpec_EnvVar] = ExtPlats.sdist
with tmp_ctypesgen_pin():
_run_pypi_build(["--sdist"])

Expand Down
2 changes: 1 addition & 1 deletion setupsrc/pypdfium2_setup/emplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def main():
)
args = parser.parse_args()

if args.plat_spec == ExtPlats.none:
if args.plat_spec == ExtPlats.sdist:
print("Remove existing in-tree platform files, if any.", file=sys.stderr)
clean_platfiles()
return
Expand Down
5 changes: 2 additions & 3 deletions setupsrc/pypdfium2_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ class SysNames:
class ExtPlats:
sourcebuild = "sourcebuild"
system = "system"
none = "none" # FIXME rename to sdist?
auto = "auto"
sdist = "sdist"

# TODO align with either python or google platform names?
class PlatNames:
Expand Down Expand Up @@ -596,7 +595,7 @@ def parse_pl_spec(pl_spec, with_prepare=True):
pl_spec = pl_spec[:-len(PlatSpec_V8Sym)]
use_v8 = True

if not pl_spec or pl_spec == ExtPlats.auto:
if not pl_spec or pl_spec == "auto":
pl_name = Host.platform
if pl_name is None:
raise RuntimeError(f"No pre-built binaries available for {Host}. You may place custom binaries & bindings in data/sourcebuild and install with `{PlatSpec_EnvVar}=sourcebuild`.")
Expand Down
5 changes: 1 addition & 4 deletions src/pypdfium2/internal/bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ def _as_parameter_(self):
def _close_template(close_func, raw, obj_repr, state, parent, *args, **kwargs):

if DEBUG_AUTOCLOSE:
state = state.value
desc = "auto" if state == STATE_AUTO else "explicit" if state == STATE_EXPLICIT else "by parent" if state == STATE_BYPARENT else None
if desc is None:
raise
desc = {STATE_AUTO: "auto", STATE_EXPLICIT: "explicit", STATE_BYPARENT: "by parent"}[state.value]
# use os.write() rather than print() to avoid "reentrant call" exceptions on shutdown (see https://stackoverflow.com/q/75367828/15547292)
os.write(sys.stderr.fileno(), f"Close ({desc}) {obj_repr}\n".encode())

Expand Down

0 comments on commit b774be5

Please sign in to comment.