This commit is contained in:
ton
2024-10-07 10:13:40 +07:00
parent aa1631742f
commit 3a7d696db6
9729 changed files with 1832837 additions and 161742 deletions

View File

@@ -26,7 +26,7 @@ class Extension:
name : string
the full name of the extension, including any packages -- ie.
*not* a filename or pathname, but Python dotted name
sources : [string]
sources : [string | os.PathLike]
list of source filenames, relative to the distribution root
(where the setup script lives), in Unix form (slash-separated)
for portability. Source files may be C, C++, SWIG (.i),
@@ -102,15 +102,20 @@ class Extension:
depends=None,
language=None,
optional=None,
**kw # To catch unknown keywords
**kw, # To catch unknown keywords
):
if not isinstance(name, str):
raise AssertionError("'name' must be a string")
if not (isinstance(sources, list) and all(isinstance(v, str) for v in sources)):
raise AssertionError("'sources' must be a list of strings")
raise AssertionError("'name' must be a string") # noqa: TRY004
if not (
isinstance(sources, list)
and all(isinstance(v, (str, os.PathLike)) for v in sources)
):
raise AssertionError(
"'sources' must be a list of strings or PathLike objects."
)
self.name = name
self.sources = sources
self.sources = list(map(os.fspath, sources))
self.include_dirs = include_dirs or []
self.define_macros = define_macros or []
self.undef_macros = undef_macros or []
@@ -130,22 +135,16 @@ class Extension:
if len(kw) > 0:
options = [repr(option) for option in kw]
options = ', '.join(sorted(options))
msg = "Unknown Extension options: %s" % options
msg = f"Unknown Extension options: {options}"
warnings.warn(msg)
def __repr__(self):
return '<{}.{}({!r}) at {:#x}>'.format(
self.__class__.__module__,
self.__class__.__qualname__,
self.name,
id(self),
)
return f'<{self.__class__.__module__}.{self.__class__.__qualname__}({self.name!r}) at {id(self):#x}>'
def read_setup_file(filename): # noqa: C901
"""Reads a Setup file and returns Extension instances."""
from distutils.sysconfig import parse_makefile, expand_makefile_vars, _variable_rx
from distutils.sysconfig import _variable_rx, expand_makefile_vars, parse_makefile
from distutils.text_file import TextFile
from distutils.util import split_quoted
@@ -156,11 +155,11 @@ def read_setup_file(filename): # noqa: C901
# <module> ... [<sourcefile> ...] [<cpparg> ...] [<library> ...]
file = TextFile(
filename,
strip_comments=1,
skip_blanks=1,
join_lines=1,
lstrip_ws=1,
rstrip_ws=1,
strip_comments=True,
skip_blanks=True,
join_lines=True,
lstrip_ws=True,
rstrip_ws=True,
)
try:
extensions = []
@@ -173,7 +172,7 @@ def read_setup_file(filename): # noqa: C901
continue
if line[0] == line[-1] == "*":
file.warn("'%s' lines not handled yet" % line)
file.warn(f"'{line}' lines not handled yet")
continue
line = expand_makefile_vars(line, vars)
@@ -239,7 +238,7 @@ def read_setup_file(filename): # noqa: C901
# and append it to sources. Hmmmm.
ext.extra_objects.append(word)
else:
file.warn("unrecognized argument '%s'" % word)
file.warn(f"unrecognized argument '{word}'")
extensions.append(ext)
finally: