Skip to content

Commit 136c763

Browse files
Apply new ruff rules (#2063)
1 parent aa287c1 commit 136c763

File tree

15 files changed

+63
-66
lines changed

15 files changed

+63
-66
lines changed

backend/src/hatchling/builders/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import os
44
from contextlib import contextmanager
55
from functools import cached_property
6-
from typing import TYPE_CHECKING, Any, Generator, TypeVar
6+
from typing import TYPE_CHECKING, Any, TypeVar
77

88
import pathspec
99

@@ -13,6 +13,8 @@
1313
from hatchling.utils.fs import locate_file
1414

1515
if TYPE_CHECKING:
16+
from collections.abc import Generator
17+
1618
from hatchling.builders.plugin.interface import BuilderInterface
1719

1820

backend/src/hatchling/builders/plugin/interface.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import os
44
import re
55
from abc import ABC, abstractmethod
6-
from typing import TYPE_CHECKING, Any, Callable, Generator, Generic, Iterable, cast
6+
from typing import TYPE_CHECKING, Any, Callable, Generic, cast
77

88
from hatchling.builders.config import BuilderConfig, BuilderConfigBound, env_var_enabled
99
from hatchling.builders.constants import EXCLUDED_DIRECTORIES, EXCLUDED_FILES, BuildEnvVars
1010
from hatchling.builders.utils import get_relative_path, safe_walk
1111
from hatchling.plugin.manager import PluginManagerBound
1212

1313
if TYPE_CHECKING:
14+
from collections.abc import Generator, Iterable
15+
1416
from hatchling.bridge.app import Application
1517
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1618
from hatchling.metadata.core import ProjectMetadata

backend/src/hatchling/builders/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import os
44
import shutil
55
from base64 import urlsafe_b64encode
6-
from typing import TYPE_CHECKING, Iterable
6+
from typing import TYPE_CHECKING
77

88
if TYPE_CHECKING:
9+
from collections.abc import Iterable
910
from zipfile import ZipInfo
1011

1112

backend/src/hatchling/builders/wheel.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import zipfile
1010
from functools import cached_property
1111
from io import StringIO
12-
from typing import TYPE_CHECKING, Any, Callable, Iterable, NamedTuple, Sequence, Tuple, cast
12+
from typing import TYPE_CHECKING, Any, Callable, NamedTuple, cast
1313

1414
from hatchling.__about__ import __version__
1515
from hatchling.builders.config import BuilderConfig
@@ -29,12 +29,13 @@
2929
from hatchling.metadata.spec import DEFAULT_METADATA_VERSION, get_core_metadata_constructors
3030

3131
if TYPE_CHECKING:
32+
from collections.abc import Iterable, Sequence
3233
from types import TracebackType
3334

3435
from hatchling.builders.plugin.interface import IncludedFile
3536

3637

37-
TIME_TUPLE = Tuple[int, int, int, int, int, int]
38+
TIME_TUPLE = tuple[int, int, int, int, int, int]
3839

3940

4041
class FileSelectionOptions(NamedTuple):

backend/src/hatchling/utils/context.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
from abc import ABC, abstractmethod
66
from collections import ChainMap
77
from contextlib import contextmanager
8-
from typing import Any, Iterable, Iterator, Mapping, MutableMapping, Sequence
8+
from typing import TYPE_CHECKING, Any
99

1010
from hatchling.utils.fs import path_to_uri
1111

12+
if TYPE_CHECKING:
13+
from collections.abc import Iterable, Iterator, Mapping, MutableMapping, Sequence
14+
1215

1316
class ContextFormatter(ABC):
1417
@abstractmethod

backend/src/hatchling/version/scheme/standard.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Any, Tuple, cast
3+
from typing import TYPE_CHECKING, Any, cast
44

55
from hatchling.version.scheme.plugin.interface import VersionSchemeInterface
66

@@ -95,4 +95,4 @@ def update_release(original_version: Version, new_release_parts: list[int]) -> t
9595
def parse_letter_version(*args: Any, **kwargs: Any) -> tuple[str, int]:
9696
from packaging.version import _parse_letter_version # noqa: PLC2701
9797

98-
return cast(Tuple[str, int], _parse_letter_version(*args, **kwargs))
98+
return cast(tuple[str, int], _parse_letter_version(*args, **kwargs))

src/hatch/env/plugin/interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
from contextlib import contextmanager
77
from functools import cached_property
88
from os.path import isabs
9-
from typing import TYPE_CHECKING, Generator
9+
from typing import TYPE_CHECKING
1010

1111
from hatch.config.constants import AppEnvVars
1212
from hatch.env.utils import add_verbosity_flag, get_env_var_option
1313
from hatch.project.utils import format_script_commands, parse_script_command
1414
from hatch.utils.structures import EnvVars
1515

1616
if TYPE_CHECKING:
17-
from collections.abc import Iterable
17+
from collections.abc import Generator, Iterable
1818

1919
from hatch.utils.fs import Path
2020

src/hatch/project/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
import re
44
from contextlib import contextmanager
55
from functools import cached_property
6-
from typing import TYPE_CHECKING, Generator, cast
6+
from typing import TYPE_CHECKING, cast
77

88
from hatch.project.env import EnvironmentMetadata
99
from hatch.utils.fs import Path
1010
from hatch.utils.runner import ExecutionContext
1111

1212
if TYPE_CHECKING:
13+
from collections.abc import Generator
14+
1315
from hatch.cli.application import Application
1416
from hatch.config.model import RootConfig
1517
from hatch.env.plugin.interface import EnvironmentInterface

src/hatch/project/frontend/core.py

Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from __future__ import annotations
22

33
import json
4-
import sys
5-
from functools import lru_cache
4+
from functools import cache
65
from typing import TYPE_CHECKING, Any, Literal
76

87
from hatch.utils.fs import Path
@@ -295,58 +294,33 @@ def get_core_metadata(self, *, output_dir: str, project_root: str) -> str:
295294
)
296295

