Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix precommit #75

Merged
merged 27 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f215d39
create Session object wrapping fastapi_utils
geospatial-jeff Jan 21, 2021
352c057
add Session to core, try it out with /collections endpoint
geospatial-jeff Jan 21, 2021
2d40c9a
init session on app creation
geospatial-jeff Jan 21, 2021
9c17c5d
push Session lower
geospatial-jeff Jan 21, 2021
506879f
remove db middlewares and event hooks
geospatial-jeff Jan 21, 2021
e10dfb3
relock
geospatial-jeff Jan 24, 2021
580c2da
finish updating core
geospatial-jeff Jan 24, 2021
6300108
update pagination client
geospatial-jeff Jan 24, 2021
304663d
remove PostgresClient from core
geospatial-jeff Jan 24, 2021
ba5800c
remove PostgresClient from pagination, switch to mixin
geospatial-jeff Jan 24, 2021
1c18ab9
add lookup_id staticmethod
geospatial-jeff Jan 24, 2021
d9e0ea4
make private method
geospatial-jeff Jan 24, 2021
e1d8ab7
refactor transactions
geospatial-jeff Jan 24, 2021
d41b4c7
client tests working
geospatial-jeff Jan 25, 2021
dacf3d4
resource tests working
geospatial-jeff Jan 25, 2021
48e7208
lock pygeos to 0.8
geospatial-jeff Jan 25, 2021
3a90507
oops
geospatial-jeff Jan 25, 2021
a9692e0
do exception handling in one place
geospatial-jeff Jan 25, 2021
625c302
remove old code
geospatial-jeff Jan 25, 2021
e97686e
switch back to pygeos 0.9
geospatial-jeff Jan 25, 2021
ad364e6
update except
geospatial-jeff Jan 26, 2021
4a14c5e
add tox, update pre-commit config, lint
geospatial-jeff Jan 26, 2021
e750df8
make precommit happy
geospatial-jeff Jan 26, 2021
930df78
add precommit check
geospatial-jeff Jan 26, 2021
7810b1f
fix syntax
geospatial-jeff Jan 26, 2021
278961a
remove python-version
geospatial-jeff Jan 26, 2021
ccf4d97
switch pre-commit to 3.8
geospatial-jeff Jan 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ jobs:
with:
python-version: "3.8"

- name: Lint code
uses: pre-commit/action@v2.0.0

- name: Install pipenv
run: |
python -m pip install --upgrade pipenv wheel
Expand Down
21 changes: 10 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
repos:
-
repo: https://github.com/pre-commit/mirrors-isort
rev: v4.3.21
hooks:
- id: isort
language_version: python3.7
- repo: https://github.com/PyCQA/isort
rev: 5.4.2
hooks:
- id: isort
language_version: python3.8
-
repo: https://github.com/psf/black
rev: stable
hooks:
- id: black
args: ['--safe']
language_version: python3.7
language_version: python3.8
-
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.4.0
hooks:
- id: flake8
language_version: python3.7
language_version: python3.8
args: [
# E501 let black handle all line length decisions
# W503 black conflicts with "line break before operator" rule
# E203 black conflicts with "whitespace before ':'" rule
'--ignore=E501,W503,E203']
'--ignore=E501,W503,E203,C901']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nevermind I see that elsewhere in the config.

