Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#9756)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/asottile/pyupgrade: v3.9.0 → v3.10.1](asottile/pyupgrade@v3.9.0...v3.10.1)
- [github.com/astral-sh/ruff-pre-commit: v0.0.278 → v0.0.281](astral-sh/ruff-pre-commit@v0.0.278...v0.0.281)
- [github.com/PyCQA/flake8: 6.0.0 → 6.1.0](PyCQA/flake8@6.0.0...6.1.0)

* fix issues reported by ruff

- also remove redundant flake8 plugins
- remove beautysh as we don't have any scripts now
- remove pyupgrade as it is redundant due to ruff

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Saugat Pachhai (सौगात) <suagatchhetri@outlook.com>
  • Loading branch information
pre-commit-ci[bot] and skshetry authored Aug 2, 2023
1 parent 5c2fd67 commit 502b3df
Show file tree
Hide file tree
Showing 25 changed files with 59 additions and 66 deletions.
15 changes: 8 additions & 7 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
[flake8]
ignore=
max_line_length = 88
extend-ignore=
# Whitespace before ':'
E203
# Too many leading '#' for block comment
E266
# Line break occurred before a binary operator
W503
# unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
P1
# use `!r` instead of surrounding by quotes
B028
max_line_length = 88
max-complexity = 10
select = B,C,E,F,W,T4,B902,T,P,TYP
show_source = true
count = true
min_python_version = 3.8.0
per-file-ignores =
dvc/testing/benchmarks/conftest.py:F401
dvc/testing/conftest.py:F401
dvc/testing/plugin.py:F401
tests/conftest.py:F401
tests/func/experiments/executor/test_ssh.py:F401
18 changes: 2 additions & 16 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,6 @@ repos:
- id: mixed-line-ending
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/lovesegfault/beautysh
rev: v6.2.1
hooks:
- id: beautysh
args: ["-i", "2"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.9.0
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
Expand All @@ -43,7 +32,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.278'
rev: 'v0.0.282'
hooks:
- id: ruff
- repo: https://github.com/codespell-project/codespell
Expand All @@ -52,13 +41,10 @@ repos:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
- flake8-typing-imports
- repo: https://github.com/PyCQA/bandit
Expand Down
2 changes: 1 addition & 1 deletion dvc/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __getattr__(self, name):
raise AttributeError("dvc.api.open() should be used in a with statement.")


def open( # noqa, pylint: disable=redefined-builtin
def open( # noqa: A001, pylint: disable=redefined-builtin
path: str,
repo: Optional[str] = None,
rev: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def main(argv=None): # noqa: C901, PLR0912, PLR0915
logger.exception("")
except DvcParserError:
ret = 254
except Exception as exc: # noqa, pylint: disable=broad-except
except Exception as exc: # noqa: BLE001, pylint: disable=broad-except
# pylint: disable=no-member
ret = _log_exceptions(exc) or 255

Expand Down
9 changes: 4 additions & 5 deletions dvc/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def column(self, name: str) -> Column:
return self._columns[name]

def items(self) -> ItemsView[str, Column]:
projection = {k: self.column(k) for k in self.keys()} # noqa: SIM118
projection = {k: self.column(k) for k in self.keys()}
return projection.items()

def keys(self) -> List[str]:
Expand Down Expand Up @@ -171,8 +171,7 @@ def row_from_dict(self, d: Mapping[str, "CellT"]) -> None:
self.add_column(key)

row: List["CellT"] = [
with_value(d.get(key), self._fill_value)
for key in self.keys() # noqa: SIM118
with_value(d.get(key), self._fill_value) for key in self.keys()
]
self.append(row)

Expand Down Expand Up @@ -227,7 +226,7 @@ def dropna( # noqa: C901, PLR0912
to_drop -= match_line

if axis == "rows":
for name in self.keys(): # noqa: SIM118
for name in self.keys():
self._columns[name] = Column(
[x for n, x in enumerate(self._columns[name]) if n not in to_drop]
)
Expand Down Expand Up @@ -275,7 +274,7 @@ def drop_duplicates( # noqa: C901
else:
unique_rows.append(tuple_row)

for name in self.keys(): # noqa: SIM118
for name in self.keys():
self._columns[name] = Column(
[
x
Expand Down
2 changes: 1 addition & 1 deletion dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def __init__(self, url):
super().__init__(f"The path '{url}' does not exist")


class IsADirectoryError(DvcException): # noqa,pylint:disable=redefined-builtin
class IsADirectoryError(DvcException): # noqa: A001,pylint:disable=redefined-builtin
"""Raised when a file operation is requested on a directory."""


Expand Down
2 changes: 1 addition & 1 deletion dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def emit(self, record):
self.flush()
except (BrokenPipeError, RecursionError):
raise
except Exception: # noqa, pylint: disable=broad-except
except Exception: # noqa: BLE001, pylint: disable=broad-except
self.handleError(record)


Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def used_objs( # noqa: PLR0913
used_run_cache=None,
revs=None,
num=1,
push: bool = False, # noqa: F811
push: bool = False,
):
"""Get the stages related to the given target and collect
the `info` of its outputs.
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def _collect_pipeline_files(repo, targets: List[str], props, onerror=None):
if isinstance(elem, str):
dvcfile_defs_dict[elem] = None
else:
k, v = list(elem.items())[0]
k, v = next(iter(elem.items()))
dvcfile_defs_dict[k] = v

resolved = _resolve_definitions(
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def _get_update_diff_index(
meta_cmp_key=partial(_meta_checksum, remote.fs),
with_unchanged=True,
):
if change.typ == ADD or change.typ == MODIFY:
if change.typ in (ADD, MODIFY):
entry = change.new
# preserve md5's which were calculated in out.save() after
# downloading
Expand Down
2 changes: 1 addition & 1 deletion dvc/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def map_scm_exception(with_cause: bool = False) -> Iterator[None]:
into = SCMError(str(exc))
if with_cause:
raise into from exc
raise into
raise into # noqa: B904


@overload
Expand Down
2 changes: 1 addition & 1 deletion dvc/testing/benchmarks/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .fixtures import * # noqa, pylint: disable=wildcard-import
from .fixtures import * # noqa: F403 # pylint: disable=wildcard-import
2 changes: 1 addition & 1 deletion dvc/testing/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .fixtures import * # noqa, pylint: disable=wildcard-import
from .fixtures import * # noqa: F403, pylint: disable=wildcard-import
4 changes: 2 additions & 2 deletions dvc/testing/plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .benchmarks.fixtures import * # noqa, pylint: disable=wildcard-import
from .fixtures import * # noqa, pylint: disable=wildcard-import
from .benchmarks.fixtures import * # noqa: F403, pylint: disable=wildcard-import
from .fixtures import * # noqa: F403, pylint: disable=wildcard-import


def pytest_generate_tests(metafunc):
Expand Down
10 changes: 5 additions & 5 deletions dvc/utils/serialize/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from collections import defaultdict
from typing import DefaultDict

from ._common import * # noqa, pylint: disable=wildcard-import
from ._json import * # noqa, pylint: disable=wildcard-import
from ._py import * # noqa, pylint: disable=wildcard-import
from ._toml import * # noqa, pylint: disable=wildcard-import
from ._yaml import * # noqa, pylint: disable=wildcard-import
from ._common import * # noqa: F403, pylint: disable=wildcard-import
from ._json import * # noqa: F403, pylint: disable=wildcard-import
from ._py import * # noqa: F403, pylint: disable=wildcard-import
from ._toml import * # noqa: F403, pylint: disable=wildcard-import
from ._yaml import * # noqa: F403, pylint: disable=wildcard-import

LOADERS: DefaultDict[str, LoaderFn] = defaultdict( # noqa: F405
lambda: load_yaml # noqa: F405
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ ignore-variadic-names = true
known-first-party = ["dvc", "dvc_data", "dvc_objects", "dvc_render", "dvc_task", "tests"]

[tool.ruff.pep8-naming]
ignore-names = ["M", "SCM"]
extend-ignore-names = ["M", "SCM"]

[tool.ruff.per-file-ignores]
"dvc/commands/**" = ["N806"]
Expand Down
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from dvc import env
from dvc.stage import PipelineStage
from dvc.testing.fixtures import * # noqa, pylint: disable=wildcard-import
from dvc.testing.fixtures import * # noqa: F403, pylint: disable=wildcard-import

from .dir_helpers import * # noqa, pylint: disable=wildcard-import
from .remotes import * # noqa, pylint: disable=wildcard-import
from .scripts import * # noqa, pylint: disable=wildcard-import
from .dir_helpers import * # noqa: F403 # pylint: disable=wildcard-import
from .remotes import * # noqa: F403 # pylint: disable=wildcard-import
from .scripts import * # noqa: F403, pylint: disable=wildcard-import

# Prevent updater and analytics from running their processes
os.environ["DVC_TEST"] = "true"
Expand Down
2 changes: 1 addition & 1 deletion tests/func/api/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from dvc import api
from dvc.exceptions import OutputNotFoundError, PathMissingError
from dvc.testing.api_tests import TestAPI # noqa, pylint: disable=unused-import
from dvc.testing.api_tests import TestAPI # noqa: F401, pylint: disable=unused-import
from dvc.testing.tmp_dir import make_subrepo
from dvc.utils.fs import remove

Expand Down
3 changes: 2 additions & 1 deletion tests/func/experiments/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

from tests.unit.repo.experiments.conftest import ( # noqa, pylint disable=unused-argument
# pylint: disable-next=unused-argument
from tests.unit.repo.experiments.conftest import ( # noqa: F401
exp_stage,
failed_exp_stage,
session_app,
Expand Down
4 changes: 3 additions & 1 deletion tests/func/experiments/executor/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from dvc.repo.experiments.executor.base import ExecutorInfo, ExecutorResult
from dvc.repo.experiments.executor.ssh import SSHExecutor
from dvc.repo.experiments.refs import EXEC_HEAD, EXEC_MERGE
from tests.func.machine.conftest import * # noqa, pylint: disable=wildcard-import

# pylint: disable-next=wildcard-import
from tests.func.machine.conftest import * # noqa: F403


@contextmanager
Expand Down
4 changes: 2 additions & 2 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,9 @@ def temporary_windows_drive(tmp_path_factory):
if len(s) > 0
]

new_drive_name = [
new_drive_name = next(
letter for letter in string.ascii_uppercase if letter not in drives
][0]
)
new_drive = f"{new_drive_name}:"

target_path = tmp_path_factory.mktemp("tmp_windows_drive")
Expand Down
6 changes: 2 additions & 4 deletions tests/func/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_list_bad_args(tmp_dir, dvc, caplog, args):


def test_set_invalid_key(dvc):
with pytest.raises(ConfigError, match=r"extra keys not allowed"): # noqa: PT012
with pytest.raises(ConfigError, match=r"extra keys not allowed"):
with dvc.config.edit() as conf:
conf["core"]["invalid_key"] = "value"

Expand All @@ -227,9 +227,7 @@ def test_merging_two_levels(dvc):
with dvc.config.edit() as conf:
conf["remote"]["test"] = {"url": "ssh://example.com"}

with pytest.raises( # noqa: PT012
ConfigError, match=r"expected 'url' for dictionary value"
):
with pytest.raises(ConfigError, match=r"expected 'url' for dictionary value"):
with dvc.config.edit("global") as conf:
conf["remote"]["test"] = {"password": "1"}

Expand Down
4 changes: 3 additions & 1 deletion tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from dvc.exceptions import CheckoutError
from dvc.repo.open_repo import clean_repos
from dvc.stage.exceptions import StageNotFound
from dvc.testing.remote_tests import TestRemote # noqa, pylint: disable=unused-import
from dvc.testing.remote_tests import ( # noqa: F401, pylint: disable=unused-import
TestRemote,
)
from dvc.utils.fs import remove
from dvc_data.hashfile.db import HashFileDB
from dvc_data.hashfile.db.local import LocalHashFileDB
Expand Down
14 changes: 9 additions & 5 deletions tests/func/test_stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_default_wdir_ignored_in_checksum(tmp_dir, dvc):
stage = dvc.run(cmd="cp bar foo", deps=["bar"], outs=["foo"], name="copy-foo-bar")

d = stage.dumpd()
assert Stage.PARAM_WDIR not in d.keys()
assert Stage.PARAM_WDIR not in d

d = load_yaml("dvc.yaml")
assert Stage.PARAM_WDIR not in d["stages"]["copy-foo-bar"]
Expand Down Expand Up @@ -246,13 +246,17 @@ def test_collect_symlink(tmp_dir, dvc, with_deps):
with pytest.raises(StageNotFoundError):
dvc.stage.collect(target=str(data_link / "foo.dvc"), with_deps=with_deps)
else:
stage = list(
dvc.stage.collect(target=str(data_link / "foo.dvc"), with_deps=with_deps)
)[0]
stage = next(
iter(
dvc.stage.collect(
target=str(data_link / "foo.dvc"), with_deps=with_deps
)
)
)

assert stage.addressing == os.path.join("data_link", "foo.dvc")

stage = list(dvc.stage.collect(target=f"{foo_path}.dvc", with_deps=with_deps))[0]
stage = next(iter(dvc.stage.collect(target=f"{foo_path}.dvc", with_deps=with_deps)))

assert stage.addressing == os.path.join("data", "foo.dvc")

Expand Down
2 changes: 1 addition & 1 deletion tests/remotes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dvc_ssh.tests.fixtures import ( # noqa, pylint: disable=unused-import
from dvc_ssh.tests.fixtures import ( # noqa: F401, pylint: disable=unused-import
make_ssh,
ssh,
ssh_server,
Expand Down

0 comments on commit 502b3df

Please sign in to comment.