Skip to content

Commit

Permalink
refactor: more cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jun 28, 2024
1 parent 06bfc2e commit 2794b44
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 48 deletions.
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import importlib
import importlib.metadata
import inspect
import os
import sys
Expand Down
7 changes: 2 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -274,20 +274,17 @@ known-local-folder = ["pathutils"]
"typing.Mapping".msg = "Use collections.abc.Mapping instead."
"typing.Sequence".msg = "Use collections.abc.Sequence instead."
"typing.Set".msg = "Use collections.abc.Set instead."
"typing.Literal".msg = "Use scikit_build_core._compat.typing.Literal instead."
"typing.Protocol".msg = "Use scikit_build_core._compat.typing.Protocol instead."
"typing.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
"typing_extensions.Self".msg = "Use scikit_build_core._compat.typing.Self instead."
"typing.runtime_checkable".msg = "Add and use scikit_build_core._compat.typing.runtime_checkable instead."
"typing.Final".msg = "Add scikit_build_core._compat.typing.Final instead."
"typing.NotRequired".msg = "Add scikit_build_core._compat.typing.NotRequired instead."
"typing.OrderedDict".msg = "Add scikit_build_core._compat.typing.OrderedDict instead."
"typing.TypedDict".msg = "Add scikit_build_core._compat.typing.TypedDict instead."
"typing.assert_never".msg = "Add scikit_build_core._compat.typing.assert_never instead."
"tomli".msg = "Use scikit_build_core._compat.tomllib instead."
"tomllib".msg = "Use scikit_build_core._compat.tomllib instead."
"importlib.metadata".msg = "Use scikit_build_core._compat.importlib.metadata instead."
"importlib_metadata".msg = "Use scikit_build_core._compat.importlib.metadata instead."
"importlib_metadata".msg = "Use importlib.metadata directly instead."
"importlib.metadata.entry_points".msg = "Use scikit_build_core._compat.importlib.metadata.entry_points instead."
"importlib.resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"importlib_resources".msg = "Use scikit_build_core._compat.importlib.resources instead."
"pyproject_metadata".msg = "Use scikit_build_core._vendor.pyproject_metadata instead."
Expand Down
9 changes: 4 additions & 5 deletions src/scikit_build_core/_compat/importlib/metadata.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import annotations

import importlib.metadata as _metadata
import importlib.metadata
import sys
import typing
from importlib.metadata import PathDistribution, version

if typing.TYPE_CHECKING:
if sys.version_info < (3, 10):
Expand All @@ -13,14 +12,14 @@
else:
from importlib.metadata import EntryPoints

__all__ = ["entry_points", "PathDistribution", "version"]
__all__ = ["entry_points"]


def entry_points(*, group: str) -> EntryPoints:
if sys.version_info >= (3, 10):
return _metadata.entry_points(group=group)
return importlib.metadata.entry_points(group=group)

epg = _metadata.entry_points()
epg = importlib.metadata.entry_points()
return epg.get(group, [])


Expand Down
3 changes: 0 additions & 3 deletions src/scikit_build_core/_compat/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import sys
import typing
from typing import Literal, Protocol

if sys.version_info < (3, 9):
from typing_extensions import Annotated, get_args, get_origin
Expand All @@ -24,8 +23,6 @@ def assert_never(_: object) -> None:

__all__ = [
"Annotated",
"Literal",
"Protocol",
"Self",
"assert_never",
"get_args",
Expand Down
18 changes: 7 additions & 11 deletions src/scikit_build_core/_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
import re
import sys
from typing import Any

__all__ = ["ScikitBuildLogger", "logger", "raw_logger", "rich_print", "LEVEL_VALUE"]

Expand Down Expand Up @@ -44,34 +43,31 @@ def __repr__(self) -> str:
)


opts: Any = {"stacklevel": 2}


class ScikitBuildLogger:
# pylint: disable-next=redefined-outer-name
def __init__(self, logger: logging.Logger) -> None:
self.logger = logger

