Skip to content

Commit

Permalink
chore: fix some setuptools types (#888)
Browse files Browse the repository at this point in the history
* chore: fix some setuptools types

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* chore: make sure setuptools types are up to date

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Mar 20, 2023
1 parent f66b77d commit 0a70d93
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Expand Up @@ -74,4 +74,4 @@ repos:
- pytest
- tomli
- types-requests
- types-setuptools
- types-setuptools>=67.6.0.5
2 changes: 1 addition & 1 deletion skbuild/command/build_ext.py
Expand Up @@ -22,7 +22,7 @@ def copy_extensions_to_source(self) -> None:
"""
build_py = self.get_finalized_command("build_py")
for ext in self.extensions:
fullname: str = self.get_ext_fullname(ext.name) # type: ignore[no-untyped-call]
fullname: str = self.get_ext_fullname(ext.name)
filename: str = self.get_ext_filename(fullname) # type: ignore[no-untyped-call]
modpath = fullname.split(".")
package = ".".join(modpath[:-1])
Expand Down
11 changes: 6 additions & 5 deletions skbuild/command/egg_info.py
Expand Up @@ -5,6 +5,7 @@

import os
import os.path
from typing import Any

from setuptools.command.egg_info import egg_info as _egg_info

Expand All @@ -16,15 +17,15 @@
class egg_info(set_build_base_mixin, _egg_info):
"""Custom implementation of ``egg_info`` setuptools command."""

def finalize_options(self, *args: object, **kwargs: object) -> None:
def finalize_options(self, *args: Any, **kwargs: Any) -> None:
if self.egg_base is None:
if self.distribution.package_dir is not None and len(self.distribution.package_dir) == 1: # type: ignore[attr-defined]
if self.distribution.package_dir is not None and len(self.distribution.package_dir) == 1:
# Recover directory specified in setup() function
# using `package_dir={'':<egg_base>}`
# This is required to successfully update the python path when
# running the test command.
package_name = list(self.distribution.package_dir.keys())[0] # type: ignore[attr-defined]
egg_base = to_unix_path(list(self.distribution.package_dir.values())[0]) # type: ignore[attr-defined]
package_name = list(self.distribution.package_dir.keys())[0]
egg_base = to_unix_path(list(self.distribution.package_dir.values())[0])
cmake_install_dir = to_unix_path(CMAKE_INSTALL_DIR())
if egg_base.startswith(cmake_install_dir):
egg_base = egg_base[len(cmake_install_dir) + 1 :]
Expand All @@ -35,7 +36,7 @@ def finalize_options(self, *args: object, **kwargs: object) -> None:
# pylint:disable=attribute-defined-outside-init
self.egg_base = egg_base
else:
script_path = os.path.abspath(self.distribution.script_name) # type: ignore[attr-defined]
script_path = os.path.abspath(self.distribution.script_name or "")
script_dir = os.path.dirname(script_path)
# pylint:disable=attribute-defined-outside-init
self.egg_base = os.path.join(script_dir, self.egg_base)
Expand Down
2 changes: 1 addition & 1 deletion skbuild/command/sdist.py
Expand Up @@ -30,7 +30,7 @@ def make_archive(
) -> str:
"""Handle --hide-listing option."""
logger.info("creating '%s' %s archive and adding '%s' to it", base_name, _format, base_dir)
with distribution_hide_listing(self.distribution): # type: ignore[attr-defined]
with distribution_hide_listing(self.distribution):
return super().make_archive(base_name, _format, root_dir, base_dir, owner, group)

def run(self, *args: object, **kwargs: object) -> None:
Expand Down
10 changes: 5 additions & 5 deletions skbuild/setuptools_wrap.py
Expand Up @@ -205,7 +205,7 @@ def _parse_setuptools_arguments(

# Update class attribute to also ensure the argument is processed
# when ``setuptools.setup`` is called.
upstream_Distribution.global_options.extend( # type: ignore[attr-defined]
upstream_Distribution.global_options.extend(
[
("hide-listing", None, "do not display list of files being included in the distribution"),
("force-cmake", None, "always run CMake"),
Expand All @@ -222,7 +222,7 @@ def _parse_setuptools_arguments(
# SystemExit to suppress tracebacks.

with _capture_output():
result = dist.parse_command_line() # type: ignore[attr-defined]
result = dist.parse_command_line() # type: ignore[no-untyped-call]
display_only = not result
if not hasattr(dist, "hide_listing"):
dist.hide_listing = False # type: ignore[attr-defined]
Expand All @@ -232,7 +232,7 @@ def _parse_setuptools_arguments(
dist.skip_cmake = False # type: ignore[attr-defined]

plat_names = set()
for cmd in [dist.get_command_obj(command) for command in dist.commands]: # type: ignore[attr-defined]
for cmd in [dist.get_command_obj(command) for command in dist.commands]:
plat_name = getattr(cmd, "plat_name", None)
if plat_name is not None:
plat_names.add(plat_name)
Expand All @@ -250,7 +250,7 @@ def _parse_setuptools_arguments(
return (
display_only,
dist.help_commands, # type: ignore[attr-defined]
dist.commands, # type: ignore[attr-defined]
dist.commands,
dist.hide_listing, # type: ignore[attr-defined]
dist.force_cmake, # type: ignore[attr-defined]
dist.skip_cmake, # type: ignore[attr-defined]
Expand Down Expand Up @@ -590,7 +590,7 @@ def setup(
if Requirement(package).name == "cmake":
setup_requires = [package]
dist = upstream_Distribution({"setup_requires": setup_requires})
dist.fetch_build_eggs(setup_requires) # type: ignore[no-untyped-call]
dist.fetch_build_eggs(setup_requires)

with contextlib.suppress(ImportError):
# Considering packages associated with "setup_requires" keyword are
Expand Down
12 changes: 9 additions & 3 deletions skbuild/utils/__init__.py
Expand Up @@ -5,6 +5,7 @@
import contextlib
import logging
import os
import typing
from contextlib import contextmanager
from typing import Any, Iterable, Iterator, Mapping, NamedTuple, Sequence, TypeVar

Expand All @@ -15,6 +16,9 @@

from .._compat.typing import Protocol

if typing.TYPE_CHECKING:
import setuptools._distutils.dist


class CommonLog(Protocol):
def info(self, __msg: str, *args: object) -> None:
Expand All @@ -24,7 +28,7 @@ def info(self, __msg: str, *args: object) -> None:
logger: CommonLog

try:
import setuptools.logging # noqa: F401
import setuptools.logging

skb_log = logging.getLogger("skbuild")
skb_log.setLevel(logging.INFO)
Expand Down Expand Up @@ -186,15 +190,17 @@ def to_unix_path(path: OptStr) -> OptStr:


@contextmanager
def distribution_hide_listing(distribution: Distribution) -> Iterator[bool | int]:
def distribution_hide_listing(
distribution: setuptools._distutils.dist.Distribution | Distribution,
) -> Iterator[bool | int]:
"""Given a ``distribution``, this context manager temporarily
sets distutils threshold to WARN if ``--hide-listing`` argument
was provided.
It yields True if ``--hide-listing`` argument was provided.
"""

hide_listing = hasattr(distribution, "hide_listing") and distribution.hide_listing # type: ignore[attr-defined]
hide_listing = getattr(distribution, "hide_listing", False)
wheel_log = logging.getLogger("wheel")
root_log = logging.getLogger() # setuptools 65.6+ needs this hidden too
if logging_module:
Expand Down

0 comments on commit 0a70d93

Please sign in to comment.