Skip to content

Commit f9106b5

Browse files
authored
Merge pull request #164 from cdce8p/dev
Release v0.4.0
2 parents a693041 + 6f9c4ee commit f9106b5

19 files changed

+374
-381
lines changed

.github/workflows/ci.yaml

+21-50
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
pull_request: ~
99

1010
env:
11-
CACHE_VERSION: 0
11+
CACHE_VERSION: 1
1212
DEFAULT_PYTHON: 3.8
1313
LIB_FOLDER: python_typing_update
1414
PRE_COMMIT_CACHE: ~/.cache/pre-commit
@@ -23,10 +23,10 @@ jobs:
2323
pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }}
2424
steps:
2525
- name: Check out code from GitHub
26-
uses: actions/checkout@v2.3.4
26+
uses: actions/checkout@v3.0.0
2727
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
2828
id: python
29-
uses: actions/setup-python@v2.2.2
29+
uses: actions/setup-python@v3.1.1
3030
with:
3131
python-version: ${{ env.DEFAULT_PYTHON }}
3232
- name: Generate partial Python venv restore key
@@ -37,7 +37,7 @@ jobs:
3737
'requirements_test_pre_commit.txt') }}"
3838
- name: Restore Python virtual environment
3939
id: cache-venv
40-
uses: actions/cache@v2.1.6
40+
uses: actions/cache@v3.0.1
4141
with:
4242
path: venv
4343
key: >-
@@ -60,7 +60,7 @@ jobs:
6060
hashFiles('.pre-commit-config.yaml') }}"
6161
- name: Restore pre-commit environment
6262
id: cache-precommit
63-
uses: actions/cache@v2.1.6
63+
uses: actions/cache@v3.0.1
6464
with:
6565
path: ${{ env.PRE_COMMIT_CACHE }}
6666
key: >-
@@ -79,15 +79,15 @@ jobs:
7979
needs: prepare-base
8080
steps:
8181
- name: Check out code from GitHub
82-
uses: actions/checkout@v2.3.4
82+
uses: actions/checkout@v3.0.0
8383
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
8484
id: python
85-
uses: actions/setup-python@v2.2.2
85+
uses: actions/setup-python@v3.1.1
8686
with:
8787
python-version: ${{ env.DEFAULT_PYTHON }}
8888
- name: Restore Python virtual environment
8989
id: cache-venv
90-
uses: actions/cache@v2.1.6
90+
uses: actions/cache@v3.0.1
9191
with:
9292
path: venv
9393
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
@@ -99,7 +99,7 @@ jobs:
9999
exit 1
100100
- name: Restore pre-commit environment
101101
id: cache-precommit
102-
uses: actions/cache@v2.1.6
102+
uses: actions/cache@v3.0.1
103103
with:
104104
path: ${{ env.PRE_COMMIT_CACHE }}
105105
key: ${{ runner.os }}-${{ needs.prepare-base.outputs.pre-commit-key }}
@@ -120,15 +120,15 @@ jobs:
120120
needs: prepare-base
121121
steps:
122122
- name: Check out code from GitHub
123-
uses: actions/checkout@v2.3.4
123+
uses: actions/checkout@v3.0.0
124124
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
125125
id: python
126-
uses: actions/setup-python@v2.2.2
126+
uses: actions/setup-python@v3.1.1
127127
with:
128128
python-version: ${{ env.DEFAULT_PYTHON }}
129129
- name: Restore Python virtual environment
130130
id: cache-venv
131-
uses: actions/cache@v2.1.6
131+
uses: actions/cache@v3.0.1
132132
with:
133133
path: venv
134134
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
@@ -150,15 +150,15 @@ jobs:
150150
needs: prepare-base
151151
steps:
152152
- name: Check out code from GitHub
153-
uses: actions/checkout@v2.3.4
153+
uses: actions/checkout@v3.0.0
154154
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
155155
id: python
156-
uses: actions/setup-python@v2.2.2
156+
uses: actions/setup-python@v3.1.1
157157
with:
158158
python-version: ${{ env.DEFAULT_PYTHON }}
159159
- name: Restore Python virtual environment
160160
id: cache-venv
161-
uses: actions/cache@v2.1.6
161+
uses: actions/cache@v3.0.1
162162
with:
163163
path: venv
164164
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
@@ -174,20 +174,20 @@ jobs:
174174
mypy ${{ env.LIB_FOLDER }} tests
175175
176176
177-
prepare-tests-linux:
178-
name: Prepare tests for Python ${{ matrix.python-version }} (Linux)
177+
pytest-linux:
178+
name: Run tests Python ${{ matrix.python-version }} (Linux)
179179
runs-on: ubuntu-latest
180180
strategy:
181181
matrix:
182-
python-version: [3.8, 3.9]
182+
python-version: [3.8, 3.9, "3.10"]
183183
outputs:
184184
python-key: ${{ steps.generate-python-key.outputs.key }}
185185
steps:
186186
- name: Check out code from GitHub
187-
uses: actions/checkout@v2.3.4
187+
uses: actions/checkout@v3.0.0
188188
- name: Set up Python ${{ matrix.python-version }}
189189
id: python
190-
uses: actions/setup-python@v2.2.2
190+
uses: actions/setup-python@v3.1.1
191191
with:
192192
python-version: ${{ matrix.python-version }}
193193
- name: Generate partial Python venv restore key
@@ -198,7 +198,7 @@ jobs:
198198
'requirements_test_pre_commit.txt') }}"
199199
- name: Restore Python virtual environment
200200
id: cache-venv
201-
uses: actions/cache@v2.1.6
201+
uses: actions/cache@v3.0.1
202202
with:
203203
path: venv
204204
key: >-
@@ -214,35 +214,6 @@ jobs:
214214
python -m pip install -U pip setuptools wheel
215215
pip install -U -r requirements_test.txt
216216
pip install -e .
217-
218-
pytest-linux:
219-
name: Run tests Python ${{ matrix.python-version }} (Linux)
220-
runs-on: ubuntu-latest
221-
needs: prepare-tests-linux
222-
strategy:
223-
fail-fast: false
224-
matrix:
225-
python-version: [3.8, 3.9]
226-
steps:
227-
- name: Check out code from GitHub
228-
uses: actions/[email protected]
229-
- name: Set up Python ${{ matrix.python-version }}
230-
id: python
231-
uses: actions/[email protected]
232-
with:
233-
python-version: ${{ matrix.python-version }}
234-
- name: Restore Python virtual environment
235-
id: cache-venv
236-
uses: actions/[email protected]
237-
with:
238-
path: venv
239-
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
240-
needs.prepare-tests-linux.outputs.python-key }}
241-
- name: Fail job if Python cache restore failed
242-
if: steps.cache-venv.outputs.cache-hit != 'true'
243-
run: |
244-
echo "Failed to restore Python venv from cache"
245-
exit 1
246217
- name: Run pytest
247218
run: |
248219
. venv/bin/activate

