summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2020-07-08 20:42:40 -0400
committerJason R. Coombs <jaraco@jaraco.com>2020-07-08 20:42:40 -0400
commitcafc9f4d3a840f16dcaf096a76f0a7965ad264bf (patch)
tree19b09c7fdb7e061a244319e6744ef561d9973ef2
parentec410c356578b5c51aec9a76b2f1de38f788b167 (diff)
parent9ec01c3a48fa9ae5c188ec5a8d9c77f06df47d09 (diff)
downloadpython-setuptools-git-bugfix/2232-ubuntu-patch.tar.gz
Merge https://github.com/pypa/distutils into bugfix/2232-ubuntu-patchbugfix/2232-ubuntu-patch
-rw-r--r--setuptools/_distutils/_platform.py21
-rw-r--r--setuptools/_distutils/command/install.py46
-rw-r--r--setuptools/_distutils/command/install_egg_info.py31
-rw-r--r--setuptools/_distutils/sysconfig.py7
-rw-r--r--setuptools/_distutils/tests/test_bdist_dumb.py8
-rw-r--r--setuptools/_distutils/tests/test_install.py3
6 files changed, 109 insertions, 7 deletions
diff --git a/setuptools/_distutils/_platform.py b/setuptools/_distutils/_platform.py
new file mode 100644
index 00000000..b03659a9
--- /dev/null
+++ b/setuptools/_distutils/_platform.py
@@ -0,0 +1,21 @@
+import re
+import pathlib
+import contextlib
+
+
+# from jaraco.context
+class suppress(contextlib.suppress, contextlib.ContextDecorator):
+ """
+ A version of contextlib.suppress with decorator support.
+
+ >>> @suppress(KeyError)
+ ... def key_error():
+ ... {}['']
+ >>> key_error()
+ """
+
+
+@suppress(Exception)
+def is_debian():
+ issue = pathlib.Path('/etc/issue').read_text()
+ return bool(re.search('(debian|buntu|mint)', issue, re.IGNORE_CASE))
diff --git a/setuptools/_distutils/command/install.py b/setuptools/_distutils/command/install.py
index 13feeb89..889e683d 100644
--- a/setuptools/_distutils/command/install.py
+++ b/setuptools/_distutils/command/install.py
@@ -14,6 +14,7 @@ from distutils.file_util import write_file
from distutils.util import convert_path, subst_vars, change_root
from distutils.util import get_platform
from distutils.errors import DistutilsOptionError
+from distutils._platform import is_debian
from site import USER_BASE
from site import USER_SITE
@@ -35,6 +36,20 @@ INSTALL_SCHEMES = {
'scripts': '$base/bin',
'data' : '$base',
},
+ 'unix_local': {
+ 'purelib': '$base/local/lib/python$py_version_short/dist-packages',
+ 'platlib': '$platbase/local/lib/python$py_version_short/dist-packages',
+ 'headers': '$base/local/include/python$py_version_short/$dist_name',
+ 'scripts': '$base/local/bin',
+ 'data' : '$base/local',
+ },
+ 'deb_system': {
+ 'purelib': '$base/lib/python3/dist-packages',
+ 'platlib': '$platbase/lib/python3/dist-packages',
+ 'headers': '$base/include/python$py_version_short/$dist_name',
+ 'scripts': '$base/bin',
+ 'data' : '$base',
+ },
'unix_home': {
'purelib': '$base/lib/python',
'platlib': '$base/$platlibdir/python',
@@ -145,6 +160,9 @@ class install(Command):
('record=', None,
"filename in which to record list of installed files"),
+
+ ('install-layout=', None,
+ "installation layout to choose (known values: deb, unix)"),
]
boolean_options = ['compile', 'force', 'skip-build']
@@ -165,6 +183,7 @@ class install(Command):
self.exec_prefix = None
self.home = None
self.user = 0
+ self.prefix_option = None
# These select only the installation base; it's up to the user to
# specify the installation scheme (currently, that means supplying
@@ -186,6 +205,9 @@ class install(Command):
self.install_userbase = USER_BASE
self.install_usersite = USER_SITE
+ # enable custom installation, known values: deb
+ self.install_layout = None
+
self.compile = None
self.optimize = None
@@ -428,6 +450,7 @@ class install(Command):
self.install_base = self.install_platbase = self.home
self.select_scheme("unix_home")
else:
+ self.prefix_option = self.prefix
if self.prefix is None:
if self.exec_prefix is not None:
raise DistutilsOptionError(
@@ -442,7 +465,28 @@ class install(Command):
self.install_base = self.prefix
self.install_platbase = self.exec_prefix
- self.select_scheme("unix_prefix")
+ if self.install_layout:
+ if self.install_layout.lower() in ['deb']:
+ self.select_scheme("deb_system")
+ elif self.install_layout.lower() in ['unix']:
+ self.select_scheme("unix_prefix")
+ else:
+ raise DistutilsOptionError(
+ "unknown value for --install-layout")
+ elif ((self.prefix_option and
+ os.path.normpath(self.prefix) != '/usr/local')
+ or sys.base_prefix != sys.prefix
+ or 'PYTHONUSERBASE' in os.environ
+ or 'VIRTUAL_ENV' in os.environ
+ or 'real_prefix' in sys.__dict__):
+ self.select_scheme("unix_prefix")
+ elif is_debian():
+ if os.path.normpath(self.prefix) == '/usr/local':
+ self.prefix = self.exec_prefix = '/usr'
+ self.install_base = self.install_platbase = '/usr'
+ self.select_scheme("unix_local")
+ else:
+ self.select_scheme("unix_prefix")
def finalize_other(self):
"""Finalizes options for non-posix platforms"""
diff --git a/setuptools/_distutils/command/install_egg_info.py b/setuptools/_distutils/command/install_egg_info.py
index 0ddc7367..a9b6067a 100644
--- a/setuptools/_distutils/command/install_egg_info.py
+++ b/setuptools/_distutils/command/install_egg_info.py
@@ -6,6 +6,7 @@ a package's PKG-INFO metadata."""
from distutils.cmd import Command
from distutils import log, dir_util
+from distutils._platform import is_debian
import os, sys, re
class install_egg_info(Command):
@@ -14,18 +15,38 @@ class install_egg_info(Command):
description = "Install package's PKG-INFO metadata as an .egg-info file"
user_options = [
('install-dir=', 'd', "directory to install to"),
+ ('install-layout', None, "custom installation layout"),
]
def initialize_options(self):
self.install_dir = None
+ self.install_layout = None
+ self.prefix_option = None
def finalize_options(self):
self.set_undefined_options('install_lib',('install_dir','install_dir'))
- basename = "%s-%s-py%d.%d.egg-info" % (
- to_filename(safe_name(self.distribution.get_name())),
- to_filename(safe_version(self.distribution.get_version())),
- *sys.version_info[:2]
- )
+ self.set_undefined_options('install',('install_layout','install_layout'))
+ self.set_undefined_options('install',('prefix_option','prefix_option'))
+ if self.install_layout:
+ if not self.install_layout.lower() in ['deb', 'unix']:
+ raise DistutilsOptionError(
+ "unknown value for --install-layout")
+ no_pyver = (self.install_layout.lower() == 'deb')
+ elif self.prefix_option:
+ no_pyver = False
+ else:
+ no_pyver = is_debian()
+ if no_pyver:
+ basename = "%s-%s.egg-info" % (
+ to_filename(safe_name(self.distribution.get_name())),
+ to_filename(safe_version(self.distribution.get_version()))
+ )
+ else:
+ basename = "%s-%s-py%d.%d.egg-info" % (
+ to_filename(safe_name(self.distribution.get_name())),
+ to_filename(safe_version(self.distribution.get_version())),
+ *sys.version_info[:2]
+ )
self.target = os.path.join(self.install_dir, basename)
self.outputs = [self.target]
diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py
index 879b6981..8e42b7b8 100644
--- a/setuptools/_distutils/sysconfig.py
+++ b/setuptools/_distutils/sysconfig.py
@@ -150,6 +150,7 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
return os.path.join(prefix, "lib-python", sys.version[0])
return os.path.join(prefix, 'site-packages')
+ is_default_prefix = not prefix or os.path.normpath(prefix) in ('/usr', '/usr/local')
if prefix is None:
if standard_lib:
prefix = plat_specific and BASE_EXEC_PREFIX or BASE_PREFIX
@@ -168,6 +169,12 @@ def get_python_lib(plat_specific=0, standard_lib=0, prefix=None):
"python" + get_python_version())
if standard_lib:
return libpython
+ elif (is_default_prefix and
+ 'PYTHONUSERBASE' not in os.environ and
+ 'VIRTUAL_ENV' not in os.environ and
+ 'real_prefix' not in sys.__dict__ and
+ sys.prefix == sys.base_prefix):
+ return os.path.join(prefix, "lib", "python3", "dist-packages")
else:
return os.path.join(libpython, "site-packages")
elif os.name == "nt":
diff --git a/setuptools/_distutils/tests/test_bdist_dumb.py b/setuptools/_distutils/tests/test_bdist_dumb.py
index 01a233bc..e58d775d 100644
--- a/setuptools/_distutils/tests/test_bdist_dumb.py
+++ b/setuptools/_distutils/tests/test_bdist_dumb.py
@@ -9,6 +9,7 @@ from test.support import run_unittest
from distutils.core import Distribution
from distutils.command.bdist_dumb import bdist_dumb
from distutils.tests import support
+from distutils._platform import is_debian
SETUP_PY = """\
from distutils.core import setup
@@ -85,7 +86,12 @@ class BuildDumbTestCase(support.TempdirManager,
fp.close()
contents = sorted(filter(None, map(os.path.basename, contents)))
- wanted = ['foo-0.1-py%s.%s.egg-info' % sys.version_info[:2], 'foo.py']
+ egg_info_name = (
+ 'foo-0.1.egg-info' if is_debian() else
+ 'foo-0.1-py%s.%s.egg-info' % sys.version_info[:2]
+ )
+ wanted = [egg_info_name, 'foo.py']
+
if not sys.dont_write_bytecode:
wanted.append('foo.%s.pyc' % sys.implementation.cache_tag)
self.assertEqual(contents, sorted(wanted))
diff --git a/setuptools/_distutils/tests/test_install.py b/setuptools/_distutils/tests/test_install.py
index eb684a09..907442bb 100644
--- a/setuptools/_distutils/tests/test_install.py
+++ b/setuptools/_distutils/tests/test_install.py
@@ -15,6 +15,7 @@ from distutils.command.install import INSTALL_SCHEMES
from distutils.core import Distribution
from distutils.errors import DistutilsOptionError
from distutils.extension import Extension
+from distutils._platform import is_debian
from distutils.tests import support
from test import support as test_support
@@ -195,6 +196,7 @@ class InstallTestCase(support.TempdirManager,
found = [os.path.basename(line) for line in content.splitlines()]
expected = ['hello.py', 'hello.%s.pyc' % sys.implementation.cache_tag,
'sayhi',
+ 'UNKNOWN-0.0.0.egg-info' if is_debian() else
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
self.assertEqual(found, expected)
@@ -228,6 +230,7 @@ class InstallTestCase(support.TempdirManager,
found = [os.path.basename(line) for line in content.splitlines()]
expected = [_make_ext_name('xx'),
+ 'UNKNOWN-0.0.0.egg-info' if is_debian() else
'UNKNOWN-0.0.0-py%s.%s.egg-info' % sys.version_info[:2]]
self.assertEqual(found, expected)