Skip to content

Commit

Permalink
Use Ruff for linting and import sorting (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Feb 24, 2024
1 parent 0e99faa commit 9762262
Show file tree
Hide file tree
Showing 84 changed files with 649 additions and 519 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Lint

on: [push, pull_request]

jobs:
precommit:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up latest Python
uses: actions/setup-python@v4
with:
python-version: "3.12"

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.0
48 changes: 24 additions & 24 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@ jobs:
name: Build and publish Python distributions to PyPI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish distribution to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ jobs:
- name: black
python: "3.12"
toxenv: black
- name: flake8
- name: ruff
python: "3.12"
toxenv: flake8
toxenv: ruff

steps:
- uses: actions/checkout@v4
Expand Down
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.2
hooks:
- id: ruff
args: [--fix]

- repo: https://github.com/psf/black
rev: 24.2.0
hooks:
- id: black
language_version: python3.12

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ sphinx:

python:
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.txt
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ as possible. Here is a quick guide.

It's useful to have a virtual environment to work in. I use
commands like these:

```
$ cd pyanalyze
$ python3 -m venv .venv
Expand All @@ -13,7 +14,7 @@ $ pip install -e .

## Black

The code is formatted using [*Black*](https://black.readthedocs.io).
The code is formatted using [_Black_](https://black.readthedocs.io).
You can run the formatter with:

```
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#
import os
import sys

from pkg_resources import get_distribution

sys.path.insert(0, os.path.abspath(".."))
Expand Down
2 changes: 1 addition & 1 deletion pyanalyze/analysis_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import ast
import linecache
import os
from pathlib import Path
import secrets
import sys
import types
from dataclasses import dataclass
from pathlib import Path
from typing import Callable, List, Mapping, Optional, Set, Union


Expand Down
4 changes: 2 additions & 2 deletions pyanalyze/annotated_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
"""

import enum
from dataclasses import dataclass
from datetime import datetime, timezone
import enum
from typing import Any, Callable, Iterable, Optional, Union, Type
from typing import Any, Callable, Iterable, Optional, Type, Union

from pyanalyze.value import CanAssign, CanAssignContext, Value, flatten_values

Expand Down
30 changes: 14 additions & 16 deletions pyanalyze/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import contextlib
import typing
from collections.abc import Callable, Hashable
from dataclasses import dataclass, field, InitVar
from dataclasses import InitVar, dataclass, field
from typing import (
TYPE_CHECKING,
Any,
cast,
Container,
ContextManager,
Generator,
Expand All @@ -43,20 +43,18 @@
Sequence,
Set,
Tuple,
TYPE_CHECKING,
TypeVar,
Union,
cast,
)
import typing_extensions

import qcore

from typing_extensions import ParamSpec, TypedDict, get_origin, get_args
import typing_extensions
from typing_extensions import ParamSpec, TypedDict, get_args, get_origin

from pyanalyze.annotated_types import get_annotated_types_extension

from . import type_evaluation

from .error_code import ErrorCode
from .extensions import (
AsynqCallable,
Expand All @@ -81,40 +79,40 @@
SigParameter,
)
from .value import (
_HashableValue,
DictIncompleteValue,
KVPair,
TypeAlias,
TypeAliasValue,
TypeIsExtension,
annotate_value,
NO_RETURN_VALUE,
AnnotatedValue,
AnySource,
AnyValue,
CallableValue,
CustomCheckExtension,
DictIncompleteValue,
Extension,
GenericValue,
HasAttrGuardExtension,
KnownValue,
KVPair,
MultiValuedValue,
NewTypeValue,
NO_RETURN_VALUE,
NoReturnGuardExtension,
ParameterTypeGuardExtension,
ParamSpecArgsValue,
ParamSpecKwargsValue,
SelfTVV,
SequenceValue,
SubclassValue,
TypeAlias,
TypeAliasValue,
TypedDictValue,
TypedValue,
TypeGuardExtension,
TypeIsExtension,
TypeVarLike,
TypeVarValue,
unite_values,
UnpackedValue,
Value,
_HashableValue,
annotate_value,
unite_values,
)

if TYPE_CHECKING:
Expand Down
21 changes: 9 additions & 12 deletions pyanalyze/arg_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import inspect
import sys
import textwrap
import typing
from dataclasses import dataclass, replace
from types import FunctionType, MethodType, ModuleType
import typing
from typing import (
Any,
Callable,
Expand All @@ -37,15 +37,12 @@
from typing_extensions import is_typeddict

import pyanalyze

from . import implementation
from .analysis_lib import is_positional_only_arg_name
from .annotations import Context, RuntimeEvaluator, type_from_runtime
from .extensions import (
CustomCheck,
get_overloads as pyanalyze_get_overloads,
get_type_evaluations,
TypeGuard,
)
from .extensions import CustomCheck, TypeGuard, get_type_evaluations
from .extensions import get_overloads as pyanalyze_get_overloads
from .find_unused import used
from .functions import translate_vararg_type
from .options import Options, PyObjectSequenceOption
Expand All @@ -63,15 +60,15 @@
)
from .signature import (
ANY_SIGNATURE,
ConcreteSignature,
ELLIPSIS_PARAM,
ConcreteSignature,
Impl,
make_bound_method,
MaybeSignature,
OverloadedSignature,
ParameterKind,
Signature,
SigParameter,
make_bound_method,
)
from .stacked_scopes import Composite, uniq_chain
from .typeshed import TypeshedFinder
Expand All @@ -80,18 +77,18 @@
AnyValue,
CanAssignContext,
Extension,
extract_typevars,
GenericBases,
GenericValue,
KnownValue,
KVPair,
make_coro_type,
NewTypeValue,
SubclassValue,
TypedDictValue,
TypedValue,
TypeVarValue,
Value,
extract_typevars,
make_coro_type,
)

_GET_OVERLOADS = []
Expand Down Expand Up @@ -306,8 +303,8 @@ def unwrap(cls, typ: type, options: Options) -> type:
_BUILTIN_KNOWN_SIGNATURES = []

try:
import pytest
import _pytest
import pytest
except ImportError:
# if pytest is not installed in this environment, don't use it
pass
Expand Down
8 changes: 4 additions & 4 deletions pyanalyze/attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .signature import MaybeSignature
from .stacked_scopes import Composite
from .value import (
UNINITIALIZED_VALUE,
AnnotatedValue,
AnySource,
AnyValue,
Expand All @@ -33,16 +34,15 @@
KnownValue,
KnownValueWithTypeVars,
MultiValuedValue,
SubclassValue,
SyntheticModuleValue,
TypeAliasValue,
annotate_value,
set_self,
SubclassValue,
TypedValue,
TypeVarValue,
UnboundMethodValue,
UNINITIALIZED_VALUE,
Value,
annotate_value,
set_self,
)

# these don't appear to be in the standard types module
Expand Down
4 changes: 2 additions & 2 deletions pyanalyze/boolability.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
from pyanalyze.safe import safe_getattr, safe_hasattr

from .value import (
KNOWN_MUTABLE_TYPES,
AnnotatedValue,
AnyValue,
DictIncompleteValue,
KNOWN_MUTABLE_TYPES,
KnownValue,
MultiValuedValue,
replace_known_sequence_value,
SequenceValue,
SubclassValue,
TypedDictValue,
TypedValue,
UnboundMethodValue,
Value,
replace_known_sequence_value,
)


Expand Down
Loading

0 comments on commit 9762262

Please sign in to comment.