generated from tercen/template-python-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 08297a0
Showing
16 changed files
with
5,099 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
renv/library/ | ||
renv/local/ | ||
renv/lock/ | ||
renv/python/ | ||
renv/staging/ | ||
|
||
test | ||
tests | ||
workflow_tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: CI Workflow | ||
|
||
on: | ||
push: | ||
branches: ['main'] | ||
|
||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. | ||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: read | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
# | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/[email protected] | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# A PAT is needed for this action, GITHUB_TOKEN cannot get relevant permission | ||
# secrets: | | ||
# github_pat=${{ secrets.GH_PAT }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Release Workflow | ||
|
||
on: | ||
push: | ||
tags: | ||
- '[0-9]+.[0-9]+.[0-9]+' # Push events to any matching semantic tag. For example, 1.10.1 or 2.0.0. | ||
|
||
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. | ||
env: | ||
REGISTRY: ghcr.io | ||
IMAGE_NAME: ${{ github.repository }} | ||
|
||
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. | ||
jobs: | ||
build-and-push-image: | ||
runs-on: ubuntu-latest | ||
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. | ||
permissions: | ||
contents: write | ||
packages: write | ||
attestations: write | ||
id-token: write | ||
# | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Update container in operator JSON | ||
run: | | ||
jq --arg variable "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" '.container = $variable' operator.json | ||
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. | ||
- name: Log in to the Container registry | ||
uses: docker/[email protected] | ||
with: | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. | ||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/[email protected] | ||
with: | ||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | ||
tags: | | ||
# minimal | ||
type=pep440,pattern={{version}} | ||
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. | ||
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. | ||
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/[email protected] | ||
with: | ||
context: . | ||
push: true | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
# A PAT is needed for this action, GITHUB_TOKEN cannot get relevant permission | ||
# secrets: | | ||
# github_pat=${{ secrets.GH_PAT }} | ||
- name: Create required package.json | ||
run: echo '{}' > package.json | ||
- name: Build changelog | ||
id: Changelog | ||
uses: tercen/generate-changelog-action@master | ||
- name: Create release | ||
id: create_release | ||
uses: actions/create-release@latest | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
body: ${{steps.Changelog.outputs.changelog}} | ||
draft: false | ||
prerelease: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.Rproj.user | ||
.Rhistory | ||
.RData | ||
.Ruserdata | ||
.idea | ||
venv/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["ms-python.python", "ms-toolsai.jupyter"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"python": "/config/.pyenv/versions/3.9.0/bin/python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal", | ||
"justMyCode": true, | ||
"env": { "PYTHONPATH": "${workspaceRoot}"} | ||
|
||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM tercen/runtime-python39:0.1.0 | ||
|
||
COPY . /operator | ||
WORKDIR /operator | ||
|
||
ENV PYTHONPATH "${PYTHONPATH}:~/.pyenv/versions/3.9.0/bin/python3" | ||
RUN python3 -m pip install -r ./requirements.txt | ||
|
||
ENV TERCEN_SERVICE_URI https://tercen.com | ||
|
||
ENTRYPOINT ["python3", "main.py"] | ||
CMD ["--taskId", "someid", "--serviceUri", "https://tercen.com", "--token", "sometoken"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
# Template Python Operator | ||
|
||
Cell-wise mean calculated implemented in Python. | ||
|
||
## Python operator - Development workflow | ||
|
||
* Set up [the Tercen Studio development environment](https://github.com/tercen/tercen_studio) | ||
* Create a new git repository based on the [template Python operator](https://github.com/tercen/template-python-operator) | ||
* Open VS Code Server by going to: http://127.0.0.1:8443 | ||
* Clone this repository into VS Code (using the 'Clone from GitHub' command from the Command Palette for example) | ||
* Load the environment and install core requirements by running the following commands in the terminal: | ||
|
||
```bash | ||
source /config/.pyenv/versions/3.9.0/bin/activate | ||
pip install -r requirements.txt | ||
``` | ||
|
||
* Develop your operator. Note that you can interact with an existing data step by specifying arguments to the `TercenContext` function: | ||
|
||
```python | ||
tercenCtx = ctx.TercenContext() | ||
``` | ||
|
||
```python | ||
tercenCtx = ctx.TercenContext( | ||
workflowId="YOUR_WORKFLOW_ID", | ||
stepId="YOUR_STEP_ID", | ||
username="admin", # if using the local Tercen instance | ||
password="admin", # if using the local Tercen instance | ||
serviceUri = "http://tercen:5400/" # if using the local Tercen instance | ||
) | ||
``` | ||
|
||
* Generate requirements | ||
|
||
```bash | ||
python3 -m tercen.util.requirements . > requirements.txt | ||
``` | ||
|
||
* Push your changes to GitHub: triggers CI GH workflow | ||
* Tag the repository: triggers Release GH workflow | ||
* Go to tercen and install your operator | ||
|
||
|
||
## Helpful Commands | ||
|
||
### Install Tercen Python Client | ||
|
||
```bash | ||
python3 -m pip install --force git+https://github.com/tercen/[email protected] | ||
``` | ||
|
||
### Wheel | ||
|
||
Though not strictly mandatory, many packages require it. | ||
|
||
```bash | ||
python3 -m pip install wheel | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from tercen.client import context as ctx | ||
import numpy as np | ||
|
||
tercenCtx = ctx.TercenContext() | ||
|
||
df = ( | ||
tercenCtx | ||
.select(['.y', '.ci', '.ri'], df_lib="pandas") | ||
.groupby(['.ci','.ri'], as_index=False) | ||
.mean() | ||
.rename(columns={".y":"mean"}) | ||
.astype({".ci": np.int32, ".ri": np.int32}) | ||
) | ||
|
||
df = tercenCtx.add_namespace(df) | ||
tercenCtx.save(df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "Template Python operator", | ||
"description": "Mean operator implemented in Python", | ||
"tags": ["template"], | ||
"authors": ["tercen"], | ||
"urls": ["https://github.com/tercen/template-python-operator"], | ||
"container":"ghcr.io/tercen/template-python-operator:latest", | ||
"properties": [ | ||
{ | ||
"kind": "DoubleProperty", | ||
"name": "Property1", | ||
"defaultValue": 42.0, | ||
"description": "Example Double Property" | ||
}, | ||
{ | ||
"kind": "StringProperty", | ||
"name": "Property2", | ||
"defaultValue": "42", | ||
"description": "Example String Property" | ||
}, | ||
{ | ||
"kind": "BooleanProperty", | ||
"name": "Property3", | ||
"defaultValue": true, | ||
"description": "Example Boolean Property" | ||
}, | ||
{ | ||
"kind": "EnumeratedProperty", | ||
"isSingleSelection":true, | ||
"name": "Property4", | ||
"defaultValue": "element2", | ||
"values": ["element1", "element2", "element3"], | ||
"description": "Example Enumerated Property" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
git+https://github.com/tercen/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
".ci",".ri","ds0.mean" | ||
0,0,20728.444444444445 | ||
0,1,21271.853658536584 | ||
0,3,20552.3153638814 | ||
1,0,20162.29411764706 | ||
1,1,16876.354166666668 | ||
1,2,7086.0 | ||
1,3,19007.806094182826 | ||
2,0,18338.166666666668 | ||
2,1,5464.103896103896 | ||
2,2,2256.0841121495328 | ||
2,3,5343.584082156611 | ||
3,0,21081.26595744681 | ||
3,1,14656.041958041958 | ||
3,2,6559.210526315789 | ||
3,3,16740.50725416443 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"Rating.Imaging" | ||
"Above" | ||
"Below" | ||
"None" | ||
"Same" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"Rating.Effectiveness" | ||
"Above" | ||
"Below" | ||
"None" | ||
"Same" |
Oops, something went wrong.