Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ jobs:
python-version: ${{ matrix.py-version-img[0] }}
- name: Install requirements
run: |
pip install -e .[dev]
pip install setuptools
pip install poetry
poetry install --with=code_quality,docs,test,types
- name: Lint with flake8
run: flake8
run: poetry run flake8
- name: Run mypy
run: mypy foca
run: poetry run mypy foca
- name: Start MongoDB
uses: supercharge/mongodb-github-action@1.7.0
with:
mongodb-version: ${{ matrix.mongodb-version }}
mongodb-port: ${{ matrix.mongodb-port }}
- name: Calculate unit test coverage
run: |
coverage run --source foca -m pytest -W ignore::DeprecationWarning
coverage xml
poetry run coverage run --source foca -m pytest -W ignore::DeprecationWarning
poetry run coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
Expand All @@ -72,10 +72,10 @@ jobs:
--build-arg PY_IMAGE=${PY_IMAGE} \
.
cd ./examples/petstore
docker-compose up --build -d
docker compose up --build -d
cd ../..
sleep 10
pytest ./tests/integration_tests.py
poetry run pytest ./tests/integration_tests.py

Docker:
runs-on: ubuntu-latest
Expand Down
13 changes: 5 additions & 8 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ build:
os: ubuntu-22.04
tools:
python: "3.10"
jobs:
post_create_environment:
- python -m pip install poetry
post_install:
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --with docs
# You can also specify other tool versions:
# nodejs: "20"
# rust: "1.70"
Expand All @@ -26,11 +31,3 @@ sphinx:
# formats:
# - pdf
# - epub

python:
install:
- method: pip
path: .
extra_requirements:
- docs
- dev
6 changes: 0 additions & 6 deletions MANIFEST.in

This file was deleted.

74 changes: 74 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# NOTE: This Makefile assumes that dependencies are installed and, if a virtual
# environment is used, it is activated.

## Variables ##################################################################
# NOTE: Define any variables here if needed in the future

## Documentation ##############################################################
# NOTE: Keep all the targets in alphabetical order for better readability.

default: help

.PHONY: help
help:
@echo "\nUsage: make [target] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
@echo "Available targets:\n"

@echo "Code Quality ------------------------------------------------------------------"
@echo " \033[1m\033[35mformat-lint\033[0m \033[37m(fl)\033[0m: \033[36mRun linter, formatter, spellcheck.\033[0m"
@echo " \033[1m\033[35mtype-check\033[0m \033[37m(tc)\033[0m: \033[36mPerform type checking.\033[0m\n"

@echo "Environment Management --------------------------------------------------------"
@echo " \033[1m\033[35mclean-venv\033[0m \033[37m(cv)\033[0m: \033[36mRemove virtual environment.\033[0m"
@echo " \033[1m\033[35minstall\033[0m \033[37m(i)\033[0m: \033[36mInstall app and dependencies.\033[0m"
@echo " \033[1m\033[35mvenv\033[0m \033[37m(v)\033[0m: \033[36mCreate virtual environment.\033[0m\n"

@echo "Testing -----------------------------------------------------------------------"
@echo " \033[1m\033[35mtest\033[0m \033[37m(t)\033[0m: \033[36mRun all tests.\033[0m\n"

.PHONY: clean-venv cv
clean-venv:
@echo "\nRemoving the virtual environment ++++++++++++++++++++++++++++++++++++++++++++++\n"
@rm -rf .venv

cv: clean-venv

.PHONY: format-lint fl
format-lint:
@echo "\nRunning linter and formatter using ruff and typos +++++++++++++++++++++++++++++\n"
@poetry run flake8
@typos .

fl: format-lint

.PHONY: install i
install:
@echo "\nInstalling this package its dependencies +++++++++++++++++++++++++++++++++\n"
@poetry install --with=code_quality,docs,test,types

i: install

.PHONY: test t
test:
@echo "\nRunning tests using pytest ++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
@poetry run pytest tests/

