Skip to content

Commit

Permalink
Add UWS support to FastAPI Safir app template
Browse files Browse the repository at this point in the history
Add a new configuration option for the FastAPI Safir app project
template that allows the user to indicate whether they are building
a UWS app with a separate backend and a queuing system (defaulting
to no). If that option is enabled, add in the machinery for a UWS
application, including stub models and a stub worker function.

This template uncovered a Ruff diagnostic for unused class method
parameters that would fire on the initial application as generated
from the template. Add an ignore rule for that diagnostic for the
same reason as the similar diagnostic for unused method arguments.
  • Loading branch information
rra committed Jul 29, 2024
1 parent ce585b5 commit a49a497
Show file tree
Hide file tree
Showing 72 changed files with 2,210 additions and 8 deletions.
11 changes: 11 additions & 0 deletions project_templates/fastapi_safir_app/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ from templatekit.builder import cookiecutter_project_builder
env = Environment(BUILDERS={'Cookiecutter': cookiecutter_project_builder})
env.Cookiecutter(AlwaysBuild(Dir('example')),
'cookiecutter.json')

# Run cookiecutter to generate the 'example-uws' package
# This represents an IVOA UWS service that does work via an arq queue
# The explicit target directory, with AlwaysBuild, is needed for Scons to
# differentiate this build from the example build above. We can't use Scons'
# default build caching because we'd have to compute the cookiecutter
# template anyways.
env.Cookiecutter(AlwaysBuild(Dir('example-uws')),
'cookiecutter.json',
cookiecutter_context={'name': 'example-uws',
'uws_service': 'True'})
1 change: 1 addition & 0 deletions project_templates/fastapi_safir_app/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"lsst-dm",
"lsst-sqre-testing"
],
"uws_service": ["False", "True"],
"uses_helm": ["True", "False"],
"_extensions": ["jinja2_time.TimeExtension", "templatekit.TemplatekitExtension"]
}
142 changes: 142 additions & 0 deletions project_templates/fastapi_safir_app/example-uws/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# VSCode
.vscode/

# Everything below this point is a copy of .gitignore.

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# macOS
.DS_Store
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: CI

env:
# Current supported Python version. For applications, there is generally no
# reason to support multiple Python versions, so all actions are run with
# this version. Quote the version to avoid interpretation as a floating
# point number.
PYTHON_VERSION: "3.12"

"on":
merge_group: {}
pull_request: {}
push:
branches-ignore:
# These should always correspond to pull requests, so ignore them for
# the push trigger and let them be triggered by the pull_request
# trigger, avoiding running the workflow twice. This is a minor
# optimization so there's no need to ensure this is comprehensive.
- "dependabot/**"
- "gh-readonly-queue/**"
- "renovate/**"
- "tickets/**"
- "u/**"
tags:
- "*"

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Run pre-commit
uses: pre-commit/[email protected]

test:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4

- name: Run tox
uses: lsst-sqre/run-tox@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
tox-envs: "py,coverage-report,typing"
tox-requirements: requirements/tox.txt

build:
runs-on: ubuntu-latest
needs: [lint, test]
timeout-minutes: 10

# Only do Docker builds of tagged releases and pull requests from ticket
# branches. This will still trigger on pull requests from untrusted
# repositories whose branch names match our tickets/* branch convention,
# but in this case the build will fail with an error since the secret
# won't be set.
if: >
github.event_name != 'merge_group'
&& (startsWith(github.ref, 'refs/tags/')
|| startsWith(github.head_ref, 'tickets/'))
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: lsst-sqre/build-and-push-to-ghcr@v1
id: build
with:
image: ${{ github.repository }}
github_token: ${{ secrets.GITHUB_TOKEN }}

- uses: lsst-sqre/build-and-push-to-ghcr@v1
id: build-worker
with:
image: ${{ github.repository }}-worker
github_token: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This is a separate run of the Python test suite that runs from a schedule,
# doesn't cache the tox environment, and updates pinned dependencies first.
# The purpose is to test compatibility with the latest versions of
# dependencies.

name: Periodic CI

env:
# Current supported Python version. For applications, there is generally no
# reason to support multiple Python versions, so all actions are run with
# this version. Quote the version to avoid interpretation as a floating
# point number.
PYTHON_VERSION: "3.12"

"on":
schedule:
- cron: "0 12 * * 1"
workflow_dispatch: {}

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Update dependencies
run: |
pip install --upgrade uv
uv venv
source .venv/bin/activate
make update-deps
shell: bash

- name: Run tests in tox
uses: lsst-sqre/run-tox@v1
with:
python-version: ${{ env.PYTHON_VERSION }}
tox-envs: "lint,typing,py"
tox-requirements: requirements/tox.txt
use-cache: false

- name: Report status
if: failure()
uses: ravsamhq/notify-slack-action@v2
with:
status: ${{ job.status }}
notify_when: "failure"
notification_title: "Periodic test for {repo} failed"
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_ALERT_WEBHOOK }}
Loading

0 comments on commit a49a497

Please sign in to comment.