commit:     48c08a284d4f2916404682bcab9980d9a5c66c06
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Mar  3 12:39:15 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Mar  4 07:17:21 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=48c08a28

setup.py: fix EPREFIX and PORTAGE_BASE_PATH for pip install

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 setup.py | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 file 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
 

Reply via email to