Skip to content

Commit

Permalink
Add python and python-async
Browse files Browse the repository at this point in the history
  • Loading branch information
jennydaman committed Oct 7, 2024
1 parent 0fca500 commit ea04c6e
Show file tree
Hide file tree
Showing 957 changed files with 222,176 additions and 0 deletions.
200 changes: 200 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
# TODO ADD PIXI
name: Release

on:
push:
branches: [ main ]
paths:
- 'version.txt'

jobs:
build:
name: Build
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
name:
- python
- python-async
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install build
run: pip install --break-system-packages build
- name: Build dist
run: python -m build ${{ matrix.name }}
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.name }}
path: ${{ matrix.name }}/dist/
publish:
name: Publish
runs-on: ubuntu-24.04
needs: build
steps:
- name: Download distributions packages
uses: actions/download-artifact@v4
with:
path: dist
pattern: python*
merge-multiple: true
- name: Parse PEP 508 requirement strings
id: requirements
run: |
find dist -type f -name '*.whl' -printf "%f\n" \
| sed 's/-py3-none-any.whl//' \
| sed 's/-/==/' \
| xargs -I '%' bash -c 'echo "$(sed "s/==.*//" <<< %)=%"' \
| tee -a "$GITHUB_OUTPUT"
- name: Assert PEP 508 requirement strings are not empty
run: |
if [ -z '${{ steps.requirements.outputs.chris_oag}}' ]; then
echo "::error ::steps.requirements.outputs.chris_oag is empty"
exit 1
fi
if [ -z '${{ steps.requirements.outputs.aiochris_oag}}' ]; then
echo "::error ::steps.requirements.outputs.aiochris_oag is empty"
exit 1
fi
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
# TODO change to prod PyPI
repository-url: https://test.pypi.org/legacy/
password: '${{ secrets.TEST_PYPI_TOKEN }}'
# password: '${{ secrets.PYPI_API_TOKEN }}'
outputs:
pep508_chris_oag: ${{ steps.requirements.outputs.chris_oag }}
pep508_aiochris_oag: ${{ steps.requirements.outputs.aiochris_oag }}

