Skip to content

Commit

Permalink
Merge pull request python-trio#209 from jakkdl/rename_files
Browse files Browse the repository at this point in the history
rename files, update references to them
  • Loading branch information
Zac-HD authored Feb 26, 2024
2 parents 7748d40 + 6281cb3 commit eb2de73
Show file tree
Hide file tree
Showing 82 changed files with 66 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
hooks:
- id: pyupgrade
args: [--py39-plus]
exclude: tests/eval_files/trio103.py
exclude: tests/eval_files/async103.py

- repo: https://github.com/pycqa/isort
rev: 5.13.2
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- id: flake8-trio
name: flake8-trio
entry: flake8-trio
- id: flake8-async
name: flake8-async
entry: flake8-async
language: python
types: [python]
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tox -p --develop
```

## Meta-tests
To check that all codes are tested and documented there's a test that error codes mentioned in `README.md`, `CHANGELOG.md` (matching `TRIO\d\d\d`), the keys in `flake8_trio.Error_codes` and codes parsed from filenames and files in `tests/eval_files/`, are all equal.
To check that all codes are tested and documented there's a test that error codes mentioned in `README.md`, `CHANGELOG.md` (matching `TRIO\d\d\d`), the keys in `flake8_async.Error_codes` and codes parsed from filenames and files in `tests/eval_files/`, are all equal.

## Test generator
Tests are automatically generated for files in the `tests/eval_files/` directory, with the code that it's testing interpreted from the file name. The file extension is split off, if there's a match for for `_py\d*` it strips that off and uses it to determine if there's a minimum python version for which the test should only run.
Expand All @@ -36,7 +36,7 @@ During tests the result of running the checker on the eval file with autofix ena
Files without this marker will be checked that they *don't* modify the file content.

### `error:`
Lines containing `error:` are parsed as expecting an error of the code matching the file name, with everything on the line after the colon `eval`'d and passed as arguments to `flake8_trio.Error_codes[<error_code>].str_format`. The `globals` argument to `eval` contains a `lineno` variable assigned the current line number, and the `flake8_trio.Statement` namedtuple. The first element after `error:` *must* be an integer containing the column where the error on that line originates.
Lines containing `error:` are parsed as expecting an error of the code matching the file name, with everything on the line after the colon `eval`'d and passed as arguments to `flake8_async.Error_codes[<error_code>].str_format`. The `globals` argument to `eval` contains a `lineno` variable assigned the current line number, and the `flake8_async.Statement` namedtuple. The first element after `error:` *must* be an integer containing the column where the error on that line originates.
#### `TRIOxxx:`
You can instead of `error` specify the error code.

Expand Down Expand Up @@ -73,6 +73,6 @@ or rote memorization of an arbitrary convention.
We want to ship bigfixes or new features as soon as they're ready,
so our release process is automated:

1. Increment `__version__` in `src/flake8_trio.py`
1. Increment `__version__` in `src/flake8_async.py`
2. Ensure there's a corresponding entry in `CHANGELOG.md` with same version
3. Merge to master, and CI will do the rest!
8 changes: 4 additions & 4 deletions flake8_trio/__init__.py → flake8_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import libcst as cst

from .base import Options, error_has_subidentifier
from .runner import Flake8TrioRunner, Flake8TrioRunner_cst
from .runner import Flake8AsyncRunner, Flake8AsyncRunner_cst
from .visitors import ERROR_CLASSES, ERROR_CLASSES_CST, default_disabled_error_codes

if TYPE_CHECKING:
Expand Down Expand Up @@ -75,7 +75,7 @@ def cst_parse_module_native(source: str) -> cst.Module:


def main() -> int:
parser = ArgumentParser(prog="flake8-trio")
parser = ArgumentParser(prog="flake8-async")
Plugin.add_options(parser)
args = parser.parse_args()
Plugin.parse_options(args)
Expand Down Expand Up @@ -156,11 +156,11 @@ def run(self) -> Iterable[Error]:
if not self.standalone:
self.options.disable_noqa = True

cst_runner = Flake8TrioRunner_cst(self.options, self.module)
cst_runner = Flake8AsyncRunner_cst(self.options, self.module)
# any noqa'd errors are suppressed upon being generated
yield from cst_runner.run()

problems_ast = Flake8TrioRunner.run(self._tree, self.options)
problems_ast = Flake8AsyncRunner.run(self._tree, self.options)
if self.options.disable_noqa:
yield from problems_ast
return
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions flake8_trio/runner.py → flake8_async/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Contains Flake8TrioRunner.
"""Contains Flake8AsyncRunner.
The runner is what's run by the Plugin, and handles traversing
the AST and letting all registered ERROR_CLASSES do their visit'ing on them.
Expand Down Expand Up @@ -26,7 +26,7 @@
from libcst import Module

from .base import Error, Options
from .visitors.flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst
from .visitors.flake8asyncvisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst


@dataclass
Expand All @@ -53,7 +53,7 @@ def selected(self, error_codes: Mapping[str, str]) -> bool:
return bool(set(error_codes) & enabled_or_autofix)


class Flake8TrioRunner(ast.NodeVisitor, __CommonRunner):
class Flake8AsyncRunner(ast.NodeVisitor, __CommonRunner):
def __init__(self, options: Options):
super().__init__(options)
# utility visitors that need to run before the error-checking visitors
Expand Down Expand Up @@ -110,7 +110,7 @@ def visit(self, node: ast.AST):
subclass.set_state(subclass.outer.pop(node, {}))


class Flake8TrioRunner_cst(__CommonRunner):
class Flake8AsyncRunner_cst(__CommonRunner):
def __init__(self, options: Options, module: Module):
super().__init__(options)
self.options = options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst
from .flake8asyncvisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst

__all__ = [
"ERROR_CLASSES",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Sequence

from .flake8triovisitor import (
from .flake8asyncvisitor import (
Flake8AsyncVisitor,
Flake8AsyncVisitor_cst,
HasLineCol,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import libcst as cst
import libcst.matchers as m

from .flake8triovisitor import Flake8AsyncVisitor_cst
from .flake8asyncvisitor import Flake8AsyncVisitor_cst
from .helpers import (
AttributeCall,
error_class_cst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8AsyncVisitor_cst
from .flake8asyncvisitor import Flake8AsyncVisitor_cst
from .helpers import (
cancel_scope_names,
error_class_cst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import TYPE_CHECKING, Any

from ..base import Statement
from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import cancel_scope_names, critical_except, error_class, get_matching_call

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ast
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import critical_except, error_class, iter_guaranteed_once

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import error_class

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
from typing import TYPE_CHECKING, Any, NamedTuple

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import error_class, get_matching_call

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import re
from typing import TYPE_CHECKING

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import error_class

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import re
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import error_class, fnmatch_qualified_name, get_matching_call

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from libcst.metadata import PositionProvider

from ..base import Statement
from .flake8triovisitor import Flake8AsyncVisitor_cst
from .flake8asyncvisitor import Flake8AsyncVisitor_cst
from .helpers import (
disabled_by_default,
error_class_cst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import libcst.matchers as m
from libcst.metadata import PositionProvider

from .flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst
from .flake8asyncvisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst
from .helpers import utility_visitor, utility_visitor_cst

if TYPE_CHECKING:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
from typing import TYPE_CHECKING, Any, cast

from .flake8triovisitor import Flake8AsyncVisitor
from .flake8asyncvisitor import Flake8AsyncVisitor
from .helpers import disabled_by_default, error_class, get_matching_call, has_decorator

if TYPE_CHECKING:
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ reportUninitializedInstanceVariable = true
# can't enable until https://github.com/python/mypy/issues/12358
reportUnnecessaryTypeIgnoreComment = false
reportUnusedCallResult = false
strict = ["*.py", "tests/*.py", "flake8_trio/**/*.py"]
strict = ["*.py", "tests/*.py", "flake8_async/**/*.py"]

[tool.ruff]
extend-exclude = [
Expand Down Expand Up @@ -104,10 +104,10 @@ select = ["ALL"]
# docstrings, and arguments we can't modify
"*.pyi" = ["D", 'FBT001', 'PLR0913', "PIE790", "PYI048"]
# imports
"flake8_trio/visitors/__init__.py" = [
"flake8_async/visitors/__init__.py" = [
"F401",
"E402"
]
# visitor_utility contains comments specifying how it parses noqa comments, which get
# parsed as noqa comments
"flake8_trio/visitors/visitor_utility.py" = ["RUF100", "PGH004"]
"flake8_async/visitors/visitor_utility.py" = ["RUF100", "PGH004"]
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def local_file(name: str) -> Path:
return Path(__file__).parent / name


with open(Path(__file__).parent / "flake8_trio" / "__init__.py") as o:
with open(Path(__file__).parent / "flake8_async" / "__init__.py") as o:
for line in o:
if line.startswith("__version__"):
_, __version__, _ = line.split('"')
Expand All @@ -24,7 +24,7 @@ def local_file(name: str) -> Path:
version=__version__,
author="Zac Hatfield-Dodds, John Litborn, and Contributors",
author_email="zac@zhd.dev",
packages=find_packages(include=["flake8_trio", "flake8_trio.*"]),
packages=find_packages(include=["flake8_async", "flake8_async.*"]),
url="https://github.com/python-trio/flake8-trio",
license="MIT",
description="A highly opinionated flake8 plugin for Trio-related problems.",
Expand Down Expand Up @@ -54,7 +54,7 @@ def local_file(name: str) -> Path:
# You're not allowed to register error codes longer than 3 characters. But flake8
# doesn't enforce anything about the characters trailing the code, so we can say
# the code is ASY and then just always happen to print NCxxx directly after it.
"flake8.extension": ["ASY = flake8_trio:Plugin"],
"console_scripts": ["flake8-async=flake8_trio:main"],
"flake8.extension": ["ASY = flake8_async:Plugin"],
"console_scripts": ["flake8-async=flake8_async:main"],
},
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions tests/test_all_visitors_imported.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Check that all visitors are imported.
Checks that all flake8_trio/visitor*.py files are imported in flake8_trio/visitor/__init__
so their decorators are run.
Checks that all flake8_async/visitor*.py files are imported in
flake8_async/visitor/__init__.py so their decorators are run.
"""

from __future__ import annotations
Expand All @@ -11,7 +11,7 @@


def test_all_visitors_imported():
visitor_dir = Path(__file__).parent.parent / "flake8_trio" / "visitors"
visitor_dir = Path(__file__).parent.parent / "flake8_async" / "visitors"
visitor_files = {
f.stem for f in visitor_dir.iterdir() if f.stem.startswith("visitor")
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_changelog_and_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
ROOT_PATH = Path(__file__).parent.parent
CHANGELOG = ROOT_PATH / "CHANGELOG.md"
README = ROOT_PATH / "README.md"
INIT_FILE = ROOT_PATH / "flake8_trio" / "__init__.py"
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"

T = TypeVar("T", bound="Version")

Expand Down Expand Up @@ -86,7 +86,7 @@ def update_version() -> None:
# If we've added a new version to the changelog, update __version__ to match
last_version = next(iter(get_releases()))
if last_version != VERSION:
INIT_FILE = ROOT_PATH / "flake8_trio" / "__init__.py"
INIT_FILE = ROOT_PATH / "flake8_async" / "__init__.py"
subs = (f'__version__ = "{VERSION}"', f'__version__ = "{last_version}"')
INIT_FILE.write_text(INIT_FILE.read_text().replace(*subs))

Expand Down
12 changes: 6 additions & 6 deletions tests/test_config_and_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

import pytest

from flake8_trio import Plugin, main
from flake8_async import Plugin, main

from .test_flake8_trio import initialize_options
from .test_flake8_async import initialize_options

EXAMPLE_PY_TEXT = """import trio
with trio.move_on_after(10):
Expand Down Expand Up @@ -47,7 +47,7 @@ def monkeypatch_argv(
monkeypatch.setattr(sys, "argv", argv)


def test_run_flake8_trio(tmp_path: Path):
def test_run_flake8_async(tmp_path: Path):
write_examplepy(tmp_path)
res = subprocess.run(
[
Expand All @@ -71,7 +71,7 @@ def test_systemexit_0(
tmp_path.joinpath("example.py").write_text("")

with pytest.raises(SystemExit) as exc_info:
from flake8_trio import __main__ # noqa: F401
from flake8_async import __main__ # noqa: F401

assert exc_info.value.code == 0
out, err = capsys.readouterr()
Expand All @@ -86,7 +86,7 @@ def test_systemexit_1(
monkeypatch_argv(monkeypatch, tmp_path)

with pytest.raises(SystemExit) as exc_info:
from flake8_trio import __main__ # noqa: F401
from flake8_async import __main__ # noqa: F401

assert exc_info.value.code == 1
out, err = capsys.readouterr()
Expand Down Expand Up @@ -168,7 +168,7 @@ def test_anyio_from_config(tmp_path: Path, capsys: pytest.CaptureFixture[str]):
"""
)

from flake8_trio.visitors.visitor2xx import Visitor22X
from flake8_async.visitors.visitor2xx import Visitor22X

err_msg = Visitor22X.error_codes["ASYNC220"].format(
"subprocess.Popen",
Expand Down
6 changes: 3 additions & 3 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

from flake8.main.application import Application

from flake8_trio.base import Statement
from flake8_trio.visitors.helpers import fnmatch_qualified_name
from flake8_trio.visitors.visitor91x import Visitor91X
from flake8_async.base import Statement
from flake8_async.visitors.helpers import fnmatch_qualified_name
from flake8_async.visitors.visitor91x import Visitor91X

if TYPE_CHECKING:
import pytest
Expand Down
2 changes: 1 addition & 1 deletion tests/test_exception_on_invalid_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import libcst as cst
import pytest

from flake8_trio.visitors.helpers import iter_guaranteed_once, iter_guaranteed_once_cst
from flake8_async.visitors.helpers import iter_guaranteed_once, iter_guaranteed_once_cst


def _raises_on_code_cst(source: str):
Expand Down
Loading

0 comments on commit eb2de73

Please sign in to comment.