Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle distutils deprecation #7766

Merged
merged 2 commits into from
Apr 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 5 additions & 48 deletions src/poetry/utils/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import subprocess
import sys
import sysconfig
import warnings

from contextlib import contextmanager
from copy import deepcopy
Expand Down Expand Up @@ -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))
"""
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/extended_with_no_setup/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/extended_with_no_setup/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"