297296

298-
if sys.version_info[:2] >= (3, 9):
297+
@cache
298+
def hook_caller_script() -> str:
299+
from importlib.resources import files
299300

300-
@lru_cache(maxsize=None)
301-
def hook_caller_script() -> str:
302-
from importlib.resources import files
301+
script = files('pyproject_hooks._in_process') / '_in_process.py'
302+
return script.read_text(encoding='utf-8')
303303

304-
script = files('pyproject_hooks._in_process') / '_in_process.py'
305-
return script.read_text(encoding='utf-8')
306304

307-
@lru_cache(maxsize=None)
308-
def runner_script() -> str:
309-
from importlib.resources import files
305+
@cache
306+
def runner_script() -> str:
307+
from importlib.resources import files
310308

311-
script = files('hatch.project.frontend.scripts') / 'standard.py'
312-
return script.read_text(encoding='utf-8')
309+
script = files('hatch.project.frontend.scripts') / 'standard.py'
310+
return script.read_text(encoding='utf-8')
313311

314-
@lru_cache(maxsize=None)
315-
def hatch_build_deps_script() -> str:
316-
from importlib.resources import files
317312

318-
script = files('hatch.project.frontend.scripts') / 'build_deps.py'
319-
return script.read_text(encoding='utf-8')
313+
@cache
314+
def hatch_build_deps_script() -> str:
315+
from importlib.resources import files
320316

321-
@lru_cache(maxsize=None)
322-
def hatch_core_metadata_script() -> str:
323-
from importlib.resources import files
317+
script = files('hatch.project.frontend.scripts') / 'build_deps.py'
318+
return script.read_text(encoding='utf-8')
324319

325-
script = files('hatch.project.frontend.scripts') / 'core_metadata.py'
326-
return script.read_text(encoding='utf-8')
327320

328-
else:
321+
@cache
322+
def hatch_core_metadata_script() -> str:
323+
from importlib.resources import files
329324

330-
@lru_cache(maxsize=None)
331-
def hook_caller_script() -> str:
332-
from importlib.resources import read_text
333-
334-
return read_text('pyproject_hooks._in_process', '_in_process.py')
335-
336-
@lru_cache(maxsize=None)
337-
def runner_script() -> str:
338-
from importlib.resources import read_text
339-
340-
return read_text('hatch.project.frontend.scripts', 'standard.py')
341-
342-
@lru_cache(maxsize=None)
343-
def hatch_build_deps_script() -> str:
344-
from importlib.resources import read_text
345-
346-
return read_text('hatch.project.frontend.scripts', 'build_deps.py')
347-
348-
@lru_cache(maxsize=None)
349-
def hatch_core_metadata_script() -> str:
350-
from importlib.resources import read_text
351-
352-
return read_text('hatch.project.frontend.scripts', 'core_metadata.py')
325+
script = files('hatch.project.frontend.scripts') / 'core_metadata.py'
326+
return script.read_text(encoding='utf-8')

src/hatch/project/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import Any, Iterable
3+
from typing import TYPE_CHECKING, Any
4+
5+
if TYPE_CHECKING:
6+
from collections.abc import Iterable
47

58

69
def parse_script_command(command: str) -> tuple[str, str, bool]:

0 commit comments

Comments
 (0)