Skip to content
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
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ testpaths = [
]

[tool.ruff]
target-version = "py310"
line-length = 79
force-exclude = true
src = ["./"]
Expand All @@ -100,9 +101,10 @@ select = [
"RUF", # Ruff-specific rules
"I001", # isort
]

[tool.ruff.lint.pydocstyle]
convention = "numpy"
extend-select = [
"UP006", # Prefer builtin generics in annotations
"UP007", # Prefer | syntax for unions and optionals
]

[tool.ruff.lint.isort]
# Use a single line between direct and from import
Expand Down
13 changes: 6 additions & 7 deletions src/douki/_base/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from abc import ABC, abstractmethod
from pathlib import Path
from typing import List, Tuple

from douki._base.discovery import (
DiscoveryConfig,
Expand All @@ -25,11 +24,11 @@ class BaseConfig(ABC):

@property
@abstractmethod
def file_extensions(self) -> Tuple[str, ...]:
def file_extensions(self) -> tuple[str, ...]:
"""
title: File extensions handled by the language backend.
returns:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
"""
... # pragma: no cover

Expand All @@ -46,18 +45,18 @@ def load_discovery_config(self, cwd: Path) -> DiscoveryConfig:

def collect_files(
self,
paths: List[Path],
paths: list[Path],
discovery: DiscoveryConfig,
) -> List[Path]:
) -> list[Path]:
"""
title: Expand paths into source files, filtering excluded ones.
parameters:
paths:
type: List[Path]
type: list[Path]
discovery:
type: DiscoveryConfig
returns:
type: List[Path]
type: list[Path]
"""
return collect_source_files(
paths,
Expand Down
18 changes: 9 additions & 9 deletions src/douki/_base/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any, Dict, Tuple
from typing import Any


@dataclass
Expand All @@ -27,13 +27,13 @@ class LanguageDefaults:
type: str
description: Default scope for class methods.
file_extensions:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
description: File extensions to collect (e.g. ('.py',)).
config_files:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
description: Config files to search for exclude patterns.
field_defaults:
type: Dict[str, Any]
type: dict[str, Any]
description: >-
Mapping of top-level YAML key to the default value that should be
omitted when emitting.
Expand All @@ -43,17 +43,17 @@ class LanguageDefaults:
mutability: str = 'mutable'
scope_function: str = 'static'
scope_method: str = 'instance'
file_extensions: Tuple[str, ...] = ()
config_files: Tuple[str, ...] = ()
field_defaults: Dict[str, Any] = field(default_factory=dict)
file_extensions: tuple[str, ...] = ()
config_files: tuple[str, ...] = ()
field_defaults: dict[str, Any] = field(default_factory=dict)

def get_field_defaults(self) -> Dict[str, Any]:
def get_field_defaults(self) -> dict[str, Any]:
"""
title: >-
Return the mapping of top-level YAML key to the default value that
should be omitted.
returns:
type: Dict[str, Any]
type: dict[str, Any]
"""
defaults = {
'visibility': self.visibility,
Expand Down
48 changes: 24 additions & 24 deletions src/douki/_base/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from dataclasses import dataclass
from pathlib import Path
from typing import Dict, Iterable, List, Pattern, Tuple
from typing import Iterable, Pattern

if sys.version_info >= (3, 11):
import tomllib
Expand All @@ -25,13 +25,13 @@ class DiscoveryConfig:
root:
type: Path
exclude_patterns:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
respect_gitignore:
type: bool
"""

root: Path
exclude_patterns: Tuple[str, ...] = ()
exclude_patterns: tuple[str, ...] = ()
respect_gitignore: bool = True


Expand Down Expand Up @@ -84,25 +84,25 @@ def load_douki_discovery_config(cwd: Path) -> DiscoveryConfig:


def collect_source_files(
paths: List[Path],
paths: list[Path],
*,
file_extensions: Tuple[str, ...],
file_extensions: tuple[str, ...],
discovery: DiscoveryConfig,
) -> List[Path]:
) -> list[Path]:
"""
title: Expand paths into source files using shared discovery rules.
parameters:
paths:
type: List[Path]
type: list[Path]
file_extensions:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
discovery:
type: DiscoveryConfig
returns:
type: List[Path]
type: list[Path]
"""
matcher = _GitIgnoreMatcher(discovery.root)
result: List[Path] = []
result: list[Path] = []

for path in paths:
if path.is_dir():
Expand Down Expand Up @@ -138,7 +138,7 @@ def _load_pyproject_discovery_config(pyproject: Path) -> DiscoveryConfig:
returns:
type: DiscoveryConfig
"""
excludes: Tuple[str, ...] = ()
excludes: tuple[str, ...] = ()
respect_gitignore = True

try:
Expand All @@ -164,14 +164,14 @@ def _load_pyproject_discovery_config(pyproject: Path) -> DiscoveryConfig:
)


def _matches_extension(path: Path, file_extensions: Tuple[str, ...]) -> bool:
def _matches_extension(path: Path, file_extensions: tuple[str, ...]) -> bool:
"""
title: Check whether a path uses one of the configured file extensions.
parameters:
path:
type: Path
file_extensions:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
returns:
type: bool
"""
Expand Down Expand Up @@ -206,7 +206,7 @@ def _is_excluded(
def _matches_exclude_patterns(
path: Path,
*,
exclude_patterns: Tuple[str, ...],
exclude_patterns: tuple[str, ...],
root: Path,
) -> bool:
"""
Expand All @@ -215,7 +215,7 @@ def _matches_exclude_patterns(
path:
type: Path
exclude_patterns:
type: Tuple[str, Ellipsis]
type: tuple[str, Ellipsis]
root:
type: Path
returns:
Expand Down Expand Up @@ -274,12 +274,12 @@ class _GitIgnoreMatcher:
_root:
type: Path
_rules_by_dir:
type: Dict[Path, Tuple[_GitIgnoreRule, Ellipsis]]
type: dict[Path, tuple[_GitIgnoreRule, Ellipsis]]
"""

def __init__(self, root: Path) -> None:
self._root: Path = root.resolve()
self._rules_by_dir: Dict[Path, Tuple[_GitIgnoreRule, ...]] = {}
self._rules_by_dir: dict[Path, tuple[_GitIgnoreRule, ...]] = {}

def is_ignored(self, path: Path) -> bool:
"""
Expand Down Expand Up @@ -321,14 +321,14 @@ def _iter_scope_dirs(self, path: Path) -> Iterable[Path]:
curr = curr / part
yield curr

def _load_rules(self, scope_dir: Path) -> Tuple[_GitIgnoreRule, ...]:
def _load_rules(self, scope_dir: Path) -> tuple[_GitIgnoreRule, ...]:
"""
title: Load and cache parsed rules for a scope directory.
parameters:
scope_dir:
type: Path
returns:
type: Tuple[_GitIgnoreRule, Ellipsis]
type: tuple[_GitIgnoreRule, Ellipsis]
"""
if scope_dir in self._rules_by_dir:
return self._rules_by_dir[scope_dir]
Expand All @@ -338,7 +338,7 @@ def _load_rules(self, scope_dir: Path) -> Tuple[_GitIgnoreRule, ...]:
self._rules_by_dir[scope_dir] = ()
return ()

rules: List[_GitIgnoreRule] = []
rules: list[_GitIgnoreRule] = []
try:
lines = gitignore.read_text(encoding='utf-8').splitlines()
except OSError:
Expand Down Expand Up @@ -432,17 +432,17 @@ def _rule_matches_path(rule: _GitIgnoreRule, path: Path) -> bool:
return any(rule.regex.fullmatch(prefix) for prefix in prefixes)


def _relative_prefixes(path_str: str) -> List[str]:
def _relative_prefixes(path_str: str) -> list[str]:
"""
title: Return cumulative relative path prefixes for a path string.
parameters:
path_str:
type: str
returns:
type: List[str]
type: list[str]
"""
parts = [part for part in path_str.split('/') if part]
prefixes: List[str] = []
prefixes: list[str] = []
for idx in range(len(parts)):
prefixes.append('/'.join(parts[: idx + 1]))
return prefixes
Expand All @@ -457,7 +457,7 @@ def _compile_gitignore_regex(pattern: str) -> Pattern[str]:
returns:
type: Pattern[str]
"""
regex: List[str] = ['^']
regex: list[str] = ['^']
idx = 0
while idx < len(pattern):
char = pattern[idx]
Expand Down
8 changes: 4 additions & 4 deletions src/douki/_base/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from __future__ import annotations

from abc import ABC, abstractmethod
from typing import Dict, Optional, Type
from typing import Optional

from douki._base.config import BaseConfig

Expand Down Expand Up @@ -61,15 +61,15 @@ def sync_source(
# Registry
# ---------------------------------------------------------------------------

_REGISTRY: Dict[str, Type[BaseLanguage]] = {}
_REGISTRY: dict[str, type[BaseLanguage]] = {}


def register_language(lang_class: Type[BaseLanguage]) -> None:
def register_language(lang_class: type[BaseLanguage]) -> None:
"""
title: Register a language plugin class.
parameters:
lang_class:
type: Type[BaseLanguage]
type: type[BaseLanguage]
"""
# Create a temporary instance just to get its name
instance = lang_class()
Expand Down
Loading
Loading