[pre-commit.ci] pre-commit autoupdate (#9632)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/asottile/pyupgrade: v3.3.1 → v3.9.0](https://github.com/asottile/pyupgrade/compare/v3.3.1...v3.9.0)
- https://github.com/charliermarsh/ruff-pre-commit → https://github.com/astral-sh/ruff-pre-commit
- [github.com/astral-sh/ruff-pre-commit: v0.0.261 → v0.0.277](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.261...v0.0.277)
- [github.com/codespell-project/codespell: v2.2.4 → v2.2.5](https://github.com/codespell-project/codespell/compare/v2.2.4...v2.2.5)

* fix ruff complaints

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Saugat Pachhai (सौगात) <[email protected]>
This commit is contained in:
pre-commit-ci[bot]
2023-07-14 20:11:15 +05:45
committed by GitHub
co-authored by Saugat Pachhai
parent f1764bdc77
commit ca3704997b
33 changed files with 60 additions and 88 deletions
+5 -5
View File
@@ -29,25 +29,25 @@ repos:
- id: beautysh
args: ["-i", "2"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.9.0
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.261'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.0.278'
hooks:
- id: ruff
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.5
hooks:
- id: codespell
additional_dependencies: ["tomli"]
+1 -1
View File
@@ -192,7 +192,7 @@ def main(argv=None): # noqa: C901, PLR0912, PLR0915
from dvc import PKG, __version__
pyv = " ".join([python_implementation(), python_version()])
pyv = f"{python_implementation()} {python_version()}"
pkg = f" ({PKG})" if PKG else ""
logger.debug("v%s%s, %s on %s", __version__, pkg, pyv, platform())
logger.debug("command: %s", " ".join(argv or sys.argv))
+1 -3
View File
@@ -16,9 +16,7 @@ def append_doc_link(help_message, path):
if not path:
return help_message
doc_base = "https://man.dvc.org/"
return "{message}\nDocumentation: {link}".format(
message=help_message, link=format_link(doc_base + path)
)
return f"{help_message}\nDocumentation: {format_link(doc_base + path)}"
def hide_subparsers_from_help(subparsers):
+1 -3
View File
@@ -90,9 +90,7 @@ class CmdDataStatus(CmdBase):
ui.write(f" ({hint})")
if isinstance(stage_status, dict):
items = [
": ".join([state, file]) for file, state in stage_status.items()
]
items = [f"{state}: {file}" for file, state in stage_status.items()]
else:
items = stage_status
+1 -3
View File
@@ -127,9 +127,7 @@ class CmdRemoteRename(CmdRemote):
all_config = self.config.load_config_to_level(None)
if self.args.new in all_config.get("remote", {}):
raise ConfigError(
"Rename failed. Remote name '{}' already exists.".format(
{self.args.new}
)
f"Rename failed. Remote name {self.args.new!r} already exists."
)
with self.config.edit(self.args.level) as conf:
+1 -1
View File
@@ -75,7 +75,7 @@ def ByUrl(mapping): # noqa: N802
class RelPath(str):
pass
__slots__ = ()
class FeatureSchema(Schema):
+3 -1
View File
@@ -28,7 +28,9 @@ def _popen(cmd, **kwargs) -> Popen:
os.path.abspath(os.path.dirname(__file__)), "__main__.py"
)
prefix += [main_entrypoint]
return Popen(prefix + cmd, close_fds=True, shell=False, **kwargs) # nosec B603
return Popen(
prefix + cmd, close_fds=True, shell=False, **kwargs # nosec B603 # noqa: S603
)
def _spawn_windows(cmd, env):
+1 -3
View File
@@ -97,9 +97,7 @@ class FileMixin:
self.verify = verify
def __repr__(self):
return "{}: {}".format(
self.__class__.__name__, relpath(self.path, self.repo.root_dir)
)
return f"{self.__class__.__name__}: {relpath(self.path, self.repo.root_dir)}"
def __hash__(self):
return hash(self.path)
+3 -11
View File
@@ -63,9 +63,7 @@ class OutputNotFoundError(DvcException):
self.output = output
self.repo = repo
super().__init__(
"Unable to find DVC file with output '{path}'".format(
path=relpath(self.output)
)
f"Unable to find DVC file with output {relpath(self.output)!r}"
)
@@ -80,11 +78,7 @@ class StagePathAsOutputError(DvcException):
def __init__(self, stage, output):
assert isinstance(output, str)
super().__init__(
"{stage} is within an output '{output}' of another stage".format(
stage=stage, output=output
)
)
super().__init__(f"{stage} is within an output {output!r} of another stage")
class CircularDependencyError(DvcException):
@@ -156,9 +150,7 @@ class CyclicGraphError(DvcException):
class ConfirmRemoveError(DvcException):
def __init__(self, path):
super().__init__(
"unable to remove '{}' without a confirmation. Use `-f` to force.".format(
path
)
f"unable to remove {path!r} without a confirmation. Use `-f` to force."
)
+1 -1
View File
@@ -56,7 +56,7 @@ def add_logging_level(level_name, level_num, method_name=None):
class LoggingException(Exception):
def __init__(self, record):
msg = f"failed to log {str(record)}"
msg = f"failed to log {record!s}"
super().__init__(msg)
+2 -4
View File
@@ -471,9 +471,7 @@ class Output:
return fs.path.abspath(fs.path.normpath(fs_path))
def __repr__(self):
return "{class_name}: '{def_path}'".format(
class_name=type(self).__name__, def_path=self.def_path
)
return f"{type(self).__name__}: {self.def_path!r}"
def __str__(self):
if self.fs.protocol != "local":
@@ -693,7 +691,7 @@ class Output:
def save(self) -> None:
if self.use_cache and not self.is_in_repo:
raise DvcException(
f"Saving cached external output {str(self)} is not supported "
f"Saving cached external output {self!s} is not supported "
"since DVC 3.0. See "
f"{format_link('https://dvc.org/doc/user-guide/upgrade')} "
"for more info."
+1 -1
View File
@@ -482,7 +482,7 @@ class Repo:
used_run_cache=None,
revs=None,
num=1,
push: bool = False,
push: bool = False, # noqa: F811
):
"""Get the stages related to the given target and collect
the `info` of its outputs.
+1 -1
View File
@@ -234,7 +234,7 @@ def fix_exp_head(scm: Union["Git", "NoSCM"], ref: Optional[str]) -> Optional[str
if ref:
name, tail = Git.split_ref_pattern(ref)
if name == "HEAD" and scm.get_ref(EXEC_BASELINE):
return "".join((EXEC_BASELINE, tail))
return f"{EXEC_BASELINE}{tail}"
return ref
+1 -1
View File
@@ -27,7 +27,7 @@ def get(url, path, out=None, rev=None, jobs=None, force=False):
out = resolve_output(path, out, force=force)
if is_valid_filename(out):
raise GetDVCFileError()
raise GetDVCFileError
with Repo.open(
url=url,
+2 -4
View File
@@ -31,15 +31,13 @@ RWLOCK_LOCK = "rwlock.lock"
class RWLockFileCorruptedError(DvcException):
def __init__(self, path):
super().__init__(
"Unable to read RWLock-file '{}'. JSON structure is corrupted".format(
relpath(path)
)
f"Unable to read RWLock-file {relpath(path)!r}. JSON structure is corrupted"
)
class RWLockFileFormatError(DvcException):
def __init__(self, path):
super().__init__(f"RWLock-file '{relpath(path)}' format error.")
super().__init__(f"RWLock-file {relpath(path)!r} format error.")
@contextmanager
+1 -4
View File
@@ -426,10 +426,7 @@ class Stage(params.StageParams):
logger.info("Stage '%s' didn't change, skipping", self.addressing)
return None
msg = "Going to reproduce {stage}. Are you sure you want to continue?".format(
stage=self
)
msg = f"Going to reproduce {self}. Are you sure you want to continue?"
if interactive and not prompt.confirm(msg):
raise DvcException("reproduction aborted by the user")
+1 -1
View File
@@ -80,7 +80,7 @@ def _run(executable, cmd, **kwargs):
exec_cmd = _make_cmd(executable, cmd)
try:
p = subprocess.Popen(exec_cmd, **kwargs) # nosec B603
p = subprocess.Popen(exec_cmd, **kwargs) # nosec B603 # noqa: S603
if main_thread:
old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)
+1 -1
View File
@@ -90,7 +90,7 @@ def make_dvc_bin(
dvc_bin = bench_config.dvc_bin
def _dvc_bin(*args):
return check_output([dvc_bin, *args], text=True) # nosec B603
return check_output([dvc_bin, *args], text=True) # nosec B603 # noqa: S603
_dvc_bin.version = parse_tuple(_dvc_bin("--version")) # type: ignore[attr-defined]
return _dvc_bin
+5 -3
View File
@@ -233,8 +233,8 @@ def docker_services(
pytest.skip("disabled for Windows on CI")
try:
subprocess.check_output( # nosec B607, B602
"docker ps", stderr=subprocess.STDOUT, shell=True
subprocess.check_output( # nosec B607, B602,
"docker ps", stderr=subprocess.STDOUT, shell=True # noqa: S602, S607
)
except subprocess.CalledProcessError as err:
out = (err.output or b"").decode("utf-8")
@@ -242,7 +242,9 @@ def docker_services(
try:
cmd = "docker-compose version"
subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True) # nosec
subprocess.check_output(
cmd, stderr=subprocess.STDOUT, shell=True # nosec B602 # noqa: S602
)
except subprocess.CalledProcessError as err:
out = (err.output or b"").decode("utf-8")
pytest.skip(f"docker-compose is not installed: {out}")
+1 -1
View File
@@ -147,7 +147,7 @@ class Console:
return self.write(json.text, stderr=stderr)
return self.rich_print(json, stderr=stderr, soft_wrap=True)
def rich_print(
def rich_print( # noqa: PLR0913
self,
*objects: Any,
sep: str = " ",
+2 -1
View File
@@ -59,7 +59,8 @@ def find_pager():
if not pager:
pager = os.getenv(PAGER_ENV)
if not pager:
if os.system(f"({DEFAULT_PAGER}) 2>{os.devnull}") != 0: # nosec B605
ret = os.system(f"({DEFAULT_PAGER}) 2>{os.devnull}") # nosec B605 # noqa: S605
if ret != 0:
logger.warning(
"Unable to find `less` in the PATH. Check out %s for more info.",
format_link("https://man.dvc.org/pipeline/show"),
+1 -1
View File
@@ -319,7 +319,7 @@ def resolve_paths(repo, out, always_local=False):
def format_link(link):
return "<{blue}{link}{nc}>".format(
return "<{blue}{link}{nc}>".format( # noqa: UP032
blue=colorama.Fore.CYAN, link=link, nc=colorama.Fore.RESET
)
+2 -2
View File
@@ -268,8 +268,8 @@ ignored-argument-names = "_.*|args|kwargs"
[tool.ruff]
# external flake8 codes that should be preserved
external = ["B301", "C901", "E302", "W601"]
ignore = ["N818", "S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR2004", "PLW2901", "RUF005"]
select = ["F", "E", "W", "C90", "N", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PT", "Q", "RET501", "RET504", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "RUF"]
ignore = ["N818", "S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR2004", "PLW2901", "RUF005", "RUF012"]
select = ["F", "E", "W", "C90", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10", "EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET501", "RET504", "SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "FLY", "RUF"]
show-source = true
[tool.ruff.flake8-pytest-style]
+2 -2
View File
@@ -187,7 +187,7 @@ def test_params_show_stages(params_repo):
def test_params_show_stage_addressing(tmp_dir, dvc):
for subdir in {"subdir1", "subdir2"}:
for subdir in ("subdir1", "subdir2"):
subdir = tmp_dir / subdir
subdir.mkdir()
with subdir.chdir():
@@ -195,7 +195,7 @@ def test_params_show_stage_addressing(tmp_dir, dvc):
dvc.run(name="stage-0", cmd="echo stage-0", params=["foo"])
for s in {"subdir1", "subdir2"}:
for s in ("subdir1", "subdir2"):
dvcyaml = os.path.join(s, "dvc.yaml")
assert api.params_show(stages=f"{dvcyaml}:stage-0") == {"foo": 1}
+2 -2
View File
@@ -119,7 +119,7 @@ def test_reproduce(tmp_dir, scm, dvc, cloud, exp_stage, mocker):
rev,
fs_factory=partial(_ssh_factory, cloud),
)
assert mock_execute.called_once()
mock_execute.assert_called_once()
_name, args, _kwargs = mock_execute.mock_calls[0]
assert f"dvc exp exec-run --infofile {infofile}" in args[0]
@@ -148,7 +148,7 @@ def test_run_machine(tmp_dir, scm, dvc, cloud, exp_stage, mocker):
tmp_dir.gen("params.yaml", "foo: 2")
dvc.experiments.run(exp_stage.addressing, machine="foo")
assert mock_repro.called_once()
mock_repro.assert_called_once()
_name, _args, kwargs = mock_repro.mock_calls[0]
info = kwargs["info"]
url = urlparse(info.git_url)
@@ -488,16 +488,6 @@ def test_run_celery(tmp_dir, scm, dvc, exp_stage, mocker):
assert expected == metrics
def test_run_metrics(tmp_dir, scm, dvc, exp_stage, mocker):
from dvc.cli import main
mocker.patch.object(dvc.experiments, "run", return_value={"abc123": "abc123"})
show_mock = mocker.patch.object(dvc.metrics, "show", return_value={})
main(["exp", "run", "-m"])
assert show_mock.called_once()
def test_checkout_targets_deps(tmp_dir, scm, dvc, exp_stage):
from dvc.utils.fs import remove
+2 -2
View File
@@ -452,7 +452,7 @@ def test_show_csv(tmp_dir, scm, dvc, exp_stage, capsys):
assert "metrics.yaml:foo,params.yaml:foo,copy.py" in cap.out
assert f",workspace,baseline,,,3,3,{data_hash}" in cap.out
assert (
",master,baseline,{},,1,1,{}".format(
",master,baseline,{},,1,1,{}".format( # noqa: UP032
_get_rev_isotimestamp(baseline_rev), data_hash
)
in cap.out
@@ -682,7 +682,7 @@ def test_metrics_renaming(tmp_dir, dvc, scm, capsys, copy_script):
assert f",master,baseline,{_get_rev_isotimestamp(scores_rev)},,1,,1" in cap.out
assert (
",{},baseline,{},,,1,1".format(
",{},baseline,{},,,1,1".format( # noqa: UP032
metrics_rev[:7], _get_rev_isotimestamp(metrics_rev)
)
in cap.out
+1 -3
View File
@@ -848,9 +848,7 @@ def test_repro_dry_no_exec(tmp_dir, dvc):
idir,
"-o",
odir,
'python -c \'import shutil; shutil.copytree("{}", "{}")\''.format(
idir, odir
),
f'python -c \'import shutil; shutil.copytree("{idir}", "{odir}")\'',
]
)
assert ret == 0
+1 -1
View File
@@ -377,7 +377,7 @@ def test_repo_with_removed_plots(tmp_dir, capsys, repo_with_plots):
remove("confusion.json")
remove("image.png")
for s in {"show", "diff"}:
for s in ("show", "diff"):
_, json_result, split_json_result = call(capsys, subcommand=s)
errors = [
{
@@ -71,7 +71,7 @@ def test_post_run_after_kill(test_queue):
except ProcessLookupError:
time.sleep(0.1)
if time.time() > timeout:
raise TimeoutError()
raise TimeoutError
assert result_foo.get(timeout=10) == "foo"
@@ -132,9 +132,11 @@ def test_celery_queue_kill(test_queue, mocker, force):
)
with pytest.raises(CannotKillTasksError, match="Task 'foobar' is initializing,"):
test_queue.kill(["bar", "foo", "foobar"], force=force)
assert kill_mock.called_once_with(mock_entry_foo.stash_rev)
assert kill_mock.called_once_with(mock_entry_bar.stash_rev)
assert kill_mock.called_once_with(mock_entry_foobar.stash_rev)
assert kill_mock.call_args_list == [
mocker.call(mock_entry_bar.stash_rev),
mocker.call(mock_entry_foo.stash_rev),
mocker.call(mock_entry_foobar.stash_rev),
]
mark_mocker.assert_called_once_with("bar", None)
@@ -157,7 +159,7 @@ def test_celery_queue_kill_invalid(test_queue, mocker, force):
with pytest.raises(UnresolvedExpNamesError):
test_queue.kill(["bar", "foo", "foobar"], force=force)
assert kill_mock.called_once_with(
kill_mock.assert_called_once_with(
{mock_entry_foo: "foo", mock_entry_bar: "bar"}, force
)
+1 -1
View File
@@ -8,7 +8,7 @@ from dvc.repo.experiments.utils import check_ref_format, resolve_name, to_studio
def commit_exp_ref(tmp_dir, scm, file="foo", contents="foo", name="foo"):
tmp_dir.scm_gen(file, contents, commit="init")
rev = scm.get_rev()
ref = "/".join([EXPS_NAMESPACE, "ab", "c123", name])
ref = f"{EXPS_NAMESPACE}/ab/c123/{name}"
scm.gitpython.set_ref(ref, rev)
return ref, rev
+2 -2
View File
@@ -212,7 +212,7 @@ def test_unhashable(tmp_dir, dvc, mocker, kwargs):
stage = create_stage(Stage, path="stage.dvc", repo=dvc, **kwargs)
get_stage_hash = mocker.patch("dvc.stage.cache._get_stage_hash")
assert cache.save(stage) is None
assert get_stage_hash.not_called
get_stage_hash.assert_not_called()
with pytest.raises(RunCacheNotFoundError):
cache.restore(stage)
assert get_stage_hash.not_called
get_stage_hash.assert_not_called()
+3 -3
View File
@@ -69,7 +69,7 @@ def test_stage_update(dvc, mocker):
is_repo_import.return_value = True
with dvc.lock:
stage.update()
assert reproduce.called_once_with()
reproduce.assert_called_once_with(no_download=None, jobs=None)
is_repo_import.return_value = False
with pytest.raises(StageUpdateError):
@@ -92,8 +92,8 @@ def test_stage_run_ignore_sigint(dvc, mocker):
dvc.run(cmd="path", name="train")
assert popen.called_once()
assert communicate.called_once_with()
popen.assert_called_once()
communicate.assert_called_once_with()
signal_mock.assert_any_call(signal.SIGINT, signal.SIG_IGN)
assert signal.getsignal(signal.SIGINT) == signal.default_int_handler