commit:     708ba6d6ef40b528e9ac344f88cbe10d0a78e3ce
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Jun 23 02:33:56 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Jun 23 11:08:27 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=708ba6d6

setup.py: align venv EPREFIX with sys.prefix

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

 setup.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 72 insertions(+), 8 deletions(-)

diff --git a/setup.py b/setup.py
index 879e0ca5e..fb4d5c1a5 100755
--- a/setup.py
+++ b/setup.py
@@ -519,26 +519,29 @@ class x_install_lib(install_lib):
 
                val_dict = {}
                if create_entry_points:
-                       val_dict.update(
-                               {
-                                       "GLOBAL_CONFIG_PATH": 
self.portage_confdir,
-                               }
-                       )
                        re_sub_file(
                                "portage/const.py",
                                (
+                                       (
+                                               
r"^(GLOBAL_CONFIG_PATH\s*=\s*[\"'])(.*)([\"'])",
+                                               lambda m: "{}{}{}".format(
+                                                       m.group(1),
+                                                       
m.group(2).partition("/usr")[-1],
+                                                       m.group(3),
+                                               ),
+                                       ),
                                        (
                                                
r"^(PORTAGE_BASE_PATH\s*=\s*)(.*)",
                                                lambda m: "{}{}".format(
                                                        m.group(1),
-                                                       
'os.path.realpath(os.path.join(__file__, "../../usr/lib/portage"))',
+                                                       
'os.path.join(os.path.realpath(__import__("sys").prefix), "lib/portage")',
                                                ),
                                        ),
                                        (
                                                r"^(EPREFIX\s*=\s*)(.*)",
                                                lambda m: "{}{}".format(
                                                        m.group(1),
-                                                       
'os.path.realpath(os.path.join(__file__, "../.."))',
+                                                       
'__import__("sys").prefix',
                                                ),
                                        ),
                                ),
@@ -571,6 +574,10 @@ class x_install_scripts_custom(install_scripts):
                if self.root is not None:
                        self.install_dir = change_root(self.root, 
self.install_dir)
 
+       def run(self):
+               if not create_entry_points:
+                       install_scripts.run(self)
+
 
 class x_install_scripts_bin(x_install_scripts_custom):
        dir_name = 'bin'
@@ -732,6 +739,48 @@ class build_ext(_build_ext):
                        _build_ext.run(self)
 
 
+def venv_data_files(locations):
+       if not create_entry_points:
+               return
+       for dest_prefix, source_path, file_args in locations:
+               specific_files = []
+               mode_arg = None
+               for arg in file_args:
+                       if arg.startswith("-m"):
+                               mode_arg = int(arg[2:], 8)
+                       else:
+                               specific_files.append(arg)
+
+               abs_source_path = os.path.abspath(source_path)
+               for root, dirs, files in os.walk(abs_source_path):
+
+                       root_offset = root[len(abs_source_path) :].lstrip("/")
+                       dest_path = os.path.join(dest_prefix, root_offset)
+
+                       if specific_files:
+                               matched_files = list(
+                                       itertools.chain.from_iterable(
+                                               glob.glob(os.path.join(root, 
x)) for x in specific_files
+                                       )
+                               )
+                       else:
+                               matched_files = [os.path.join(root, x) for x in 
files]
+
+                       if mode_arg:
+                               for filename in matched_files:
+                                       if not os.path.islink(filename):
+                                               os.chmod(filename, mode_arg)
+
+                       yield (dest_path, matched_files)
+
+
+def get_data_files(regular_files, venv_files):
+       if create_entry_points:
+               return list(venv_data_files(venv_files))
+
+       return regular_files
+
+
 setup(
        name = 'portage',
        version = '3.0.20',
@@ -752,7 +801,7 @@ setup(
        # something to cheat build & install commands
        scripts = list(find_scripts()),
 
-       data_files = list(get_manpages()) + [
+       data_files = get_data_files(list(get_manpages()) + [
                ['$sysconfdir', ['cnf/etc-update.conf', 
'cnf/dispatch-conf.conf']],
                ['$logrotatedir', ['cnf/logrotate.d/elog-save-summary']],
                ['$portage_confdir', [
@@ -762,6 +811,21 @@ setup(
                ['$portage_base/bin', ['bin/deprecated-path']],
                ['$sysconfdir/portage/repo.postsync.d', 
['cnf/repo.postsync.d/example']],
        ],
+       [
+               ("etc", "cnf", ("etc-update.conf", "dispatch-conf.conf")),
+               ("etc/logrotate.d", "cnf/logrotate.d", ("elog-save-summary",)),
+               ("etc/portage/repo.postsync.d", "cnf/repo.postsync.d", 
("example",)),
+               (
+                       "share/portage/config",
+                       "cnf",
+                       ("make.conf.example", "make.globals", "repos.conf"),
+               ),
+               ("share/portage/config/sets", "cnf/sets", ("*.conf",)),
+               ("share/man/man1", "man", ("*.1",)),
+               ("share/man/man5", "man", ("*.5",)),
+               ("share/portage/doc", "", ("NEWS", "RELEASE-NOTES")),
+               ("lib/portage/bin", "bin", ("-m0755",)),
+       ]),
        entry_points={
                "console_scripts": [
                        
"{}=portage.util.bin_entry_point:bin_entry_point".format(os.path.basename(path))

Reply via email to