Skip to content

Commit

Permalink
Merge pull request #1455 from tqa236/setup-ruff
Browse files Browse the repository at this point in the history
Setup ruff
  • Loading branch information
snowman2 authored Oct 30, 2024
2 parents 2fbca30 + 6a38287 commit 5e39d2a
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 56 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ repos:
rev: v2.2.6
hooks:
- id: codespell
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
hooks:
- id: ruff
85 changes: 37 additions & 48 deletions pyproj/_crs.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ class Axis:
unit_name: str
unit_auth_code: str
unit_code: str
def __str__(self) -> str: ...
def __repr__(self) -> str: ...

class AreaOfUse:
west: float
south: float
east: float
north: float
name: str
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
@property
def bounds(self) -> tuple[float, float, float, float]: ...

Expand All @@ -40,51 +36,49 @@ class Base:
) -> str: ...
def to_json(self, pretty: bool = False, indentation: int = 2) -> str: ...
def to_json_dict(self) -> dict: ...
def __str__(self) -> str: ...
def __repr__(self) -> str: ...
def __eq__(self, other: Any) -> bool: ...
def __eq__(self, other: object) -> bool: ...
def is_exact_same(self, other: Any) -> bool: ...

class _CRSParts(Base):
@classmethod
def from_user_input(cls, user_input: Any) -> "_CRSParts": ...
def from_user_input(cls, user_input: Any) -> _CRSParts: ...

class Ellipsoid(_CRSParts):
semi_major_metre: float
semi_minor_metre: float
is_semi_minor_computed: float
inverse_flattening: float
@staticmethod
def from_authority(auth_name: str, code: int | str) -> "Ellipsoid": ...
def from_authority(auth_name: str, code: int | str) -> Ellipsoid: ...
@staticmethod
def from_epsg(code: int | str) -> "Ellipsoid": ...
def from_epsg(code: int | str) -> Ellipsoid: ...
@staticmethod
def from_string(ellipsoid_string: str) -> "Ellipsoid": ...
def from_string(ellipsoid_string: str) -> Ellipsoid: ...
@staticmethod
def from_json_dict(ellipsoid_dict: dict) -> "Ellipsoid": ...
def from_json_dict(ellipsoid_dict: dict) -> Ellipsoid: ...
@staticmethod
def from_json(ellipsoid_json_str: str) -> "Ellipsoid": ...
def from_json(ellipsoid_json_str: str) -> Ellipsoid: ...
@staticmethod
def from_name(ellipsoid_name: str, auth_name: str | None = None) -> "Ellipsoid": ...
def from_name(ellipsoid_name: str, auth_name: str | None = None) -> Ellipsoid: ...

class PrimeMeridian(_CRSParts):
longitude: float
unit_conversion_factor: str
unit_name: str
@staticmethod
def from_authority(auth_name: str, code: int | str) -> "PrimeMeridian": ...
def from_authority(auth_name: str, code: int | str) -> PrimeMeridian: ...
@staticmethod
def from_epsg(code: int | str) -> "PrimeMeridian": ...
def from_epsg(code: int | str) -> PrimeMeridian: ...
@staticmethod
def from_string(prime_meridian_string: str) -> "PrimeMeridian": ...
def from_string(prime_meridian_string: str) -> PrimeMeridian: ...
@staticmethod
def from_json_dict(prime_meridian_dict: dict) -> "PrimeMeridian": ...
def from_json_dict(prime_meridian_dict: dict) -> PrimeMeridian: ...
@staticmethod
def from_json(prime_meridian_json_str: str) -> "PrimeMeridian": ...
def from_json(prime_meridian_json_str: str) -> PrimeMeridian: ...
@staticmethod
def from_name(
prime_meridian_name: str, auth_name: str | None = None
) -> "PrimeMeridian": ...
) -> PrimeMeridian: ...

class Datum(_CRSParts):
type_name: str
Expand All @@ -93,28 +87,28 @@ class Datum(_CRSParts):
@property
def prime_meridian(self) -> PrimeMeridian | None: ...
@staticmethod
def from_authority(auth_name: str, code: int | str) -> "Datum": ...
def from_authority(auth_name: str, code: int | str) -> Datum: ...
@staticmethod
def from_epsg(code: int | str) -> "Datum": ...
def from_epsg(code: int | str) -> Datum: ...
@staticmethod
def from_string(datum_string: str) -> "Datum": ...
def from_string(datum_string: str) -> Datum: ...
@staticmethod
def from_json_dict(datum_dict: dict) -> "Datum": ...
def from_json_dict(datum_dict: dict) -> Datum: ...
@staticmethod
def from_json(datum_json_str: str) -> "Datum": ...
def from_json(datum_json_str: str) -> Datum: ...
@staticmethod
def from_name(datum_name: str, auth_name: str | None = None) -> "Datum": ...
def from_name(datum_name: str, auth_name: str | None = None) -> Datum: ...

