-
Notifications
You must be signed in to change notification settings - Fork 1
fastapi-pydantic-containerization #3
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
Open
alfrice
wants to merge
2
commits into
main
Choose a base branch
from
fastapi-rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # --- Python junk --- | ||
| __pycache__/ | ||
| *.pyc | ||
| *.pyo | ||
| *.pyd | ||
|
|
||
| # --- Virtual environments --- | ||
| .venv/ | ||
| venv/ | ||
| env/ | ||
| .env/ | ||
|
|
||
| logs | ||
|
|
||
| # --- Build and dependency artifacts --- | ||
| dist/ | ||
| build/ | ||
| *.egg-info/ | ||
| .eggs/ | ||
| .cache/ | ||
| *.log | ||
|
|
||
| .flake8 | ||
|
|
||
| # --- Development / tooling directories --- | ||
| .idea/ | ||
| .vscode/ | ||
| tests/ | ||
| docs/ | ||
| .git/ | ||
| .gitignore | ||
|
|
||
| # --- OS & editor clutter --- | ||
| .DS_Store | ||
| Thumbs.db | ||
|
|
||
| # --- Node / frontend (if present) --- | ||
| node_modules/ | ||
| npm-debug.log | ||
| yarn.lock | ||
|
|
||
| # --- Docker --- | ||
| Dockerfile* | ||
| compose*.yml | ||
| docker-compose*.yml | ||
|
|
||
| # --- Local data --- | ||
| *.db | ||
| *.sqlite3 | ||
|
|
||
| /docker | ||
| !/docker/entrypoint.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [flake8] | ||
| extend-ignore = E501 E712 | ||
| exclude = .git,__pycache__,.venv,old,build,dist,trimet.asset.egg-info | ||
| max-complexity = 30 | ||
| max-line-length = 88 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: ["**"] # runs on any branch | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run Tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| env: | ||
| POETRY_VIRTUALENVS_CREATE: false | ||
| POETRY_NO_INTERACTION: 1 | ||
| PYTHONUNBUFFERED: 1 | ||
| PYTHONDONTWRITEBYTECODE: 1 | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.12" | ||
|
|
||
| - name: Install Poetry | ||
| run: | | ||
| curl -sSL https://install.python-poetry.org | python3 - | ||
| echo "$HOME/.local/bin" >> $GITHUB_PATH | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| poetry install --with dev --no-interaction --no-ansi | ||
|
|
||
| - name: Run tests | ||
| run: | | ||
| poetry run black . --check | ||
| poetry run pytest --cov=com -v -s --log-cli-level=DEBUG | ||
| env: | ||
| PYTHONPATH: ${{ github.workspace }} | ||
|
|
||
| build: | ||
| name: Build Docker Image | ||
| runs-on: ubuntu-latest | ||
| needs: test # only build if tests pass | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GitHub Container Registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract branch name | ||
| id: extract_branch | ||
| run: | | ||
| # Strip refs/heads/ from the branch name | ||
| BRANCH_NAME=${GITHUB_REF#refs/heads/} | ||
| # Replace slashes with dashes for Docker tag safety | ||
| SAFE_BRANCH_NAME=${BRANCH_NAME//\//-} | ||
| echo "branch=$SAFE_BRANCH_NAME" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Build and push Docker image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| file: docker/Dockerfile | ||
| push: true | ||
| tags: | | ||
| ghcr.io/opentransittools/pelias-adapter:${{ steps.extract_branch.outputs.branch }} | ||
| build-args: | | ||
| POETRY_VERSION=2.2.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,8 @@ develop-eggs | |
| lib | ||
| lib64 | ||
|
|
||
| .venv | ||
|
|
||
| # Installer logs | ||
| pip-log.txt | ||
|
|
||
|
|
||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,24 @@ | ||
| Pelias.Adapter | ||
| ============== | ||
|
|
||
| Python wrapper to make Pelias look like SOLR (geosearch instance) | ||
|
|
||
|
|
||
| build: | ||
| ------ | ||
| 1. install python 3.x, along easy_install, zc.buildout ("zc.buildout==1.5.2") and git | ||
| 1. git clone https://github.com/OpenTransitTools/pelias.adapter.git | ||
| 1. cd pelias.adapter | ||
| 1. buildout | ||
|
|
||
| run: | ||
| ---- | ||
| 1. rm nohup.out; nohup bin/pserve config/development.ini --reload PELIAS_SOLR=1 & | ||
| 1. http://localhost:45454/solr/select?q=2 | ||
| 1. http://localhost:45454/solr/boundary/select?q=8 | ||
|
|
||
| test: | ||
| ----- | ||
| 1. run the server (see above) | ||
| 1. bin/test | ||
|
|
||
| rules: | ||
| ----- | ||
| 1. try 'autocomplete' .. if that fails, try 'search' | ||
| 1. (or should we look at length of string and try 'search' first on longer strings?) | ||
| 1. fix 'same string' problem: | ||
| - remove duplicate points (strings 99% similar and lat/lon very close by) | ||
| - clean up duplicate strings (e.g., Starbucks problem) | ||
| 1. call Pelias with configurable url (sources=oa,osm,transit, etc...) | ||
| 1. if we get WoF a city record(s), then strip city from query string and resubmit (e.g., bad city problem) | ||
| 1. ... | ||
|
|
||
| urls: | ||
| ----- | ||
| 1. Pelias TriMet-only: https://ws.trimet.org/peliaswrap/v1/autocomplete?text=6 | ||
| 1 Pelias Multi-Agency: https://ws.trimet.org/peliaswrap/v1/rtp/autocomplete?text=6 | ||
| 1. SOLR: https://ws-st.trimet.org/solrwrap/v1/select?start=0&limit=10&wt=json&qt=dismax&rows=10&q=834%20SE&fq=type:stop | ||
| 1. SOLR Stops Only: https://ws-st.trimet.org/solrwrap/v1/select?start=0&limit=10&wt=json&qt=dismax&rows=10&q=834%20SE&fq=type:stop | ||
| # Pelias Adapter API | ||
|
|
||
| A FastAPI-based web API for Open Transit Tools, providing Pelias geocoding services. | ||
|
|
||
| ## Features | ||
|
|
||
| - FastAPI web server | ||
| - Pelias geocoding endpoints | ||
| - CORS support | ||
| - Configurable logging | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Python 3.12+ | ||
| - Dependencies listed in `pyproject.toml` | ||
|
|
||
| ## Installation | ||
|
|
||
| Clone the repository and install dependencies using Poetry: | ||
|
|
||
| ```sh | ||
| git clone https://github.com/OpenTransitTools/pelias.adapter.git | ||
| cd pelias.adapter | ||
| poetry install |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # FastAPI Oracle Template Application |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Core configuration and settings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import os | ||
| from logging import getLogger | ||
| from zoneinfo import ZoneInfo | ||
|
|
||
| from ott.utils.svr.pyramid.globals import CACHE_LONG | ||
| from pydantic import ConfigDict | ||
| from pydantic_settings import BaseSettings | ||
|
|
||
| logger = getLogger(__name__) | ||
|
|
||
| ENVIRONMENT = os.getenv("ENVIRONMENT", "dev") # default to dev | ||
|
|
||
| CACHE_LONG_STR = f"public, max-age={CACHE_LONG}" | ||
|
|
||
| logger.info(f"Environment: {ENVIRONMENT}") | ||
|
|
||
| ENV_FILE = f"{ENVIRONMENT}.env" | ||
|
|
||
| TIME_ZONE: ZoneInfo = ZoneInfo("America/Los_Angeles") | ||
|
|
||
| DATE_STRING_FORMAT = "%Y-%m-%d %H:%M:%S %Z%z" | ||
|
|
||
|
|
||
| class Settings(BaseSettings): | ||
| """ | ||
| Application settings with Oracle database configuration | ||
| """ | ||
|
|
||
| # Application settings | ||
| app_name: str = "FastAPI Trimet Pelias Adapter" | ||
| debug: bool = False | ||
|
|
||
| model_config = ConfigDict( | ||
| env_file=ENV_FILE, # or f"{ENVIRONMENT}.env" | ||
| case_sensitive=False, | ||
| extra="allow", | ||
| ) | ||
|
|
||
|
|
||
| # Global settings instance | ||
| settings = Settings() | ||
|
|
||
| logger.info(f"Loaded settings for environment: {ENVIRONMENT}, {settings.debug}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class PeliasAdapterError(Exception): | ||
| """Base class for all Pelias Adapter exceptions.""" | ||
|
|
||
| def __init__(self, message): | ||
| super().__init__(message) | ||
| self.message = message | ||
|
|
||
| def __str__(self): | ||
| return self.message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # SQLAlchemy models |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.