Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add python3.12, drop python3.7 #44

Merged
merged 11 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]
```
Expand Down Expand Up @@ -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.*"]
Expand Down
6 changes: 3 additions & 3 deletions assets/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/simple_package/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]
2 changes: 1 addition & 1 deletion examples/sync_cmdclass_pyproject/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["."]
11 changes: 5 additions & 6 deletions pysen/dist_version.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
2 changes: 1 addition & 1 deletion pysen/ext/black_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]:
Expand Down
2 changes: 1 addition & 1 deletion pysen/ext/flake8_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}, "
Expand Down
2 changes: 1 addition & 1 deletion pysen/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pysen/py_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/fakes/configs/base.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
2 changes: 1 addition & 1 deletion tests/fakes/configs/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion tests/fakes/configs/non_pysen_config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[tool.nonpysen]
line-length = 100
target-version = ["py37"]
target-version = ["py38"]
8 changes: 3 additions & 5 deletions tests/test_isort.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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)
Expand All @@ -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)
26 changes: 13 additions & 13 deletions tests/test_py_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_pyproject_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ 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")

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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand All @@ -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"
Expand Down
Loading