diff --git a/README.md b/README.md index b812b19..102f919 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ enable_isort = true enable_mypy = true mypy_preset = "strict" line_length = 88 -py_version = "py37" +py_version = "py38" [[tool.pysen.lint.mypy_targets]] paths = ["."] ``` @@ -215,7 +215,7 @@ enable_isort = true enable_mypy = true mypy_preset = "strict" line_length = 88 -py_version = "py37" +py_version = "py38" isort_known_third_party = ["numpy"] isort_known_first_party = ["pysen"] mypy_ignore_packages = ["pysen.generated.*"] diff --git a/assets/Dockerfile b/assets/Dockerfile index abe3549..acd2bc2 100644 --- a/assets/Dockerfile +++ b/assets/Dockerfile @@ -1,17 +1,17 @@ # Dockerfile for pysen-test FROM alpine:3.17 -COPY --from=python:3.7.16-alpine3.17 /usr/local/ /usr/local/ COPY --from=python:3.8.16-alpine3.17 /usr/local/ /usr/local/ COPY --from=python:3.9.16-alpine3.17 /usr/local/ /usr/local/ COPY --from=python:3.10.11-alpine3.17 /usr/local/ /usr/local/ COPY --from=python:3.11.3-alpine3.17 /usr/local/ /usr/local/ +COPY --from=python:3.12.0-alpine3.17 /usr/local/ /usr/local/ RUN apk add --no-cache expat gcc libffi musl-dev \ - && for MINOR in 7 8 9 10 11; do \ + && for MINOR in 8 9 10 11 12; do \ sed "s|^#!/usr/local/bin/python$|#!/usr/local/bin/python3.${MINOR}|" \ -i /usr/local/bin/*3.${MINOR}; done RUN apk add --no-cache bash git \ - && pip3.11 install --no-cache-dir tox==3.15.0 + && pip3.12 install --no-cache-dir tox==3.15.0 ENV TOX_PARALLEL_NO_SPINNER 1 diff --git a/examples/simple_package/pyproject.toml b/examples/simple_package/pyproject.toml index 533b96b..9f99828 100644 --- a/examples/simple_package/pyproject.toml +++ b/examples/simple_package/pyproject.toml @@ -3,7 +3,7 @@ enable_black = true enable_mypy = true mypy_preset = "strict" line_length = 100 -py_version = "py37" +py_version = "py38" [[tool.pysen.lint.mypy_targets]] paths = ["."] diff --git a/examples/sync_cmdclass_pyproject/pyproject.toml b/examples/sync_cmdclass_pyproject/pyproject.toml index 533b96b..9f99828 100644 --- a/examples/sync_cmdclass_pyproject/pyproject.toml +++ b/examples/sync_cmdclass_pyproject/pyproject.toml @@ -3,7 +3,7 @@ enable_black = true enable_mypy = true mypy_preset = "strict" line_length = 100 -py_version = "py37" +py_version = "py38" [[tool.pysen.lint.mypy_targets]] paths = ["."] diff --git a/pysen/dist_version.py b/pysen/dist_version.py index f815c07..ba0c461 100644 --- a/pysen/dist_version.py +++ b/pysen/dist_version.py @@ -1,18 +1,17 @@ import logging +from importlib.metadata import Distribution, PackageNotFoundError, distribution from typing import Optional -import pkg_resources - from pysen.exceptions import DistributionNotFound from pysen.py_version import VersionRepresentation _logger = logging.getLogger(__name__) -def _get_distro(name: str) -> Optional[pkg_resources.Distribution]: +def _get_distro(name: str) -> Optional[Distribution]: try: - return pkg_resources.get_distribution(name) - except pkg_resources.DistributionNotFound: + return distribution(name) + except PackageNotFoundError: _logger.debug(f"distribution {name} not found", exc_info=True) return None @@ -21,7 +20,7 @@ def get_version(name: str) -> VersionRepresentation: distro = _get_distro(name) if distro is None: raise DistributionNotFound( - f"Expected {name} to be installed but pkg_resources could not find it.\n" + f"Expected {name} to be installed but importlib could not find it.\n" f'Hint: Did you install "{name}" in the same Python environment as pysen?' ) return VersionRepresentation.from_str(distro.version) diff --git a/pysen/ext/black_wrapper.py b/pysen/ext/black_wrapper.py index b4f4f4d..91a90d5 100644 --- a/pysen/ext/black_wrapper.py +++ b/pysen/ext/black_wrapper.py @@ -24,7 +24,7 @@ def default( # NOTE(igarashi) safe to use as an argument since it is immutable py_version: Optional[PythonVersion] = None, ) -> "BlackSetting": - py_version = py_version or PythonVersion(3, 7) + py_version = py_version or PythonVersion(3, 8) return BlackSetting(target_version=[py_version]) def export(self) -> Tuple[List[str], Dict[str, Any]]: diff --git a/pysen/ext/flake8_wrapper.py b/pysen/ext/flake8_wrapper.py index 516c9a2..f2e4de9 100644 --- a/pysen/ext/flake8_wrapper.py +++ b/pysen/ext/flake8_wrapper.py @@ -92,7 +92,7 @@ def export(self) -> Tuple[Sequence[str], Dict[str, Any]]: @functools.lru_cache(1) def _check_flake8_version() -> None: version = get_version("flake8") - minimum_supported = VersionRepresentation(3, 7) + minimum_supported = VersionRepresentation(3, 8) if version < minimum_supported: raise IncompatibleVersionError( f"pysen only supports flake8 >= {minimum_supported}, " diff --git a/pysen/factory.py b/pysen/factory.py index f8de1e5..6f11a39 100644 --- a/pysen/factory.py +++ b/pysen/factory.py @@ -67,7 +67,7 @@ def configure_lint(options: ConfigureLintOptions) -> List[ComponentBase]: if options.py_version is not None: python_version = options.py_version else: - python_version = PythonVersion(3, 7) + python_version = PythonVersion(3, 8) line_length = options.line_length or 88 diff --git a/pysen/py_version.py b/pysen/py_version.py index 6ce62f8..8432249 100644 --- a/pysen/py_version.py +++ b/pysen/py_version.py @@ -107,9 +107,9 @@ def parse_short_representation(value: str) -> "PythonVersion": # NOTE(igarashi): PythonVersion class is immutable _PythonVersions = { "PY27": PythonVersion(2, 7), - "PY37": PythonVersion(3, 7), "PY38": PythonVersion(3, 8), "PY39": PythonVersion(3, 9), "PY310": PythonVersion(3, 10), "PY311": PythonVersion(3, 11), + "PY312": PythonVersion(3, 12), } diff --git a/setup.py b/setup.py index 71f52c0..33271d9 100644 --- a/setup.py +++ b/setup.py @@ -22,11 +22,11 @@ url="https://github.com/pfnet/pysen", license="MIT License", classifiers=[ - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python", "License :: OSI Approved :: MIT License", "Operating System :: POSIX", diff --git a/tests/fakes/configs/base.toml b/tests/fakes/configs/base.toml index d37b7dd..f5d65df 100644 --- a/tests/fakes/configs/base.toml +++ b/tests/fakes/configs/base.toml @@ -2,7 +2,7 @@ base = "base2.toml" enable_isort = true line_length = 88 -py_version = "py37" +py_version = "py38" isort_known_third_party = ["fuga", "piyo"] isort_known_first_party = ["foo"] diff --git a/tests/fakes/configs/example.toml b/tests/fakes/configs/example.toml index e627490..929918f 100644 --- a/tests/fakes/configs/example.toml +++ b/tests/fakes/configs/example.toml @@ -10,7 +10,7 @@ enable_isort = true enable_mypy = true mypy_preset = "strict" line_length = 88 -py_version = "py37" +py_version = "py38" isort_known_first_party = ["alpha"] isort_known_third_party = ["beta", "gamma"] mypy_ignore_packages = ["pysen.stubs", "pysen.proto"] diff --git a/tests/fakes/configs/non_pysen_config.toml b/tests/fakes/configs/non_pysen_config.toml index 4a5abf3..2ed0cf5 100644 --- a/tests/fakes/configs/non_pysen_config.toml +++ b/tests/fakes/configs/non_pysen_config.toml @@ -1,3 +1,3 @@ [tool.nonpysen] line-length = 100 -target-version = ["py37"] +target-version = ["py38"] diff --git a/tests/test_isort.py b/tests/test_isort.py index 64c9e99..f8a6a5f 100644 --- a/tests/test_isort.py +++ b/tests/test_isort.py @@ -1,7 +1,7 @@ +from importlib.metadata import PackageNotFoundError from pathlib import Path from unittest import mock -import pkg_resources import pytest from pysen.exceptions import ( @@ -101,7 +101,7 @@ def get_version() -> VersionRepresentation: _get_isort_version.cache_clear() return _get_isort_version() - distro = "pkg_resources.get_distribution" + distro = "pysen.dist_version.distribution" # pass case with mock.patch(distro, return_value=mock.Mock(version="4.3.21")): assert get_version() == VersionRepresentation(4, 3, 21) @@ -114,8 +114,6 @@ def get_version() -> VersionRepresentation: assert "version 3.0.0 is not supported" in str(e) # isort cannot be imported with pytest.raises(DistributionNotFound) as e: - with mock.patch( - distro, side_effect=pkg_resources.DistributionNotFound("req", "requires") - ): + with mock.patch(distro, side_effect=PackageNotFoundError("req", "requires")): get_version() assert "Expected isort to be installed" in str(e) diff --git a/tests/test_py_version.py b/tests/test_py_version.py index 63c5fa4..b347fe4 100644 --- a/tests/test_py_version.py +++ b/tests/test_py_version.py @@ -4,24 +4,24 @@ def test_python_version() -> None: - py37 = PythonVersion(3, 7) + py38 = PythonVersion(3, 8) - assert py37 == PythonVersion(3, 7) - assert py37 != PythonVersion(3, 8) + assert py38 == PythonVersion(3, 8) + assert py38 != PythonVersion(3, 9) - assert py37.version == "3.7" - assert py37.full_representation == "Python3.7" - assert py37.short_representation == "py37" + assert py38.version == "3.8" + assert py38.full_representation == "Python3.8" + assert py38.short_representation == "py38" - py378 = PythonVersion(3, 7, 8) + py388 = PythonVersion(3, 8, 8) - assert py378 == PythonVersion(3, 7, 8) - assert py378 != PythonVersion(3, 7, 9) - assert py378 != py37 + assert py388 == PythonVersion(3, 8, 8) + assert py388 != PythonVersion(3, 8, 9) + assert py388 != py38 - assert py378.version == "3.7.8" - assert py378.full_representation == "Python3.7.8" - assert py378.short_representation == "py37" + assert py388.version == "3.8.8" + assert py388.full_representation == "Python3.8.8" + assert py388.short_representation == "py38" def test_version_ops() -> None: diff --git a/tests/test_pyproject_model.py b/tests/test_pyproject_model.py index f080652..9ee9629 100644 --- a/tests/test_pyproject_model.py +++ b/tests/test_pyproject_model.py @@ -138,7 +138,7 @@ def test__parse_source() -> None: def test__parse_python_version() -> None: - assert _parse_python_version("py37") == PythonVersion(3, 7) + assert _parse_python_version("py38") == PythonVersion(3, 8) assert _parse_python_version("PY38") == PythonVersion(3, 8) with pytest.raises(dacite.DaciteError) as ex: _parse_python_version("PY999") @@ -146,7 +146,7 @@ def test__parse_python_version() -> None: assert "one of" in str(ex.value) # ensure that we suggest some options with pytest.raises(dacite.WrongTypeError): - _parse_python_version(37) + _parse_python_version(38) def test__parse_mypy_target() -> None: @@ -291,7 +291,7 @@ def test_example() -> None: assert lint.enable_mypy assert lint.line_length == 88 assert isinstance(lint.line_length, int) - assert lint.py_version == PythonVersion(3, 7) + assert lint.py_version == PythonVersion(3, 8) assert lint.isort_known_first_party == ["alpha"] assert lint.isort_known_third_party == ["beta", "gamma"] assert lint.isort_default_section == IsortSectionName.THIRDPARTY diff --git a/tox.ini b/tox.ini index ac95d4e..e3c279f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py37-dacite{110,120,150}-isort43-black20-mypy078, py37-dacite150-isort{43,50,51}-black{19,20}-mypy078, py{38,39,310}-dacite150-isort51-black{20,22}-mypy078, py311-dacite150-isort51-black22-mypy099, development, latest +envlist = py{38,39,310}-dacite150-isort51-black{20,22}-mypy078, py{311,312}-dacite150-isort51-black22-mypy099, development, latest [testenv] deps = @@ -17,6 +17,7 @@ deps = mypy099: mypy==0.991 flake8==4.0.1 flake8-bugbear==21.9.2 + setuptools>=66.1.0 commands = pytest -m "not examples"