def debug(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.debug(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.debug(FStringMessage(msg, *args, **kwargs), stacklevel=2)

def info(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.info(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.info(FStringMessage(msg, *args, **kwargs), stacklevel=2)

def warning(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.warning(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.warning(FStringMessage(msg, *args, **kwargs), stacklevel=2)

def error(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.error(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.error(FStringMessage(msg, *args, **kwargs), stacklevel=2)

Check warning on line 61 in src/scikit_build_core/_logging.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_logging.py#L61

Added line #L61 was not covered by tests

def critical(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.critical(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.critical(FStringMessage(msg, *args, **kwargs), stacklevel=2)

Check warning on line 64 in src/scikit_build_core/_logging.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_logging.py#L64

Added line #L64 was not covered by tests

def exception(self, msg: str, *args: object, **kwargs: object) -> None:
self.logger.exception(FStringMessage(msg, *args, **kwargs), **opts)
self.logger.exception(FStringMessage(msg, *args, **kwargs), stacklevel=2)

Check warning on line 67 in src/scikit_build_core/_logging.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_logging.py#L67

Added line #L67 was not covered by tests

def log(self, level: int, msg: str, *args: object, **kwargs: object) -> None:
self.logger.log(level, FStringMessage(msg, *args, **kwargs), **opts)
self.logger.log(level, FStringMessage(msg, *args, **kwargs), stacklevel=2)

Check warning on line 70 in src/scikit_build_core/_logging.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/_logging.py#L70

Added line #L70 was not covered by tests

def setLevel(self, level: int) -> None: # noqa: N802
self.logger.setLevel(level)
Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/build/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import sysconfig
import tempfile
from pathlib import Path
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from .. import __version__
from .._compat import tomllib
from .._compat.typing import Literal, assert_never
from .._compat.typing import assert_never
from .._logging import logger, rich_print
from .._shutil import fix_win_37_all_permissions
from ..builder.builder import Builder, archs_to_tags, get_archs
Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/builder/get_requires.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import importlib.util
import os
import sysconfig
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Literal

from packaging.tags import sys_tags

Expand All @@ -24,7 +24,7 @@
if TYPE_CHECKING:
from collections.abc import Generator, Mapping

from .._compat.typing import Literal, Self
from .._compat.typing import Self

Check warning on line 27 in src/scikit_build_core/builder/get_requires.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/builder/get_requires.py#L27

Added line #L27 was not covered by tests
from ..settings.skbuild_model import ScikitBuildSettings

__all__ = ["GetRequires"]
Expand Down
7 changes: 3 additions & 4 deletions src/scikit_build_core/hatch/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@
from __future__ import annotations

import copy
import importlib.metadata
import os
import shutil
import sys
import sysconfig
import tempfile
import typing
from pathlib import Path
from typing import Any
from typing import Any, Literal

from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from packaging.version import Version

from scikit_build_core.settings.skbuild_model import ScikitBuildSettings

from .. import __version__
from .._compat.importlib.metadata import version as pkg_version
from .._compat.typing import Literal
from .._logging import logger, rich_print
from ..build._init import setup_logging
from ..builder.builder import Builder, archs_to_tags, get_archs
Expand Down Expand Up @@ -220,7 +219,7 @@ def _initialize(self, *, build_data: dict[str, Any]) -> None:
f"SKBUILD_{k.upper()}_DIR": v for k, v in wheel_dirs.items()
}
cache_entries["SKBUILD_STATE"] = state
cache_entries["SKBUILD_HATCHLING"] = pkg_version("hatchling")
cache_entries["SKBUILD_HATCHLING"] = importlib.metadata.version("hatchling")

Check warning on line 222 in src/scikit_build_core/hatch/plugin.py

View check run for this annotation

Codecov / codecov/patch

src/scikit_build_core/hatch/plugin.py#L222

Added line #L222 was not covered by tests
builder.configure(
defines=defines,
cache_entries=cache_entries,
Expand Down
4 changes: 1 addition & 3 deletions src/scikit_build_core/settings/_load_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import importlib
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any, Union

from .._compat.typing import Protocol
from typing import TYPE_CHECKING, Any, Protocol, Union

if TYPE_CHECKING:
from collections.abc import Generator, Iterable, Mapping
Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/settings/json_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import dataclasses
import sys
from pathlib import Path
from typing import Any, Union
from typing import Any, Literal, Union

from packaging.specifiers import SpecifierSet
from packaging.version import Version

from .._compat.builtins import ExceptionGroup
from .._compat.typing import Annotated, Literal, get_args, get_origin
from .._compat.typing import Annotated, get_args, get_origin
from .documentation import pull_docs

__all__ = ["FailedConversionError", "convert_type", "to_json_schema"]
Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/settings/skbuild_model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dataclasses
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Literal, Optional, Union

from packaging.specifiers import SpecifierSet
from packaging.version import Version

from .._compat.typing import Annotated, Literal
from .._compat.typing import Annotated

__all__ = [
"BackportSettings",
Expand Down
3 changes: 1 addition & 2 deletions src/scikit_build_core/settings/skbuild_read_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import re
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal

from packaging.specifiers import SpecifierSet
from packaging.version import Version
Expand All @@ -23,7 +23,6 @@
if TYPE_CHECKING:
from collections.abc import Generator, Mapping

from .._compat.typing import Literal

__all__ = ["SettingsReader"]

Expand Down
4 changes: 2 additions & 2 deletions src/scikit_build_core/settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
import dataclasses
import os
import typing
from typing import Any, TypeVar, Union
from typing import Any, Literal, Protocol, TypeVar, Union

from .._compat.builtins import ExceptionGroup
from .._compat.typing import Annotated, Literal, Protocol, get_args, get_origin
from .._compat.typing import Annotated, get_args, get_origin

if typing.TYPE_CHECKING:
from collections.abc import Generator, Iterator, Mapping, Sequence
Expand Down
3 changes: 1 addition & 2 deletions src/scikit_build_core/setuptools/build_cmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shutil
import sys
from pathlib import Path
from typing import TYPE_CHECKING, ClassVar
from typing import TYPE_CHECKING, ClassVar, Literal

import setuptools
import setuptools.errors
Expand All @@ -18,7 +18,6 @@
if TYPE_CHECKING:
from setuptools.dist import Distribution

from .._compat.typing import Literal
from ..settings.skbuild_model import ScikitBuildSettings

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pyproject_pep517.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import tarfile
import time
import zipfile
from importlib.metadata import PathDistribution
from pathlib import Path

import build.util
import pytest

from scikit_build_core._compat.importlib.metadata import PathDistribution
from scikit_build_core.build import (
_file_processor,
build_sdist,
Expand Down
3 changes: 1 addition & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import dataclasses
import re
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Literal, Optional, Union

import pytest
from packaging.version import Version

from scikit_build_core._compat.builtins import ExceptionGroup
from scikit_build_core._compat.typing import Literal
from scikit_build_core.settings.sources import (
ConfSource,
EnvSource,
Expand Down

0 comments on commit 2794b44

Please sign in to comment.