aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2021-03-03 04:39:15 -0800
committerZac Medico <zmedico@gentoo.org>2021-03-03 23:17:21 -0800
commit48c08a284d4f2916404682bcab9980d9a5c66c06 (patch)
treece01dadff48296aa74667f5948c74e890087f022 /setup.py
parentbin_entry_point: rewrite python shebangs for venv (diff)
downloadportage-48c08a284d4f2916404682bcab9980d9a5c66c06.tar.gz
portage-48c08a284d4f2916404682bcab9980d9a5c66c06.tar.bz2
portage-48c08a284d4f2916404682bcab9980d9a5c66c06.zip
setup.py: fix EPREFIX and PORTAGE_BASE_PATH for pip install
Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'setup.py')
-rwxr-xr-xsetup.py51
1 files changed, 44 insertions, 7 deletions
diff --git a/setup.py b/setup.py
index 311f66dfd..343921525 100755
--- a/setup.py
+++ b/setup.py
@@ -33,7 +33,7 @@ autodetect_pip = os.path.basename(os.environ.get("_", "")) == "pip" or os.path.b
).startswith("pip-")
venv_prefix = "" if sys.prefix == sys.base_prefix else sys.prefix
create_entry_points = bool(autodetect_pip or venv_prefix)
-eprefix = sysconfig.get_python_lib() if venv_prefix else ""
+eprefix = ""
with open(os.path.join(os.path.dirname(__file__), 'README'), 'rt') as f:
long_description = f.read()
@@ -497,12 +497,49 @@ class x_install_lib(install_lib):
rewrite_file('portage/__init__.py', {
'VERSION': self.distribution.get_version(),
})
- rewrite_file('portage/const.py', {
- 'EPREFIX': eprefix,
- 'GLOBAL_CONFIG_PATH': self.portage_confdir,
- 'PORTAGE_BASE_PATH': eprefix + self.portage_base,
- 'PORTAGE_BIN_PATH': eprefix + self.portage_bindir,
- })
+
+ def re_sub_file(path, pattern_repl_items):
+ path = os.path.join(self.install_dir, path)
+ print("Rewriting %s" % path)
+ with codecs.open(path, "r", "utf-8") as f:
+ data = f.read()
+ for pattern, repl in pattern_repl_items:
+ data = re.sub(pattern, repl, data, flags=re.MULTILINE)
+ with codecs.open(path, "w", "utf-8") as f:
+ f.write(data)
+
+ val_dict = {
+ "GLOBAL_CONFIG_PATH": self.portage_confdir,
+ }
+ if create_entry_points:
+ re_sub_file(
+ "portage/const.py",
+ (
+ (
+ "^(PORTAGE_BASE_PATH\s*=\s*)(.*)",
+ lambda m: "{}{}".format(
+ m.group(1),
+ 'os.path.realpath(os.path.join(__file__, "../../usr/lib/portage"))',
+ ),
+ ),
+ (
+ "^(EPREFIX\s*=\s*)(.*)",
+ lambda m: "{}{}".format(
+ m.group(1),
+ 'os.path.realpath(os.path.join(__file__, "../.."))',
+ ),
+ ),
+ ),
+ )
+ else:
+ val_dict.update(
+ {
+ "EPREFIX": eprefix,
+ "PORTAGE_BASE_PATH": eprefix + self.portage_base,
+ "PORTAGE_BIN_PATH": eprefix + self.portage_bindir,
+ }
+ )
+ rewrite_file("portage/const.py", val_dict)
return ret