Skip to content

Commit 6533cb3

Browse files
committed
style: apply ruff fixes (post template ruff config)
1 parent 8162d17 commit 6533cb3

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

hooks/post_gen_project.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import os
88
import shutil
99
import sys
10+
from collections.abc import Iterable
1011
from glob import glob
1112
from pathlib import Path
12-
from typing import Iterable, Optional
1313

1414
module_dir = 'src/{{ cookiecutter.module_name }}'
1515

@@ -146,10 +146,10 @@ def handle_config():
146146
if config_file == 'yaml':
147147
_delete_files(files_config_hocon)
148148
shutil.rmtree(f'{module_dir}/res')
149-
_rename_files(f'src/**/*__yaml.py', '__yaml', '')
149+
_rename_files('src/**/*__yaml.py', '__yaml', '')
150150
elif config_file == 'hocon':
151151
_delete_files(files_config_yaml)
152-
_rename_files(f'src/**/*__hocon.py', '__hocon', '')
152+
_rename_files('src/**/*__hocon.py', '__hocon', '')
153153
else:
154154
_delete_files(files_config_hocon + files_config_yaml + ['tests/test_util.py'])
155155
os.rmdir(f'{module_dir}/res')
@@ -201,7 +201,7 @@ def _rename_files(file_pattern, old, new):
201201
path.rename(path.with_name(path.name.replace(old, new)))
202202

203203

204-
def _delete_files(files: Iterable[str], exclude: Optional[str] = None):
204+
def _delete_files(files: Iterable[str], exclude: str | None = None):
205205
try:
206206
for file in files:
207207
if file != exclude:
@@ -211,7 +211,7 @@ def _delete_files(files: Iterable[str], exclude: Optional[str] = None):
211211
sys.exit(1)
212212

213213

214-
def _delete_folders(folders: Iterable[str], exclude: Optional[str] = None):
214+
def _delete_folders(folders: Iterable[str], exclude: str | None = None):
215215
for folder in folders:
216216
if folder != exclude:
217217
shutil.rmtree(folder, ignore_errors=True)

tests/test_validation.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
from collections.abc import Callable
12
from runpy import run_path
2-
from typing import Any, Callable
3+
from typing import Any
34

45
import pytest
56
from cookiecutter.exceptions import CookiecutterException

tests/util.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import subprocess
33
import sys
4+
from collections.abc import Callable
45
from pathlib import Path
56
from tempfile import TemporaryDirectory
6-
from typing import Callable, Dict, List, Union
77

88
from cookiecutter.main import cookiecutter
99

@@ -26,11 +26,11 @@ def get_module_name(project_dir: Path) -> str:
2626
return module_name
2727

2828

29-
def resolve_module_dir(files: List[str], module_name: str) -> List[str]:
29+
def resolve_module_dir(files: list[str], module_name: str) -> list[str]:
3030
return [(s.format(module_name=module_name) if '{' in s else s) for s in files] if files else []
3131

3232

33-
def check_files(project_dir: Path, files: List[str], exist=True):
33+
def check_files(project_dir: Path, files: list[str], exist=True):
3434
for file in files:
3535
path = (project_dir / file).resolve()
3636
assert path.exists() == exist, f"file '{path}' should {'' if exist else 'not '}have existed"
@@ -47,8 +47,8 @@ def list_files(base_dir, indent=4):
4747

4848

4949
def check_project(
50-
project_name="Test Project", settings: Dict[str, str] = None, files_existent: List = None,
51-
files_non_existent: List = None, test_cli=False, run_pytest=False,
50+
project_name="Test Project", settings: dict[str, str] = None, files_existent: list = None,
51+
files_non_existent: list = None, test_cli=False, run_pytest=False,
5252
fun: Callable[[Path], None] = None):
5353
# define cookiecutter settings
5454
if settings is None:
@@ -81,7 +81,7 @@ def check_project(
8181
fun(project_dir)
8282

8383

84-
def assert_file_contains(file: Union[str, Path], contains: str = None, not_contains: str = None):
84+
def assert_file_contains(file: str | Path, contains: str = None, not_contains: str = None):
8585
with open(file) as fp:
8686
content = fp.read()
8787
if contains:
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
# Ruff configuration file
2-
# Template version for generated projects
1+
# Ruff configuration file for generated projects (standalone .ruff.toml)
2+
# This file will be copied into generated projects and must be valid TOML
33

4-
[tool.ruff]
54
line-length = 100
65
target-version = "py311"
76
exclude = ["__init__.py"]
87
extend-exclude = ["notebooks/*"]
98

10-
[tool.ruff.lint]
9+
[lint]
1110
select = [
1211
"E", # Pycodestyle errors
1312
"F", # Pyflakes errors
@@ -19,5 +18,5 @@ select = [
1918
]
2019
task-tags = ["TODO", "FIXME", "NOTE"]
2120

22-
[tool.isort]
23-
known_first_party = ["{{ cookiecutter.project_slug }}"]
21+
[isort]
22+
known-first-party = ["{{ cookiecutter.project_slug }}"]

{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/util__hocon.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1+
import importlib.resources as resources
12
import logging
23
from pathlib import Path
3-
from typing import Union
44

5-
import importlib.resources as resources
6-
from pyhocon import ConfigTree, ConfigFactory
5+
from pyhocon import ConfigFactory, ConfigTree
76

87
logger = logging.getLogger('{{ cookiecutter.module_name }}')
98

109

11-
def get_resource_string(path: str, decode=True) -> Union[str, bytes]:
10+
def get_resource_string(path: str, decode=True) -> str | bytes:
1211
"""
1312
Load a package resource (i.e. a file from within this package)
1413
@@ -23,7 +22,7 @@ def get_resource_string(path: str, decode=True) -> Union[str, bytes]:
2322
return s.decode(errors='ignore') if decode else s
2423

2524

26-
def load_config(config_file: Union[str, Path] = None) -> ConfigTree:
25+
def load_config(config_file: str | Path = None) -> ConfigTree:
2726
"""
2827
Load the config from the specified file and use it to override fields in the default config.
2928
If no config file is specified, only the default config is loaded.

{{cookiecutter.project_slug}}/src/{{cookiecutter.module_name}}/util__yaml.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
import importlib.resources as resources
12
import logging
23
from pathlib import Path
3-
from typing import Any, Dict, Union
4+
from typing import Any
45

5-
import importlib.resources as resources
66
import yaml
77

88
logger = logging.getLogger('{{ cookiecutter.module_name }}')
99

1010

11-
def get_resource_string(path: str, decode=True) -> Union[str, bytes]:
11+
def get_resource_string(path: str, decode=True) -> str | bytes:
1212
"""
1313
Load a package resource (i.e. a file from within this package)
1414
@@ -23,7 +23,7 @@ def get_resource_string(path: str, decode=True) -> Union[str, bytes]:
2323
return s.decode(errors='ignore') if decode else s
2424

2525

26-
def load_config(config_file: Union[str, Path]) -> Dict[str, Any]:
26+
def load_config(config_file: str | Path) -> dict[str, Any]:
2727
"""
2828
Load the config from the specified yaml file
2929
@@ -34,7 +34,7 @@ def load_config(config_file: Union[str, Path]) -> Dict[str, Any]:
3434
return yaml.safe_load(fp)
3535

3636

37-
def logging_setup(config: Dict):
37+
def logging_setup(config: dict):
3838
"""
3939
setup logging based on the configuration
4040

0 commit comments

Comments
 (0)