Skip to content

Commit

Permalink
Prefer sysconfig over distutils
Browse files Browse the repository at this point in the history
distutils will be removed in python3.10, and is now deprecated.
  • Loading branch information
gaborbernat committed Sep 26, 2020
1 parent 4bcf20e commit caab966
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/virtualenv/create/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def bin_dir(self):

@property
def script_dir(self):
return self.dest / Path(self.interpreter.distutils_install["scripts"])
return Path(self.interpreter.sysconfig_path("scripts", config_var=self._config_vars))

@property
def purelib(self):
return self.dest / self.interpreter.distutils_install["purelib"]
return Path(self.interpreter.sysconfig_path("purelib", config_var=self._config_vars))

@property
def platlib(self):
return self.dest / self.interpreter.distutils_install["platlib"]
return Path(self.interpreter.sysconfig_path("platlib", config_var=self._config_vars))

@property
def libs(self):
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/create/via_global_ref/_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

def patch_dist(dist):
"""
Distutils allows user to configure some arguments via a configuration file:
distutils allows user to configure some arguments via a configuration file:
https://docs.python.org/3/install/index.html#distutils-configuration-files
Some of this arguments though don't make sense in context of the virtual environment files, let's fix them up.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def host_include_marker(cls, interpreter):

@property
def include(self):
# the pattern include the distribution name too at the end, remove that via the parent call
return (self.dest / self.interpreter.distutils_install["headers"]).parent
# the pattern includes the distribution name too at the end, remove that via the parent call
return Path(self.interpreter.sysconfig_path("include", config_var=self._config_vars)).parent

@classmethod
def modules(cls):
Expand Down
2 changes: 1 addition & 1 deletion src/virtualenv/create/via_global_ref/builtin/pypy/pypy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def host_include_marker(cls, interpreter):

@property
def include(self):
return self.dest / self.interpreter.distutils_install["headers"]
return Path(self.interpreter.sysconfig_path("include", config_var=self._config_vars))

@classmethod
def modules(cls):
Expand Down
7 changes: 5 additions & 2 deletions src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import sys
import sysconfig
from collections import OrderedDict, namedtuple
from distutils import dist
from distutils.command.install import SCHEME_KEYS
from string import digits

VersionInfo = namedtuple("VersionInfo", ["major", "minor", "micro", "releaselevel", "serial"])
Expand Down Expand Up @@ -122,6 +120,11 @@ def _fast_get_system_executable(self):
def _distutils_install():
# follow https://github.com/pypa/pip/blob/main/src/pip/_internal/locations.py#L95
# note here we don't import Distribution directly to allow setuptools to patch it
try:
from distutils import dist
from distutils.command.install import SCHEME_KEYS
except ImportError:
return {}
d = dist.Distribution({"script_args": "--no-user-cfg"}) # conf files not parsed so they do not hijack paths
if hasattr(sys, "_framework"):
sys._framework = None # disable macOS static paths for framework
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/discovery/py_info/test_py_info_exe_based_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_discover_empty_folder(tmp_path, monkeypatch, session_app_data):
CURRENT.discover_exe(session_app_data, prefix=str(tmp_path))


BASE = (CURRENT.distutils_install["scripts"], ".")
BASE = (Path(CURRENT.sysconfig_paths["scripts"]).name, ".")


@pytest.mark.skipif(not fs_supports_symlink(), reason="symlink is not supported")
Expand Down

0 comments on commit caab966

Please sign in to comment.