class CoordinateSystem(_CRSParts):
def __init__(self) -> None: ...
@property
def axis_list(self) -> Iterable[Axis]: ...
@staticmethod
def from_string(coordinate_system_string: str) -> "CoordinateSystem": ...
def from_string(coordinate_system_string: str) -> CoordinateSystem: ...
@staticmethod
def from_json_dict(coordinate_system_dict: dict) -> "CoordinateSystem": ...
def from_json_dict(coordinate_system_dict: dict) -> CoordinateSystem: ...
@staticmethod
def from_json(coordinate_system_json_str: str) -> "CoordinateSystem": ...
def from_json(coordinate_system_json_str: str) -> CoordinateSystem: ...
def to_cf(self, rotated_pole: bool = False) -> list[dict]: ...

class Param:
Expand All @@ -127,8 +121,6 @@ class Param:
unit_auth_name: str
unit_code: str
unit_category: str
def __str__(self) -> str: ...
def __repr__(self) -> str: ...

class Grid:
short_name: str
Expand All @@ -138,8 +130,6 @@ class Grid:
direct_download: str
open_license: str
available: str
def __str__(self) -> str: ...
def __repr__(self) -> str: ...

class CoordinateOperation(_CRSParts):
method_name: str
Expand All @@ -158,19 +148,18 @@ class CoordinateOperation(_CRSParts):
@property
def towgs84(self) -> Iterable[float]: ...
@property
def operations(self) -> tuple["CoordinateOperation"]: ...
def operations(self) -> tuple[CoordinateOperation]: ...
def __init__(self) -> None: ...
def __repr__(self) -> str: ...
@staticmethod
def from_authority(auth_name: str, code: int | str) -> "CoordinateOperation": ...
def from_authority(auth_name: str, code: int | str) -> CoordinateOperation: ...
@staticmethod
def from_epsg(code: int | str) -> "CoordinateOperation": ...
def from_epsg(code: int | str) -> CoordinateOperation: ...
@staticmethod
def from_string(ellipsoid_string: str) -> "CoordinateOperation": ...
def from_string(ellipsoid_string: str) -> CoordinateOperation: ...
@staticmethod
def from_json_dict(ellipsoid_dict: dict) -> "CoordinateOperation": ...
def from_json_dict(ellipsoid_dict: dict) -> CoordinateOperation: ...
@staticmethod
def from_json(ellipsoid_json_str: str) -> "CoordinateOperation": ...
def from_json(ellipsoid_json_str: str) -> CoordinateOperation: ...
def to_proj4(self, version: ProjVersion | int = ProjVersion.PROJ_5) -> str: ...
@staticmethod
def from_name(
Expand All @@ -179,7 +168,7 @@ class CoordinateOperation(_CRSParts):
coordinate_operation_type: (
CoordinateOperationType | str
) = CoordinateOperationType.CONVERSION,
) -> "CoordinateOperation": ...
) -> CoordinateOperation: ...

class AuthorityMatchInfo(NamedTuple):
auth_name: str
Expand All @@ -201,13 +190,13 @@ class _CRS(Base):
@property
def datum(self) -> Datum | None: ...
@property
def sub_crs_list(self) -> Iterable["_CRS"]: ...
def sub_crs_list(self) -> Iterable[_CRS]: ...
@property
def source_crs(self) -> Optional["_CRS"]: ...
def source_crs(self) -> Optional[_CRS]: ...
@property
def target_crs(self) -> Optional["_CRS"]: ...
def target_crs(self) -> Optional[_CRS]: ...
@property
def geodetic_crs(self) -> Optional["_CRS"]: ...
def geodetic_crs(self) -> Optional[_CRS]: ...
@property
def coordinate_system(self) -> CoordinateSystem | None: ...
@property
Expand All @@ -218,8 +207,8 @@ class _CRS(Base):
def list_authority(
self, auth_name: str | None = None, min_confidence: int = 70
) -> list[AuthorityMatchInfo]: ...
def to_3d(self, name: str | None = None) -> "_CRS": ...
def to_2d(self, name: str | None = None) -> "_CRS": ...
def to_3d(self, name: str | None = None) -> _CRS: ...
def to_2d(self, name: str | None = None) -> _CRS: ...
@property
def is_geographic(self) -> bool: ...
@property
Expand All @@ -237,7 +226,7 @@ class _CRS(Base):
def equals(self, other: Any, ignore_axis_order: bool) -> bool: ...
@property
def is_deprecated(self) -> bool: ...
def get_non_deprecated(self) -> list["_CRS"]: ...
def get_non_deprecated(self) -> list[_CRS]: ...

