Skip to content

Commit

Permalink
Merge pull request #2944 from pypa/bugfix/2938-easy-install-schemes
Browse files Browse the repository at this point in the history
Add support for extended install schemes in easy_install.
  • Loading branch information
jaraco committed Dec 20, 2021
2 parents 9288c6f + 4a9d555 commit 9beae2c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 31 deletions.
1 change: 1 addition & 0 deletions changelog.d/2944.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for extended install schemes in easy_install.
65 changes: 42 additions & 23 deletions setuptools/_distutils/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,47 @@ def _get_implementation():
return 'Python'


def _select_scheme(ob, name):
vars(ob).update(_remove_set(ob, _scheme_attrs(_resolve_scheme(name))))


def _remove_set(ob, attrs):
"""
Include only attrs that are None in ob.
"""
return {
key: value
for key, value in attrs.items()
if getattr(ob, key) is None
}


def _resolve_scheme(name):
os_name, sep, key = name.partition('_')
try:
resolved = sysconfig.get_preferred_scheme(key)
except Exception:
resolved = _pypy_hack(name)
return resolved


def _scheme_attrs(name):
"""Resolve install directories by applying the install schemes."""
scheme = _load_schemes()[name]
return {
f'install_{key}': scheme[key]
for key in SCHEME_KEYS
}


def _pypy_hack(name):
PY37 = sys.version_info < (3, 8)
old_pypy = hasattr(sys, 'pypy_version_info') and PY37
prefix = not name.endswith(('_user', '_home'))
pypy_name = 'pypy' + '_nt' * (os.name == 'nt')
return pypy_name if old_pypy and prefix else name


class install(Command):

description = "install everything from build directory"
Expand Down Expand Up @@ -520,29 +561,7 @@ def finalize_other(self):
"I don't know how to install stuff on '%s'" % os.name)

def select_scheme(self, name):
os_name, sep, key = name.partition('_')
try:
resolved = sysconfig.get_preferred_scheme(key)
except Exception:
resolved = self._pypy_hack(name)
return self._select_scheme(resolved)

def _select_scheme(self, name):
"""Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name!
scheme = _load_schemes()[name]
for key in SCHEME_KEYS:
attrname = 'install_' + key
if getattr(self, attrname) is None:
setattr(self, attrname, scheme[key])

@staticmethod
def _pypy_hack(name):
PY37 = sys.version_info < (3, 8)
old_pypy = hasattr(sys, 'pypy_version_info') and PY37
prefix = not name.endswith(('_user', '_home'))
pypy_name = 'pypy' + '_nt' * (os.name == 'nt')
return pypy_name if old_pypy and prefix else name
_select_scheme(self, name)

def _expand_attrs(self, attrs):
for attr in attrs:
Expand Down
21 changes: 13 additions & 8 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
DistutilsArgError, DistutilsOptionError,
DistutilsError, DistutilsPlatformError,
)
from distutils.command.install import INSTALL_SCHEMES, SCHEME_KEYS
from distutils import log, dir_util
from distutils.command.build_scripts import first_line_re
from distutils.spawn import find_executable
from distutils.command import install
import sys
import os
import zipimport
Expand Down Expand Up @@ -251,7 +251,14 @@ def finalize_options(self): # noqa: C901 # is too complex (25) # FIXME
'exec_prefix': exec_prefix,
# Only python 3.2+ has abiflags
'abiflags': getattr(sys, 'abiflags', ''),
'platlibdir': getattr(sys, 'platlibdir', 'lib'),
}
with contextlib.suppress(AttributeError):
# only for distutils outside stdlib
self.config_vars.update({
'implementation_lower': install._get_implementation().lower(),
'implementation': install._get_implementation(),
})

if site.ENABLE_USER_SITE:
self.config_vars['userbase'] = self.install_userbase
Expand Down Expand Up @@ -711,13 +718,11 @@ def install_item(self, spec, download, tmpdir, deps, install_needed=False):
return dist

def select_scheme(self, name):
"""Sets the install directories by applying the install schemes."""
# it's the caller's problem if they supply a bad name!
scheme = INSTALL_SCHEMES[name]
for key in SCHEME_KEYS:
attrname = 'install_' + key
if getattr(self, attrname) is None:
setattr(self, attrname, scheme[key])
try:
install._select_scheme(self, name)
except AttributeError:
# stdlib distutils
install.install.select_scheme(self, name)

# FIXME: 'easy_install.process_distribution' is too complex (12)
def process_distribution( # noqa: C901
Expand Down

0 comments on commit 9beae2c

Please sign in to comment.