Skip to content

Commit

Permalink
Make get_ext_filename typesafe
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Aug 24, 2024
1 parent 8e96382 commit c1c6c02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions newsfragments/xxxx.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
If somehow the ``EXT_SUFFIX`` configuration variable and ``SETUPTOOLS_EXT_SUFFIX`` environment variables are both missing, ``setuptools.command.build_ext.pyget_ext_filename`` will now raise an `OSError` instead of a `TypeError` -- by :user:`Avasam`
18 changes: 11 additions & 7 deletions setuptools/command/build_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,25 @@ def _get_output_mapping(self) -> Iterator[tuple[str, str]]:
output_cache = _compiled_file_name(regular_stub, optimization=opt)
yield (output_cache, inplace_cache)

def get_ext_filename(self, fullname):
def get_ext_filename(self, fullname: str) -> str:
so_ext = os.getenv('SETUPTOOLS_EXT_SUFFIX')
if so_ext:
filename = os.path.join(*fullname.split('.')) + so_ext
else:
filename = _build_ext.get_ext_filename(self, fullname)
so_ext = get_config_var('EXT_SUFFIX')
ext_suffix = get_config_var('EXT_SUFFIX')
if not isinstance(ext_suffix, str):
raise OSError(
"Configuration variable EXT_SUFFIX not found for this platform "
+ "and environment variable SETUPTOOLS_EXT_SUFFIX is missing"
)
so_ext = ext_suffix

if fullname in self.ext_map:
ext = self.ext_map[fullname]
use_abi3 = ext.py_limited_api and get_abi3_suffix()
if use_abi3:
filename = filename[: -len(so_ext)]
so_ext = get_abi3_suffix()
filename = filename + so_ext
abi3_suffix = get_abi3_suffix()
if ext.py_limited_api and abi3_suffix: # Use abi3
filename = filename[: -len(so_ext)] + abi3_suffix
if isinstance(ext, Library):
fn, ext = os.path.splitext(filename)
return self.shlib_compiler.library_filename(fn, libtype)
Expand Down

0 comments on commit c1c6c02

Please sign in to comment.