Skip to content

Commit

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

updates:
- [github.com/asottile/pyupgrade: v3.3.1 → v3.9.0](asottile/pyupgrade@v3.3.1...v3.9.0)
- https://github.com/charliermarsh/ruff-pre-commithttps://github.com/astral-sh/ruff-pre-commit
- [github.com/astral-sh/ruff-pre-commit: v0.0.261 → v0.0.277](astral-sh/ruff-pre-commit@v0.0.261...v0.0.277)
- [github.com/codespell-project/codespell: v2.2.4 → v2.2.5](codespell-project/codespell@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 (सौगात) <suagatchhetri@outlook.com>
  • Loading branch information
pre-commit-ci[bot] and skshetry authored Jul 14, 2023
1 parent f1764bd commit ca37049
Show file tree
Hide file tree
Showing 33 changed files with 60 additions and 88 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion dvc/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions dvc/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions dvc/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ def _show_status(cls, status: "DataStatus") -> int: # noqa: C901
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

Expand Down
4 changes: 1 addition & 3 deletions dvc/commands/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,7 @@ def run(self):
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:
Expand Down
2 changes: 1 addition & 1 deletion dvc/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def validate(data):


class RelPath(str):
pass
__slots__ = ()


class FeatureSchema(Schema):
Expand Down
4 changes: 3 additions & 1 deletion dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 1 addition & 3 deletions dvc/dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ def __init__(self, repo, path, verify=True, **kwargs):
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)
Expand Down
14 changes: 3 additions & 11 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def __init__(self, output, repo=None):
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}"
)


Expand All @@ -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):
Expand Down Expand Up @@ -156,9 +150,7 @@ def __init__(self, stages):
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."
)


Expand Down
2 changes: 1 addition & 1 deletion dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def log_to_root(message, *args, **kwargs):

class LoggingException(Exception):
def __init__(self, record):
msg = f"failed to log {str(record)}"
msg = f"failed to log {record!s}"
super().__init__(msg)


Expand Down
6 changes: 2 additions & 4 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,7 @@ def _parse_path(self, fs, fs_path):
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":
Expand Down Expand Up @@ -693,7 +691,7 @@ def ignore_remove(self) -> None:
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."
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ def used_objs( # noqa: PLR0913
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.
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions dvc/rwlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@
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
Expand Down
5 changes: 1 addition & 4 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,7 @@ def reproduce(self, interactive=False, **kwargs) -> Optional["Stage"]:
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")

Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion dvc/testing/benchmarks/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions dvc/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,18 @@ 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")
pytest.skip(f"docker is not installed or the daemon is not running: {out}")

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}")
Expand Down
2 changes: 1 addition & 1 deletion dvc/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def write_json( # noqa: PLR0913
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 = " ",
Expand Down
3 changes: 2 additions & 1 deletion dvc/ui/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions tests/func/api/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ 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():
subdir.gen("params.yaml", "foo: 1")

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}

Expand Down
4 changes: 2 additions & 2 deletions tests/func/experiments/executor/test_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions tests/func/experiments/test_experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def _get_rev_isotimestamp(rev):
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
Expand Down Expand Up @@ -682,7 +682,7 @@ def _get_rev_isotimestamp(rev):

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
Expand Down
4 changes: 1 addition & 3 deletions tests/func/repro/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/plots/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
Loading

0 comments on commit ca37049

Please sign in to comment.