Skip to content
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

Convert project to use poetry and pre-commit #81

Merged
merged 7 commits into from
Jan 9, 2023
Merged
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
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
doctests = True
exclude = .venv,.git,.tox,dist,doc,build,__pycache__
max-line-length = 160
65 changes: 30 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,63 +12,58 @@ permissions:
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10', 'pypy3.9' ]
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Update version number
if: startsWith(github.ref, 'refs/tags/')
run: sed -i -e "s/0.0.0/${GITHUB_REF##*/}/" pyproject.toml
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install build tools
run: python3 -m pip install --upgrade build
- name: Install
run: pip install -r requirements.txt
- name: Install sphinx
run: |
pip install sphinx
pip install sphinx-rtd-theme
- name: Check with pyflakes
- name: Check isort, black, and flake8
run: |
pip install pyflakes
pyflakes `find . -name "*.py"`
- name: Install coverage
run: pip install coverage
- name: Test
pip install black flake8 isort
isort --profile black .
black .
flake8 .
- name: Install Python Poetry
uses: snok/install-poetry@v1.3.3
- name: Install project dependencies
run: poetry install --no-interaction --with dev
- name: Run tests with coverage
run: |
python3 -m coverage run -a -m unittest discover -v src
- name: Document
run: |
sphinx-apidoc -o docs/ -f -a -e src/ --doc-project "Python SDK for Arcaflow"
make -C docs html
- name: Run example plugin
run: python3 -m coverage run -a ./example_plugin.py -f example.yaml
- name: Run example plugin test
run: python3 -m coverage run -a ./test_example_plugin.py
- name: Collect coverage report
run: |
python3 -m coverage html
# Run the unit tests
poetry run python3 -m coverage run -a -m unittest discover -v src
# Run the example plugin
poetry run python3 -m coverage run -a ./example_plugin.py -f example.yaml
# Test the example plugin
poetry run python3 -m coverage run -a ./test_example_plugin.py
# Generate the coverage HTML report
poetry run python3 -m coverage html
- name: Publish coverage report to job summary
# publishing only once
if: ${{ matrix.python-version == '3.9'}}
run: |
pip install html2text
html2text --ignore-images --ignore-links -b 0 htmlcov/index.html >> $GITHUB_STEP_SUMMARY
- name: Update version number
if: startsWith(github.ref, 'refs/tags/')
run: sed -i -e "s/0.0.0/${GITHUB_REF##*/}/" pyproject.toml
poetry run html2text --ignore-images --ignore-links -b 0 htmlcov/index.html >> $GITHUB_STEP_SUMMARY
- name: Generate documentation
run: |
poetry run sphinx-apidoc -o docs/ -f -a -e src/ --doc-project "Python SDK for Arcaflow"
poetry run make -C docs html
- name: Build
run: python3 -m build
- name: Upload artifacts
run: poetry build
- name: Upload dist artifact
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
if-no-files-found: error
- name: Upload artifacts
- name: Upload coverage HTML artifact
uses: actions/upload-artifact@v3
with:
name: coverage
Expand Down
41 changes: 41 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-toml
- repo: https://github.com/python/black
rev: 22.3.0
hooks:
- id: black
name: black (python3)
language_version: python3
args: ["--check"]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python3)
language_version: python3
args: ["--check", "--profile=black"]
- repo: https://github.com/python-poetry/poetry
rev: 1.2.2
hooks:
- id: poetry-check
- id: poetry-lock
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.4
hooks:
- id: shellcheck
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.32.2
hooks:
- id: markdownlint
27 changes: 11 additions & 16 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,32 @@
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

import sys
sys.path.insert(0, '/home/sbonazzo/NotBackedUp/upstream/arcaflow-plugin-sdk-python/src')

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'Python SDK for Arcaflow'
copyright = '2022, Arcalot Authors'
author = 'Arcalot Authors'
project = "Python SDK for Arcaflow"
copyright = "2022, Arcalot Authors"
author = "Arcalot Authors"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.viewcode',
'sphinx.ext.todo',
"sphinx.ext.autodoc",
"sphinx.ext.viewcode",
"sphinx.ext.todo",
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

language = 'en'
language = "en"

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]

# -- Options for todo extension ----------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/extensions/todo.html#configuration
Expand Down
49 changes: 32 additions & 17 deletions example_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
import sys
import typing
from dataclasses import dataclass
from arcaflow_plugin_sdk import plugin, validation, annotations, schema

from arcaflow_plugin_sdk import annotations, plugin, schema, validation


@dataclass
class FullName:
"""
A full name holds the first and last name of an individual.
"""

first_name: typing.Annotated[
str,
validation.min(1),
Expand Down Expand Up @@ -38,6 +40,7 @@ class Nickname:
"""
A nickname is a simplified form of the name that only holds the preferred name of an individual.
"""

nick: typing.Annotated[
str,
validation.min(1),
Expand All @@ -58,6 +61,7 @@ class InputParams:
"""
This is the data structure for the input parameters of the step defined below.
"""

name: typing.Annotated[
typing.Union[
typing.Annotated[
Expand All @@ -74,15 +78,19 @@ class InputParams:
schema.name("Name"),
schema.description("Who do we say hello to?"),
annotations.discriminator("_type"),
schema.example({
"_type": "fullname",
"first_name": "Arca",
"last_name": "Lot",
}),
schema.example({
"_type": "nickname",
"nick": "Arcalot",
}),
schema.example(
{
"_type": "fullname",
"first_name": "Arca",
"last_name": "Lot",
}
),
schema.example(
{
"_type": "nickname",
"nick": "Arcalot",
}
),
]


Expand All @@ -91,6 +99,7 @@ class SuccessOutput:
"""
This is the output data structure for the success case.
"""

message: str


Expand All @@ -99,6 +108,7 @@ class ErrorOutput:
"""
This is the output data structure in the error case.
"""

error: str


Expand All @@ -110,7 +120,9 @@ class ErrorOutput:
description="Says hello :)",
outputs={"success": SuccessOutput, "error": ErrorOutput},
)
def hello_world(params: InputParams) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
def hello_world(
params: InputParams,
) -> typing.Tuple[str, typing.Union[SuccessOutput, ErrorOutput]]:
"""
The function is the implementation for the step. It needs the decorator above to make it into a step. The type
hints for the params are required.
Expand All @@ -120,12 +132,15 @@ def hello_world(params: InputParams) -> typing.Tuple[str, typing.Union[SuccessOu
:return: the string identifying which output it is, as well the output structure
"""

return "success", SuccessOutput(
"Hello, {}!".format(params.name))
return "success", SuccessOutput("Hello, {}!".format(params.name))


if __name__ == "__main__":
sys.exit(plugin.run(plugin.build_schema(
# List your step functions here:
hello_world,
)))
sys.exit(
plugin.run(
plugin.build_schema(
# List your step functions here:
hello_world,
)
)
)
Loading