Skip to content

Commit

Permalink
Add some checks before ignoring dirty state
Browse files Browse the repository at this point in the history
Also ensure that tmp_replace_ctx() will actually replace
  • Loading branch information
mara004 committed Jan 18, 2024
1 parent 4558229 commit db4ebbb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,17 @@ def run_setup(modnames, pl_name, pdfium_ver):
kwargs["version"] = str(pdfium_ver)

if ModuleHelpers in modnames:
# is_editable = None: unknown/fallback in case the cmdclass is not reached
helpers_info = get_helpers_info()
# ignore dirty state due to craft_packages::tmp_ctypesgen_pin()
if pl_name == ExtPlats.sdist:
# ignore dirty state due to craft_packages::tmp_ctypesgen_pin()
helpers_info["dirty"] = False
if helpers_info["dirty"]:
status = run_cmd(["git", "status", "--porcelain"], capture=True, cwd=ProjectDir).strip()
if status == "M pyproject.toml":
helpers_info["dirty"] = False
else:
print("Warning: sdist built without ctypesgen pin?", file=sys.stderr)
kwargs["version"] = merge_tag(helpers_info, mode="py")
# is_editable = None: unknown/fallback in case the cmdclass is not reached
helpers_info["is_editable"] = None
write_json(ModuleDir_Helpers/VersionFN, helpers_info)
kwargs["cmdclass"]["build_py"] = pypdfium_build_py
Expand Down
1 change: 1 addition & 0 deletions setupsrc/pypdfium2_setup/craft_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __exit__(self, *_):
@contextlib.contextmanager
def tmp_replace_ctx(fp, orig, tmp):
orig_txt = fp.read_text()
assert orig_txt.count(orig) == 1
tmp_txt = orig_txt.replace(orig, tmp)
fp.write_text(tmp_txt)
try:
Expand Down

0 comments on commit db4ebbb

Please sign in to comment.