Skip to content

Commit

Permalink
runtime changes for typeshed merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Jul 22, 2024
1 parent 08bd311 commit f7b0e67
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions newsfragments/4505.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Changed the order of type checks in ``setuptools.command.easy_install.CommandSpec.from_param`` to support any `collections.abc.Iterable` of `str` param and to always fallback to the environment if the param type is unsupported -- by :user:`Avasam`
3 changes: 1 addition & 2 deletions setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from typing import Iterator
from pathlib import Path

from distutils.command.build_ext import build_ext as _du_build_ext
from distutils.ccompiler import new_compiler
from distutils.sysconfig import customize_compiler, get_config_var
from distutils import log
Expand All @@ -24,7 +23,7 @@
# also. Ref #1229.
__import__('Cython.Compiler.Main')
except ImportError:
_build_ext = _du_build_ext
from distutils.command.build_ext import build_ext as _build_ext

# make sure _config_vars is initialized
get_config_var("LDSHARED")
Expand Down
15 changes: 9 additions & 6 deletions setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from __future__ import annotations

from collections.abc import Iterable
from glob import glob
from distutils.util import get_platform
from distutils.util import convert_path, subst_vars
Expand All @@ -26,6 +27,7 @@
from distutils.command import install
import sys
import os
from typing import TYPE_CHECKING
import zipimport
import shutil
import tempfile
Expand Down Expand Up @@ -78,6 +80,8 @@
from .._path import ensure_directory
from jaraco.text import yield_lines

if TYPE_CHECKING:
from typing_extensions import Self

# Turn on PEP440Warnings
warnings.filterwarnings("default", category=pkg_resources.PEP440Warning)
Expand Down Expand Up @@ -2055,19 +2059,18 @@ def _sys_executable(cls):
return os.environ.get('__PYVENV_LAUNCHER__', _default)

@classmethod
def from_param(cls, param):
def from_param(cls, param: Self | str | Iterable[str] | None) -> Self:
"""
Construct a CommandSpec from a parameter to build_scripts, which may
be None.
"""
if isinstance(param, cls):
return param
if isinstance(param, list):
if isinstance(param, str):
return cls.from_string(param)
if isinstance(param, Iterable):
return cls(param)
if param is None:
return cls.from_environment()
# otherwise, assume it's a string.
return cls.from_string(param)
return cls.from_environment()

@classmethod
def from_environment(cls):
Expand Down
2 changes: 1 addition & 1 deletion setuptools/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def assert_string_list(dist, attr, value):
try:
# verify that value is a list or tuple to exclude unordered
# or single-use iterables
assert isinstance(value, (list, tuple))
assert isinstance(value, sequence)
# verify that elements of value are strings
assert ''.join(value) != value
except (TypeError, ValueError, AttributeError, AssertionError) as e:
Expand Down
7 changes: 5 additions & 2 deletions setuptools/extension.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import annotations
import re
import functools
import distutils.core
Expand Down Expand Up @@ -126,10 +127,12 @@ class Extension(_Extension):
specified on Windows. (since v63)
"""

def __init__(self, name, sources, *args, **kw):
def __init__(
self, name: str, sources: list[str], *args, py_limited_api: bool = False, **kw
):
# The *args is needed for compatibility as calls may use positional
# arguments. py_limited_api may be set only via keyword.
self.py_limited_api = kw.pop("py_limited_api", False)
self.py_limited_api = py_limited_api
super().__init__(name, sources, *args, **kw)

def _convert_pyx_sources_to_lang(self):
Expand Down

0 comments on commit f7b0e67

Please sign in to comment.