.github/workflows/release.yaml

+4-7
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,16 @@ jobs:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- name: Check out code from Github
17-
uses: actions/checkout@v2.3.4
17+
uses: actions/checkout@v3.0.0
1818
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
1919
id: python
20-
uses: actions/setup-python@v2.2.2
20+
uses: actions/setup-python@v3.1.1
2121
with:
2222
python-version: ${{ env.DEFAULT_PYTHON }}
23-
- name: Install requirements
24-
run: |
25-
python -m pip install -U pip twine wheel
26-
python -m pip install -U "setuptools>=57.1.0"
2723
- name: Build distributions
2824
run: |
29-
python setup.py sdist bdist_wheel
25+
python -m pip install -U pip twine build wheel
26+
python -m build
3027
- name: Upload to PyPI
3128
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags')
3229
env:

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
repos:
22
- repo: https://github.com/asottile/pyupgrade
3-
rev: v2.21.2
3+
rev: v2.32.0
44
hooks:
55
- id: pyupgrade
66
args: [--py38-plus]
77
exclude: &fixtures ^tests/fixtures/.+\.py$
88
- repo: https://gitlab.com/pycqa/flake8
9-
rev: 3.9.2
9+
rev: 4.0.1
1010
hooks:
1111
- id: flake8
1212
files: ^(python_typing_update|script|tests)/.+\.py$
1313
exclude: *fixtures
1414
- repo: https://github.com/PyCQA/isort
15-
rev: 5.9.2
15+
rev: 5.10.1
1616
hooks:
1717
- id: isort
1818
exclude: *fixtures

README.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ so always check `git diff` before comitting any changes!
1717
Since this tool uses [pyupgrade][pyu], it's best used for
1818
projects that use it already.
1919

20+
**Python 3.10**
21+
This tool depends on `autoflake` which doesn't yet support Python 3.10.
22+
However, you can use `3.10` to update older Python syntax.
23+
2024

2125
## Limitations
2226
Due to the way the tool works, it will reorder the imports multiple times.
@@ -72,7 +76,7 @@ Number of files to process concurrently during initial load.
7276
**`--full-reorder`**
7377
Use additional options from [python-reorder-imports][pri] to rewrite
7478
- `--py38-plus` (default): Imports from `mypy_extensions` and `typing_extensions` when possible.
75-
- `--py39-plus`: Rewrite [PEP 585][PEP585] typing imports. Additionally `typing.Hashable` and `typing.Sized` will also be replace by their `collections.abc` equivalents.
79+
- `--py39-plus`: Rewrite [PEP 585][PEP585] typing imports. Additionally `typing.Hashable` and `typing.Sized` will also be replaced by their `collections.abc` equivalents.
7680

