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

Make command.build_ext.get_ext_filename typesafe #4592

Merged
merged 1 commit into from
Aug 27, 2024
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
1 change: 1 addition & 0 deletions newsfragments/4592.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
Loading