Skip to content

Commit

Permalink
Python 3.12 support added (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakancelikdev authored Dec 24, 2023
1 parent 4db41d8 commit df95354
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3.5.3
- uses: actions/setup-python@v4.6.1
with:
python-version: "3.11"
python-version: "3.12"
architecture: "x64"

- name: Install Dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3.5.3
- uses: actions/setup-python@v4.6.1
with:
python-version: "3.11"
python-version: "3.12"
architecture: "x64"

- name: Install Dependencies
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3.5.3
- uses: actions/setup-python@v4.6.1
with:
python-version: "3.11"
python-version: "3.12"
architecture: "x64"

- name: Install Dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v3.5.3

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.11-alpine
FROM python:3.12-alpine

COPY . /app
WORKDIR /app
Expand Down
6 changes: 6 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased] - YYYY-MM-DD

## [1.2.1] - 2023-12-24

### Added

- Python 3.12 support added

## [1.2.0] - 2023-12-22

### Changed
Expand Down
10 changes: 5 additions & 5 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ $ git rebase upstream/main

## Testing

First, make sure you have at least one of the python versions py3.8, py3.9, py3.10 and
py3.11. If not all versions are available, after opening PR, github action will run the
tests for each version, so you can be sure that you wrote the correct code. You can skip
the tox step below.
First, make sure you have at least one of the python versions py3.8, py3.9, py3.10,
py3.11 and py3.12 If not all versions are available, after opening PR, github action
will run the tests for each version, so you can be sure that you wrote the correct code.
You can skip the tox step below.

After typing your codes, you should run the tests by typing the following command.

```shell
$ python3.11 -m pip install tox
$ python3.12 -m pip install tox
$ tox
```

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ skip_gitignore = true

[tool.black]
line-length = 120
target-version = ['py38', 'py39', 'py310', 'py311']
target-version = ['py38', 'py39', 'py310', 'py311', 'py312']

[tool.unimport]
include_star_import = true
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ classifiers =
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Programming Language :: Python :: Implementation :: CPython
Environment :: Console
Topic :: Software Development :: Libraries :: Python Modules
Expand All @@ -31,7 +32,7 @@ project_urls =
Changelog = https://unimport.hakancelik.dev/1.2.0/CHANGELOG/

[options]
python_requires = >=3.8, <3.12
python_requires = >=3.8, <3.13
include_package_data = true
zip_safe = true
packages =
Expand Down
2 changes: 1 addition & 1 deletion src/unimport/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "1.2.0"
__version__ = "1.2.1"
__description__ = "A linter, formatter for finding and removing unused import statements."
2 changes: 2 additions & 0 deletions src/unimport/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"INIT_FILE_IGNORE_REGEX",
"PY39_PLUS",
"PY310_PLUS",
"PY312_PLUS",
"STDLIB_PATH",
"SUBSCRIPT_TYPE_VARIABLE",
)
Expand All @@ -27,6 +28,7 @@
# CONF
PY39_PLUS = sys.version_info >= (3, 9)
PY310_PLUS = sys.version_info >= (3, 10)
PY312_PLUS = sys.version_info >= (3, 12)

SUBSCRIPT_TYPE_VARIABLE = frozenset(
{
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/analyzer/typing/type_parameter_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import List, Union

from unimport.statement import Import, ImportFrom, Name

__all__ = ["NAMES", "IMPORTS", "UNUSED_IMPORTS"]


NAMES: List[Name] = [
Name(lineno=6, name="Point", is_all=False),
Name(lineno=6, name="tuple", is_all=False),
Name(lineno=6, name="x", is_all=False),
Name(lineno=6, name="float", is_all=False),
]
IMPORTS: List[Union[Import, ImportFrom]] = [
Import(lineno=3, column=1, name="x", package="x"),
Import(lineno=4, column=1, name="y", package="y"),
]
UNUSED_IMPORTS: List[Union[Import, ImportFrom]] = [
Import(lineno=4, column=1, name="y", package="y"),
]
5 changes: 5 additions & 0 deletions tests/cases/refactor/typing/type_parameter_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# pytest.mark.skipif(not PY312_PLUS, reason: "type parameter syntax is supported above python 3.12")

import x

type Point = tuple[x, float]
6 changes: 6 additions & 0 deletions tests/cases/source/typing/type_parameter_syntax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# pytest.mark.skipif(not PY312_PLUS, reason: "type parameter syntax is supported above python 3.12")

import x
import y

type Point = tuple[x, float]
4 changes: 2 additions & 2 deletions tests/cases/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest

from unimport.analyzers import MainAnalyzer
from unimport.constants import PY310_PLUS # noqa using eval expression
from unimport.constants import PY310_PLUS, PY312_PLUS # noqa using eval expression
from unimport.refactor import refactor_string
from unimport.statement import Import, Name
from unimport.utils import list_paths
Expand All @@ -32,7 +32,7 @@ def test_cases(path: Path, logger):

source = path.read_text()
skip_if = re.search(r"# pytest.mark.skipif\((?P<condition>.*), reason: (?P<reason>.*)\)", source, re.IGNORECASE)
if skip_if and (condition := skip_if.group("condition")) and condition in ("not PY310_PLUS",):
if skip_if and (condition := skip_if.group("condition")) and condition in ("not PY310_PLUS", "not PY312_PLUS"):
reason = skip_if.group("reason")
pytest.mark.skipif(False, reason, allow_module_level=True)

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = 3.8, 3.9, 3.10, 3.11, pre-commit
envlist = 3.8, 3.9, 3.10, 3.11, 3.12, pre-commit
isolated_build = true

[testenv]
Expand Down

0 comments on commit df95354

Please sign in to comment.