From 495a595af35f987e8b5af68498aafa8f523552fd Mon Sep 17 00:00:00 2001 From: David Hotham Date: Tue, 4 Apr 2023 20:52:22 +0100 Subject: [PATCH 1/2] handle distutils deprecation --- src/poetry/utils/env.py | 53 ++++------------------------------------- 1 file changed, 5 insertions(+), 48 deletions(-) diff --git a/src/poetry/utils/env.py b/src/poetry/utils/env.py index 0c1d3df8741..5122d69a597 100644 --- a/src/poetry/utils/env.py +++ b/src/poetry/utils/env.py @@ -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 From 988410f2de22c63954386264ebe74eecb245e404 Mon Sep 17 00:00:00 2001 From: David Hotham Date: Sun, 16 Apr 2023 13:20:28 +0100 Subject: [PATCH 2/2] more distutils deprecation --- tests/fixtures/extended_with_no_setup/build.py | 8 ++++---- tests/fixtures/extended_with_no_setup/pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/fixtures/extended_with_no_setup/build.py b/tests/fixtures/extended_with_no_setup/build.py index 3ef8cfae13a..12538fe8bb3 100644 --- a/tests/fixtures/extended_with_no_setup/build.py +++ b/tests/fixtures/extended_with_no_setup/build.py @@ -3,9 +3,9 @@ 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"])] @@ -13,7 +13,7 @@ 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() diff --git a/tests/fixtures/extended_with_no_setup/pyproject.toml b/tests/fixtures/extended_with_no_setup/pyproject.toml index 779fb1bd9dc..2e3b7273336 100644 --- a/tests/fixtures/extended_with_no_setup/pyproject.toml +++ b/tests/fixtures/extended_with_no_setup/pyproject.toml @@ -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"