-
Notifications
You must be signed in to change notification settings - Fork 0
Reworked entire service t #19
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
20ac4b7
Reworked entire service to FastAPI, uv, dependency updates, Makefile,…
morgangraphics e4c1911
newline
morgangraphics 1aa23db
Potential fix for pull request finding
morgangraphics 0eea373
Potential fix for pull request finding
morgangraphics 23813a7
Potential fix for pull request finding
morgangraphics ea8a082
Potential fix for pull request finding
morgangraphics b8b085c
Potential fix for pull request finding
morgangraphics a9dc4af
Potential fix for pull request finding
morgangraphics 801848f
Potential fix for pull request finding
morgangraphics c5280ec
Potential fix for pull request finding
morgangraphics 5f97699
issues with unused imports, documentation, codacy false positives
morgangraphics 9188279
Merge branch 'feature/flask-to-fastapi-upgrade' of github.com:morgang…
morgangraphics dc10a0a
Update service/models.py
morgangraphics 145e1e0
Update service/routes/marvel.py
morgangraphics fb0cf11
Update service/routes/dc.py
morgangraphics bc356c7
Update service/routes/marvel.py
morgangraphics f54e058
Update service/routes/dc.py
morgangraphics 2ce6700
Initial plan (#20)
Copilot 3f124e4
[WIP] [WIP] Address feedback on service rework implementation (#21)
Copilot 471147b
Codacy linting issues
morgangraphics d546d1c
Codacy linting updates
morgangraphics ca036cd
Codacy issues
morgangraphics 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,17 @@ | ||
| .git | ||
| .venv | ||
| *.pem | ||
| htmlcov | ||
| coverage | ||
| .github | ||
| .circleci | ||
| img | ||
| unit | ||
| tests | ||
| config/.env | ||
| __pycache__ | ||
| *.pyc | ||
| *.egg-info | ||
| dist | ||
| build | ||
| simple-super-hero-service-upgrade.md |
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
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
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,6 +1,11 @@ | ||
| venv/ | ||
| .venv/ | ||
| .idea/ | ||
|
|
||
| # Environment / secrets | ||
| .env | ||
| config/.env | ||
|
|
||
| *.pyc | ||
| __pycache__/ | ||
|
|
||
|
|
||
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,37 @@ | ||
| [MASTER] | ||
| # Support both old pylint ([MASTER]) and new pylint ([MAIN]) section names. | ||
| py-version = 3.12 | ||
|
|
||
| [MAIN] | ||
| py-version = 3.12 | ||
|
|
||
| [BASIC] | ||
| # h and s are intentional short names that map directly to API query parameters. | ||
| # bp_* are idiomatic FastAPI APIRouter instance names, not constants. | ||
| good-names = h,s,e,i,j,k,_,bp_dc,bp_hc,bp_marvel | ||
|
|
||
| [DESIGN] | ||
| # _build_options and route handlers mirror the full set of API query parameters. | ||
| max-args = 15 | ||
| max-positional-arguments = 15 | ||
|
|
||
| [MESSAGES CONTROL] | ||
| # redefined-builtin: 'format' and 'help' shadow builtins intentionally — they | ||
| # are public API query-parameter names that cannot be renamed. | ||
| # line-too-long: not enforced in this project. | ||
| # missing-module-docstring: modules use file-level docstrings only where needed. | ||
| # E0611 (no-name-in-module): false positive — Annotated/Literal exist in | ||
| # typing since Python 3.8/3.9; old pylint doesn't know this. | ||
| # E1136 (unsubscriptable-object): false positive — list[x]/dict[x] are valid | ||
| # in Python 3.9+; old pylint doesn't know this. | ||
| # C0326 (bad-whitespace): false positive — PEP 8 requires spaces around '=' | ||
| # for annotated function parameters; old pylint flags these incorrectly. | ||
| # C0330 (wrong-hanging-indentation): removed in pylint 2.6+ but triggers as a | ||
| # false positive in older Codacy pylint builds. | ||
| disable = redefined-builtin, | ||
| line-too-long, | ||
| missing-module-docstring, | ||
| no-name-in-module, | ||
| unsubscriptable-object, | ||
| bad-whitespace, | ||
| wrong-hanging-indentation |
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,4 @@ | ||
| plugins: | ||
| - remark-lint | ||
| - - remark-lint-ordered-list-marker-value | ||
| - false |
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,58 @@ | ||
| # ARG before FROM parameterises the base image tag; override with --build-arg PYTHON=3.13 | ||
| ARG PYTHON=3.12 | ||
|
|
||
| FROM python:${PYTHON}-slim | ||
| LABEL maintainer="MORGANGRAPHICS,INC" | ||
|
|
||
| ARG PORT=8000 | ||
|
|
||
| # Install curl (HEALTHCHECK) and dumb-init (PID 1 / signal forwarding). | ||
| # Clean up apt cache so it is not stored in the layer. | ||
| RUN apt-get update -y \ | ||
| && apt-get upgrade -y \ | ||
| && apt-get install -y --no-install-recommends curl dumb-init \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install uv for fast, reproducible dependency installation. | ||
| COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv | ||
|
|
||
| # The official python image ships with a non-root user we create explicitly. | ||
| RUN groupadd --gid 1000 appuser && useradd --uid 1000 --gid appuser --shell /bin/bash --create-home appuser | ||
|
|
||
| USER appuser | ||
|
|
||
| ENV PORT=${PORT} | ||
| # Keep Python from writing .pyc files and buffering stdout/stderr | ||
| ENV PYTHONDONTWRITEBYTECODE=1 | ||
| ENV PYTHONUNBUFFERED=1 | ||
| # Tell uv to install into the system Python inside the container | ||
| ENV UV_SYSTEM_PYTHON=1 | ||
| # TLS certificate paths — leave empty for plain HTTP, set both for HTTPS | ||
| ENV SSL_CERT="" | ||
| ENV SSL_KEY="" | ||
|
|
||
| WORKDIR /home/appuser/service | ||
|
|
||
| # Copy dependency manifests first so the install layer is only invalidated | ||
| # when dependencies change, not on every source file change. | ||
| COPY --chown=appuser:appuser pyproject.toml uv.lock* ./ | ||
|
|
||
| RUN uv sync --no-dev --frozen | ||
|
|
||
| # NOTE: sssp-cert.pem and sssp-key.pem are excluded via .dockerignore and must | ||
| # be mounted at runtime, e.g.: | ||
| # docker run -v /path/to/certs:/home/appuser/service ... | ||
| COPY --chown=appuser:appuser . . | ||
|
|
||
| EXPOSE ${PORT} | ||
|
|
||
| HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \ | ||
| CMD if [ -n "$SSL_CERT" ] && [ -n "$SSL_KEY" ]; then \ | ||
| curl -fsk https://localhost:${PORT}/healthcheck; \ | ||
| else \ | ||
| curl -fs http://localhost:${PORT}/healthcheck; \ | ||
| fi || exit 1 | ||
|
|
||
| # https://github.com/Yelp/dumb-init#usage | ||
| ENTRYPOINT ["/usr/bin/dumb-init", "--"] | ||
| CMD ["python", "main.py"] | ||
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,97 @@ | ||
| .DEFAULT_GOAL := help | ||
|
|
||
| # ─── Virtual environment ────────────────────────────────────────────────────── | ||
|
|
||
| .venv: | ||
| uv venv .venv --python 3.12 | ||
|
|
||
| install: .venv ## Install all dependencies (including dev) | ||
| uv sync --extra dev | ||
|
|
||
| # ─── Service ────────────────────────────────────────────────────────────────── | ||
|
|
||
| start: ## Start the service (foreground) | ||
| uv run python main.py | ||
|
|
||
| dev: ## Start the service with auto-reload | ||
| uv run uvicorn service:create_app --factory --reload --host 127.0.0.1 --port 8000 | ||
|
|
||
| stop: ## Stop any background uvicorn process | ||
| @pkill -f "uvicorn service:create_app" && echo "Service stopped." || echo "No running service found." | ||
|
|
||
| # ─── Tests ──────────────────────────────────────────────────────────────────── | ||
|
|
||
| test: ## Run all unit tests | ||
| uv run pytest unit/ | ||
|
|
||
| test-unit: ## Run unit tests (alias) | ||
| uv run pytest unit/ | ||
|
|
||
| test-file: ## Run file utility tests only | ||
| uv run pytest unit/test_file.py -s | ||
|
|
||
| test-verbose: ## Run unit tests with verbose output | ||
| uv run pytest unit/ -v | ||
|
|
||
| # ─── Coverage ───────────────────────────────────────────────────────────────── | ||
|
|
||
| coverage: ## Run tests with coverage report (terminal) | ||
| uv run coverage erase | ||
| uv run coverage run -m pytest unit/ | ||
| uv run coverage report --show-missing | ||
|
|
||
| coverage-html: ## Run tests with coverage report (HTML) | ||
| uv run coverage erase | ||
| uv run coverage run -m pytest unit/ | ||
| uv run coverage html | ||
| @echo "Report available at htmlcov/index.html" | ||
|
|
||
| # ─── Code quality ───────────────────────────────────────────────────────────── | ||
|
|
||
| lint: ## Run ruff linter | ||
| uv run ruff check . | ||
|
|
||
| lint-fix: ## Run ruff linter and auto-fix | ||
| uv run ruff check . --fix | ||
|
|
||
| format: ## Run black formatter | ||
| uv run black . | ||
|
|
||
| format-check: ## Check formatting without making changes | ||
| uv run black . --check | ||
|
|
||
| # ─── SSL certs ──────────────────────────────────────────────────────────────── | ||
|
|
||
| certs: ## Generate self-signed SSL certs for local development | ||
| openssl req -x509 -newkey rsa:4096 -keyout sssp-key.pem -out sssp-cert.pem \ | ||
| -days 365 -nodes -subj "/CN=localhost" | ||
|
|
||
| # ─── Docker ─────────────────────────────────────────────────────────────────── | ||
|
|
||
| IMAGE ?= simple-superhero-service-python | ||
|
|
||
| docker-build: ## Build the Docker image | ||
| docker build -t $(IMAGE) . | ||
|
|
||
| docker-start: ## Run the container (mounts local certs, exposes port 8000) | ||
| docker run --rm -p 8000:8000 \ | ||
| -v $(PWD)/sssp-cert.pem:/home/appuser/service/sssp-cert.pem:ro \ | ||
| -v $(PWD)/sssp-key.pem:/home/appuser/service/sssp-key.pem:ro \ | ||
| -v $(PWD)/config/.env:/home/appuser/service/config/.env:ro \ | ||
| $(IMAGE) | ||
|
|
||
| docker-stop: ## Stop the running container | ||
| @docker stop $$(docker ps -q --filter ancestor=$(IMAGE)) 2>/dev/null && echo "Container stopped." || echo "No running container found." | ||
|
|
||
| docker-shell: ## Open a shell in a new container | ||
| docker run --rm -it $(IMAGE) /bin/bash | ||
|
|
||
| # ─── Help ───────────────────────────────────────────────────────────────────── | ||
|
|
||
| help: ## Show this help message | ||
| @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \ | ||
| | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
|
|
||
| .PHONY: install start dev stop test test-unit test-file test-verbose \ | ||
| coverage coverage-html lint lint-fix format format-check certs \ | ||
| docker-build docker-start docker-stop docker-shell help |
Oops, something went wrong.
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.