Gentoo Archives: gentoo-commits

From: Zac Medico <zmedico@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
Date: Sun, 28 Feb 2021 10:10:23
Message-Id: 1614505745.695be424d3ef3bba6cf26f6ff70df066e1cd248c.zmedico@gentoo
1 commit: 695be424d3ef3bba6cf26f6ff70df066e1cd248c
2 Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
3 AuthorDate: Sun Feb 28 07:34:13 2021 +0000
4 Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
5 CommitDate: Sun Feb 28 09:49:05 2021 +0000
6 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=695be424
7
8 setup.py: add entry_points when installed with pip
9
10 Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
11
12 lib/portage/util/bin_entry_point.py | 24 ++++++++++++++++++++++++
13 setup.py | 27 +++++++++++++++++++++------
14 2 files changed, 45 insertions(+), 6 deletions(-)
15
16 diff --git a/lib/portage/util/bin_entry_point.py b/lib/portage/util/bin_entry_point.py
17 new file mode 100644
18 index 000000000..7f2ee3849
19 --- /dev/null
20 +++ b/lib/portage/util/bin_entry_point.py
21 @@ -0,0 +1,24 @@
22 +# Copyright 2021 Gentoo Authors
23 +# Distributed under the terms of the GNU General Public License v2
24 +
25 +__all__ = ["bin_entry_point"]
26 +
27 +import sys
28 +
29 +from portage.const import PORTAGE_BIN_PATH
30 +from portage import os
31 +
32 +
33 +def bin_entry_point():
34 + """
35 + Adjust sys.argv[0] to point to a script in PORTAGE_BIN_PATH, and
36 + then execute the script, in order to implement entry_points when
37 + portage has been installed by pip.
38 + """
39 + script_path = os.path.join(PORTAGE_BIN_PATH, os.path.basename(sys.argv[0]))
40 + if os.access(script_path, os.X_OK):
41 + sys.argv[0] = script_path
42 + os.execvp(sys.argv[0], sys.argv)
43 + else:
44 + print("File not found:", script_path, file=sys.stderr)
45 + return 127
46
47 diff --git a/setup.py b/setup.py
48 index 96d9932e0..7d6fb6609 100755
49 --- a/setup.py
50 +++ b/setup.py
51 @@ -2,6 +2,7 @@
52 # Copyright 1998-2021 Gentoo Authors
53 # Distributed under the terms of the GNU General Public License v2
54
55 +from distutils import sysconfig
56 from distutils.core import setup, Command, Extension
57 from distutils.command.build import build
58 from distutils.command.build_ext import build_ext as _build_ext
59 @@ -19,6 +20,7 @@ from distutils.util import change_root, subst_vars
60 import codecs
61 import collections
62 import glob
63 +import itertools
64 import os
65 import os.path
66 import platform
67 @@ -26,6 +28,12 @@ import re
68 import subprocess
69 import sys
70
71 +autodetect_pip = os.path.basename(os.environ.get("_", "")) == "pip" or os.path.basename(
72 + os.path.dirname(__file__)
73 +).startswith("pip-")
74 +venv_prefix = "" if sys.prefix == sys.base_prefix else sys.prefix
75 +create_entry_points = bool(autodetect_pip or venv_prefix)
76 +eprefix = sysconfig.get_python_lib() if venv_prefix else ""
77
78 # TODO:
79 # - smarter rebuilds of docs w/ 'install_docbook' and 'install_apidoc'.
80 @@ -220,8 +228,9 @@ class x_build_scripts_custom(build_scripts):
81 self.scripts = x_scripts[self.dir_name]
82 else:
83 self.scripts = set(self.scripts)
84 - for other_files in x_scripts.values():
85 - self.scripts.difference_update(other_files)
86 + if not (create_entry_points and self.dir_name == "portage"):
87 + for other_files in x_scripts.values():
88 + self.scripts.difference_update(other_files)
89
90 def run(self):
91 # group scripts by subdirectory
92 @@ -471,9 +480,10 @@ class x_install_lib(install_lib):
93 'VERSION': self.distribution.get_version(),
94 })
95 rewrite_file('portage/const.py', {
96 - 'PORTAGE_BASE_PATH': self.portage_base,
97 - 'PORTAGE_BIN_PATH': self.portage_bindir,
98 - 'PORTAGE_CONFIG_PATH': self.portage_confdir,
99 + 'EPREFIX': eprefix,
100 + 'GLOBAL_CONFIG_PATH': self.portage_confdir,
101 + 'PORTAGE_BASE_PATH': eprefix + self.portage_base,
102 + 'PORTAGE_BIN_PATH': eprefix + self.portage_bindir,
103 })
104
105 return ret
106 @@ -675,7 +685,12 @@ setup(
107 ['$portage_base/bin', ['bin/deprecated-path']],
108 ['$sysconfdir/portage/repo.postsync.d', ['cnf/repo.postsync.d/example']],
109 ],
110 -
111 + entry_points={
112 + "console_scripts": [
113 + "{}=portage.util.bin_entry_point:bin_entry_point".format(os.path.basename(path))
114 + for path in itertools.chain.from_iterable(x_scripts.values())
115 + ],
116 + } if create_entry_points else {},
117 ext_modules = [Extension(name=n, sources=m,
118 extra_compile_args=['-D_FILE_OFFSET_BITS=64',
119 '-D_LARGEFILE_SOURCE', '-D_LARGEFILE64_SOURCE'])