Skip to content

Commit

Permalink
Merge pull request #1 from GeodetischeInfrastructuur/restructure-repo
Browse files Browse the repository at this point in the history
restructure repo into Python package
  • Loading branch information
WouterVisscher authored Aug 1, 2023
2 parents c5a0d99 + 2199d80 commit 5f73023
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 8 deletions.
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": [
"coordinates_transformation_api.main:start",
"--reload"
],
"jinja": true,
"justMyCode": true
}
]
}
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM python:3.11.4-slim-bullseye
LABEL maintainer="NSGI <[email protected]>"

COPY . /src

RUN apt-get update && \
apt-get install -y \
moreutils && \
pip install --upgrade setuptools && \
pip install /src

# TODO: investigate how to properly setup Dockerfile for production use

ENTRYPOINT [ "ct-api" ]
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,16 @@ Design rues. Examples of these are:
parameter.
- with additional scenarios for other combinations.

## Install

```bash
pip3 install .
```

## Run

```bash
uvicorn main:app --reload
ct-api
```

## Exanple operaties
Expand Down Expand Up @@ -129,3 +135,17 @@ that one forwarded to <https://api.nsgi.nl/coordinatestransformation/v2>
### new URL

<https://api.nsgi.nl/coordinatestransformation/v2>

## Docker

### Build container

```bash
docker build -t nsgi/coordinatestransformation-api .
```

### Run container

```bash
docker run --rm -d -p 8000:8000 --name ct-api nsgi/coordinatestransformation-api
```
Empty file.
File renamed without changes.
20 changes: 13 additions & 7 deletions main.py → coordinates_transformation_api/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from fastapi import FastAPI, Response
from fastapi import FastAPI
from pydantic import BaseModel
from starlette.responses import RedirectResponse, JSONResponse
from typing import List

import yaml
import json
import uvicorn

from importlib import resources as impresources
from . import assets

default_headers = {"API-Version": "2.0.0"}

default_headers = {"API-Version": "2.0.1"}

app = FastAPI(docs_url="/api")

Expand Down Expand Up @@ -83,8 +85,12 @@ async def transform():


def custom_openapi():
with open("openapi.yaml", "rb") as openapi:
return yaml.load(openapi, yaml.SafeLoader)
oas_file_resource = (impresources.files(assets) / "openapi.yaml")
with oas_file_resource.open("rb") as oas_file:
return yaml.load(oas_file, yaml.SafeLoader)


app.openapi = custom_openapi

def start():
uvicorn.run("coordinates_transformation_api.main:app", workers=2, host="0.0.0.0", port=8000, reload=True)
3 changes: 3 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[mypy]
warn_return_any = True
warn_unused_configs = True
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[project]
name = "coordinates-transformation-api"
description = "Coordinates transformation API of the Nederlandse Samenwerking Geodetische Infrastructuur (NSGI)"
keywords = ["NSGI", "pyproj", "fastapi", "coordinates", "geo"]
license = {text = "MIT"}
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
]
readme = { file = "./README.md", content-type = "text/markdown" }
dependencies = [
"fastapi == 0.100.1",
"uvicorn == 0.23.2",
"pyyaml == 5.3.1",
]
requires-python = ">=3.11.4"
dynamic = ["version"]

[project.optional-dependencies]
dev = ["black", "mypy", "autoflake", "isort"]

[build-system]
build-backend = "setuptools.build_meta"
requires = [
"setuptools>=45",
"setuptools-git-versioning==1.13.1",
"wheel==0.38.4"
]

[project.scripts]
ct-api = "coordinates_transformation_api.main:start"

[tool.setuptools-git-versioning]
enabled = true

[tool.setuptools.packages.find]
include = ["coordinates_transformation_api*"] # package names should match these glob patterns (["*"] by default)
exclude = [] # exclude packages matching these glob patterns (empty by default)

[tool.setuptools.package-data]
"coordinates_transformation_api.assets" = ["*"]
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()

0 comments on commit 5f73023

Please sign in to comment.