Skip to content

Commit

Permalink
remove flake8/bandit (#10082)
Browse files Browse the repository at this point in the history
ruff already runs most of the flake8/bandit checks
  • Loading branch information
skshetry authored Nov 9, 2023
1 parent 4ee8f55 commit cbc111b
Show file tree
Hide file tree
Showing 31 changed files with 41 additions and 84 deletions.
21 changes: 0 additions & 21 deletions .flake8

This file was deleted.

14 changes: 0 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ repos:
hooks:
- id: codespell
additional_dependencies: ["tomli"]
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies:
- flake8-string-format
- flake8-typing-imports
- repo: https://github.com/PyCQA/bandit
rev: '1.7.5'
hooks:
- id: bandit
args: ["-c", "pyproject.toml", "--quiet", "--format=custom"]
files: ^dvc/
additional_dependencies: [".[toml]"]
- repo: local
hooks:
- id: mypy
Expand Down
2 changes: 1 addition & 1 deletion dvc/commands/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def run(self):

shell = self.args.shell
parser = self.args.parser
script = shtab.complete(parser, shell=shell, preamble=PREAMBLE) # nosec B604
script = shtab.complete(parser, shell=shell, preamble=PREAMBLE)
ui.write(script, force=True)
return 0

Expand Down
2 changes: 1 addition & 1 deletion dvc/commands/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _collect_targets(repo, target, outs):
targets.extend([str(out) for out in stage.outs])
continue

for out in outs_trie.itervalues(prefix=repo.fs.path.parts(path)): # noqa: B301
for out in outs_trie.itervalues(prefix=repo.fs.path.parts(path)):
targets.extend(str(out))

return targets
Expand Down
2 changes: 1 addition & 1 deletion dvc/commands/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def baseline_styler(typ):
return {"style": "bold"} if typ == "baseline" else {}


def show_experiments( # noqa: C901
def show_experiments(
td: "TabularData",
headers: Dict[str, Iterable[str]],
keep=None,
Expand Down
8 changes: 4 additions & 4 deletions dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import inspect
import logging
import os
import subprocess # nosec B404
import subprocess
import sys
from contextlib import nullcontext
from typing import TYPE_CHECKING, Any, List, Mapping, Optional, Sequence, Union
Expand All @@ -28,7 +28,7 @@ def _suppress_resource_warning(popen: subprocess.Popen) -> None:
def _win_detached_subprocess(args: Sequence[str], **kwargs) -> int:
assert os.name == "nt"

from subprocess import ( # type: ignore[attr-defined] # nosec B404
from subprocess import ( # type: ignore[attr-defined]
CREATE_NEW_PROCESS_GROUP,
CREATE_NO_WINDOW,
STARTF_USESHOWWINDOW,
Expand All @@ -44,7 +44,7 @@ def _win_detached_subprocess(args: Sequence[str], **kwargs) -> int:
popen = subprocess.Popen(
args,
close_fds=True,
shell=False, # noqa: S603 # nosec B603
shell=False, # noqa: S603
startupinfo=startupinfo,
creationflags=creationflags,
**kwargs,
Expand Down Expand Up @@ -108,7 +108,7 @@ def _posix_detached_subprocess(args: Sequence[str], **kwargs) -> int:

proc = subprocess.Popen(
args,
shell=False, # noqa: S603 # nosec B603
shell=False, # noqa: S603
close_fds=True,
**kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion dvc/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
DVC_SITE_CACHE_DIR = "DVC_SITE_CACHE_DIR"
DVC_STUDIO_OFFLINE = "DVC_STUDIO_OFFLINE"
DVC_STUDIO_REPO_URL = "DVC_STUDIO_REPO_URL"
DVC_STUDIO_TOKEN = "DVC_STUDIO_TOKEN" # noqa: S105 # nosec B105
DVC_STUDIO_TOKEN = "DVC_STUDIO_TOKEN" # noqa: S105
DVC_STUDIO_URL = "DVC_STUDIO_URL"
DVC_SYSTEM_CONFIG_DIR = "DVC_SYSTEM_CONFIG_DIR"
DVC_UPDATER_ENDPOINT = "DVC_UPDATER_ENDPOINT"
2 changes: 1 addition & 1 deletion dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def isdvc(self, path, **kwargs) -> bool:
except FileNotFoundError:
return False

def ls(self, path, detail=True, dvc_only=False, **kwargs): # noqa: C901
def ls(self, path, detail=True, dvc_only=False, **kwargs):
key = self._get_key_from_relative(path)
repo, dvc_fs, subkey = self._get_subrepo_info(key)

Expand Down
2 changes: 1 addition & 1 deletion dvc/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +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( # nosec B324, B303 # noqa: S324
hasher = hashlib.md5( # noqa: S324
self._claimfile.encode()
)
filename = hasher.hexdigest()
Expand Down
2 changes: 1 addition & 1 deletion dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def emit(self, record):
if not _is_verbose():
return
# pylint: disable-next=broad-except
except Exception: # noqa: BLE001, S110 # nosec B110
except Exception: # noqa: BLE001, S110
pass

msg = self.format(record)
Expand Down
2 changes: 1 addition & 1 deletion dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ def _collect_used_dir_cache(
return obj.filter(prefix)
return obj

def get_used_objs( # noqa: C901, PLR0911
def get_used_objs( # noqa: PLR0911
self, **kwargs
) -> Dict[Optional["HashFileDB"], Set["HashInfo"]]:
"""Return filtered set of used object IDs for this out."""
Expand Down
2 changes: 1 addition & 1 deletion dvc/parsing/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def embrace(s: str):

def escape_str(value):
if os.name == "nt":
from subprocess import list2cmdline # nosec B404
from subprocess import list2cmdline

return list2cmdline([value])
from shlex import quote
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def site_cache_dir(self) -> str:
# that just happened to be at the same path as old deleted ones.
btime = self._btime or getattr(os.stat(root_dir), "st_birthtime", None)

md5 = hashlib.md5( # noqa: S324 # nosec B324, B303
md5 = hashlib.md5( # noqa: S324
str(
(
root_dir,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _download_studio(
return len(to_infos), relpath(localfs.path.commonpath(to_infos))

@classmethod
def get( # noqa: C901, PLR0913
def get( # noqa: PLR0913
cls,
url: str,
name: str,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/brancher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
logger = logging.getLogger(__name__)


def brancher( # noqa: E302
def brancher(
self,
revs=None,
all_branches=False,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def queue_one(
**kwargs,
)

def reproduce_celery( # noqa: C901
def reproduce_celery(
self, entries: Optional[Iterable["QueueEntry"]] = None, **kwargs
) -> Dict[str, str]:
results: Dict[str, str] = {}
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@locked
@scm_context
def apply(repo: "Repo", rev: str, **kwargs): # noqa: C901
def apply(repo: "Repo", rev: str, **kwargs):
from dvc.repo.checkout import checkout as dvc_checkout
from dvc.scm import RevError, resolve_rev

Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/experiments/executor/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
import os
import pickle # nosec B403
import pickle
import shutil
from abc import ABC, abstractmethod
from contextlib import contextmanager
Expand Down Expand Up @@ -364,7 +364,7 @@ def pack_repro_args(path, *args, fs=None, extra=None, **kwargs):
@staticmethod
def unpack_repro_args(path):
with open(path, "rb") as fobj:
data = pickle.load(fobj) # noqa: S301 # nosec B301
data = pickle.load(fobj) # noqa: S301
return data["args"], data["kwargs"]

def fetch_exps(
Expand Down Expand Up @@ -583,7 +583,7 @@ def _repro_commit(

@classmethod
@contextmanager
def _repro_dvc( # noqa: C901
def _repro_dvc(
cls,
info: "ExecutorInfo",
infofile: Optional[str] = None,
Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/experiments/queue/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def logs(
output.
"""

def _stash_exp( # noqa: C901
def _stash_exp(
self,
*args,
params: Optional[Dict[str, List[str]]] = None,
Expand Down Expand Up @@ -425,7 +425,7 @@ def _stash_msg(
return msg

def _pack_args(self, *args, **kwargs) -> None:
import pickle # nosec B403
import pickle

if os.path.exists(self.args_file) and self.scm.is_tracked(self.args_file):
logger.warning(
Expand All @@ -440,7 +440,7 @@ def _pack_args(self, *args, **kwargs) -> None:
)
with open(self.args_file, "rb") as fobj:
try:
data = pickle.load(fobj) # noqa: S301 # nosec B301
data = pickle.load(fobj) # noqa: S301
except Exception: # noqa: BLE001, pylint: disable=broad-except
data = {}
extra = int(data.get("extra", 0)) + 1
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _collect_indexes( # noqa: PLR0913


@locked
def fetch( # noqa: C901, PLR0913
def fetch( # noqa: PLR0913
self,
targets=None,
jobs=None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/imp_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@locked
@scm_context
def imp_url( # noqa: C901, PLR0913
def imp_url( # noqa: PLR0913
self: "Repo",
url,
out=None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/open_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _cached_clone(url, rev):


@wrap_with(threading.Lock())
def _clone_default_branch(url, rev): # noqa: C901, PLR0912
def _clone_default_branch(url, rev): # noqa: PLR0912
"""Get or create a clean clone of the url.
The cloned is reactualized with git pull unless rev is a known sha.
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _update_meta(index, **kwargs):


@locked
def push( # noqa: C901, PLR0913
def push( # noqa: PLR0913
self,
targets=None,
jobs=None,
Expand Down
6 changes: 2 additions & 4 deletions dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,7 @@ def commit(self, allow_missing=False, filter_info=None, **kwargs) -> None:
raise CacheLinkError(link_failures)

@rwlocked(write=["outs"])
def add_outs( # noqa: C901
self, filter_info=None, allow_missing: bool = False, **kwargs
):
def add_outs(self, filter_info=None, allow_missing: bool = False, **kwargs):
from dvc.output import OutputDoesNotExistError

link_failures = []
Expand All @@ -582,7 +580,7 @@ def add_outs( # noqa: C901
raise CacheLinkError(link_failures)

@rwlocked(read=["deps", "outs"])
def run( # noqa: C901
def run(
self,
dry=False,
no_commit=False,
Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def __len__(self):
return len(self.resolver.get_keys())

def __contains__(self, name):
return self.resolver.has_key(name) # noqa: W601
return self.resolver.has_key(name)

def is_foreach_or_matrix_generated(self, name: str) -> bool:
return (
Expand Down
4 changes: 2 additions & 2 deletions dvc/stage/run.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import os
import signal
import subprocess # nosec B404
import subprocess
import threading

from dvc.utils import fix_env
Expand Down Expand Up @@ -83,7 +83,7 @@ def _run(executable, cmd, **kwargs):
exec_cmd = _make_cmd(executable, cmd)

try:
p = subprocess.Popen(exec_cmd, **kwargs) # nosec B603 # noqa: S603
p = subprocess.Popen(exec_cmd, **kwargs) # noqa: S603
if main_thread:
old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN)

Expand Down
4 changes: 2 additions & 2 deletions dvc/testing/benchmarks/cli/stories/test_modify_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_partial_add(bench_dvc, tmp_dir, dvc, dataset, remote):
# Move some files to create a partial dataset
os.makedirs("partial-copy")
for f in glob.glob("*", root_dir=dataset, recursive=True): # type: ignore[call-arg]
if random.random() > 0.5: # noqa: S311 # nosec
if random.random() > 0.5: # noqa: S311
shutil.move(dataset / f, tmp_dir / "partial-copy" / f)

# Add/push partial dataset
Expand All @@ -42,7 +42,7 @@ def test_partial_remove(bench_dvc, tmp_dir, dvc, dataset, remote):

# Remove some files
for f in glob.glob("*", root_dir=dataset, recursive=True): # type: ignore[call-arg]
if random.random() > 0.5: # noqa: S311 # nosec
if random.random() > 0.5: # noqa: S311
if os.path.isfile(dataset / f):
os.remove(dataset / f)
elif os.path.isdir(dataset / f):
Expand Down
4 changes: 2 additions & 2 deletions dvc/testing/benchmarks/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import shutil
from pathlib import Path
from subprocess import check_output # nosec B404
from subprocess import check_output

import pytest
from dulwich.porcelain import clone
Expand Down Expand Up @@ -88,7 +88,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 # noqa: S603
return check_output([dvc_bin, *args], text=True) # noqa: S603

_dvc_bin.version = parse_tuple(_dvc_bin("--version")) # type: ignore[attr-defined]
return _dvc_bin
Expand Down
Loading

0 comments on commit cbc111b

Please sign in to comment.