Skip to content

Commit

Permalink
📚 Docs (#10)
Browse files Browse the repository at this point in the history
* Adds auto generating docs from docstrings

* Deploy docs with reusable workflow

* Split models into own docs

* Change Pipeline.apps to AnyHttpUrl

* Move test deps into test group, made optional

* Adds poetry_args to pytest workflow

* Fix flake errors
  • Loading branch information
mrharpo authored Mar 23, 2023
1 parent 6187f3a commit 9ea57de
Show file tree
Hide file tree
Showing 14 changed files with 782 additions and 98 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: 📖 Docs

on:
push:
branches:
- main
- docs
jobs:
build:
name: 📓 Build and deploy docs
uses: WGBH-MLA/.github/.github/workflows/docs.yml@main
11 changes: 8 additions & 3 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
default: 3.11
type: string

poetry_args:
description: Additional args to pass to poetry.
type: string
default: --with test

pytest_args:
description: Additional args to pass to pytest.
type: string
Expand Down Expand Up @@ -36,14 +41,14 @@ jobs:
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
key: venv-test-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: 🏋 Download dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root ${{ inputs.poetry_args }}

- name: 🏗️ Install dependencies
run: poetry install --no-interaction
run: poetry install --no-interaction ${{ inputs.poetry_args }}

- name: 🧪 Run pytest suite
run: poetry run pytest -v --cov --cov-report lcov ${{ inputs.pytest_args }}
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Coverage files
htmlcov
.coverage
coverage.lcov
coverage.lcov

# Docs
site
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FROM python
RUN pip install -U pip uvicorn

WORKDIR /app

COPY ./pyproject.toml .
COPY ./README.md .
COPY ./fastclam /app/fastclam
COPY pyproject.toml poetry.lock README.md ./
COPY fastclam fastclam

RUN pip install . uvicorn
RUN pip install .


CMD [ "uvicorn", "fastclam.app:app", "--host", "0.0.0.0" ]
26 changes: 26 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# FastCLAM

FastAPI for CLAMS

## install

Clone the repository

```bash
git clone https://github.com/WGBH-MLA/FastCLAM
cd FastCLAM/
```

### Poetry (Recommended)

Install with poetry

```bash
poetry install
```

### Pip

```bash
pip3 install .
```
3 changes: 3 additions & 0 deletions docs/reference/app.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# App

::: fastclam.app
3 changes: 3 additions & 0 deletions docs/reference/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Reference

::: fastclam
3 changes: 3 additions & 0 deletions docs/reference/models.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Models

::: fastclam.models
12 changes: 12 additions & 0 deletions fastclam/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""# FastCLAM
FastAPI for CLAMS
Example:
Run the server:
`$ uvicorn fastclam.app`
Use the API docs to make requests:
[localhost:8000/docs](http://localhost:8000/docs)
"""
16 changes: 4 additions & 12 deletions fastclam/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,22 @@
from fastapi.responses import PlainTextResponse
from starlette.exceptions import HTTPException as StarletteHTTPException
from clams.source import generate_source_mmif
from pydantic import BaseModel
from typing import List
from json import loads
import requests
from .log import log
from .models import Inputs, Pipeline
from .version import __VERSION__
from xml.etree import ElementTree
from xml.etree.ElementTree import ParseError
from json import loads
from json.decoder import JSONDecodeError


class Inputs(BaseModel):
files: List[str]


class Pipeline(Inputs):
apps: List[str]


class MMIFException(HTTPException):
pass


app = FastAPI()
app = FastAPI(title='FastCLAM')


@app.exception_handler(StarletteHTTPException)
Expand All @@ -35,7 +27,7 @@ async def http_exception_handler(request, exc):

@app.get('/')
def home() -> dict:
"""version info"""
"""Return version info"""
return {'FastCLAM': __VERSION__}


Expand Down
31 changes: 31 additions & 0 deletions fastclam/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Models
Pipeline validation models
"""

from pydantic import BaseModel, AnyHttpUrl
from typing import List


class Inputs(BaseModel):
"""Inputs
Accepts list of files as input
Attributes:
files: A List of file paths as strings
"""

files: List[str]


class Pipeline(Inputs):
"""Pipeline
A simple pieline validator, based on Inputs
Attributes:
apps: A List of apps to run, where each appp is a url string for the service
"""

apps: List[AnyHttpUrl]
60 changes: 60 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
site_name: FastCLAM
site_description: FastAPI for CLAMS
repo_url: https://github.com/WGBH-MLA/FastCLAM
edit_uri: ''

markdown_extensions:
- pymdownx.highlight
- pymdownx.superfences
- pymdownx.tabbed:
alternate_style: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
- def_list
- admonition
- pymdownx.details
- attr_list
- md_in_html
- tables

theme:
name: material
palette:
- media: '(prefers-color-scheme: dark)'
scheme: slate
toggle:
icon: material/lightbulb-outline
name: Switch to light mode
- media: '(prefers-color-scheme: light)'
scheme: default
toggle:
icon: material/lightbulb-on-outline
name: Switch to dark mode
features:
- navigation.instant
- navigation.tracking
- navigation.tabs
- navigation.tabs.sticky
- navigation.sections
- navigation.expand
- navigation.indexes
- toc.integrate
- navigation.top
- content.code.annotate

plugins:
- search
- mkdocstrings

watch:
- fastclam

extra:
social:
- icon: fontawesome/brands/github
link: https://github.com/WGBH-MLA/FastCLAM
version:
provider: mike
Loading

0 comments on commit 9ea57de

Please sign in to comment.