Skip to content

Commit

Permalink
Merge pull request #164 from cdce8p/dev
Browse files Browse the repository at this point in the history
Release v0.4.0
  • Loading branch information
cdce8p authored Apr 13, 2022
2 parents a693041 + 6f9c4ee commit f9106b5
Show file tree
Hide file tree
Showing 19 changed files with 374 additions and 381 deletions.
71 changes: 21 additions & 50 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
pull_request: ~

env:
CACHE_VERSION: 0
CACHE_VERSION: 1
DEFAULT_PYTHON: 3.8
LIB_FOLDER: python_typing_update
PRE_COMMIT_CACHE: ~/.cache/pre-commit
Expand All @@ -23,10 +23,10 @@ jobs:
pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Generate partial Python venv restore key
Expand All @@ -37,7 +37,7 @@ jobs:
'requirements_test_pre_commit.txt') }}"
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: venv
key: >-
Expand All @@ -60,7 +60,7 @@ jobs:
hashFiles('.pre-commit-config.yaml') }}"
- name: Restore pre-commit environment
id: cache-precommit
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: >-
Expand All @@ -79,15 +79,15 @@ jobs:
needs: prepare-base
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: venv
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
Expand All @@ -99,7 +99,7 @@ jobs:
exit 1
- name: Restore pre-commit environment
id: cache-precommit
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: ${{ env.PRE_COMMIT_CACHE }}
key: ${{ runner.os }}-${{ needs.prepare-base.outputs.pre-commit-key }}
Expand All @@ -120,15 +120,15 @@ jobs:
needs: prepare-base
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: venv
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
Expand All @@ -150,15 +150,15 @@ jobs:
needs: prepare-base
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: venv
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
Expand All @@ -174,20 +174,20 @@ jobs:
mypy ${{ env.LIB_FOLDER }} tests
prepare-tests-linux:
name: Prepare tests for Python ${{ matrix.python-version }} (Linux)
pytest-linux:
name: Run tests Python ${{ matrix.python-version }} (Linux)
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8, 3.9]
python-version: [3.8, 3.9, "3.10"]
outputs:
python-key: ${{ steps.generate-python-key.outputs.key }}
steps:
- name: Check out code from GitHub
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ matrix.python-version }}
- name: Generate partial Python venv restore key
Expand All @@ -198,7 +198,7 @@ jobs:
'requirements_test_pre_commit.txt') }}"
- name: Restore Python virtual environment
id: cache-venv
uses: actions/cache@v2.1.6
uses: actions/cache@v3.0.1
with:
path: venv
key: >-
Expand All @@ -214,35 +214,6 @@ jobs:
python -m pip install -U pip setuptools wheel
pip install -U -r requirements_test.txt
pip install -e .
pytest-linux:
name: Run tests Python ${{ matrix.python-version }} (Linux)
runs-on: ubuntu-latest
needs: prepare-tests-linux
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9]
steps:
- name: Check out code from GitHub
uses: actions/[email protected]
- name: Set up Python ${{ matrix.python-version }}
id: python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Restore Python virtual environment
id: cache-venv
uses: actions/[email protected]
with:
path: venv
key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{
needs.prepare-tests-linux.outputs.python-key }}
- name: Fail job if Python cache restore failed
if: steps.cache-venv.outputs.cache-hit != 'true'
run: |
echo "Failed to restore Python venv from cache"
exit 1
- name: Run pytest
run: |
. venv/bin/activate
Expand Down
11 changes: 4 additions & 7 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code from Github
uses: actions/checkout@v2.3.4
uses: actions/checkout@v3.0.0
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
id: python
uses: actions/setup-python@v2.2.2
uses: actions/setup-python@v3.1.1
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install requirements
run: |
python -m pip install -U pip twine wheel
python -m pip install -U "setuptools>=57.1.0"
- name: Build distributions
run: |
python setup.py sdist bdist_wheel
python -m pip install -U pip twine build wheel
python -m build
- name: Upload to PyPI
if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags')
env:
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v2.21.2
rev: v2.32.0
hooks:
- id: pyupgrade
args: [--py38-plus]
exclude: &fixtures ^tests/fixtures/.+\.py$
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
rev: 4.0.1
hooks:
- id: flake8
files: ^(python_typing_update|script|tests)/.+\.py$
exclude: *fixtures
- repo: https://github.com/PyCQA/isort
rev: 5.9.2
rev: 5.10.1
hooks:
- id: isort
exclude: *fixtures
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ so always check `git diff` before comitting any changes!
Since this tool uses [pyupgrade][pyu], it's best used for
projects that use it already.

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


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

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

