From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/, /
Date: Sun, 28 Feb 2021 10:10:19 +0000 (UTC) [thread overview]
Message-ID: <1614505745.695be424d3ef3bba6cf26f6ff70df066e1cd248c.zmedico@gentoo> (raw)
commit: 695be424d3ef3bba6cf26f6ff70df066e1cd248c
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 28 07:34:13 2021 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 28 09:49:05 2021 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=695be424
setup.py: add entry_points when installed with pip
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/util/bin_entry_point.py | 24 ++++++++++++++++++++++++
setup.py | 27 +++++++++++++++++++++------
2 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/lib/portage/util/bin_entry_point.py b/lib/portage/util/bin_entry_point.py
new file mode 100644
index 000000000..7f2ee3849
--- /dev/null
+++ b/lib/portage/util/bin_entry_point.py
@@ -0,0 +1,24 @@
+# Copyright 2021 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+__all__ = ["bin_entry_point"]
+
+import sys
+
+from portage.const import PORTAGE_BIN_PATH
+from portage import os
+
+
+def bin_entry_point():
+ """
+ Adjust sys.argv[0] to point to a script in PORTAGE_BIN_PATH, and
+ then execute the script, in order to implement entry_points when
+ portage has been installed by pip.
+ """
+ script_path = os.path.join(PORTAGE_BIN_PATH, os.path.basename(sys.argv[0]))
+ if os.access(script_path, os.X_OK):
+ sys.argv[0] = script_path
+ os.execvp(sys.argv[0], sys.argv)
+ else:
+ print("File not found:", script_path, file=sys.stderr)
+ return 127
diff --git a/setup.py b/setup.py
index 96d9932e0..7d6fb6609 100755
--- a/setup.py
+++ b/setup.py
@@ -2,6 +2,7 @@
# Copyright 1998-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
+from distutils import sysconfig
from distutils.core import setup, Command, Extension
from distutils.command.build import build
from distutils.command.build_ext import build_ext as _build_ext
@@ -19,6 +20,7 @@ from distutils.util import change_root, subst_vars
import codecs
import collections
import glob
+import itertools
import os
import os.path
import platform
@@ -26,6 +28,12 @@ import re
import subprocess
import sys
+autodetect_pip = os.path.basename(os.environ.get("_", "")) == "pip" or os.path.basename(
+ os.path.dirname(__file__)
+).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 ""
# TODO:
# - smarter rebuilds of docs w/ 'install_docbook' and 'install_apidoc'.
@@ -220,8 +228,9 @@ class x_build_scripts_custom(build_scripts):
self.scripts = x_scripts[self.dir_name]
else:
self.scripts = set(self.scripts)
- for other_files in x_scripts.values():
- self.scripts.difference_update(other_files)
+ if not (create_entry_points and self.dir_name == "portage"):
+ for other_files in x_scripts.values():
+ self.scripts.difference_update(other_files)
def run(self):
# group scripts by subdirectory
@@ -471,9 +480,10 @@ class x_install_lib(install_lib):
'VERSION': self.distribution.get_version(),
})
rewrite_file('portage/const.py', {
- 'PORTAGE_BASE_PATH': self.portage_base,
- 'PORTAGE_BIN_PATH': self.portage_bindir,
- 'PORTAGE_CONFIG_PATH': self.portage_confdir,
+ 'EPREFIX': eprefix,
+ 'GLOBAL_CONFIG_PATH': self.portage_confdir,
+ 'PORTAGE_BASE_PATH': eprefix + self.portage_base,
+ 'PORTAGE_BIN_PATH': eprefix + self.portage_bindir,
})
return ret
@@ -675,7 +685,12 @@ setup(
['$portage_base/bin', ['bin/deprecated-path']],
['$sysconfdir/portage/repo.postsync.d', ['cnf/repo.postsync.d/example']],
],
-
+ entry_points={
+ "console_scripts": [
+ "{}=portage.util.bin_entry_point:bin_entry_point".format(os.path.basename(path))
+ for path in itertools.chain.from_iterable(x_scripts.values())
+ ],
+ } if create_entry_points else {},
ext_modules = [Extension(name=n, sources=m,
extra_compile_args=['-D_FILE_OFFSET_BITS=64',
'-D_LARGEFILE_SOURCE', '-D_LARGEFILE64_SOURCE'])
next reply other threads:[~2021-02-28 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-28 10:10 Zac Medico [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-11-30 22:29 [gentoo-commits] proj/portage:master commit in: lib/portage/util/, / Sam James
2023-07-26 7:58 Sam James
2023-08-02 6:31 Sam James
2023-10-02 21:40 James Le Cuirot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1614505745.695be424d3ef3bba6cf26f6ff70df066e1cd248c.zmedico@gentoo \
--to=zmedico@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox