Skip to content

Commit

Permalink
FEA: Add initial example service
Browse files Browse the repository at this point in the history
  • Loading branch information
cortadocodes committed Jan 15, 2025
1 parent 21cf177 commit 459630c
Show file tree
Hide file tree
Showing 18 changed files with 2,033 additions and 44 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/add-issues-to-octue-board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: add-issues-to-octue-board

on:
issues:
types: [opened, reopened, transferred]

jobs:
add-issues-to-octue-board:
runs-on: ubuntu-latest
steps:
- name: Add to Board
uses: actions/add-to-project@v0.5.0
with:
project-url: https://github.com/orgs/octue/projects/22
github-token: ${{ secrets.OCTUE_PROJECT_ISSUES_TOKEN }}
80 changes: 80 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# For most projects, this workflow file will not need changing; you simply need
# to commit it to your repository.
#
# You may wish to alter this file to override the set of languages analyzed,
# or to provide custom queries or build logic.
#
# ******** NOTE ********
# We have attempted to detect the languages in your repository. Please check
# the `language` matrix defined below to confirm you have the correct set of
# supported CodeQL languages.
#
name: "CodeQL"

on:
push:
branches: [ "main" ]

jobs:
analyze:
name: Analyze
# Runner size impacts CodeQL analysis time. To learn more, please see:
# - https://gh.io/recommended-hardware-resources-for-running-codeql
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: 'ubuntu-latest'

permissions:
# required for all workflows
security-events: write

# only required for workflows in private repositories
actions: read
contents: read

strategy:
fail-fast: false
matrix:
language: [ 'python' ]
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
# queries: security-extended,security-and-quality


# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v3

# ℹ️ Command-line programs to run using the OS shell.
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun

# If the Autobuild fails above, remove it and uncomment the following three lines.
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.

# - run: |
# echo "Run, Build Application using script"
# ./location_of_script_within_repo/buildscript.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release the package on merge into main

# Only trigger when a pull request into main branch is closed.
on:
pull_request:
types: [closed]
branches:
- main

jobs:
release:
# This job will only run if the PR has been merged (and not closed without merging).
if: "github.event.pull_request.merged == true && !contains(github.event.pull_request.head.message, 'skipci')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Poetry
uses: snok/install-poetry@v1.3.2

- name: Get package version
id: get-package-version
run: echo "PACKAGE_VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT

- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, no need to create your own.
with:
tag_name: ${{ steps.get-package-version.outputs.PACKAGE_VERSION }}
release_name: ${{ github.event.pull_request.title }}
body: ${{ github.event.pull_request.body }}
draft: false
prerelease: false
14 changes: 14 additions & 0 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: semantic

on:
push:
branches-ignore:
- main

jobs:
check-semantic-version:
if: "!contains(github.event.head_commit.message, 'skipci')"
uses: octue/workflows/.github/workflows/check-semantic-version.yml@main
with:
path: pyproject.toml
breaking_change_indicated_by: minor
18 changes: 18 additions & 0 deletions .github/workflows/update-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This workflow updates the pull request description with an auto-generated section containing the categorised commit
# message headers of the commits since the last pull request merged into main. The auto generated section is enveloped
# between two comments: "<!--- START AUTOGENERATED NOTES --->" and "<!--- END AUTOGENERATED NOTES --->". Anything
# outside these in the description is left untouched. Auto-generated updates can be skipped for a commit if
# "<!--- SKIP AUTOGENERATED NOTES --->" is added to the pull request description.

name: update-pull-request

on: [pull_request]

jobs:
description:
uses: octue/workflows/.github/workflows/generate-pull-request-description.yml@main
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
permissions:
contents: read
pull-requests: write
49 changes: 5 additions & 44 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
Expand Down Expand Up @@ -49,7 +50,6 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
Expand All @@ -72,7 +72,6 @@ instance/
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
Expand All @@ -83,9 +82,7 @@ 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
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand All @@ -94,30 +91,7 @@ ipython_config.py
# install all needed dependencies.
#Pipfile.lock

# UV
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
#uv.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

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

# Celery stuff
Expand Down Expand Up @@ -154,18 +128,5 @@ dmypy.json
# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# PyPI configuration file
.pypirc
.idea
.DS_store
58 changes: 58 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
exclude: "build|.git/|.tox|dist|octue.egg-info"
default_stages: [commit]
fail_fast: true
default_language_version:
python: python3 # force all unspecified python hooks to run python3
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
args: ["--line-length", "120"]

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
language_version: python3
additional_dependencies:
- "pep8-naming"
args:
- --ignore-names=setUp,tearDown,setUpClass,tearDownClass,asyncSetUp,asyncTearDown,setUpTestData,failureException,longMessage,maxDiff,startTestRun,stopTestRun

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier

- repo: https://github.com/pycqa/pydocstyle
rev: 6.1.1
hooks:
- id: pydocstyle

- repo: https://github.com/windpioneers/pre-commit-hooks
rev: 0.0.5
hooks:
- id: check-branch-name
args:
- "^main$"
- "^([a-z][a-z0-9]*)(-[a-z0-9]+)*$"

- repo: https://github.com/octue/conventional-commits
rev: 0.9.0
hooks:
- id: check-commit-message-is-conventional
stages: [commit-msg]
3 changes: 3 additions & 0 deletions app_configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"output_location": "gs://octue-sdk-python-test-bucket/example-service-kueue/outputs"
}
Empty file.
28 changes: 28 additions & 0 deletions example_service_kueue/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import logging
import os
import tempfile
import time

from octue.resources import Datafile, Dataset

from example_service_kueue.submodule import do_something


logger = logging.getLogger(__name__)


def run(analysis):
logger.info("Started example analysis.")
do_something()
time.sleep(2)
analysis.output_values = [1, 2, 3, 4, 5]

with tempfile.TemporaryDirectory() as temporary_directory:

with Datafile(os.path.join(temporary_directory, "output.dat"), mode="w") as (datafile, f):
f.write("This is some example service output.")

analysis.output_manifest.datasets["example_dataset"] = Dataset(path=temporary_directory, files={datafile})
analysis.finalise(upload_output_datasets_to=analysis.output_location)

logger.info("Finished example analysis.")
8 changes: 8 additions & 0 deletions example_service_kueue/submodule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import logging


logger = logging.getLogger(__name__)


def do_something():
logger.info("Submodules are included in logging.")
6 changes: 6 additions & 0 deletions octue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
- namespace: octue
name: example-service-kueue
app_source_path: example_service_kueue
app_configuration_path: app_configuration.json
event_store_table_id: octue_sdk_python_test_dataset.service-events
Loading

0 comments on commit 459630c

Please sign in to comment.