t: test

.PHONY: type-check tc
type-check:
@echo "\nPerforming type checking with mypy ++++++++++++++++++++++++++++++++++++++++++++\n"
@poetry run mypy foca

tc: type-check

.PHONY: venv v
venv:
@echo "\nCreating a virtual environment ++++++++++++++++++++++++++++++++++++++++++++++++\n"
@python -m venv .venv
@echo "\nSummary +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
@echo "Virtual environment created successfully."
@echo "To activate the environment for this shell session, run:"
@echo "source .venv/bin/activate"

v: venv
80 changes: 39 additions & 41 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
###################################################
# Stage 1: Get poetry #
###################################################
ARG PY_IMAGE=3.12-slim-bookworm
FROM python:$PY_IMAGE as base

# Metadata
LABEL software="FOCA"
LABEL software.description="Kickstart OpenAPI-based microservice development with Flask & Connexion"
LABEL software.website="https://github.com/elixir-cloud-aai/foca"
LABEL software.license="https://spdx.org/licenses/Apache-2.0"
LABEL maintainer="alexander.kanitz@alumni.ethz.ch"
LABEL maintainer.organisation="ELIXIR Cloud & AAI"

# Build image
FROM base as builder

# Install general dependencies
ENV PACKAGES openssl git build-essential python3-dev curl jq
RUN apt-get update && \
apt-get install -y --no-install-recommends ${PACKAGES} && \
rm -rf /var/lib/apt/lists/*
FROM python:$PY_IMAGE AS poetry

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
&& rm -rf /var/lib/apt/lists/*

RUN curl -sSL https://install.python-poetry.org | python3 - && \
ln -s /root/.local/bin/poetry /usr/local/bin/poetry

###################################################
# Stage 2: Get deps #
###################################################
FROM poetry AS builder

WORKDIR /app

# Install Python dependencies
COPY requirements.txt ./
RUN pip install \
--no-warn-script-location \
--prefix="/install" \
-r requirements.txt
COPY . /app/

# Install FOCA
COPY setup.py README.md ./
COPY foca/ ./foca/
RUN pip install --upgrade pkginfo && \
pip install . \
--no-warn-script-location \
--prefix="/install"
RUN poetry config virtualenvs.create false \
&& poetry build

# Final image
FROM base
# ###################################################
# # Stage 3: Add Metadata and install wheel #
# ###################################################
FROM python:$PY_IMAGE

COPY --from=builder /app/dist /app/dist

RUN pip install /app/dist/*.whl

LABEL org.opencontainers.image.title="FOCA"
LABEL org.opencontainers.image.description="Kickstart OpenAPI-based microservice development with Flask & Connexion"
LABEL org.opencontainers.image.source="https://github.com/elixir-cloud-aai/foca"
LABEL org.opencontainers.image.licenses="Apache-2.0"
LABEL org.opencontainers.image.authors="alexander.kanitz@alumni.ethz.ch"
LABEL org.opencontainers.image.vendor="ELIXIR Cloud & AAI"

# Python UserID workaround for OpenShift/K8S
ENV LOGNAME=ipython
ENV USER=ipython
ENV HOME=/tmp/user

# Install general dependencies
ENV PACKAGES openssl git build-essential python3-dev curl jq
RUN apt-get update && \
apt-get install -y --no-install-recommends ${PACKAGES} && \
rm -rf /var/lib/apt/lists/*

# Copy Python packages
COPY --from=builder /install /usr/local
WORKDIR /app
2 changes: 1 addition & 1 deletion foca/api/register_openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def register_openapi(
if spec.add_operation_fields is not None:
for key, val in spec.add_operation_fields.items():
for path_item_object in spec_parsed.get('paths', {}).values():
for operation, operation_object in path_item_object.items():
for operation, operation_object in path_item_object.items(): # noqa: E501
if operation not in _OPERATION_OBJECT_FIELDS:
continue
operation_object[key] = val
Expand Down
Loading