Skip to content

Commit

Permalink
Merge pull request #540 from hugovk/rm-3.7
Browse files Browse the repository at this point in the history
Drop support for EOL Python 3.7
  • Loading branch information
akaihola authored Feb 29, 2024
2 parents d90b545 + ff23faa commit e630694
Show file tree
Hide file tree
Showing 12 changed files with 13 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pyupgrade.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
from pyupgrade._main import main
from glob import glob
files = glob('**/*.py', recursive=True)
sys.exit(main(files + ['--py37-plus']))
sys.exit(main(files + ['--py38-plus']))
" || ( git diff ; false )
3 changes: 1 addition & 2 deletions action/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ def test_runs_darker(tmp_path, env, expect):
run_module("main")

darker = str(tmp_path / ".darker-env" / BIN / "darker")
# We can change `c[0][0][0]` to `c.args[0][0]` after dropping Python 3.7 support.
# This gets the first list item of the first positional argument to the `run` call.
assert darker in [c[0][0][0] for c in main_patch.subprocess.run.call_args_list]
assert darker in [c.args[0][0] for c in main_patch.subprocess.run.call_args_list]


def test_error_if_pip_fails(tmp_path, capsys):
Expand Down
8 changes: 1 addition & 7 deletions release_tools/bump_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@
import sys
from datetime import date
from pathlib import Path
from typing import Dict, List, Match, Optional, Tuple
from typing import Dict, List, Match, Optional, Tuple, TypedDict
from warnings import warn

import click
import requests
from packaging.version import Version

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict


VERSION_PY_PATH = "src/darker/version.py"


Expand Down
8 changes: 1 addition & 7 deletions release_tools/update_contributors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
# pylint: disable=too-few-public-methods,abstract-method

import re
import sys
import xml.etree.ElementTree as ET # nosec
from dataclasses import dataclass
from functools import total_ordering
from itertools import groupby
from pathlib import Path
from textwrap import dedent, indent
from typing import Any, Dict, Iterable, List, MutableMapping, Optional, cast
from typing import Any, Dict, Iterable, List, MutableMapping, Optional, TypedDict, cast

import click
import defusedxml.ElementTree
Expand All @@ -30,11 +29,6 @@
from requests_cache.session import CachedSession
from ruamel import yaml

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict


@click.group()
def cli() -> None:
Expand Down
4 changes: 1 addition & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ description = Apply Black formatting only in regions changed since last commit
long_description_content_type = text/x-rst
classifiers =
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -30,10 +29,9 @@ install_requires =
# NOTE: remember to keep `constraints-oldest.txt` in sync with these
black>=21.5b1,<24.2 # upper limit until incompatibility fixed
toml>=0.10.0
typing-extensions ; python_version < "3.8"
# NOTE: remember to keep `.github/workflows/python-package.yml` in sync
# with the minimum required Python version
python_requires = >=3.7
python_requires = >=3.8

