diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-20 11:49:26 -0500 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2021-12-20 11:49:26 -0500 |
commit | 5807a33dd87bf8f4909bae37e25d30d5605dc9c5 (patch) | |
tree | af16463243c2bb1d7095121fbd86994f1381d961 /setuptools/_distutils/command | |
parent | 9288c6f3f039bf51f997a99ae8766ed02ed92cda (diff) | |
parent | aefe5d10cda2692f5ea63e5f130a9c8be288b0f4 (diff) | |
download | python-setuptools-git-5807a33dd87bf8f4909bae37e25d30d5605dc9c5.tar.gz |
Merge https://github.com/pypa/distutils into bugfix/2938-easy-install-schemes
Diffstat (limited to 'setuptools/_distutils/command')
-rw-r--r-- | setuptools/_distutils/command/install.py | 65 |
1 files changed, 42 insertions, 23 deletions
diff --git a/setuptools/_distutils/command/install.py b/setuptools/_distutils/command/install.py index 80f5f8c7..40be5ba6 100644 --- a/setuptools/_distutils/command/install.py +++ b/setuptools/_distutils/command/install.py @@ -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" @@ -520,29 +561,7 @@ class install(Command): "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: |