Skip to content

Commit

Permalink
Upgrade Ruff (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored Nov 25, 2023
1 parent 06744d8 commit 6c252f8
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 86 deletions.
6 changes: 3 additions & 3 deletions backend/src/hatchling/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def build_sdist(sdist_directory: str, config_settings: dict[str, Any] | None = N
from hatchling.builders.sdist import SdistBuilder

builder = SdistBuilder(os.getcwd())
return os.path.basename(next(builder.build(sdist_directory, ['standard'])))
return os.path.basename(next(builder.build(directory=sdist_directory, versions=['standard'])))


def get_requires_for_build_wheel(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
Expand All @@ -55,7 +55,7 @@ def build_wheel(
from hatchling.builders.wheel import WheelBuilder

builder = WheelBuilder(os.getcwd())
return os.path.basename(next(builder.build(wheel_directory, ['standard'])))
return os.path.basename(next(builder.build(directory=wheel_directory, versions=['standard'])))


def get_requires_for_build_editable(config_settings: dict[str, Any] | None = None) -> list[str]: # noqa: ARG001
Expand All @@ -79,7 +79,7 @@ def build_editable(
from hatchling.builders.wheel import WheelBuilder

builder = WheelBuilder(os.getcwd())
return os.path.basename(next(builder.build(wheel_directory, ['editable'])))
return os.path.basename(next(builder.build(directory=wheel_directory, versions=['editable'])))


# Any builder that has build-time hooks like Hatchling and setuptools cannot technically keep PEP 517's identical
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/builders/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]: # noqa: PLR6301
return ['bootstrap']

def clean(
self, # noqa: PLR6301
def clean( # noqa: PLR6301
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/builders/hooks/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def initialize(
) -> None:
version_file = VersionFile(self.root, self.config_path)
if self.config_pattern:
version_file.read(self.config_pattern)
version_file.read(pattern=self.config_pattern)
version_file.set_version(self.metadata.version)
else:
version_file.write(self.metadata.version, self.config_template)
Expand Down
3 changes: 2 additions & 1 deletion backend/src/hatchling/builders/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,13 @@ def __init__(

def build(
self,
*,
directory: str | None = None,
versions: list[str] | None = None,
hooks_only: bool | None = None,
clean: bool | None = None,
clean_hooks_after: bool | None = None,
clean_only: bool | None = False, # noqa: FBT002
clean_only: bool | None = False,
) -> Generator[str, None, None]:
# Fail early for invalid project metadata
self.metadata.validate_fields()
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/builders/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]: # noqa: PLR6301
return ['standard']

def clean(
self, # noqa: PLR6301
def clean( # noqa: PLR6301
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
Expand Down
4 changes: 2 additions & 2 deletions backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@ def get_version_api(self) -> dict[str, Callable]:
def get_default_versions(self) -> list[str]: # noqa: PLR6301
return ['standard']

def clean(
self, # noqa: PLR6301
def clean( # noqa: PLR6301
self,
directory: str,
versions: list[str], # noqa: ARG002
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, formatters: ChainMap) -> None:
def vformat(self, format_string: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> str:
# We override to increase the recursion limit from 2 to 10
#
# TODO remove type ignore after https://github.com/python/typeshed/pull/9228
# TODO: remove type ignore after https://github.com/python/typeshed/pull/9228
used_args = set() # type: ignore[var-annotated]
result, _ = self._vformat(format_string, args, kwargs, used_args, 10)
self.check_unused_args(used_args, args, kwargs)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, root: str, relative_path: str) -> None:
self.__path = os.path.normpath(os.path.join(root, relative_path))
self.__cached_read_data: tuple | None = None

def read(self, pattern: str | bool) -> str:
def read(self, *, pattern: str | bool) -> str:
if not os.path.isfile(self.__path):
message = f'file does not exist: {self.__relative_path}'
raise OSError(message)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/hatchling/version/source/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_version_data(self) -> dict:
raise TypeError(message)

version_file = VersionFile(self.root, relative_path)
version = version_file.read(pattern)
version = version_file.read(pattern=pattern)

return {'version': version, 'version_file': version_file}

Expand Down
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ write-summary-report = "python scripts/write_coverage_summary_report.py"
detached = true
dependencies = [
"mypy>=1.0.0",
"ruff==0.1.4",
"ruff==0.1.6",
]
[envs.lint.scripts]
typing = "mypy --install-types --non-interactive {args:backend/src/hatchling src/hatch tests}"
Expand Down
22 changes: 18 additions & 4 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ select = [
"E116",
"E201",
"E202",
"E203",
"E211",
"E221",
"E222",
Expand Down Expand Up @@ -185,9 +186,12 @@ select = [
"FURB113",
"FURB131",
"FURB132",
"FURB136",
"FURB145",
"FURB148",
"FURB152",
"FURB168",
"FURB169",
"FURB171",
"FURB177",
"G001",
Expand Down Expand Up @@ -265,6 +269,7 @@ select = [
"PLE0604",
"PLE0605",
"PLE0704",
"PLE1142",
"PLE1205",
"PLE1206",
"PLE1300",
Expand All @@ -283,6 +288,7 @@ select = [
"PLR0206",
"PLR0402",
"PLR1701",
"PLR1704",
"PLR1706",
"PLR1711",
"PLR1714",
Expand Down Expand Up @@ -311,11 +317,8 @@ select = [
"PLW2901",
"PLW3201",
"PLW3301",
"PT001",
"PT002",
"PT003",
"PT004",
"PT005",
"PT006",
"PT007",
"PT008",
Expand All @@ -333,7 +336,6 @@ select = [
"PT020",
"PT021",
"PT022",
"PT023",
"PT024",
"PT025",
"PT026",
Expand Down Expand Up @@ -461,6 +463,7 @@ select = [
"S609",
"S612",
"S701",
"S702",
"SIM101",
"SIM102",
"SIM103",
Expand Down Expand Up @@ -499,7 +502,18 @@ select = [
"TCH003",
"TCH004",
"TCH005",
"TD004",
"TD005",
"TD006",
"TD007",
"TID251",
"TID252",
"TID253",
"TRIO100",
"TRIO105",
"TRIO109",
"TRIO110",
"TRIO115",
"TRY002",
"TRY003",
"TRY004",
Expand Down
14 changes: 7 additions & 7 deletions src/hatch/cli/env/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ def create(app, env_name):
)

incompatible = {}
for env_name in environments:
environment = app.get_environment(env_name)
for env in environments:
environment = app.get_environment(env)

try:
environment.check_compatibility()
except Exception as e: # noqa: BLE001
if root_env_name in project_config.matrices:
incompatible[env_name] = str(e)
incompatible[env] = str(e)
continue

app.abort(f'Environment `{env_name}` is incompatible: {e}')
app.abort(f'Environment `{env}` is incompatible: {e}')

if environment.exists():
app.display_warning(f'Environment `{env_name}` already exists')
app.display_warning(f'Environment `{env}` already exists')
continue

app.prepare_environment(environment)
Expand All @@ -43,5 +43,5 @@ def create(app, env_name):
app.display_warning(
f'Skipped {num_incompatible} incompatible environment{"s" if num_incompatible > 1 else ""}:'
)
for env_name, reason in incompatible.items():
app.display_warning(f'{env_name} -> {reason}')
for env, reason in incompatible.items():
app.display_warning(f'{env} -> {reason}')
4 changes: 2 additions & 2 deletions src/hatch/cli/env/find.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def find(app, env_name):
else [root_env_name]
)

for env_name in environments:
environment = app.get_environment(env_name)
for env in environments:
environment = app.get_environment(env)

try:
environment.check_compatibility()
Expand Down
4 changes: 2 additions & 2 deletions src/hatch/cli/python/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ def install(app: Application, *, names: tuple[str, ...], private: bool, update:
f'\nThe following director{"ies" if multiple else "y"} ha{"ve" if multiple else "s"} '
f'been added to your PATH (pending a shell restart):\n'
)
for directory in directories_made_public:
app.display(directory)
for public_directory in directories_made_public:
app.display(public_directory)
6 changes: 3 additions & 3 deletions src/hatch/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,11 @@ def display_table(self, title, columns, *, show_lines=False, column_options=None
table = Table(title=title, show_lines=show_lines, title_style='', **table_options)
columns = dict(columns)

for title, indices in list(columns.items()):
for column_title, indices in list(columns.items()):
if indices:
table.add_column(title, style='bold', **column_options.get(title, {}))
table.add_column(column_title, style='bold', **column_options.get(column_title, {}))
else:
columns.pop(title)
columns.pop(column_title)

if not columns:
return
Expand Down
4 changes: 2 additions & 2 deletions src/hatch/env/plugin/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ def expand_command(self, command):
else:
yield self.metadata.context.format(command, args=args).strip()

def construct_build_command(
self, # noqa: PLR6301
def construct_build_command( # noqa: PLR6301
self,
*,
directory=None,
targets=(),
Expand Down
4 changes: 2 additions & 2 deletions tests/backend/builders/plugin/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def test_unknown_version(self, isolation):
builder.get_version_api = lambda: {'1': str}

with pytest.raises(ValueError, match='Unknown versions for target `foo`: 42, 9000'):
next(builder.build(str(isolation), versions=['9000', '42']))
next(builder.build(directory=str(isolation), versions=['9000', '42']))

def test_invalid_metadata(self, isolation):
config = {
Expand All @@ -133,7 +133,7 @@ def test_invalid_metadata(self, isolation):
ValueError,
match='Metadata field `version` cannot be both statically defined and listed in field `project.dynamic`',
):
next(builder.build(str(isolation)))
next(builder.build(directory=str(isolation)))


class TestHookConfig:
Expand Down
8 changes: 4 additions & 4 deletions tests/backend/builders/test_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def get_builder():
return CustomWheelBuilder
class CustomWheelBuilder(WheelBuilder):
def build(self, *args, **kwargs):
for i, artifact in enumerate(super().build(*args, **kwargs)):
def build(self, **kwargs):
for i, artifact in enumerate(super().build(**kwargs)):
build_dir = os.path.dirname(artifact)
new_path = os.path.join(build_dir, f'{self.PLUGIN_NAME}-{i}.whl')
os.replace(artifact, new_path)
Expand Down Expand Up @@ -155,8 +155,8 @@ def get_builder():
return CustomWheelBuilder
class CustomWheelBuilder(WheelBuilder):
def build(self, *args, **kwargs):
for i, artifact in enumerate(super().build(*args, **kwargs)):
def build(self, **kwargs):
for i, artifact in enumerate(super().build(**kwargs)):
build_dir = os.path.dirname(artifact)
new_path = os.path.join(build_dir, f'{self.PLUGIN_NAME}-{i}.whl')
os.replace(artifact, new_path)
Expand Down
12 changes: 6 additions & 6 deletions tests/backend/builders/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def test_default_no_reproducible(self, hatch, helpers, temp_dir, config_file):
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down Expand Up @@ -783,7 +783,7 @@ def test_default_support_legacy(self, hatch, helpers, temp_dir, config_file):
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down Expand Up @@ -857,7 +857,7 @@ def initialize(self, version, build_data):
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down Expand Up @@ -932,7 +932,7 @@ def initialize(self, version, build_data):
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down Expand Up @@ -1380,7 +1380,7 @@ def test_default_vcs_git_exclusion_files(self, hatch, helpers, temp_dir, config_
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def test_default_vcs_mercurial_exclusion_files(self, hatch, helpers, temp_dir, c
build_path.mkdir()

with project_path.as_cwd():
artifacts = list(builder.build(str(build_path)))
artifacts = list(builder.build(directory=str(build_path)))

assert len(artifacts) == 1
expected_artifact = artifacts[0]
Expand Down
Loading

0 comments on commit 6c252f8

Please sign in to comment.