[options.packages.find]
where = src
Expand Down
8 changes: 1 addition & 7 deletions src/darker/black_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
"""
import inspect
import logging
import sys
from pathlib import Path
from typing import Collection, Optional, Pattern, Set, Tuple, Union
from typing import Collection, Optional, Pattern, Set, Tuple, TypedDict, Union

# `FileMode as Mode` required to satisfy mypy==0.782. Strange.
from black import FileMode as Mode
Expand All @@ -57,11 +56,6 @@
from darker.config import ConfigurationError
from darker.utils import TextDocument

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict

__all__ = ["BlackConfig", "Mode", "run_black"]

logger = logging.getLogger(__name__)
Expand Down
8 changes: 1 addition & 7 deletions src/darker/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

import logging
import os
import sys
from argparse import ArgumentParser, Namespace
from dataclasses import dataclass, field
from pathlib import Path
from typing import Dict, Iterable, List, Optional, Set, Union, cast
from typing import Dict, Iterable, List, Optional, Set, TypedDict, Union, cast

import toml

from darker.black_compat import find_project_root

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict


class TomlArrayLinesEncoder(toml.TomlEncoder): # type: ignore
"""Format TOML so list items are each on their own line"""
Expand Down
15 changes: 1 addition & 14 deletions src/darker/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@
from darker.multiline_strings import get_multiline_string_ranges
from darker.utils import GIT_DATEFORMAT, TextDocument

if sys.version_info < (3, 8):

def shlex_join(split_command: Iterable[str]) -> str:
"""Backport `shlex.join` for Python 3.7
:param split_command: The elements on the command line
:return: The command line as one string, with appropriate quoting
"""
return " ".join(shlex.quote(arg) for arg in split_command)

else:
shlex_join = shlex.join

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -338,7 +325,7 @@ def _git_check_output(
encoding: Optional[str] = None,
) -> Union[str, bytes]:
"""Log command line, run Git, return stdout, exit with 123 on error"""
logger.debug("[%s]$ git %s", cwd, shlex_join(cmd))
logger.debug("[%s]$ git %s", cwd, shlex.join(cmd))
try:
return check_output( # nosec
["git"] + cmd,
Expand Down
9 changes: 1 addition & 8 deletions src/darker/import_sorting.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
"""Helpers for invoking ``isort`` and acting on its output"""

import logging
import sys
from pathlib import Path
from typing import Any, Collection, List, Optional
from typing import Any, Collection, List, Optional, TypedDict

from darker.black_compat import find_project_root
from darker.diff import diff_chunks
from darker.exceptions import IncompatiblePackageError, MissingPackageError
from darker.git import EditedLinenumsDiffer
from darker.utils import DiffChunk, TextDocument, glob_any

if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict


try:
import isort

Expand Down
8 changes: 3 additions & 5 deletions src/darker/linting.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@
git_get_content_at_revision,
git_get_root,
git_rev_parse,
shlex_join,
)
from darker.highlighting import colorize
from darker.utils import WINDOWS, fix_py37_win_tempdir_permissions
from darker.utils import WINDOWS

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -300,7 +299,7 @@ def _check_linter_output(
else:
cmdline_parts = cmdline
cmdline_and_paths = cmdline_parts + [str(path) for path in sorted(paths)]
logger.debug("[%s]$ %s", root, shlex_join(cmdline_and_paths))
logger.debug("[%s]$ %s", root, shlex.join(cmdline_and_paths))
with Popen( # nosec
cmdline_and_paths,
stdout=PIPE,
Expand Down Expand Up @@ -336,7 +335,7 @@ def run_linter( # pylint: disable=too-many-locals
cmdline_str = cmdline
else:
linter = cmdline[0]
cmdline_str = shlex_join(cmdline)
cmdline_str = shlex.join(cmdline)
# 10. run a linter subprocess for files mentioned on the command line which may be
# modified or unmodified, to get current linting status in the working tree
# (steps 10.-12. are optional)
Expand Down Expand Up @@ -534,7 +533,6 @@ def _get_messages_from_linters_for_baseline(
make_linter_env(root, rev1_commit),
normalize_whitespace,
)
fix_py37_win_tempdir_permissions(tmpdir)
return result


Expand Down
3 changes: 0 additions & 3 deletions src/darker/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from black import find_project_root as black_find_project_root

from darker.git import _git_check_output_lines, git_get_version
from darker.utils import fix_py37_win_tempdir_permissions


class GitRepoFixture:
Expand Down Expand Up @@ -122,8 +121,6 @@ def git_repo(tmp_path, monkeypatch):

yield repository

fix_py37_win_tempdir_permissions(repository.root)


@pytest.fixture
def find_project_root_cache_clear():
Expand Down
27 changes: 1 addition & 26 deletions src/darker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import io
import logging
import os
import sys
import tokenize
from datetime import datetime
from itertools import chain
from pathlib import Path
from typing import Collection, Iterable, List, Tuple, Union
from typing import Collection, Iterable, List, Tuple

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -240,27 +239,3 @@ def glob_any(path: Path, patterns: Collection[str]) -> bool:
"""
return any(path.glob(pattern) for pattern in patterns)


def fix_py37_win_tempdir_permissions(dirpath: Union[str, Path]) -> None:
"""Work around a `tempfile` clean-up issue on Windows with Python 3.7
Call this before exiting a ``with TemporaryDirectory():`` block or in teardown for
a Pytest fixture which creates a temporary directory.
See discussion in https://github.com/akaihola/darker/pull/393
Solution borrowed from https://github.com/python/cpython/pull/10320
:param dirpath: The root path of the temporary directory
"""
if not WINDOWS or sys.version_info >= (3, 8):
return
for root, dirs, files in os.walk(dirpath):
for name in dirs + files:
path = os.path.join(root, name)
try:
os.chflags(path, 0) # type: ignore[attr-defined]
except AttributeError:
pass
os.chmod(path, 0o700)

0 comments on commit e630694

Please sign in to comment.