Skip to content

Commit

Permalink
nit: fit statement/expr in the same line instead of hanging (iterativ…
Browse files Browse the repository at this point in the history
…e#10267)

The code are wrapped due to us using line-length=79 before, but now some
of the code can easily fit in 88 chars.

The formatter did not change this automatically when we changed line-length,
because of magic trailing commas that gets added when they turn into multiple lines.

Black/ruff wrapping them in parens and splitting them into multiple lines
was making it difficult to read.
  • Loading branch information
skshetry authored Jan 30, 2024
1 parent 422caa1 commit 9a1bcd7
Show file tree
Hide file tree
Showing 144 changed files with 342 additions and 1,707 deletions.
5 changes: 1 addition & 4 deletions dvc/__pyinstaller/hook-celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
# Celery dynamically imports most celery internals at runtime
# pyinstaller hook must expose all modules loaded by
# kombu.utils.imports:symbol_by_name()
_EXCLUDES = (
"celery.bin",
"celery.contrib",
)
_EXCLUDES = ("celery.bin", "celery.contrib")
hiddenimports = collect_submodules(
"celery",
filter=lambda name: not any(
Expand Down
12 changes: 2 additions & 10 deletions dvc/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ def get_url(path, repo=None, rev=None, remote=None):
class _OpenContextManager(GCM):
def __init__(self, func, args, kwds):
self.gen = func(*args, **kwds)
self.func, self.args, self.kwds = ( # type: ignore[assignment]
func,
args,
kwds,
)
self.func, self.args, self.kwds = (func, args, kwds) # type: ignore[assignment]

def __getattr__(self, name):
raise AttributeError("dvc.api.open() should be used in a with statement.")
Expand Down Expand Up @@ -262,11 +258,7 @@ def _open(
fs_path = fs.from_os_path(path)

try:
with fs.open(
fs_path,
mode=mode,
encoding=encoding,
) as fobj:
with fs.open(fs_path, mode=mode, encoding=encoding) as fobj:
yield fobj
except FileNotFoundError as exc:
raise FileMissingError(path) from exc
Expand Down
10 changes: 2 additions & 8 deletions dvc/cachemgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,9 @@ def migrate_2_to_3(repo: "Repo", dry: bool = False):
)
return

with TqdmCallback(
desc="Computing DVC 3.0 hashes",
unit="files",
) as cb:
with TqdmCallback(desc="Computing DVC 3.0 hashes", unit="files") as cb:
migration = prepare(src, dest, callback=cb)

with TqdmCallback(
desc="Migrating to DVC 3.0 cache",
unit="files",
) as cb:
with TqdmCallback(desc="Migrating to DVC 3.0 cache", unit="files") as cb:
count = migrate(migration, callback=cb)
ui.write(f"Migrated {count} files to DVC 3.0 cache location.")
6 changes: 1 addition & 5 deletions dvc/commands/experiments/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,4 @@ def _add_run_common(parser):
default=None,
help="Custom commit message to use when committing the experiment.",
)
parser.add_argument(
"-M", # obsolete
dest="message",
help=argparse.SUPPRESS,
)
parser.add_argument("-M", dest="message", help=argparse.SUPPRESS) # obsolete
6 changes: 1 addition & 5 deletions dvc/commands/experiments/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,5 @@ def add_parser(experiments_subparsers, parent_parser):
default=None,
help="Custom commit message to use when committing the experiment.",
)
save_parser.add_argument(
"-M", # obsolete
dest="message",
help=argparse.SUPPRESS,
)
save_parser.add_argument("-M", dest="message", help=argparse.SUPPRESS) # obsolete
save_parser.set_defaults(func=CmdExperimentsSave)
6 changes: 1 addition & 5 deletions dvc/commands/ls/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,7 @@ def add_parser(subparsers, parent_parser):
"specified by '--remote') in the target repository."
),
)
list_parser.add_argument(
"--size",
action="store_true",
help="Show sizes.",
)
list_parser.add_argument("--size", action="store_true", help="Show sizes.")
list_parser.add_argument(
"path",
nargs="?",
Expand Down
11 changes: 2 additions & 9 deletions dvc/commands/ls_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ def add_parser(subparsers, parent_parser):
"url", help="See `dvc import-url -h` for full list of supported URLs."
)
lsurl_parser.add_argument(
"-R",
"--recursive",
action="store_true",
help="Recursively list files.",
)
lsurl_parser.add_argument(
"--size",
action="store_true",
help="Show sizes.",
"-R", "--recursive", action="store_true", help="Recursively list files."
)
lsurl_parser.add_argument("--size", action="store_true", help="Show sizes.")
lsurl_parser.add_argument(
"--fs-config",
type=str,
Expand Down
18 changes: 3 additions & 15 deletions dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,12 @@ def _show_json(
name = renderer.name
data[name] = to_json(renderer, split)
all_errors.extend(
{
"name": name,
"rev": rev,
"source": source,
**encode_exception(e),
}
{"name": name, "rev": rev, "source": source, **encode_exception(e)}
for rev, per_rev_src_errors in src_errors.items()
for source, e in per_rev_src_errors.items()
)
all_errors.extend(
{
"name": name,
"rev": rev,
**encode_exception(e),
}
{"name": name, "rev": rev, **encode_exception(e)}
for rev, e in def_errors.items()
)

Expand Down Expand Up @@ -101,10 +92,7 @@ def run(self) -> int: # noqa: C901, PLR0911, PLR0912
return 1

try:
plots_data = self._func(
targets=self.args.targets,
props=self._props(),
)
plots_data = self._func(targets=self.args.targets, props=self._props())

if not plots_data and not self.args.json:
ui.error_write(
Expand Down
9 changes: 1 addition & 8 deletions dvc/commands/queue/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@
from dvc.cli.utils import append_doc_link
from dvc.commands.queue import kill, logs, remove, start, status, stop

SUB_COMMANDS = [
start,
stop,
status,
logs,
remove,
kill,
]
SUB_COMMANDS = [start, stop, status, logs, remove, kill]


def add_parser(subparsers, parent_parser):
Expand Down
6 changes: 1 addition & 5 deletions dvc/commands/queue/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,5 @@ def add_parser(queue_subparsers, parent_parser):
),
action="store_true",
)
queue_logs_parser.add_argument(
"task",
help="Task to show.",
metavar="<task>",
)
queue_logs_parser.add_argument("task", help="Task to show.", metavar="<task>")
queue_logs_parser.set_defaults(func=CmdQueueLogs)
8 changes: 1 addition & 7 deletions dvc/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
)
from itertools import chain, repeat, zip_longest
from operator import itemgetter
from typing import (
TYPE_CHECKING,
Any,
Optional,
Union,
overload,
)
from typing import TYPE_CHECKING, Any, Optional, Union, overload

