Skip to content

Commit

Permalink
refactor to ease usage and packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Aug 26, 2024
1 parent 49b7f2a commit 01cecd1
Show file tree
Hide file tree
Showing 30 changed files with 977 additions and 288 deletions.
33 changes: 16 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,33 @@ jobs:
test:
runs-on: ubuntu-latest

env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: mydatabase
DB_USER: myuser
DB_PASSWORD: mypassword
DB_TABLE_NAME: space2stats

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11

- name: Install dependencies
working-directory: ./space2stats_api/src
run: |
python -m pip install --upgrade pip
pip install -r space2stats_api/src/requirements.txt
pip install pre-commit pytest
- name: Set PYTHONPATH
run: echo "PYTHONPATH=$(pwd)/space2stats_api" >> $GITHUB_ENV
python -m pip install .["test"]
- name: Run pre-commit
run: pre-commit run --all-files
run: |
python -m pip install pre-commit
pre-commit run --all-files
- name: Run tests
run: pytest space2stats_api/tests
working-directory: ./space2stats_api/src
run: python -m pytest -s -vv
env:
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: mydatabase
DB_USER: myuser
DB_PASSWORD: mypassword
DB_TABLE_NAME: space2stats
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ db.env
space2stats_api/space2stats_env
*.env
cdk.out
lambda_layer
lambda_layer

.benchmarks/
11 changes: 6 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ version: '3'

services:
database:
image: ghcr.io/stac-utils/pgstac:v0.8.5
# at time of writing this, ARM64 is not supported so we make sure to use
# a supported platform: https://github.com/postgis/docker-postgis/issues/216
# Could possibly switch to https://github.com/vincentsarago/containers
platform: linux/amd64
image: postgis/postgis:15-3.4
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgis
- PGUSER=username
- PGPASSWORD=password
- PGDATABASE=postgis
ports:
- "${MY_DOCKER_IP:-127.0.0.1}:5439:5432"
command: postgres -N 500
volumes:
- ./.pgdata:/var/lib/postgresql/data
- ./.pgdata:/var/lib/postgresql/data
2 changes: 1 addition & 1 deletion space2stats_api/cdk/aws_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
self, "Space2StatsFunction",
entry="../src",
runtime=_lambda.Runtime.PYTHON_3_11,
index="app/main.py",
index="space2stats/handler.py",
timeout=Duration.seconds(120),
handler="handler",
environment=app_settings.model_dump(),
Expand Down
6 changes: 0 additions & 6 deletions space2stats_api/local_db.env

This file was deleted.

2 changes: 0 additions & 2 deletions space2stats_api/pytest.ini

This file was deleted.

541 changes: 541 additions & 0 deletions space2stats_api/src/LICENSE

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions space2stats_api/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
## space2stats
Empty file.
23 changes: 0 additions & 23 deletions space2stats_api/src/app/main.py

This file was deleted.

Empty file.
59 changes: 0 additions & 59 deletions space2stats_api/src/app/routers/api.py

This file was deleted.

16 changes: 0 additions & 16 deletions space2stats_api/src/app/settings.py

This file was deleted.

Empty file.
60 changes: 0 additions & 60 deletions space2stats_api/src/app/utils/db_utils.py

This file was deleted.

51 changes: 51 additions & 0 deletions space2stats_api/src/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[project]
name = "space2stats"
description = "Space 2 Stats"
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
authors = [
{name = "Zac Deziel", email = "[email protected]"},
]
dynamic = ["version"]
dependencies = [
"fastapi>=0.112.0",
"pandas",
"shapely",
"h3",
"psycopg[binary]",
"psycopg[pool]",
"httpx",
"geojson-pydantic",
"shapely",
"pydantic-settings>=2.0.0",
"typing_extensions",
]

[project.optional-dependencies]
test = [
"pytest",
"pytest-cov",
"pytest-postgresql",
"httpx",
]
lambda = [
"mangum",
]
server = [
"uvicorn",
]

[tool.hatch.version]
path = "space2stats/__init__.py"

[tool.hatch.build.targets.sdist]
exclude = [
"/tests",
".pytest_cache",
".local_db.env",
]

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
13 changes: 0 additions & 13 deletions space2stats_api/src/requirements.txt

This file was deleted.

5 changes: 5 additions & 0 deletions space2stats_api/src/space2stats/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""space2stats."""

from .main import fields, summaries # noqa

__version__ = "0.1.0"
23 changes: 23 additions & 0 deletions space2stats_api/src/space2stats/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import os

from .app import app

try:
import uvicorn # noqa

except ImportError: # pragma: nocover
uvicorn = None # type: ignore


if __name__ == "__main__":

assert uvicorn is not None, "uvicorn must be installed: `python -m pip install 'space2stats[server]'`"

uvicorn.run(
app=app,
host=os.getenv("UVICORN_HOST", "127.0.0.1"),
port=os.getenv("UVICORN_PORT", "8000"),
root_path=os.getenv("UVICORN_ROOT_PATH", ""),
log_level="info",
)
Loading

0 comments on commit 01cecd1

Please sign in to comment.