Skip to content

Commit

Permalink
Update Ruff rules (#1084)
Browse files Browse the repository at this point in the history
* Upgrade Ruff

* Update test_fmt.py
  • Loading branch information
ofek authored Dec 5, 2023
1 parent 5f76298 commit bbcbc41
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 52 deletions.
6 changes: 6 additions & 0 deletions ruff_defaults.toml
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ select = [
"PLW2901",
"PLW3201",
"PLW3301",
"PT001",
"PT002",
"PT003",
"PT006",
Expand All @@ -336,6 +337,7 @@ select = [
"PT020",
"PT021",
"PT022",
"PT023",
"PT024",
"PT025",
"PT026",
Expand Down Expand Up @@ -598,3 +600,7 @@ ban-relative-imports = "all"

[lint.isort]
known-first-party = ["hatch"]

[lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false
2 changes: 1 addition & 1 deletion scripts/update_ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Conflicts with type checking
'RET501', 'RET502',
# Under review https://github.com/astral-sh/ruff/issues/8796
'PT001', 'PT004', 'PT005', 'PT023',
'PT004', 'PT005',
# Buggy https://github.com/astral-sh/ruff/issues/4845
'ERA001',
# Too prone to false positives and might be removed https://github.com/astral-sh/ruff/issues/4045
Expand Down
6 changes: 6 additions & 0 deletions src/hatch/env/internal/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ def construct_config_file(self, *, preview: bool | None) -> str:
'',
'[lint.isort]',
f'known-first-party = ["{self.metadata.name.replace("-", "_")}"]',
'',
'[lint.flake8-pytest-style]',
'fixture-parentheses = false',
'mark-parentheses = false',
)
)

Expand Down Expand Up @@ -438,6 +442,7 @@ def get_config(self, section: str) -> dict[str, Any]:
'PLW1510',
'PLW2901',
'PLW3301',
'PT001',
'PT002',
'PT003',
'PT006',
Expand All @@ -457,6 +462,7 @@ def get_config(self, section: str) -> dict[str, Any]:
'PT020',
'PT021',
'PT022',
'PT023',
'PT024',
'PT025',
'PT026',
Expand Down
2 changes: 1 addition & 1 deletion tests/backend/builders/plugin/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def test_unknown(self, isolation):


class TestDirectoryRecursion:
@pytest.mark.requires_unix()
@pytest.mark.requires_unix
def test_infinite_loop_prevention(self, temp_dir):
project_dir = temp_dir / 'project'
project_dir.ensure_dir_exists()
Expand Down
6 changes: 3 additions & 3 deletions tests/backend/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ def initialize(self, version, build_data):
)
helpers.assert_files(extraction_directory, expected_files)

@pytest.mark.requires_unix()
@pytest.mark.requires_unix
def test_default_symlink(self, hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['src-layout'] = False
config_file.save()
Expand Down Expand Up @@ -2185,7 +2185,7 @@ def test_editable_default_force_include_option(self, hatch, helpers, temp_dir):
zip_info = zip_archive.getinfo(f'{metadata_directory}/WHEEL')
assert zip_info.date_time == (2020, 2, 2, 0, 0, 0)

@pytest.mark.requires_unix()
@pytest.mark.requires_unix
def test_editable_default_symlink(self, hatch, helpers, temp_dir):
project_name = 'My.App'

Expand Down Expand Up @@ -3066,7 +3066,7 @@ def initialize(self, version, build_data):
)
helpers.assert_files(extraction_directory, expected_files)

@pytest.mark.requires_macos()
@pytest.mark.requires_macos
def test_macos_max_compat(self, hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['src-layout'] = False
config_file.save()
Expand Down
24 changes: 12 additions & 12 deletions tests/backend/dep/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def test_dependency_not_found(platform):
assert not dependencies_in_sync([Requirement('binary')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_dependency_found(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'binary'], check=True, capture_output=True)
assert dependencies_in_sync([Requirement('binary')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_version_unmet(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'binary'], check=True, capture_output=True)
Expand All @@ -41,36 +41,36 @@ def test_marker_unmet(platform):
assert not dependencies_in_sync([Requirement('binary; python_version > "1"')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_extra_no_dependencies(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'binary'], check=True, capture_output=True)
assert not dependencies_in_sync([Requirement('binary[foo]')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_unknown_extra(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'requests[security]==2.25.1'], check=True, capture_output=True)
assert not dependencies_in_sync([Requirement('requests[foo]')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_extra_unmet(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'requests==2.25.1'], check=True, capture_output=True)
assert not dependencies_in_sync([Requirement('requests[security]==2.25.1')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_extra_met(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(['pip', 'install', 'requests[security]==2.25.1'], check=True, capture_output=True)
assert dependencies_in_sync([Requirement('requests[security]==2.25.1')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_git()
@pytest.mark.requires_internet
@pytest.mark.requires_git
def test_dependency_git(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(
Expand All @@ -79,8 +79,8 @@ def test_dependency_git(platform):
assert dependencies_in_sync([Requirement('requests@git+https://github.com/psf/requests')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_git()
@pytest.mark.requires_internet
@pytest.mark.requires_git
def test_dependency_git_revision(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(
Expand All @@ -89,8 +89,8 @@ def test_dependency_git_revision(platform):
assert dependencies_in_sync([Requirement('requests@git+https://github.com/psf/requests@main')], venv.sys_path)


@pytest.mark.requires_internet()
@pytest.mark.requires_git()
@pytest.mark.requires_internet
@pytest.mark.requires_git
def test_dependency_git_commit(platform):
with TempVirtualEnv(sys.executable, platform) as venv:
platform.run_command(
Expand Down
18 changes: 9 additions & 9 deletions tests/cli/env/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ def test_incompatible_matrix_partial(hatch, helpers, temp_dir, config_file):
assert env_dirs[0].name == 'test.42'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_install_project_default_dev_mode(
hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements
):
Expand Down Expand Up @@ -944,7 +944,7 @@ def test_install_project_default_dev_mode(
assert requirements[0].lower() == f'-e {str(project_path).lower()}'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_install_project_no_dev_mode(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1003,7 +1003,7 @@ def test_install_project_no_dev_mode(hatch, helpers, temp_dir, platform, config_
assert requirements[0].startswith('my-app @')


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_pre_install_commands(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def test_pre_install_commands_error(hatch, helpers, temp_dir, config_file):
)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_post_install_commands(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1123,7 +1123,7 @@ def test_post_install_commands(hatch, helpers, temp_dir, config_file):
assert (project_path / 'test.txt').is_file()


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_post_install_commands_error(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1161,7 +1161,7 @@ def test_post_install_commands_error(hatch, helpers, temp_dir, config_file):
)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_sync_dependencies(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1232,7 +1232,7 @@ def test_sync_dependencies(hatch, helpers, temp_dir, platform, config_file, extr
assert requirements[1].lower() == f'-e {str(project_path).lower()}'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_features(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1295,7 +1295,7 @@ def test_features(hatch, helpers, temp_dir, platform, config_file, extract_insta
assert requirements[1].lower() == f'-e {str(project_path).lower()}'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_sync_dynamic_dependencies(hatch, helpers, temp_dir, platform, config_file, extract_installed_requirements):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1394,7 +1394,7 @@ def update(self, metadata):
assert requirements[3].lower() == f'my-app1 @ {path_to_uri(project_path).lower()}/../my-app1'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_unknown_dynamic_feature(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down
4 changes: 4 additions & 0 deletions tests/cli/fmt/test_fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def construct_ruff_defaults_file(rules: tuple[str, ...]) -> str:
'',
'[lint.isort]',
'known-first-party = ["my_app"]',
'',
'[lint.flake8-pytest-style]',
'fixture-parentheses = false',
'mark-parentheses = false',
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/new/test_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_default_empty_plugins_table(hatch, helpers, config_file, temp_dir):
)


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_default_no_license_cache(hatch, helpers, temp_dir):
project_name = 'My.App'
cache_dir = temp_dir / 'cache'
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/project/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_field_complex(self, hatch, temp_dir, helpers):


class TestBuildDependenciesMissing:
@pytest.mark.allow_backend_process()
@pytest.mark.allow_backend_process
def test_incompatible_environment(self, hatch, temp_dir, helpers):
project_name = 'My.App'

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/publish/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def keyring_store(mocker):
return mock_store


@pytest.fixture()
@pytest.fixture
def published_project_name():
return f'c4880cdbe05de9a28415fbad{secrets.choice(range(100))}'

Expand Down
2 changes: 1 addition & 1 deletion tests/cli/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def disable_path_detectors(mocker):
mocker.patch('userpath.in_new_path', return_value=False)


@pytest.fixture()
@pytest.fixture
def dist_name(compatible_python_distributions):
return secrets.choice(compatible_python_distributions)
2 changes: 1 addition & 1 deletion tests/cli/python/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_incompatible_all(hatch, helpers, path_append, platform, mocker):
path_append.assert_not_called()


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_installation(
hatch, helpers, temp_dir_data, platform, path_append, default_shells, compatible_python_distributions
):
Expand Down
18 changes: 9 additions & 9 deletions tests/cli/run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_enter_project_directory(hatch, config_file, helpers, temp_dir):
assert str(env_path) in str(output_file.read_text())


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_sync_dependencies(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -220,7 +220,7 @@ def test_sync_dependencies(hatch, helpers, temp_dir, config_file):
assert str(output_file.read_text()) == "(1.0, 'KiB')"


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_sync_project_dependencies(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -293,7 +293,7 @@ def test_sync_project_dependencies(hatch, helpers, temp_dir, config_file):
assert str(output_file.read_text()) == "(1.0, 'KiB')"


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_sync_project_features(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -372,7 +372,7 @@ def test_sync_project_features(hatch, helpers, temp_dir, config_file):
assert str(output_file.read_text()) == "(1.0, 'KiB')"


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_dependency_hash_checking(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -586,7 +586,7 @@ def test_scripts_specific_environment(hatch, helpers, temp_dir, config_file):
assert env_var_value == 'bar'


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_scripts_no_environment(hatch, helpers, temp_dir, config_file):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1865,7 +1865,7 @@ def test_plugin_dependencies_unmet(hatch, helpers, temp_dir, config_file, mock_p
assert str(env_path) in str(output_file.read_text())


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_install_python_specific(hatch, helpers, temp_dir, config_file, mocker, available_python_version):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -1932,7 +1932,7 @@ def test_install_python_specific(hatch, helpers, temp_dir, config_file, mocker,
assert list(manager.get_installed()) == [available_python_version]


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_update_python_specific(hatch, helpers, temp_dir, config_file, mocker, available_python_version):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -2002,7 +2002,7 @@ def test_update_python_specific(hatch, helpers, temp_dir, config_file, mocker, a
assert str(env_path) in str(output_file.read_text())


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_install_python_max_compatible(hatch, helpers, temp_dir, config_file, mocker, available_python_version):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down Expand Up @@ -2065,7 +2065,7 @@ def test_install_python_max_compatible(hatch, helpers, temp_dir, config_file, mo
assert list(manager.get_installed()) == [available_python_version]


@pytest.mark.requires_internet()
@pytest.mark.requires_internet
def test_update_python_max_compatible(hatch, helpers, temp_dir, config_file, mocker, available_python_version):
config_file.model.template.plugins['default']['tests'] = False
config_file.save()
Expand Down
Loading

0 comments on commit bbcbc41

Please sign in to comment.