From 8c6e34ba667b4963eb3b51b0016fdb95fce16f4c Mon Sep 17 00:00:00 2001 From: sebres Date: Sat, 3 May 2025 23:36:13 +0200 Subject: [PATCH] retrieve library and binary path using sysconfig (and generate error if it's not possible) --- setup.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b84a144c..ad20262b 100755 --- a/setup.py +++ b/setup.py @@ -262,6 +262,7 @@ def _dispInstallFooter(): # if new packaging mechanism: if "install-ex" in sys.argv or "build-ex" in sys.argv: import getopt + import sysconfig build_base = 'build' cfg = {'dry-run':False, 'quiet':False} # Reads the command line options. @@ -315,10 +316,16 @@ if "install-ex" in sys.argv or "build-ex" in sys.argv: return join(build_base, p) print("running build-ex") if not cfg.get("lib"): - cfg["lib"] = next(filter(lambda x: x.endswith("dist-packages"), sys.path), None) + cfg["lib"] = sysconfig.get_paths().get("purelib") + if not cfg["lib"]: + cfg["lib"] = next(filter(lambda x: x.endswith("dist-packages"), sys.path), None) + if not cfg["lib"]: + raise Exception("cannot estimate library path, set it with --lib") build_lib = _rootpath(cfg["lib"]) if not cfg.get("bin"): - cfg["bin"] = re.sub(r'/lib(?=^|/).*', '/bin', cfg["lib"]); # /usr/local/lib/... =>/usr/local/bin + cfg["bin"] = sysconfig.get_paths().get("scripts") + if not cfg["lib"]: + raise Exception("cannot estimate binary path, set it with --bin") build_scripts = _rootpath(cfg["bin"]) add_args = [] if cfg["dry-run"]: add_args.append('--dry-run')