An opinionated plugin for Flake8 on how certain packages should be imported or aliased.
Project description
flake8-import-conventions
An opinionated plugin for Flake8 on how certain packages should be imported or aliased.
It is based on the pandas-vet
and flake8-2020
plugins.
Development
poetry install --with dev
poetry shell
Open the manual_test.py
file in VS Code to see the error messages.
pytest tests/ -v
or (to see print()
s)
pytest tests/ -v -s
Deployment
poetry check
poetry version minor
or
poetry version patch
git tag
git tag "v$(poetry version --short)"
git push origin "v$(poetry version --short)"
References
- Anthony Sottile's "a flake8 plugin from scratch (intermediate) anthony explains #025" tutorial.
- flake8-pie.
- wemake-python-styleguide.
Notes
- flake8-class-attributes-order.
- astpretty.
- babi (text editor).
self.generic_visit(node)
: call it at the end of eachvisit_*
method for the recursion to continue.- attrs:
- "Classes without boilerplate".
- No need to implement object protocols (dunder methods).
- "It does nothing dynamic at runtime, hence zero runtime overhead."
__attrs_post_init__
method.
- Dict vs. slotted classes.
poetry add flake8@^3.0.0 attrs
.flake8 formatter.py flake8_import_conventions --jobs 1
.poetry install --no-root
(don't install this package).import typing as t
(flake8-annotations).import geopandas
(source).- https://github.com/asottile/flake8-2020/commit/10ba36520cca00ecbc812b2b96fcaaf9f8999c06
- Poetry:
- https://python-poetry.org/docs/#installing-with-the-official-installer
poetry --version
(1.3.2)poetry init
(https://python-poetry.org/docs/basic-usage/#initialising-a-pre-existing-project)- https://python-poetry.org/docs/dependency-specification/#exact-requirements
poetry add attrs
poetry add mypy black bandit pytest --group dev
poetry add isort@^5.11.5 --group dev
orpoetry add isort --group dev --allow-prereleases
(https://github.com/PyCQA/isort/issues/2084 + https://pypi.org/project/isort/6.0.0b2/#history + https://github.com/PyCQA/isort/issues/2083)flake8 = ">=5"
(https://github.com/asottile/flake8-2020/blob/v1.7.0/setup.cfg#L25)- https://python-poetry.org/docs/cli/#add (Allow >=2.0.5 versions, without upper bound)
poetry config virtualenvs.in-project true --local
poetry env remove --all
poetry config --list
- https://www.attrs.org/en/latest/index.html#getting-started
- Delete local tag:
git tag -d v0.0.1
Minimal boilerplate for the Plugin
class:
import ast
import importlib.metadata
from typing import Any, Generator, Tuple, Type
class Plugin:
name = __name__
version = importlib.metadata.version(__name__)
def __init__(self, tree: ast.AST) -> None:
# The AST that represents a single file
self._tree = tree
def run(self) -> Generator[Tuple[int, int, str, Type[Any]], None, None]:
# Tuple[line number, character offset, message]
# Type[Any] is not being used (use `type(self)`)
pass
Syntactic sugar for attr.ib(default=attr.Factory(f))
:
@attr.s
class C(object):
x = attr.ib(factory=list)
# instead of
# x = attr.ib(default=attr.Factory(list))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for flake8_import_conventions-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24596b462d14cab1743dd200171b20a870b0bf13b9f7e23cff8626ff07a5359a |
|
MD5 | c9289902116a6dd8706385d1436aa419 |
|
BLAKE2b-256 | 2561831bc5a7d134e677a0b3b811184b92068ed5126b3f5bc31a5f0dcbad1b59 |
Close
Hashes for flake8_import_conventions-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e8a3e1d33f7a18adfbef9fd85eda246a87f57ae12cfceda9aeb1801520c170d |
|
MD5 | 0655de284447733f554afdc207a267f6 |
|
BLAKE2b-256 | 7f1e391156f60c658d9ce660ba479eeae103819d48cc0c0035498b17270c98a6 |