-
repo: https://github.com/chewse/pre-commit-mirrors-pydocstyle
# 2.1.1
rev: 22d3ccf6cf91ffce3b16caa946c155778f0cb20f
hooks:
- id: pydocstyle
language_version: python3.7
language_version: python3.8
args: [
# Check for docstring presence only
'--select=D1',
Expand All @@ -40,5 +39,5 @@ repos:
rev: v0.770
hooks:
- id: mypy
language_version: python3.7
language_version: python3.8
args: [--no-strict-optional, --ignore-missing-imports]
4 changes: 3 additions & 1 deletion alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def run_migrations_online():
configuration = config.get_section(config.config_ini_section)
configuration["sqlalchemy.url"] = get_connection_url()
connectable = engine_from_config(
configuration, prefix="sqlalchemy.", poolclass=pool.NullPool,
configuration,
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
Expand Down
2 changes: 1 addition & 1 deletion alembic/versions/131aab4d9e49_create_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

""" # noqa
import sqlalchemy as sa
from geoalchemy2.types import Geometry
from sqlalchemy.dialects.postgresql import JSONB

from alembic import op
from geoalchemy2.types import Geometry

# revision identifiers, used by Alembic.
revision = "131aab4d9e49"
Expand Down
1 change: 1 addition & 0 deletions stac_api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""stac_api"""
2 changes: 2 additions & 0 deletions stac_api/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
"""api module"""
from .routes import create_endpoint_from_model, create_endpoint_with_depends

__all__ = ("create_endpoint_from_model", "create_endpoint_with_depends")
21 changes: 14 additions & 7 deletions stac_api/api/extensions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"""stac_api.api.extensions"""
from .context import ContextExtension # noqa
from .context import ContextExtension
from .fields import FieldsExtension
from .query import QueryExtension
from .sort import SortExtension
from .tiles import TilesExtension
from .transaction import TransactionExtension

# from .extension import ApiExtension # noqa
from .fields import FieldsExtension # noqa
from .query import QueryExtension # noqa
from .sort import SortExtension # noqa
from .tiles import TilesExtension # noqa
from .transaction import TransactionExtension # noqa
__all__ = (
"ContextExtension",
"FieldsExtension",
"QueryExtension",
"SortExtension",
"TilesExtension",
"TransactionExtension",
)
11 changes: 7 additions & 4 deletions stac_api/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from typing import Callable, Type

from fastapi import Depends
from pydantic import BaseModel
from starlette.requests import Request

from pydantic import BaseModel
from stac_api.api.models import APIRequest


Expand All @@ -18,7 +18,8 @@ def create_endpoint_from_model(
"""

def _endpoint(
request: Request, request_data: request_model, # type:ignore
request: Request,
request_data: request_model, # type:ignore
):
"""endpoint"""
resp = func(request_data, request=request)
Expand All @@ -28,14 +29,16 @@ def _endpoint(


def create_endpoint_with_depends(
func: Callable, request_model: Type[APIRequest],
func: Callable,
request_model: Type[APIRequest],
) -> Callable:
"""
Create a fastapi endpoint where request model is a dataclass. This works best for validating query/patm params.
"""

def _endpoint(
request: Request, request_data: request_model = Depends(), # type:ignore
request: Request,
request_data: request_model = Depends(), # type:ignore
):
"""endpoint"""
resp = func(
Expand Down
4 changes: 2 additions & 2 deletions stac_api/clients/postgres/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
from urllib.parse import urlencode, urljoin

import attr
import geoalchemy2 as ga
import sqlalchemy as sa
from sqlakeyset import get_page
from sqlalchemy import func
from sqlalchemy.orm import Session as SqlSession
from stac_pydantic import ItemCollection
from stac_pydantic.api import ConformanceClasses, LandingPage
from stac_pydantic.api.extensions.paging import PaginationLink
from stac_pydantic.shared import Link, MimeTypes, Relations

import geoalchemy2 as ga
from sqlakeyset import get_page
from stac_api.api.extensions import ContextExtension, FieldsExtension
from stac_api.clients.base import BaseCoreClient
from stac_api.clients.postgres.session import Session
Expand Down
8 changes: 6 additions & 2 deletions stac_api/clients/postgres/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from typing import Iterator

import attr
import psycopg2
import sqlalchemy as sa
import sqlalchemy.exc
from fastapi_utils.session import FastAPISessionMaker as _FastAPISessionMaker
from sqlalchemy.orm import Session as SqlSession

import psycopg2
from fastapi_utils.session import FastAPISessionMaker as _FastAPISessionMaker
from stac_api import errors

logger = logging.getLogger(__name__)
Expand All @@ -35,16 +35,20 @@ def context_session(self) -> Iterator[SqlSession]:

@attr.s
class Session:
"""Database session management"""

reader_conn_string: str = attr.ib()
writer_conn_string: str = attr.ib()

@classmethod
def create_from_env(cls):
"""create from environment"""
return cls(
reader_conn_string=os.environ["READER_CONN_STRING"],
writer_conn_string=os.environ["WRITER_CONN_STRING"],
)

def __attrs_post_init__(self):
"""post init"""
self.reader: FastAPISessionMaker = FastAPISessionMaker(self.reader_conn_string)
self.writer: FastAPISessionMaker = FastAPISessionMaker(self.writer_conn_string)
1 change: 1 addition & 0 deletions stac_api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""stac_api.models"""
4 changes: 2 additions & 2 deletions stac_api/models/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from datetime import datetime
from typing import Optional

import geoalchemy2 as ga
import sqlalchemy as sa
from shapely.geometry import shape
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from stac_pydantic.shared import DATETIME_RFC339

import geoalchemy2 as ga
from stac_api import config
from stac_api.models import schemas
from stac_pydantic.shared import DATETIME_RFC339

BaseModel = declarative_base()

Expand Down
3 changes: 2 additions & 1 deletion stac_api/models/decompose.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
import geoalchemy2 as ga
from pydantic import BaseModel
from pydantic.utils import GetterDict
from stac_pydantic.shared import DATETIME_RFC339

from stac_api import config
from stac_api.errors import DatabaseError
from stac_api.models.links import CollectionLinks, ItemLinks, filter_links
from stac_pydantic.shared import DATETIME_RFC339


def resolve_links(links: list, base_url: str) -> List[Dict]:
Expand Down
10 changes: 5 additions & 5 deletions stac_api/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@
from typing import Any, Callable, Dict, List, Optional, Set, Union

import sqlalchemy as sa
from shapely.geometry import Polygon as ShapelyPolygon
from shapely.geometry import shape

from geojson_pydantic.geometries import Polygon
from pydantic import Field, ValidationError, root_validator
from pydantic.error_wrappers import ErrorWrapper
from stac_api import config
from stac_api.models.decompose import CollectionGetter, ItemGetter
from shapely.geometry import Polygon as ShapelyPolygon
from shapely.geometry import shape
from stac_pydantic import Collection as CollectionBase
from stac_pydantic import Item as ItemBase
from stac_pydantic.api import Search
Expand All @@ -24,6 +21,9 @@
from stac_pydantic.shared import Link
from stac_pydantic.utils import AutoValueEnum

from stac_api import config
from stac_api.models.decompose import CollectionGetter, ItemGetter

# Be careful: https://github.com/samuelcolvin/pydantic/issues/1423#issuecomment-642797287
NumType = Union[float, int]

Expand Down
17 changes: 17 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Linter configs
[flake8]
ignore = D203
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist
max-complexity = 12
max-line-length = 90

[mypy]
no_strict_optional = true
ignore_missing_imports = True

[tool:isort]
profile=black
known_arturo=arturo
known_first_party = stac_api
known_third_party = rasterio,stac-pydantic,sqlalchemy,geoalchemy2,fastapi
sections=FUTURE,STDLIB,THIRDPARTY,ARTURO,FIRSTPARTY,LOCALFOLDER