Skip to content

Commit

Permalink
Python 3.6 support dropped #306 (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
hakancelikdev authored Dec 3, 2023
1 parent 1d2847e commit 5a0dccb
Show file tree
Hide file tree
Showing 24 changed files with 168 additions and 196 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/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.8"
python-version: "3.11"
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/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.8"
python-version: "3.11"
architecture: "x64"

- name: Install Dependencies
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/[email protected]
- uses: actions/[email protected]
with:
python-version: "3.8"
python-version: "3.11"
architecture: "x64"

- name: Install Dependencies
Expand Down
26 changes: 1 addition & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
name: test
on: [push, pull_request]
jobs:
test_with_python36:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-latest, windows-latest]
python-version: ["3.6"]
steps:
- uses: actions/[email protected]

- name: Set up Python${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
architecture: x64

- name: Install Dependencies for Python${{ matrix.python-version }}
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Test with pytest for Python${{ matrix.python-version }}
run: |
tox -e ${{ matrix.python-version }}
test_other_python:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:
rev: v3.8.0
hooks:
- id: pyupgrade
args: [--py36-plus]
args: [--py37-plus]

- repo: https://github.com/hakancelikdev/unexport
rev: 0.4.0
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.0] - 2023-12-03

### Changed

- Python 3.6 support dropped

## [1.1.0] - 2023-11-17

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

## Testing

First, make sure you have at least one of the python versions py3.6, py3.7, 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.7, 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.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Unimport requires Python 3.6+ and can be easily installed using most common Python
Unimport requires Python 3.7+ and can be easily installed using most common Python
packaging tools. We recommend installing the latest stable release from PyPI with pip:

