Skip to content

Commit 698be30

Browse files
refactor (#15)
* create stac-sprint dev branch * improve local development (#12) * use postgis official image, update migration command * remove comment * update dockerfile * improve makefile * update readme * add pre-commit, make pre-commit happy * update pipfile * add settings injection (#13) * add settings injection * update cicd * decouple transactions and core endpoints (#14) * define base clients, add transaction client (#16) * define base clients, add transaction client * use absolute imports * cleanup * add transactions router factory (#17) * add transactions router factory * add create_app method * add collection router factory (#19) * improve postgres clients * rename api models * add collection router factory * add item collection route * add item router factory (#20) * standardize input (#21) * whoops * remove apiresponse * add empty request * update endpoint * fix some things * configure api extensions (#22) * create request body models * add stac api extensions to api settings * helper method to check if api extension is enabled * parametrize transaction extension * parametrize query extension * parametrize context extension * parametrize field extension * set model base * simplify app creation (#23) * add tiles add on, consolidate core endpoints (#24) * template simple tiles router * update dockerfile * update pipfile * add more tiles links * finish tiles client * create stac router * request kwargs (#25) * pass through request * rearrange * remove dependency * remove references to dependency * fix everything * unify core spec (#26) * unify core spec * update tests * cleanup * update docstrings * add get search to router factory (#27) * update titiler version, update openapi * fix item uri * updates (#28) * update dependencies * updates * update dockerfile * add tiles link * add wmts link, add link titles * add api module (#29) * update tests, fix bugs (#30) * don't mutate orm objects * oops * update tests * remove echo * add api test cases * add api test cases * fix test * update conformance (#31) * add conformance routes to factory * remove comment * update test * move liveliness probe (#32) * enable sql echo * optimize sql (#33) * faster count * remove a select * optimize fetching collection children * remove id from default sort * use a join * fix paging * raise notfounderror * update test * dont raise * update titiler (#34) * update branch rules
1 parent cffebba commit 698be30

50 files changed

Lines changed: 2594 additions & 1708 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.pre-commit-config.yaml‎

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,44 @@
11
repos:
2-
- repo: https://github.com/python/black
3-
rev: stable
4-
hooks:
5-
- id: black
6-
language_version: python3.8
2+
-
3+
repo: https://github.com/pre-commit/mirrors-isort
4+
rev: v4.3.21
5+
hooks:
6+
- id: isort
7+
language_version: python3.7
8+
-
9+
repo: https://github.com/psf/black
10+
rev: stable
11+
hooks:
12+
- id: black
13+
args: ['--safe']
14+
language_version: python3.7
15+
-
16+
repo: https://github.com/pre-commit/pre-commit-hooks
17+
rev: v2.4.0
18+
hooks:
19+
- id: flake8
20+
language_version: python3.7
21+
args: [
22+
# E501 let black handle all line length decisions
23+
# W503 black conflicts with "line break before operator" rule
24+
# E203 black conflicts with "whitespace before ':'" rule
25+
'--ignore=E501,W503,E203']
26+
-
27+
repo: https://github.com/chewse/pre-commit-mirrors-pydocstyle
28+
# 2.1.1
29+
rev: 22d3ccf6cf91ffce3b16caa946c155778f0cb20f
30+
hooks:
31+
- id: pydocstyle
32+
language_version: python3.7
33+
args: [
34+
# Check for docstring presence only
35+
'--select=D1',
36+
# Don't require docstrings for tests
37+
'--match=(?!test).*\.py']
38+
-
39+
repo: https://github.com/pre-commit/mirrors-mypy
40+
rev: v0.770
41+
hooks:
42+
- id: mypy
43+
language_version: python3.7
44+
args: [--no-strict-optional, --ignore-missing-imports]

‎Dockerfile‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ FROM python:3.8-slim
22

33
# Any python libraries that require system libraries to be installed will likely
44
# need the following packages in order to build
5-
RUN apt-get update && apt-get install -y \
6-
build-essential \
7-
libffi-dev \
8-
libssl-dev \
9-
git
5+
RUN apt-get update && apt-get install -y build-essential git
106

117
RUN pip install pipenv
128
ENV PIPENV_NOSPIN=true
139
ENV PIPENV_HIDE_EMOJIS=true
10+
ENV CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
1411

1512
ARG install_dev_dependencies=true
1613

@@ -24,8 +21,5 @@ COPY . ./
2421
ENV APP_HOST=0.0.0.0
2522
ENV APP_PORT=80
2623

27-
ENV RELOAD=''
28-
29-
3024
ENTRYPOINT ["pipenv", "run"]
31-
CMD uvicorn stac_api.app:app --host=${APP_HOST} --port=${APP_PORT} ${RELOAD:+--reload}
25+
CMD uvicorn stac_api.app:app --host=${APP_HOST} --port=${APP_PORT} --reload

‎Makefile‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ run_docker = docker run -it --rm \
1414
--env POSTGRES_HOST_WRITER=host.docker.internal \
1515
--env POSTGRES_PORT=5432 \
1616
--env ENVIRONMENT=development \
17-
arturo-stac-api_app
17+
arturo-ai/stac-api:latest
18+
19+
.PHONY: image
20+
image:
21+
docker build -t arturo-ai/stac-api:latest .
22+
23+
.PHONY: docker-run
24+
docker-run: image
25+
$(run_docker)
1826

1927
.PHONY: docker-shell
2028
docker-shell:

‎Pipfile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ sqlalchemy = "*"
1313
geoalchemy2 = "<0.8.0"
1414
sqlakeyset = "*"
1515
stac-pydantic = ">=1.1.3"
16+
pydantic = {extras=["dotenv"], version="*"}
17+
cogeo-mosaic = "==3.0a10"
18+
titiler = "==0.1a0"
1619

1720
[dev-packages]
1821
pytest = "*"
1922
pytest-cov = "*"
2023
pytest-asyncio = "*"
2124
requests = "*"
25+
pre-commit = "*"
2226

2327
[requires]
2428
python_version = "3.8"

‎Pipfile.lock‎

Lines changed: 453 additions & 85 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ FastAPI/postgres implementation of the [STAC API specification](https://github.c
1818
```
1919

2020
## Local Development
21-
Use docker-compose to deploy the application, migrate the database, and ingest an example collection:
22-
```
21+
Use docker-compose to deploy the application, migrate the database, and ingest some example data:
22+
```bash
2323
docker-compose build
2424
docker-compose up
2525
```
2626

27-
Run tests (the `docker-compose` stack must be running):
27+
For local development it is often more convenient to run the application outside of docker-compose:
28+
```bash
29+
make docker-run
2830
```
31+
32+
33+
### Testing
34+
The database container provided by the docker-compose stack must be running. Run all tests:
35+
```bash
2936
make test
37+
```
38+
39+
Run individual tests by running pytest within the docker container:
40+
```bash
41+
make docker-shell
42+
$ pytest -v
3043
```

‎alembic/env.py‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
"""Migration environment."""
12
import os
23
from logging.config import fileConfig
34

4-
from sqlalchemy import engine_from_config
5-
from sqlalchemy import pool
5+
from sqlalchemy import engine_from_config, pool
66

77
from alembic import context
88

9-
109
# this is the Alembic Config object, which provides
1110
# access to the values within the .ini file in use.
1211
config = context.config
@@ -26,15 +25,16 @@
2625
# my_important_option = config.get_main_option("my_important_option")
2726
# ... etc.
2827

28+
2929
def get_connection_url() -> str:
3030
"""
3131
Get connection URL from environment variables (see `.env.example`)
3232
"""
33-
postgres_user = os.environ['POSTGRES_USER']
34-
postgres_pass = os.environ['POSTGRES_PASS']
35-
postgres_host = os.environ['POSTGRES_HOST']
36-
postgres_port = os.environ['POSTGRES_PORT']
37-
postgres_dbname = os.environ['POSTGRES_DBNAME']
33+
postgres_user = os.environ["POSTGRES_USER"]
34+
postgres_pass = os.environ["POSTGRES_PASS"]
35+
postgres_host = os.environ["POSTGRES_HOST"]
36+
postgres_port = os.environ["POSTGRES_PORT"]
37+
postgres_dbname = os.environ["POSTGRES_DBNAME"]
3838
return f"postgresql://{postgres_user}:{postgres_pass}@{postgres_host}:{postgres_port}/{postgres_dbname}"
3939

4040

@@ -70,17 +70,13 @@ def run_migrations_online():
7070
7171
"""
7272
configuration = config.get_section(config.config_ini_section)
73-
configuration['sqlalchemy.url'] = get_connection_url()
73+
configuration["sqlalchemy.url"] = get_connection_url()
7474
connectable = engine_from_config(
75-
configuration,
76-
prefix="sqlalchemy.",
77-
poolclass=pool.NullPool,
75+
configuration, prefix="sqlalchemy.", poolclass=pool.NullPool,
7876
)
7977

8078
with connectable.connect() as connection:
81-
context.configure(
82-
connection=connection, target_metadata=target_metadata
83-
)
79+
context.configure(connection=connection, target_metadata=target_metadata)
8480

8581
with context.begin_transaction():
8682
context.run_migrations()

‎alembic/versions/131aab4d9e49_create_tables.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
Revises:
55
Create Date: 2020-02-09 13:03:09.336631
66
7-
"""
8-
from alembic import op
7+
""" # noqa
98
import sqlalchemy as sa
10-
119
from sqlalchemy.dialects.postgresql import JSONB
12-
from geoalchemy2.types import Geometry
1310

11+
from alembic import op
12+
from geoalchemy2.types import Geometry
1413

1514
# revision identifiers, used by Alembic.
1615
revision = "131aab4d9e49"
@@ -20,6 +19,7 @@
2019

2120

2221
def upgrade():
22+
"""upgrade to this revision"""
2323
op.execute("CREATE SCHEMA data")
2424
op.execute("CREATE EXTENSION IF NOT EXISTS postgis")
2525

@@ -67,6 +67,7 @@ def upgrade():
6767

6868

6969
def downgrade():
70+
"""downgrade to previous revision"""
7071
op.execute("DROP TABLE data.items")
7172
op.execute("DROP TABLE data.collections")
7273
op.execute("DROP TABLE data.paging_tokens")

‎docker-compose.yml‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,15 @@ services:
2626

2727
database:
2828
container_name: stac-db
29-
image: kartoza/postgis:latest
29+
image: postgis/postgis:12-3.0
3030
environment:
3131
- POSTGRES_USER=username
32-
- POSTGRES_PASS=password
33-
- POSTGRES_DBNAME=postgis
34-
- POSTGRES_HOST=localhost
35-
- POSTGRES_PORT=5432
36-
- ALLOW_IP_RANGE=0.0.0.0/0
32+
- POSTGRES_PASSWORD=password
33+
- POSTGRES_DB=postgis
3734
ports:
3835
- "5432:5432"
3936

4037
migration:
41-
# image: stac-api:latest
4238
build:
4339
context: .
4440
dockerfile: Dockerfile
@@ -50,8 +46,6 @@ services:
5046
- POSTGRES_HOST=host.docker.internal
5147
- POSTGRES_PORT=5432
5248
command: >
53-
bash -c "git clone https://github.com/vishnubob/wait-for-it.git &&
54-
./wait-for-it/wait-for-it.sh localhost:5432 -- alembic upgrade head &&
55-
python scripts/ingest_joplin.py"
49+
bash -c "sleep 10 && alembic upgrade head && python scripts/ingest_joplin.py"
5650
depends_on:
5751
- database

‎scripts/ingest_joplin.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
"""Ingest sample data during docker-compose"""
2+
13
from urllib.parse import urljoin
24

35
import requests
46

5-
67
bucket = "arturo-stac-api-test-data"
78
app_host = "http://host.docker.internal:8081"
89

910

1011
def ingest_joplin_data():
12+
"""ingest data"""
1113
r = requests.get(f"https://{bucket}.s3.amazonaws.com/joplin/collection.json")
1214
collection = r.json()
1315

0 commit comments

Comments
 (0)