### Python version options

**`--py37-plus`**
Set the minimum Python syntax version to **3.7**. (Default: **3.8**)

**`--py38-plus`**
Set the minimum Python syntax version to **3.8**. This is the default.

Expand Down
6 changes: 5 additions & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ignore=
load-plugins =
pylint.extensions.typing,
pylint.extensions.code_style,
py-version = 3.8

[BASIC]
good-names =
Expand Down Expand Up @@ -31,5 +33,7 @@ max-line-length = 119
score = no

[TYPING]
py-version = 3.8
runtime-typing = no

[CODE_STYLE]
max-line-length-suggestions = 72
56 changes: 56 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[build-system]
requires = ["setuptools~=60.5", "wheel~=0.37.1"]
build-backend = "setuptools.build_meta"

[tool.isort]
# https://pycqa.github.io/isort/docs/configuration/options.html
multi_line_output = 4
line_length = 72
combine_as_imports = true
force_sort_within_sections = true
known_first_party = [
"python_typing_update",
"tests",
]
forced_separate = ["tests"]

[tool.pytest.ini_options]
testpaths = ["tests"]
norecursedirs = ["fixtures"]
console_output_style = "count"
log_level = "NOTSET"
asyncio_mode = "auto" # https://github.com/pytest-dev/pytest-asyncio#modes

[tool.mypy]
# https://mypy.readthedocs.io/en/stable/config_file.html
python_version = 3.8
show_error_codes = true
ignore_missing_imports = true
strict = true
follow_imports = "normal"
exclude = "tests/fixtures/.+\\.py"
# Untyped definitions and calls
disallow_untyped_calls = true
disallow_untyped_defs = true
disallow_incomplete_defs = true
check_untyped_defs = true
# None and optional handeling
no_implicit_optional = true
strict_optional = true
# Configure warnings
warn_redundant_casts = true
warn_unused_ignores = true
warn_unused_configs = true
# Misc
implicit_reexport = false
strict_equality = true
enable_error_code = ["ignore-without-code"]
# TODO
allow_any_generics = true

# [[tool.mypy.overrides]]
# module = "tests.*"
# # Untyped definitions and calls
# disallow_untyped_calls = false
# disallow_untyped_defs = false
# disallow_incomplete_defs = false
6 changes: 5 additions & 1 deletion python_typing_update/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ async def async_main(argv: list[str] | None = None) -> int:
)

group_py_version = py_version_options.add_mutually_exclusive_group()
group_py_version.add_argument(
'--py37-plus',
action='store_const', dest='min_version', const=(3, 7), default=(3, 8),
)
group_py_version.add_argument(
'--py38-plus',
action='store_const', dest='min_version', default=(3, 8), const=(3, 8),
action='store_const', dest='min_version', const=(3, 8),
help="Default"
)
group_py_version.add_argument(
Expand Down
7 changes: 0 additions & 7 deletions python_typing_update/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from enum import Flag, auto
from typing import NamedTuple

version = (0, 3, 5)
dev_version = None # Set to `None` for release

version_str = '.'.join(map(str, version))
if dev_version is not None:
version_str += f'.dev{dev_version}'


class FileAttributes(NamedTuple):
status: FileStatus
Expand Down
6 changes: 3 additions & 3 deletions python_typing_update/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import argparse
import asyncio
import builtins
import io
import logging
from collections.abc import Iterable
from functools import partial
import io
from io import StringIO
import logging

import aiofiles
import reorder_python_imports
from autoflake import _main as autoflake_main
from isort.main import main as isort_main
from pyupgrade._main import main as pyupgrade_main
import reorder_python_imports

from .const import FileAttributes, FileStatus
from .utils import (
Expand Down
Empty file added python_typing_update/py.typed
Empty file.
4 changes: 2 additions & 2 deletions python_typing_update/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from __future__ import annotations

import asyncio
from collections.abc import Iterable
import os
from pathlib import Path
import token
import tokenize
from collections.abc import Iterable
from pathlib import Path
from typing import TextIO

from .const import FileStatus
Expand Down
Loading

0 comments on commit f9106b5

Please sign in to comment.