```shell
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ It's possible to skip `.gitignore` glob patterns.
**Warning:**
For more accurate results when using `--gitignore` parameter, please do not use Python
3.6 and Windows. For more information, please visit ->
Windows. For more information, please visit ->
https://github.com/hakancelikdev/unimport/issues/240
---
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 = ['py36', 'py37', 'py38', 'py39', 'py310']
target-version = ['py37', 'py38', 'py39', 'py310']

[tool.unimport]
include_star_import = true
Expand Down
12 changes: 3 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ classifiers =
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Expand All @@ -33,7 +32,7 @@ project_urls =
Changelog = https://unimport.hakancelik.dev/1.1.0/CHANGELOG/

[options]
python_requires = >=3.6, <3.12
python_requires = >=3.7, <3.12
include_package_data = true
zip_safe = true
packages =
Expand All @@ -48,11 +47,8 @@ install_requires =
libcst>=0.3.7, <=1.1.0; python_version == '3.9'
libcst>=0.3.0, <=1.1.0; python_version == '3.8'
libcst>=0.3.0, <=1.0.1; python_version == '3.7'
libcst>=0.3.0, <=0.4.1; python_version == '3.6'
pathspec>=0.10.1, <1; python_version >= '3.7'
pathspec>=0.5.0, <=0.9.0; python_version == '3.6'
toml>=0.9.0, <1
dataclasses>=0.5, <1; python_version == '3.6'
typing-extensions>=3.7.4, <4; python_version < '3.8'

[options.entry_points]
Expand All @@ -68,10 +64,8 @@ docs =
mkdocs-git-revision-date-localized-plugin==1.2.1
mike==2.0.0
test =
pytest==6.2.4; python_version == '3.6'
pytest==7.4.3; python_version != '3.6'
pytest-cov==4.0.0; python_version == '3.6'
pytest-cov==4.1.0; python_version != '3.6'
pytest==7.4.3
pytest-cov==4.1.0
semantic-version==2.10.0

[options.package_data]
Expand Down
11 changes: 6 additions & 5 deletions src/unimport/analyzers/import_statement.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import ast
from typing import List, Optional, Set

from unimport.analyzers.decarators import generic_visit, skip_import
from unimport.analyzers.importable import ImportableAnalyzer
Expand All @@ -20,16 +21,16 @@ class ImportAnalyzer(ast.NodeVisitor):
IGNORE_IMPORT_NAMES = ("__all__", "__doc__", "__name__")

def __init__(
self, *, source: str, include_star_import: bool = False, defined_names: Optional[Set[str]] = None
self, *, source: str, include_star_import: bool = False, defined_names: set[str] | None = None
) -> None:
self.source = source
self.include_star_import = include_star_import
self.defined_names = defined_names or set()

self.any_import_error = False

self.if_names: Set[str] = set()
self.orelse_names: Set[str] = set()
self.if_names: set[str] = set()
self.orelse_names: set[str] = set()

def traverse(self, tree) -> None:
self.visit(tree)
Expand Down Expand Up @@ -104,7 +105,7 @@ def visit_Try(self, node: ast.Try) -> None:

self.any_import_error = False

def get_suggestions(self, package: str) -> List[str]:
def get_suggestions(self, package: str) -> list[str]:
names = set(map(lambda name: name.name.split(".")[0], Name.names))
from_names = ImportableAnalyzer.get_names(package)
return sorted(from_names & (names - self.defined_names))
17 changes: 8 additions & 9 deletions src/unimport/analyzers/utils.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from __future__ import annotations

import ast
from typing import Iterator, Optional, Set
import typing

__all__ = ("set_tree_parents", "get_parents", "first_parent_match", "get_defined_names")


def set_tree_parents(tree: ast.AST, parent: Optional[ast.AST] = None) -> None:
def set_tree_parents(tree: ast.AST, parent: ast.AST | None = None) -> None:
tree.parent = parent # type: ignore
for node in ast.walk(tree):
for child in ast.iter_child_nodes(node):
child.parent = node # type: ignore


def get_parents(node: ast.AST) -> Iterator[ast.AST]:
def get_parents(node: ast.AST) -> typing.Iterator[ast.AST]:
parent = node
while parent:
parent = parent.parent # type: ignore
Expand All @@ -20,14 +22,11 @@ def get_parents(node: ast.AST) -> Iterator[ast.AST]:


def first_parent_match(node: ast.AST, *ancestors):
try:
return next(filter(lambda parent: isinstance(parent, ancestors), get_parents(node)))
except StopIteration:
return None
return next(filter(lambda parent: isinstance(parent, ancestors), get_parents(node)), None)


def get_defined_names(tree: ast.AST) -> Set[str]:
defined_names: Set[str] = set()
def get_defined_names(tree: ast.AST) -> set[str]:
defined_names: set[str] = set()
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
defined_names.add(node.name)
Expand Down
1 change: 1 addition & 0 deletions src/unimport/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"TERMINAL_SUPPORT_COLOR",
"difference",
"paint",
"Color",
)

if sys.platform == "win32": # pragma: no cover (windows)
Expand Down
5 changes: 3 additions & 2 deletions src/unimport/commands/check.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from pathlib import Path
from typing import List, Union

from unimport.color import paint
from unimport.enums import Color
Expand All @@ -8,7 +9,7 @@
__all__ = ("check",)


def check(path: Path, unused_imports: List[Union[Import, ImportFrom]], use_color: bool) -> None:
def check(path: Path, unused_imports: list[Import | ImportFrom], use_color: bool) -> None:
for imp in unused_imports:
if isinstance(imp, ImportFrom) and imp.star and imp.suggestions:
context = (
Expand Down
4 changes: 3 additions & 1 deletion src/unimport/commands/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"add_version_option",
)

from unimport.enums import ColorSelect


def add_sources_option(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
Expand Down Expand Up @@ -164,7 +166,7 @@ def add_color_option(parser: argparse.ArgumentParser) -> None:
parser.add_argument(
"--color",
default=Config.color,
type=str,
type=ColorSelect,
metavar="{" + ",".join(Config.get_color_choices()) + "}",
help="Select whether to use color in the output. Defaults to `%(default)s`.",
)
Loading

0 comments on commit 5a0dccb

Please sign in to comment.