oci-image:
name: Push OCI Image
runs-on: ubuntu-24.04
needs: build
strategy:
fail-fast: false
matrix:
name:
- python
- python-async
outputs:
python-image: ${{ steps.info.outputs.python-image }}
python-version: ${{ steps.info.outputs.python-version }}
python-async-image: ${{ steps.info.outputs.python-async-image }}
python-async-version: ${{ steps.info.outputs.python-async-version }}
steps:
- name: Download distributions packages
uses: actions/download-artifact@v4
with:
name: ${{ matrix.name }}
path: dist
- name: Create Dockerfile
run: |
tee Dockerfile << EOF
FROM docker.io/library/python:3.12.7-alpine3.20
RUN --mount=source=dist,target=/dist PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir /dist/*.whl
EOF
- name: Get version
id: info
run: |
version="$(
find dist -type f -name '*.whl' -printf "%f\n" \
| head -n 1 \
| grep -Eom 1 '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+(a|b)*[[:digit:]]*'
)"
image='ghcr.io/${{ github.repository_owner }}/${{ matrix.name }}-client'
image="${image,,}"
tee -a "$GITHUB_OUTPUT" << EOF
version=$version
${{ matrix.name }}-version=$version
image=$image
${{ matrix.name }}-image=$image
EOF
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.info.outputs.image }}
tags: |
type=semver,pattern={{version}}
type=raw,value=${{ steps.info.outputs.version }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}


gh-release:
name: Create GitHub Release
runs-on: ubuntu-24.04
needs:
- oci-image
- publish
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: version.txt
sparse-checkout-cone-mode: false
- name: Get version
id: version
run: echo "version=$(< version.txt)" >> "$GITHUB_OUTPUT"
- uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
name: ChRIS Clients - version ${{ steps.version.outputs.version }}
body: |
## Python Async Client
```shell
# using uv - https://docs.astral.sh/uv/
uv pip install ${{ needs.publish.outputs.pep508_aiochris_oag }}
# using rye - https://rye.astral.sh/
rye add ${{ needs.publish.outputs.pep508_aiochris_oag }}
# using pip
pip install ${{ needs.publish.outputs.pep508_aiochris_oag }}
# using Docker
docker pull ${{ needs.oci-image.outputs.python-async-image }}:${{ needs.oci-image.outputs.python-async-version }}
# using Podman
docker pull ${{ needs.oci-image.outputs.python-async-image }}:${{ needs.oci-image.outputs.python-async-version }}
```
## Python urllib3 Client
```shell
# using uv - https://docs.astral.sh/uv/
uv pip install ${{ needs.publish.outputs.pep508_chris_oag }}
# using rye - https://rye.astral.sh/
rye add ${{ needs.publish.outputs.pep508_chris_oag }}
# using pip
pip install ${{ needs.publish.outputs.pep508_chris_oag }}
# using Docker
docker pull ${{ needs.oci-image.outputs.python-image }}:${{ needs.oci-image.outputs.python-version }}
# using Podman
docker pull ${{ needs.oci-image.outputs.python-image }}:${{ needs.oci-image.outputs.python-version }}
```
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/schema*.yaml

/.venv

dist

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OpenAPI Generated Clients for _CUBE_

This repository contains client libraries for the [_ChRIS_ backend](https://github.com/fnndsc/ChRIS_ultron_backEnd)
created using the [OpenAPI generator](https://openapi-generator.tech/).

29 changes: 29 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
file := "schema_split.yaml"
releases_url := "https://github.com/FNNDSC/ChRIS_ultron_backEnd/releases"

generate-all:
@just generate python -g python -p packageName=chris_oag,projectName=chris-oag -p library=urllib3,packageVersion=$(just get-version-pep440)
@just generate python-async -g python -p packageName=aiochris_oag,projectName=aiochris-oag -p library=asyncio,packageVersion=$(just get-version-pep440)
# @just generate typescript-fetch -g typescript-fetch -p npmName=@fnndsc/chris-openapi-generated -p withInterfaces=true
# @just generate rust -g rust -p packageName=chris-openapi-generated -p library=reqwest,preferUnsignedInt=true,supportMiddleware=true

# generate an OpenAPI client
generate output +options:
@if ! [ -e "{{file}}" ]; then \
error="$(tput setaf 1)error$(tput sgr0): {{file}} not found."; \
suggestion="Please download the OpenAPI specification YAML from {{releases_url}} and save it as $(pwd)/{{file}}"; \
echo "$error $suggestion"; \
exit 1; \
fi
if ! [ -d {{output}} ]; then mkdir -v {{output}}; fi
podman run --rm --userns=keep-id:uid=100100,gid=100100 -u 100100:100100 \
-v "$(pwd)/{{output}}:/out:rw" -v "$(pwd)/{{file}}:/{{file}}:ro" \
docker.io/openapitools/openapi-generator-cli:v7.8.0 \
generate {{options}} -i "/{{file}}" -o "/out"

get-version-pep440:
@./semver2pep440.sh < version.txt

get-version:
@cat version.txt

38 changes: 38 additions & 0 deletions python-async/.github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# NOTE: This file is auto generated by OpenAPI Generator.
# URL: https://openapi-generator.tech
#
# ref: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: aiochris_oag Python package

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
66 changes: 66 additions & 0 deletions python-async/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# 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/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
venv/
.venv/
.python-version
.pytest_cache

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

#Ipython Notebook
.ipynb_checkpoints
31 changes: 31 additions & 0 deletions python-async/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# NOTE: This file is auto generated by OpenAPI Generator.
# URL: https://openapi-generator.tech
#
# ref: https://docs.gitlab.com/ee/ci/README.html
# ref: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml

stages:
- test

.pytest:
stage: test
script:
- pip install -r requirements.txt
- pip install -r test-requirements.txt
- pytest --cov=aiochris_oag

pytest-3.7:
extends: .pytest
image: python:3.7-alpine
pytest-3.8:
extends: .pytest
image: python:3.8-alpine
pytest-3.9:
extends: .pytest
image: python:3.9-alpine
pytest-3.10:
extends: .pytest
image: python:3.10-alpine
pytest-3.11:
extends: .pytest
image: python:3.11-alpine
Loading

0 comments on commit ea04c6e

Please sign in to comment.