Skip to content

Commit

Permalink
import assets through importlib - so assets are packages as well
Browse files Browse the repository at this point in the history
  • Loading branch information
arbakker committed Aug 1, 2023
1 parent 764b8ed commit 40e21dd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 3 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
}
]
}
Empty file.
File renamed without changes.
10 changes: 7 additions & 3 deletions coordinates_transformation_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import yaml
import uvicorn

from importlib import resources as impresources
from . import assets


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

app = FastAPI(docs_url="/api")
Expand Down Expand Up @@ -81,12 +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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ 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" = ["*"]

0 comments on commit 40e21dd

Please sign in to comment.