Skip to content

Commit

Permalink
Slightly simplify some setup code
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Sep 14, 2022
1 parent 4d564ff commit 62367d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
32 changes: 12 additions & 20 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,9 @@
get_latest_version,
)

PresetupFile = join(DataTree, ".presetup_done.txt")
LockFile = join(DataTree, ".lock_autoupdate.txt")
# NOTE Setuptools may run this code several times (if using PEP 517 style setup).

def need_presetup():
if exists(PresetupFile):
return False
else:
with open(PresetupFile, "w") as fh:
fh.write("")
return True
LockFile = join(DataTree, ".lock_autoupdate.txt")


def install_handler(latest_ver):
Expand All @@ -55,21 +48,21 @@ def install_handler(latest_ver):

if not all(exists(fp) for fp in get_platfiles(pl_name)):
need_update = True # always update if platform files are missing
else:

elif not exists(LockFile):

# Automatic updates imply some duplication across different runs. The code runs quickly enough, so this is not much of a problem.

latest_ver = get_latest_version()
ver_file = join(DataTree, pl_name, VerStatusFileName)
assert os.path.exists(ver_file)

with open(ver_file, "r") as fh:
curr_version = int( fh.read().strip() )
assert curr_version <= latest_ver
assert not curr_version > latest_ver

if curr_version < latest_ver:
if exists(LockFile):
print("Binaries are outdated, but autoupdate is locked.", file=sys.stderr)
else:
print("Updating binaries automatically. A lock file may be created to prevent this.", file=sys.stderr)
need_update = True
need_update = True

if need_update:
update_pdfium.main([pl_name])
Expand All @@ -95,10 +88,9 @@ def main():
target = os.environ.get(BinaryTargetVar, None)

if target in (None, "auto"):
if need_presetup():
check_deps.main()
latest_ver = get_latest_version()
install_handler(latest_ver)
# As check_deps needs to run only once and then never again, we could prevent repeated runs using a status file. However, it runs quickly enough, so this is not really necessary.
check_deps.main()
install_handler()
else:
packaging_handler(target)

Expand Down
8 changes: 2 additions & 6 deletions setupsrc/pl_setup/build_pdfium.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,8 @@ def find_lib(src_libname=None, directory=PDFiumBuildDir):
try_paths = [join(directory, n) for n in try_names]
found_paths = [fp for fp in try_paths if os.path.isfile(fp)]

if len(found_paths) == 1:
return found_paths[0]
elif len(found_paths) < 1:
raise RuntimeError("Binary not found.")
else:
raise RuntimeError("Multiple binaries found (ambiguity).")
assert len(found_paths) == 1
return found_paths[0]


def pack(src_libpath, destname=None):
Expand Down
1 change: 0 additions & 1 deletion setupsrc/pl_setup/packaging_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
join,
abspath,
dirname,
basename,
expanduser,
)

Expand Down

0 comments on commit 62367d1

Please sign in to comment.