diff --git a/.flake8 b/.flake8 index 4060ebaaa..d23e3e158 100644 --- a/.flake8 +++ b/.flake8 @@ -1,10 +1,16 @@ [flake8] ignore= - E203, # Whitespace before ':' - E266, # Too many leading '#' for block comment - W503, # Line break occurred before a binary operator - P1, # unindexed parameters in the str.format, see: + # 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 = 79 max-complexity = 10 select = B,C,E,F,W,T4,B902,T,P diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd6977679..72bde1b62 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,7 +6,7 @@ ci: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-added-large-files - id: check-case-conflict @@ -29,21 +29,21 @@ repos: - id: beautysh args: ["-i", "2"] - repo: https://github.com/asottile/pyupgrade - rev: v3.2.0 + rev: v3.3.1 hooks: - id: pyupgrade args: - --py38-plus - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 22.12.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.11.4 hooks: - id: isort - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.218' + rev: 'v0.0.222' hooks: - id: ruff args: ["--force-exclude"] @@ -53,11 +53,10 @@ repos: - id: codespell additional_dependencies: ["tomli"] - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: - - flake8-broken-line - flake8-bugbear - flake8-comprehensions - flake8-debugger diff --git a/dvc/config.py b/dvc/config.py index c1528ecaf..f20fc59a3 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -142,8 +142,8 @@ class Config(dict): dvc.config.Config: config object. """ config_file = os.path.join(dvc_dir, Config.CONFIG) - open(config_file, "w+", encoding="utf-8").close() - return Config(dvc_dir) + with open(config_file, "w+", encoding="utf-8"): + return Config(dvc_dir) def load(self, validate=True, config=None): """Loads config from all the config files. diff --git a/dvc/proc/process.py b/dvc/proc/process.py index c63577149..e66053acf 100644 --- a/dvc/proc/process.py +++ b/dvc/proc/process.py @@ -117,7 +117,7 @@ class ManagedProcess(AbstractContextManager): "Appending output to '%s'", self.stdout_path, ) - self._stdout = open(self.stdout_path, "ab") + self._stdout = open(self.stdout_path, "ab") # noqa: SIM115 try: self._proc = subprocess.Popen( self.args, diff --git a/dvc/utils/serialize/_yaml.py b/dvc/utils/serialize/_yaml.py index 896d5984a..12e0b70a4 100644 --- a/dvc/utils/serialize/_yaml.py +++ b/dvc/utils/serialize/_yaml.py @@ -26,7 +26,7 @@ def parse_yaml(text, path, typ="safe"): yaml = YAML(typ=typ) with reraise(_YAMLError, YAMLFileCorruptedError(path)): - return yaml.load(text) or {} # noqa: S506 + return yaml.load(text) or {} def parse_yaml_for_update(text, path): diff --git a/pyproject.toml b/pyproject.toml index c58085611..6701ecb21 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -163,7 +163,7 @@ line_length = 79 line-length = 79 target-version = "py38" show-source = true -ignore = ["S101", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "A003", "ARG002"] +ignore = ["S101", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "A003", "ARG002", "PLR2004"] select = ["F", "E", "W", "C90", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "ISC", "ICN", "T20", "PT003", "PT008", "PT009", "PT010", "PT015", "PT016", "PT017", "PT020", "PT021", "PT024", "PT025", "PT026", "Q", "RET501", "RET504", "SIM", "ARG", "TID", "PGH", "PLC", "PLE", "PLR", "PLW", "PIE", "RUF"] # external flake8 codes that should be preserved external = ["B301", "B024", "C901", "E302", "F401", "W601"] diff --git a/tests/func/experiments/test_remote.py b/tests/func/experiments/test_remote.py index 03d45af47..0cd4b88d4 100644 --- a/tests/func/experiments/test_remote.py +++ b/tests/func/experiments/test_remote.py @@ -326,7 +326,8 @@ def test_push_pull_cache( hash_ = digest(str(x)) path = os.path.join(local_remote.url, hash_[:2], hash_[2:]) assert os.path.exists(path) - assert open(path, encoding="utf-8").read() == str(x) + with open(path, encoding="utf-8") as f: + assert f.read() == str(x) remove(dvc.odb.local.path) @@ -335,7 +336,8 @@ def test_push_pull_cache( hash_ = digest(str(x)) path = os.path.join(dvc.odb.local.path, hash_[:2], hash_[2:]) assert os.path.exists(path) - assert open(path, encoding="utf-8").read() == str(x) + with open(path, encoding="utf-8") as f: + assert f.read() == str(x) def test_auth_error_list(tmp_dir, scm, dvc, http_auth_patch): diff --git a/tests/func/test_run_single_stage.py b/tests/func/test_run_single_stage.py index e42787c4c..3cea63f29 100644 --- a/tests/func/test_run_single_stage.py +++ b/tests/func/test_run_single_stage.py @@ -262,11 +262,11 @@ class TestRunBadWdir: def test_not_dir(self, tmp_dir, dvc): with pytest.raises(StagePathNotDirectoryError): - path = os.path.join(tmp_dir, str(uuid.uuid4())) - os.mkdir(path) - path = os.path.join(path, str(uuid.uuid4())) - open(path, "a", encoding="utf-8").close() - dvc.run(cmd="command", wdir=path, single_stage=True) + path = tmp_dir / str(uuid.uuid4()) + path.mkdir() + path = path / str(uuid.uuid4()) + path.touch() + dvc.run(cmd="command", wdir=os.fspath(path), single_stage=True) class TestRunBadName: