Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

reorganize code into submodules #106

Merged
merged 33 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a78e3e
move api code to submodule
geospatial-jeff Mar 3, 2021
c7bb70f
add symlink
geospatial-jeff Mar 3, 2021
07d83f9
fix symlink
geospatial-jeff Mar 3, 2021
8d3904e
fastapi_stac -> stac_fastapi
geospatial-jeff Mar 3, 2021
a8c6db1
update symlink
geospatial-jeff Mar 3, 2021
944383b
add app routes, update imports
geospatial-jeff Mar 3, 2021
02f14ff
rename
geospatial-jeff Mar 3, 2021
7dc6836
add backend submodule
geospatial-jeff Mar 3, 2021
5713a5e
add symlink
geospatial-jeff Mar 3, 2021
a4e6133
update imports
geospatial-jeff Mar 3, 2021
39452be
add extensions submodule, move core extensions from api
geospatial-jeff Mar 3, 2021
2eec4ad
add extensions symlink
geospatial-jeff Mar 3, 2021
cbc839e
move bulk transactions to third party extensions
geospatial-jeff Mar 3, 2021
67cc8a8
move tiles extension to third_party
geospatial-jeff Mar 3, 2021
4e48d07
backend.client -> backend.core
geospatial-jeff Mar 3, 2021
66f80ac
define third party clients next to the extension
geospatial-jeff Mar 3, 2021
ed9ebad
remove third party clients from core
geospatial-jeff Mar 3, 2021
d46da52
correct package names
geospatial-jeff Mar 3, 2021
778f0fa
create postgres submodule, move the sqlalchemy code
geospatial-jeff Mar 9, 2021
a702e0e
move config
geospatial-jeff Mar 9, 2021
7bcc6e8
update extension imports
geospatial-jeff Mar 9, 2021
1ce6f3d
move errors
geospatial-jeff Mar 9, 2021
52304f8
move openapi
geospatial-jeff Mar 9, 2021
be1d38e
fix tests
geospatial-jeff Mar 16, 2021
9cafb60
add types submodule for shared types, finish moving db code, save pro…
geospatial-jeff Mar 16, 2021
a07e5a8
lint everything, remove mypy for now
geospatial-jeff Mar 16, 2021
57d15a4
update pytest.ini
geospatial-jeff Mar 16, 2021
8f41986
Updates to submodules PR (#109)
lossyrob Mar 24, 2021
4c86cee
lint
geospatial-jeff Mar 24, 2021
7af256e
rename postgres package to sqlalchemy
geospatial-jeff Mar 24, 2021
c2f4ae1
rename PostgresSettings to SqlalchemySettings
geospatial-jeff Mar 24, 2021
bb211c2
update readme
geospatial-jeff Mar 25, 2021
6fec90d
relock types pipfile
geospatial-jeff Mar 25, 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
1 change: 0 additions & 1 deletion fastapi_stac/api

This file was deleted.

1 change: 1 addition & 0 deletions stac_fastapi/api
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
from stac_pydantic import ItemCollection
from stac_pydantic.api import ConformanceClasses, LandingPage

from stac_api.api.extensions import FieldsExtension
from stac_api.api.extensions.extension import ApiExtension
from stac_api.api.models import (
from stac_api.clients.base import BaseCoreClient
from stac_api.config import ApiSettings, inject_settings
from stac_api.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from stac_api.models import schemas
from stac_fastapi.api.extensions import FieldsExtension
from stac_fastapi.api.extensions.extension import ApiExtension
from stac_fastapi.api.models import (
Copy link
Contributor

Choose a reason for hiding this comment

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

It's intentional to still import from both stac_api and stac_fastapi?

Copy link
Collaborator Author

@geospatial-jeff geospatial-jeff Mar 3, 2021

Choose a reason for hiding this comment

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

I'm switching out the imports to stac_fastapi as I make the submodules. By the time I'm done everything should be stac_fastapi.

CollectionUri,
EmptyRequest,
ItemCollectionUri,
ItemUri,
SearchGetRequest,
_create_request_model,
)
from stac_api.api.routes import create_endpoint_from_model, create_endpoint_with_depends
from stac_api.clients.base import BaseCoreClient
from stac_api.config import ApiSettings, inject_settings
from stac_api.errors import DEFAULT_STATUS_CODES, add_exception_handlers
from stac_api.models import schemas
from stac_fastapi.api.routes import (
create_endpoint_from_model,
create_endpoint_with_depends,
)


@attr.s
Expand Down
68 changes: 68 additions & 0 deletions stac_fastapi_api/fastapi_stac/api/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""route factories."""
from typing import Callable, Type

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

from stac_fastapi.api.models import APIRequest


# TODO: Only use one endpoint factory
def create_endpoint_from_model(
func: Callable, request_model: Type[BaseModel]
) -> Callable:
"""Create a FastAPI endpoint from pydantic model.

Wrap a callable in a function which uses the desired request model. It is expected
that the signature of the callable matches that of the request model. This is best for validating
request bodies (ex. POST requests).

Args:
func: the wrapped function.
request_model: a pydantic model.

Returns:
callable: fastapi route which may be added to a router/application
"""

def _endpoint(
request: Request,
request_data: request_model, # type:ignore
):
"""Endpoint."""
resp = func(request_data, request=request)
return resp

return _endpoint


def create_endpoint_with_depends(
func: Callable,
request_model: Type[APIRequest],
) -> Callable:
"""Create a FastAPI endpoint from an `APIRequest` (dataclass).

Wrap a callable in a function which uses the desired `APIRequest` to define request parameters. It is expected
that the return of `APIRequest.kwargs` matches that of the callable. This works best for validating query/path
parameters (ex. GET request) and allows for dependency injection.

Args:
func: the wrapped function
request_model: subclass of `APIRequest`

Returns:
callable: fastapi route which may be added to a router/application
"""

def _endpoint(
request: Request,
request_data: request_model = Depends(), # type:ignore
):
"""Endpoint."""
resp = func(
request=request, **request_data.kwargs() # type:ignore
)
return resp

return _endpoint
10 changes: 4 additions & 6 deletions fastapi_stac_api/setup.py → stac_fastapi_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

from setuptools import find_namespace_packages, setup

name = "fastapi_stac"
name = "stac_fastapi_api"
description = (
"API subpackage of fastapi-stac, a STAC compliant API layer build with FastAPI."
)

__version__ = load_source(
"fastapi_stac.api.version",
os.path.join(
os.path.dirname(__file__), "fastapi_stac/api/version.py"
), # type:ignore
).__version__
"stac_fastapi.api.version",
os.path.join(os.path.dirname(__file__), "stac_fastapi/api/version.py"),
).__version__ # type:ignore

install_requires = [
"attrs",
Expand Down