7781
**`--keep-updates`**
7882
Keep updates even if no import was removed. Use with caution, might result in more errors.
@@ -107,6 +111,9 @@ Check `git diff` before committing!
107111

108112
### Python version options
109113

114+
**`--py37-plus`**
115+
Set the minimum Python syntax version to **3.7**. (Default: **3.8**)
116+
110117
**`--py38-plus`**
111118
Set the minimum Python syntax version to **3.8**. This is the default.
112119

pylintrc

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
ignore=
33
load-plugins =
44
pylint.extensions.typing,
5+
pylint.extensions.code_style,
6+
py-version = 3.8
57

68
[BASIC]
79
good-names =
@@ -31,5 +33,7 @@ max-line-length = 119
3133
score = no
3234

3335
[TYPING]
34-
py-version = 3.8
3536
runtime-typing = no
37+
38+
[CODE_STYLE]
39+
max-line-length-suggestions = 72

pyproject.toml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[build-system]
2+
requires = ["setuptools~=60.5", "wheel~=0.37.1"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.isort]
6+
# https://pycqa.github.io/isort/docs/configuration/options.html
7+
multi_line_output = 4
8+
line_length = 72
9+
combine_as_imports = true
10+
force_sort_within_sections = true
11+
known_first_party = [
12+
"python_typing_update",
13+
"tests",
14+
]
15+
forced_separate = ["tests"]
16+
17+
[tool.pytest.ini_options]
18+
testpaths = ["tests"]
19+
norecursedirs = ["fixtures"]
20+
console_output_style = "count"
21+
log_level = "NOTSET"
22+
asyncio_mode = "auto" # https://github.com/pytest-dev/pytest-asyncio#modes
23+
24+
[tool.mypy]
25+
# https://mypy.readthedocs.io/en/stable/config_file.html
26+
python_version = 3.8
27+
show_error_codes = true
28+
ignore_missing_imports = true
29+
strict = true
30+
follow_imports = "normal"
31+
exclude = "tests/fixtures/.+\\.py"
32+
# Untyped definitions and calls
33+
disallow_untyped_calls = true
34+
disallow_untyped_defs = true
35+
disallow_incomplete_defs = true
36+
check_untyped_defs = true
37+
# None and optional handeling
38+
no_implicit_optional = true
39+
strict_optional = true
40+
# Configure warnings
41+
warn_redundant_casts = true
42+
warn_unused_ignores = true
43+
warn_unused_configs = true
44+
# Misc
45+
implicit_reexport = false
46+
strict_equality = true
47+
enable_error_code = ["ignore-without-code"]
48+
# TODO
49+
allow_any_generics = true
50+
51+
# [[tool.mypy.overrides]]
52+
# module = "tests.*"
53+
# # Untyped definitions and calls
54+
# disallow_untyped_calls = false
55+
# disallow_untyped_defs = false
56+
# disallow_incomplete_defs = false

python_typing_update/__main__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ async def async_main(argv: list[str] | None = None) -> int:
8888
)
8989

9090
group_py_version = py_version_options.add_mutually_exclusive_group()
91+
group_py_version.add_argument(
92+
'--py37-plus',
93+
action='store_const', dest='min_version', const=(3, 7), default=(3, 8),
94+
)
9195
group_py_version.add_argument(
9296
'--py38-plus',
93-
action='store_const', dest='min_version', default=(3, 8), const=(3, 8),
97+
action='store_const', dest='min_version', const=(3, 8),
9498
help="Default"
9599
)
96100
group_py_version.add_argument(

python_typing_update/const.py

-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
from enum import Flag, auto
77
from typing import NamedTuple
88

9-
version = (0, 3, 5)
10-
dev_version = None # Set to `None` for release
11-
12-
version_str = '.'.join(map(str, version))
13-
if dev_version is not None:
14-
version_str += f'.dev{dev_version}'
15-
169

1710
class FileAttributes(NamedTuple):
1811
status: FileStatus

python_typing_update/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
import argparse
77
import asyncio
88
import builtins
9-
import io
10-
import logging
119
from collections.abc import Iterable
1210
from functools import partial
11+
import io
1312
from io import StringIO
13+
import logging
1414

1515
import aiofiles
16-
import reorder_python_imports
1716
from autoflake import _main as autoflake_main
1817
from isort.main import main as isort_main
1918
from pyupgrade._main import main as pyupgrade_main
19+
import reorder_python_imports
2020

2121
from .const import FileAttributes, FileStatus
2222
from .utils import (

python_typing_update/py.typed

Whitespace-only changes.

python_typing_update/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from __future__ import annotations
55

66
import asyncio
7+
from collections.abc import Iterable
78
import os
9+
from pathlib import Path
810
import token
911
import tokenize
10-
from collections.abc import Iterable
11-
from pathlib import Path
1212
from typing import TextIO
1313

1414
from .const import FileStatus

0 commit comments

Comments
 (0)