def is_proj(proj_string: str) -> bool: ...
def is_wkt(proj_string: str) -> bool: ...
Expand Down
3 changes: 1 addition & 2 deletions pyproj/_geod.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ class Geod:
def __init__(
self, a: float, f: float, sphere: bool, b: float, es: float
) -> None: ...
def __reduce__(self) -> tuple[type["Geod"], str]: ...
def __repr__(self) -> str: ...
def __reduce__(self) -> tuple[type[Geod], str]: ...
def _fwd(
self,
lons: Any,
Expand Down
4 changes: 2 additions & 2 deletions pyproj/_transformer.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ class _Transformer(Base):
allow_ballpark: bool | None = None,
force_over: bool = False,
only_best: bool | None = None,
) -> "_Transformer": ...
) -> _Transformer: ...
@staticmethod
def from_pipeline(proj_pipeline: bytes) -> "_Transformer": ...
def from_pipeline(proj_pipeline: bytes) -> _Transformer: ...
def _transform(
self,
inx: Any,
Expand Down
2 changes: 1 addition & 1 deletion pyproj/aoi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def bounds(self) -> tuple[float, float, float, float]:
return self.west, self.south, self.east, self.north

def __str__(self) -> str:
return f"- name: {self.name}\n" f"- bounds: {self.bounds}"
return f"- name: {self.name}\n- bounds: {self.bounds}"


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion pyproj/crs/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ def get_non_deprecated(self) -> list["CRS"]:
"""
return self._crs.get_non_deprecated()

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return self.equals(other)

def __getstate__(self) -> dict[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion pyproj/geod.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ def __repr__(self) -> str:
# no ellipse name found, call super class
return super().__repr__()

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
"""
equality operator == for Geod objects
Expand Down
2 changes: 1 addition & 1 deletion pyproj/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ def __repr__(self) -> str:
f"Area of Use:\n{self.area_of_use or '- undefined'}"
)

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, Transformer):
return False
return self._transformer.__eq__(other._transformer)
Expand Down
94 changes: 94 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,97 @@ version = {attr = "pyproj.__version__"}

[tool.black]
target_version = ["py310"]

[tool.ruff]
line-length = 88
target-version = "py310"
fix = true

[tool.ruff.lint]
unfixable = []

select = [
# pyflakes
"F",
# pycodestyle
"E", "W",
# flake8-2020
"YTT",
# flake8-bugbear
"B",
# flake8-quotes
"Q",
# flake8-debugger
"T10",
# flake8-gettext
"INT",
# pylint
# "PL",
# flake8-pytest-style
# "PT",
# misc lints
"PIE",
# flake8-pyi
"PYI",
# tidy imports
"TID",
# implicit string concatenation
"ISC",
# type-checking imports
"TCH",
# comprehensions
"C4",
# pygrep-hooks
"PGH",
# Ruff-specific rules
"RUF",
# flake8-bandit: exec-builtin
"S102",
# numpy-legacy-random
"NPY002",
# Perflint
"PERF",
# flynt
"FLY",
# flake8-logging-format
"G",
# flake8-future-annotations
"FA",
# flake8-slots
"SLOT",
# flake8-raise
"RSE"
]

ignore = [
### Intentionally disabled
# Line too long
"E501",
# Unnecessary `dict` call (rewrite as a literal)
"C408",
# Consider iterable unpacking instead of concatenation
"RUF005",
# No explicit `stacklevel` keyword argument found
"B028",
# Unused `noqa` directive # Only work if ruff is the solve linter/formatter
"RUF100",
# `zip()` without an explicit `strict=` parameter
"B905",
# Only simple default values allowed for typed arguments
"PYI011",

### TODO: Enable gradually
# Rename unused
"B007",
# Use specific rule codes when ignoring type issues
"PGH003",
# unconventional-import-alias
"ICN001",
# Move standard library import into a type-checking block
"TCH003",
# Consider f-string instead of string join
"FLY002",
# Use a list comprehension to create a transformed list
"PERF401"

]

0 comments on commit 5e39d2a

Please sign in to comment.