From 844f77b4f9f3802c1496a6744f49df62b4373999 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 30 May 2022 15:49:50 +0300 Subject: [PATCH] dvc: drop python 3.7 Also upgraded with `pyupgrade --py38-plus` Fixes #7708 --- .github/workflows/benchmarks.yaml | 2 +- .github/workflows/packages.yaml | 4 ++-- .github/workflows/tests.yaml | 2 +- dvc/commands/experiments/init.py | 2 +- dvc/info.py | 7 +------ dvc/proc/manager.py | 3 +-- dvc/testing/fixtures.py | 1 - dvc/utils/strictyaml.py | 2 +- setup.cfg | 4 +--- tests/dir_helpers.py | 4 ++-- tests/func/machine/test_machine_config.py | 4 ++-- tests/func/test_ignore.py | 3 +-- tests/integration/plots/test_json.py | 4 ++-- tests/unit/command/test_experiments.py | 2 +- tests/unit/command/test_machine.py | 2 +- tests/unit/fs/test_ssh.py | 2 +- tests/unit/remote/test_http.py | 3 +-- tests/unit/test_analytics.py | 2 +- tests/unit/utils/test_collections.py | 2 +- 19 files changed, 22 insertions(+), 33 deletions(-) diff --git a/.github/workflows/benchmarks.yaml b/.github/workflows/benchmarks.yaml index cfd60dc13..d2b089b32 100644 --- a/.github/workflows/benchmarks.yaml +++ b/.github/workflows/benchmarks.yaml @@ -16,7 +16,7 @@ jobs: access_token: ${{ github.token }} - uses: actions/setup-python@v3 with: - python-version: 3.7 + python-version: 3.8 - uses: iterative/dvc-bench@main with: pytest_options: "-k 'test_init or test_help'" diff --git a/.github/workflows/packages.yaml b/.github/workflows/packages.yaml index 79a1690df..eba2e6ef3 100644 --- a/.github/workflows/packages.yaml +++ b/.github/workflows/packages.yaml @@ -139,10 +139,10 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Set up Python 3.7 + - name: Set up Python 3.8 uses: actions/setup-python@v3 with: - python-version: 3.7 + python-version: 3.8 - name: Install run: pip install ".[all,tests]" - name: Build packages diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 55aa61e03..bed330cf0 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -42,7 +42,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-20.04, windows-latest, macos-latest] - pyv: ["3.7", "3.8", "3.9", "3.10"] + pyv: ["3.8", "3.9", "3.10"] steps: - uses: actions/checkout@v3 with: diff --git a/dvc/commands/experiments/init.py b/dvc/commands/experiments/init.py index 8632d55eb..9df531361 100644 --- a/dvc/commands/experiments/init.py +++ b/dvc/commands/experiments/init.py @@ -80,7 +80,7 @@ class CmdExperimentsInit(CmdBase): ) -> None: from dvc.utils import humanize - path_fmt = "[green]{0}[/green]".format + path_fmt = "[green]{}[/green]".format if new_deps: deps_paths = humanize.join(map(path_fmt, new_deps)) ui.write(f"Creating dependencies: {deps_paths}", styled=True) diff --git a/dvc/info.py b/dvc/info.py index 1a9fce9dc..a3dd212fc 100644 --- a/dvc/info.py +++ b/dvc/info.py @@ -1,3 +1,4 @@ +import importlib.metadata as importlib_metadata import itertools import os import pathlib @@ -13,12 +14,6 @@ from dvc.scm import SCMError from dvc.utils import error_link from dvc.utils.pkg import PKG -try: - import importlib.metadata as importlib_metadata -except ImportError: # < 3.8 - import importlib_metadata # type: ignore[no-redef] - - package = "" if PKG is None else f"({PKG})" diff --git a/dvc/proc/manager.py b/dvc/proc/manager.py index bb32bfab1..8371f5bbd 100644 --- a/dvc/proc/manager.py +++ b/dvc/proc/manager.py @@ -30,8 +30,7 @@ class ProcessManager: def __iter__(self) -> Generator[str, None, None]: if not os.path.exists(self.wdir): return - for name in os.listdir(self.wdir): - yield name + yield from os.listdir(self.wdir) def __getitem__(self, key: str) -> "ProcessInfo": info_path = os.path.join(self.wdir, key, f"{key}.json") diff --git a/dvc/testing/fixtures.py b/dvc/testing/fixtures.py index 0e79a18f6..dfb18d478 100644 --- a/dvc/testing/fixtures.py +++ b/dvc/testing/fixtures.py @@ -60,7 +60,6 @@ def make_tmp_dir(tmp_path_factory, request, worker_id): # connection resulting in PermissionErrors in Windows. ignore = ignore_patterns("cache.db*") for entry in os.listdir(cache): - # shutil.copytree's dirs_exist_ok is only available in >=3.8 _fs_copy( os.path.join(cache, entry), os.path.join(path, entry), diff --git a/dvc/utils/strictyaml.py b/dvc/utils/strictyaml.py index 3a9d988f4..c511cb25c 100644 --- a/dvc/utils/strictyaml.py +++ b/dvc/utils/strictyaml.py @@ -207,7 +207,7 @@ class YAMLValidationError(PrettyDvcException): self.path = path or "" message = f"'{rel}' validation failed" - message += " in revision '{}'".format(rev[:7]) if rev else "" + message += f" in revision '{rev[:7]}'" if rev else "" if len(self.exc.errors) > 1: message += f": {len(self.exc.errors)} errors" super().__init__(f"{message}") diff --git a/setup.cfg b/setup.cfg index 4f99370f9..492350aa5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,6 @@ keywords = data-science, data-version-control, machine-learning, git classifiers = Development Status :: 4 - Beta Programming Language :: Python :: 3 - Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 @@ -30,7 +29,7 @@ setup_requires = setuptools_scm[toml]>=6.3.1 setuptools_scm_git_archive==1.1 -python_requires = >=3.7 +python_requires = >=3.8 zip_safe = False packages = find: include_package_data = True @@ -55,7 +54,6 @@ install_requires = networkx>=2.5 psutil>=5.8.0 pydot>=1.2.4 - importlib-metadata>=1.4; python_version < '3.8' importlib-resources>=5.2.2; python_version < '3.9' flatten_dict>=0.4.1,<1 tabulate>=0.8.7 diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index e0943c7db..b9eb0dce4 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -148,7 +148,7 @@ class GitRemote: @pytest.fixture def git_upstream(tmp_dir, erepo_dir, git_dir, request): remote = erepo_dir if "dvc" in request.fixturenames else git_dir - url = "file://{}".format(remote.resolve().as_posix()) + url = f"file://{remote.resolve().as_posix()}" tmp_dir.scm.gitpython.repo.create_remote("upstream", url) return GitRemote(remote, "upstream", url) @@ -156,6 +156,6 @@ def git_upstream(tmp_dir, erepo_dir, git_dir, request): @pytest.fixture def git_downstream(tmp_dir, erepo_dir, git_dir, request): remote = erepo_dir if "dvc" in request.fixturenames else git_dir - url = "file://{}".format(tmp_dir.resolve().as_posix()) + url = f"file://{tmp_dir.resolve().as_posix()}" remote.scm.gitpython.repo.create_remote("upstream", url) return GitRemote(remote, "upstream", url) diff --git a/tests/func/machine/test_machine_config.py b/tests/func/machine/test_machine_config.py index 79ffb5a46..80a39f6b6 100644 --- a/tests/func/machine/test_machine_config.py +++ b/tests/func/machine/test_machine_config.py @@ -122,7 +122,7 @@ def test_machine_rename_success( return_value=True, ) - os.makedirs((tmp_dir / ".dvc" / "tmp" / "machine" / "terraform" / "foo")) + os.makedirs(tmp_dir / ".dvc" / "tmp" / "machine" / "terraform" / "foo") assert main(["machine", "rename", "foo", "bar"]) == 0 cap = capsys.readouterr() @@ -158,7 +158,7 @@ def test_machine_rename_error( tmp_dir, scm, dvc, machine_config, caplog, mocker ): config_file = tmp_dir / ".dvc" / "config" - os.makedirs((tmp_dir / ".dvc" / "tmp" / "machine" / "terraform" / "foo")) + os.makedirs(tmp_dir / ".dvc" / "tmp" / "machine" / "terraform" / "foo") def cmd_error(self, source, destination, **kwargs): raise tpi.TPIError("test error") diff --git a/tests/func/test_ignore.py b/tests/func/test_ignore.py index 97992c740..d39213ef2 100644 --- a/tests/func/test_ignore.py +++ b/tests/func/test_ignore.py @@ -19,8 +19,7 @@ def _to_pattern_info_list(str_list: List): def walk_files(dvc, *args): - for fs_path in dvc.dvcignore.find(*args): - yield fs_path + yield from dvc.dvcignore.find(*args) @pytest.mark.parametrize("filename", ["ignored", "ั‚ะตัั‚"]) diff --git a/tests/integration/plots/test_json.py b/tests/integration/plots/test_json.py index 0b89e4017..6ba102292 100644 --- a/tests/integration/plots/test_json.py +++ b/tests/integration/plots/test_json.py @@ -50,7 +50,7 @@ def filter_fields(datapoints: List[Dict], fields: List[str]): def verify_image(tmp_dir, version, filename, content, html_path, json_result): assert os.path.exists(html_path) - with open(html_path, "r", encoding="utf-8") as fd: + with open(html_path, encoding="utf-8") as fd: html_content = fd.read() image_data = {} @@ -92,7 +92,7 @@ def verify_vega( ): assert os.path.exists(html_path) - with open(html_path, "r", encoding="utf-8") as fd: + with open(html_path, encoding="utf-8") as fd: html_content = fd.read() assert _remove_blanks( json.dumps(dpath.util.get(json_result, [filename, 0, "content"])) diff --git a/tests/unit/command/test_experiments.py b/tests/unit/command/test_experiments.py index 5bd8f1d79..298cdf9dc 100644 --- a/tests/unit/command/test_experiments.py +++ b/tests/unit/command/test_experiments.py @@ -659,7 +659,7 @@ def test_show_experiments_sort_by(capsys, sort_order): rows = list(csv.reader(cap.out.strip().split("\n"))) # [3:] To skip header, workspace and baseline(master) # which are not affected by order - params = tuple([int(row[-1]) for row in rows[3:]]) + params = tuple(int(row[-1]) for row in rows[3:]) if sort_order == "asc": assert params == (0, 1, 2) diff --git a/tests/unit/command/test_machine.py b/tests/unit/command/test_machine.py index b657f931d..e4d4bcdce 100644 --- a/tests/unit/command/test_machine.py +++ b/tests/unit/command/test_machine.py @@ -1,8 +1,8 @@ import os +from unittest.mock import call import configobj import pytest -from mock import call from dvc.cli import parse_args from dvc.commands.machine import ( diff --git a/tests/unit/fs/test_ssh.py b/tests/unit/fs/test_ssh.py index 70ee06869..1b7874f92 100644 --- a/tests/unit/fs/test_ssh.py +++ b/tests/unit/fs/test_ssh.py @@ -2,9 +2,9 @@ import getpass import os +from unittest.mock import mock_open, patch import pytest -from mock import mock_open, patch from dvc.fs import DEFAULT_SSH_PORT, SSHFileSystem diff --git a/tests/unit/remote/test_http.py b/tests/unit/remote/test_http.py index 72b164ff6..22ffd904f 100644 --- a/tests/unit/remote/test_http.py +++ b/tests/unit/remote/test_http.py @@ -1,6 +1,5 @@ import ssl - -from mock import patch +from unittest.mock import patch from dvc.fs import HTTPFileSystem diff --git a/tests/unit/test_analytics.py b/tests/unit/test_analytics.py index 23d5ad12d..f676e6fa5 100644 --- a/tests/unit/test_analytics.py +++ b/tests/unit/test_analytics.py @@ -1,7 +1,7 @@ import json import platform +from unittest import mock -import mock import pytest from voluptuous import Any, Schema diff --git a/tests/unit/utils/test_collections.py b/tests/unit/utils/test_collections.py index 50dcbcc51..c1eaef265 100644 --- a/tests/unit/utils/test_collections.py +++ b/tests/unit/utils/test_collections.py @@ -1,9 +1,9 @@ # pylint: disable=unidiomatic-typecheck import json from json import encoder +from unittest.mock import create_autospec import pytest -from mock import create_autospec from dvc.utils.collections import ( apply_diff,