from funcy import reraise

Expand Down
7 changes: 1 addition & 6 deletions dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ def _posix_detached_subprocess(args: Sequence[str], **kwargs) -> int:
os.close(read_end)
return int(pid_str)

proc = subprocess.Popen(
args,
shell=False, # noqa: S603
close_fds=True,
**kwargs,
)
proc = subprocess.Popen(args, shell=False, close_fds=True, **kwargs) # noqa: S603
os.close(read_end)
os.write(write_end, str(proc.pid).encode("utf8"))
os.close(write_end)
Expand Down
10 changes: 1 addition & 9 deletions dvc/dependency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ def loads_from(stage, s_list, erepo=None, fs_config=None, db=None):
info = {RepoDependency.PARAM_REPO: erepo} if erepo else {}
if db:
info.update({"db": db})
return [
_get(
stage,
s,
info.copy(),
fs_config=fs_config,
)
for s in s_list
]
return [_get(stage, s, info.copy(), fs_config=fs_config) for s in s_list]


def _merge_params(s_list) -> dict[str, list[str]]:
Expand Down
10 changes: 2 additions & 8 deletions dvc/dependency/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ def __init__(self, stage, path, params=None, repo=None):
self.params = list(params) if params else []
hash_info = HashInfo()
if isinstance(params, dict):
hash_info = HashInfo(
self.PARAM_PARAMS,
params, # type: ignore[arg-type]
)
hash_info = HashInfo(self.PARAM_PARAMS, params) # type: ignore[arg-type]
repo = repo or stage.repo
path = path or os.path.join(repo.root_dir, self.DEFAULT_PARAMS_FILE)
super().__init__(stage, path, repo=repo)
Expand All @@ -103,10 +100,7 @@ def fill_values(self, values=None):
for param in self.params:
if param in values:
info[param] = values[param]
self.hash_info = HashInfo(
self.PARAM_PARAMS,
info, # type: ignore[arg-type]
)
self.hash_info = HashInfo(self.PARAM_PARAMS, info) # type: ignore[arg-type]

def read_params(
self, flatten: bool = True, **kwargs: typing.Any
Expand Down
10 changes: 1 addition & 9 deletions dvc/dvcfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import contextlib
import os
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Optional,
TypeVar,
Union,
)
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypeVar, Union

from dvc.exceptions import DvcException
from dvc.log import logger
Expand Down
14 changes: 2 additions & 12 deletions dvc/fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ def download(

from .callbacks import TqdmCallback

with TqdmCallback(
desc=f"Downloading {fs.name(fs_path)}",
unit="files",
) as cb:
with TqdmCallback(desc=f"Downloading {fs.name(fs_path)}", unit="files") as cb:
# NOTE: We use dvc-objects generic.copy over fs.get since it makes file
# download atomic and avoids fsspec glob/regex path expansion.
if fs.isdir(fs_path):
Expand All @@ -76,14 +73,7 @@ def download(
lfs_prefetch(fs, from_infos)
cb.set_size(len(from_infos))
jobs = jobs or fs.jobs
generic.copy(
fs,
from_infos,
localfs,
to_infos,
callback=cb,
batch_size=jobs,
)
generic.copy(fs, from_infos, localfs, to_infos, callback=cb, batch_size=jobs)
return len(to_infos)


Expand Down
4 changes: 1 addition & 3 deletions dvc/fs/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def _prepare_credentials(self, **config):
return config

@functools.cached_property
def fs(
self,
) -> "_DataFileSystem":
def fs(self) -> "_DataFileSystem":
from dvc_data.fs import DataFileSystem as _DataFileSystem

return _DataFileSystem(**self.fs_args)
Expand Down
4 changes: 1 addition & 3 deletions dvc/fs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ def __init__(
)

@functools.cached_property
def fs(
self,
) -> "FsspecGitFileSystem":
def fs(self) -> "FsspecGitFileSystem":
from scmrepo.fs import GitFileSystem as FsspecGitFileSystem

return FsspecGitFileSystem(**self.fs_args)
Expand Down
4 changes: 1 addition & 3 deletions dvc/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ def _set_claimfile(self):

if self._tmp_dir is not None:
# Under Windows file path length is limited so we hash it
hasher = hashlib.md5( # noqa: S324
self._claimfile.encode()
)
hasher = hashlib.md5(self._claimfile.encode()) # noqa: S324
filename = hasher.hexdigest()
self._claimfile = os.path.join(self._tmp_dir, filename + ".lock")

Expand Down
Loading

0 comments on commit 9a1bcd7

Please sign in to comment.