Skip to content

Commit

Permalink
handle distutils deprecation (#7766)
Browse files Browse the repository at this point in the history
dimbleby authored Apr 30, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5dab851 commit 3804a13
Showing 3 changed files with 10 additions and 53 deletions.
53 changes: 5 additions & 48 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,6 @@
import subprocess
import sys
import sysconfig
import warnings

from contextlib import contextmanager
from copy import deepcopy
@@ -190,33 +189,15 @@ def _version_nodot(version):
"""

GET_PATHS_FOR_GENERIC_ENVS = """\
# We can't use sysconfig.get_paths() because
# on some distributions it does not return the proper paths
# (those used by pip for instance). We go through distutils
# to get the proper ones.
import json
import site
import sysconfig
from distutils.command.install import SCHEME_KEYS
from distutils.core import Distribution
d = Distribution()
d.parse_config_files()
obj = d.get_command_obj("install", create=True)
obj.finalize_options()
paths = sysconfig.get_paths().copy()
for key in SCHEME_KEYS:
if key == "headers":
# headers is not a path returned by sysconfig.get_paths()
continue
paths[key] = getattr(obj, f"install_{key}")
if site.check_enableusersite() and hasattr(obj, "install_usersite"):
paths["usersite"] = getattr(obj, "install_usersite")
paths["userbase"] = getattr(obj, "install_userbase")
if site.check_enableusersite():
paths["usersite"] = site.getusersitepackages()
paths["userbase"] = site.getuserbase()
print(json.dumps(paths))
"""
@@ -1637,37 +1618,13 @@ def get_python_implementation(self) -> str:
return platform.python_implementation()

def get_paths(self) -> dict[str, str]:
# We can't use sysconfig.get_paths() because
# on some distributions it does not return the proper paths
# (those used by pip for instance). We go through distutils
# to get the proper ones.
import site

from distutils.command.install import SCHEME_KEYS
from distutils.core import Distribution

d = Distribution()
d.parse_config_files()
with warnings.catch_warnings():
warnings.filterwarnings("ignore", "setup.py install is deprecated")
obj = d.get_command_obj("install", create=True)
assert obj is not None
obj.finalize_options()

paths = sysconfig.get_paths().copy()
for key in SCHEME_KEYS:
if key == "headers":
# headers is not a path returned by sysconfig.get_paths()
continue

paths[key] = getattr(obj, f"install_{key}")

if site.check_enableusersite():
usersite = getattr(obj, "install_usersite", None)
userbase = getattr(obj, "install_userbase", None)
if usersite is not None and userbase is not None:
paths["usersite"] = usersite
paths["userbase"] = userbase
paths["usersite"] = site.getusersitepackages()
paths["userbase"] = site.getuserbase()

return paths

8 changes: 4 additions & 4 deletions tests/fixtures/extended_with_no_setup/build.py
Original file line number Diff line number Diff line change
@@ -3,17 +3,17 @@
import os
import shutil

from distutils.command.build_ext import build_ext
from distutils.core import Distribution
from distutils.core import Extension
from setuptools import Distribution
from setuptools import Extension
from setuptools.command.build_ext import build_ext


extensions = [Extension("extended.extended", ["extended/extended.c"])]


def build():
distribution = Distribution({"name": "extended", "ext_modules": extensions})
distribution.package_dir = "extended"
distribution.package_dir = {"extended": "extended"}

cmd = build_ext(distribution)
cmd.ensure_finalized()
2 changes: 1 addition & 1 deletion tests/fixtures/extended_with_no_setup/pyproject.toml
Original file line number Diff line number Diff line change
@@ -22,5 +22,5 @@ script = "build.py"
generate-setup-file = false

[build-system]
requires = ["poetry-core>=1.5.0"]
requires = ["poetry-core>=1.5.0", "setuptools>=67.6.1"]
build-backend = "poetry.core.masonry.api"

0 comments on commit 3804a13

Please sign in to comment.