Skip to content

Commit

Permalink
Add isort rule and lint (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron authored Jun 15, 2024
1 parent e43398b commit 732188e
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 39 deletions.
23 changes: 15 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args:
- --py38-plus
- repo: https://github.com/psf/black
rev: 24.4.0
hooks:
- id: black
language_version: python3
exclude: versioneer.py
args:
- --target-version=py38
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
language_version: python3
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
exclude: tests/.*\.json
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.9
hooks:
- id: ruff
args: ["--fix"]
- id: ruff-format
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,22 @@ ignore_missing_imports = true
[[tool.mypy.overrides]]
module = "stac_geoparquet.*"
disallow_untyped_defs = true

[tool.ruff.lint]
select = [
# Pyflakes
"F",
# Pycodestyle
"E",
"W",
# isort
"I",
]
ignore = [
"E501", # Line too long
]

[tool.ruff.lint.extend-per-file-ignores]
"__init__.py" = [
"F401", # Allow unused imports in __init__.py files
]
2 changes: 1 addition & 1 deletion stac_geoparquet/_compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pystac
import packaging.version
import pystac

PYSTAC_1_7_0 = packaging.version.parse(pystac.__version__) >= packaging.version.Version(
"1.7.0"
Expand Down
2 changes: 1 addition & 1 deletion stac_geoparquet/arrow/_util.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import operator
from functools import reduce
from itertools import islice
from typing import (
Any,
Dict,
Expand All @@ -11,7 +12,6 @@
)

import pyarrow as pa
from itertools import islice


def update_batch_schema(
Expand Down
3 changes: 2 additions & 1 deletion stac_geoparquet/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import argparse
import logging
import sys
import os
import sys

from stac_geoparquet import pc_runner

Expand Down Expand Up @@ -53,6 +53,7 @@ def parse_args(args: list[str] | None = None) -> argparse.Namespace:
def setup_logging() -> None:
import logging
import warnings

import rich.logging

warnings.filterwarnings("ignore", message=".*initial implementation of Parquet.*")
Expand Down
3 changes: 2 additions & 1 deletion stac_geoparquet/pc_runner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from __future__ import annotations

import json
import urllib.parse
from typing import Any

import azure.data.tables
import requests
import urllib.parse

from stac_geoparquet.pgstac_reader import CollectionConfig

PARTITION_FREQUENCIES = {
Expand Down
16 changes: 8 additions & 8 deletions stac_geoparquet/pgstac_reader.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
from __future__ import annotations
import textwrap
import hashlib

import collections.abc
import dataclasses
import datetime
import hashlib
import itertools
import logging
import textwrap
from typing import Any
import collections.abc
import itertools

import dateutil.tz
import fsspec
import pandas as pd
import pystac
import dateutil.tz
import dataclasses
import pyarrow.fs
import pypgstac.db
import pypgstac.hydration
import pystac
import shapely.wkb
import tqdm.auto
from stac_geoparquet import to_geodataframe

from stac_geoparquet import to_geodataframe

logger = logging.getLogger(__name__)

Expand Down
11 changes: 5 additions & 6 deletions stac_geoparquet/stac_geoparquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
"""

from __future__ import annotations
import collections

from typing import Sequence, Any, Literal
import collections
import warnings
from typing import Any, Literal, Sequence
from urllib.parse import urlparse

import pystac
import geopandas
import numpy as np
import pandas as pd
import pyarrow as pa
import numpy as np
import pystac
import shapely.geometry

from urllib.parse import urlparse

from stac_geoparquet.utils import fix_empty_multipolygon

STAC_ITEM_TYPES = ["application/json", "application/geo+json"]
Expand Down
7 changes: 4 additions & 3 deletions stac_geoparquet/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
import functools
from typing import Any

import shapely.geometry
import pystac
import shapely.geometry
import shapely.geometry.base


@functools.singledispatch
Expand Down Expand Up @@ -36,7 +37,7 @@ def assert_equal_item(
)
assert result.bbox == expected.bbox
assert result.datetime == expected.datetime
assert type(result.stac_extensions) == type(expected.stac_extensions)
assert isinstance(result.stac_extensions, type(expected.stac_extensions))
assert sorted(result.stac_extensions) == sorted(expected.stac_extensions)
assert result.collection_id == expected.collection_id
assert result.extra_fields == expected.extra_fields
Expand Down Expand Up @@ -86,7 +87,7 @@ def assert_link_equal(


def fix_empty_multipolygon(
item_geometry: dict[str, Any]
item_geometry: dict[str, Any],
) -> shapely.geometry.base.BaseGeometry:
# Filter out missing geoms in MultiPolygons
# https://github.com/shapely/shapely/issues/1407
Expand Down
1 change: 0 additions & 1 deletion tests/json_equals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from ciso8601 import parse_rfc3339


JsonValue = Union[list, tuple, int, float, dict, str, bool, None]


Expand Down
5 changes: 2 additions & 3 deletions tests/test_pgstac_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import json
import pathlib

import pystac
import dateutil
import pandas as pd
import pystac
import pytest

import stac_geoparquet.pgstac_reader
from stac_geoparquet.utils import assert_equal
from stac_geoparquet._compat import PYSTAC_1_7_0

from stac_geoparquet.utils import assert_equal

HERE = pathlib.Path(__file__).parent

Expand Down
8 changes: 4 additions & 4 deletions tests/test_stac_geoparquet.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import json
import pathlib

import stac_geoparquet
import shapely.geometry
import geopandas
import pandas as pd
import pandas.testing
import pyarrow as pa
import pystac
import geopandas
import requests
import pytest
import requests
import shapely.geometry

import stac_geoparquet
from stac_geoparquet.stac_geoparquet import to_item_collection
from stac_geoparquet.utils import assert_equal, fix_empty_multipolygon

Expand Down
3 changes: 1 addition & 2 deletions tests/test_to_dict.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import pathlib

import pytest
import geopandas
import pytest

import stac_geoparquet


HERE = pathlib.Path(__file__).parent


Expand Down

0 comments on commit 732188e

Please sign in to comment.