-
Notifications
You must be signed in to change notification settings - Fork 0
feat(pre-commit): adds pre-commit linting, yaml-compliance checking, … #10
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
Open
Matt-Carre
wants to merge
4
commits into
main
Choose a base branch
from
pre-commit-check-yaml
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3636ca1
feat(pre-commit): adds linting and diamond compliance checks to pre-c…
Matt-Carre 078b788
fix(pre-commit): moves scripts to /scripts folder
Matt-Carre 5772f7f
fix(pre-commit): adds better error messages
Matt-Carre 4bdce37
fix(pre-commit): updates based on other comments
Matt-Carre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -69,3 +69,6 @@ lockfiles/ | |
|
|
||
| # ruff cache | ||
| .ruff_cache/ | ||
|
|
||
| # environment variables file | ||
| *.env | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,66 @@ | ||
| apiVersion: argoproj.io/v1alpha1 | ||
| kind: ClusterWorkflowTemplate | ||
| metadata: | ||
| generateName: hera-division- | ||
| annotations: | ||
| workflows.argoproj.io/description: |- | ||
| Takes a numerical input and returns the | ||
| remainder, output float, and output string to a json file | ||
| workflows.argoproj.io/title: Division via hera test | ||
| workflows.diamond.ac.uk/repository: https://github.com/DiamondLightSource/python-interface-to-workflows | ||
| labels: | ||
| workflows.diamond.ac.uk/science-group-examples: 'true' | ||
| spec: | ||
| entrypoint: divide | ||
| templates: | ||
| - name: divide | ||
| steps: | ||
| - - name: first | ||
| template: do-devision | ||
| arguments: | ||
| parameters: | ||
| - name: a | ||
| value: '2' | ||
| - name: b | ||
| value: '5' | ||
| - name: do-devision | ||
| inputs: | ||
| parameters: | ||
| - name: a | ||
| - name: b | ||
| outputs: | ||
| artifacts: | ||
| - name: json-output | ||
| path: /output-dir/output.json | ||
| script: | ||
| image: None | ||
| source: |- | ||
| import os | ||
| import sys | ||
| sys.path.append(os.getcwd()) | ||
| import json | ||
| try: a = json.loads(r'''{{inputs.parameters.a}}''') | ||
| except: a = r'''{{inputs.parameters.a}}''' | ||
| try: b = json.loads(r'''{{inputs.parameters.b}}''') | ||
| except: b = r'''{{inputs.parameters.b}}''' | ||
|
|
||
| div = a / b | ||
| intdiv = a // b | ||
| remain = a % b | ||
| dictionary_of_results = {'divide': div, 'integer divisor': intdiv, 'remainder': remain} | ||
| with open('/output-dir/output.json', 'w') as otpt: | ||
| json.dump(dictionary_of_results, otpt) | ||
| command: | ||
| - python | ||
| volumeMounts: | ||
| - name: output-dir | ||
| mountPath: /output-dir/ | ||
| volumeClaimTemplates: | ||
| - metadata: | ||
| name: output-dir | ||
| spec: | ||
| accessModes: | ||
| - ReadWriteOnce | ||
| resources: | ||
| requests: | ||
| storage: 1Mi |
This file contains hidden or 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
This file contains hidden or 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,53 @@ | ||
| #!/bin/python | ||
| import os | ||
| import re | ||
|
|
||
| yamlpath = "src/python_interface_to_workflows/templates/" | ||
| yamllist: list[str] = [] | ||
| for x in os.listdir(yamlpath): | ||
| if x.endswith(".yaml"): | ||
| yamllist.append(x) | ||
|
|
||
| for file in yamllist: | ||
| z = 0 | ||
| with open(yamlpath + file) as s: | ||
| filelist = s.readlines() | ||
| cleanfilenames: list[str] = [] | ||
| for line in filelist: | ||
| line = line.rstrip() | ||
| cleanfilenames.append(line) | ||
| api_ver = any( | ||
| re.search(r"apiVersion:\sargoproj\.io\/v1alpha1", line) | ||
| for line in cleanfilenames | ||
| ) | ||
| # replace regex with r"kind:\sClusterWorkflowTemplate" on graphql | ||
| clst_tmpt = any(re.search(r"kind:\sWorkflow", line) for line in cleanfilenames) | ||
| title = any( | ||
| re.search(r"\s\s\s\sworkflows.argoproj.io/title:\s.+", line) | ||
| for line in cleanfilenames | ||
| ) | ||
| repo = any( | ||
| re.search(r"\s\s\s\sworkflows.diamond.ac.uk/repository:\s.+", line) | ||
| for line in cleanfilenames | ||
| ) | ||
| group = any( | ||
| re.search(r"\s\s\s\sworkflows.diamond.ac.uk/science-group-.+:\s.+", line) | ||
| for line in cleanfilenames | ||
| ) | ||
| gen_name = any(re.search(r"\s\sgenerateName:\s.+", line) for line in cleanfilenames) | ||
| normal_name = any(re.search(r"^\s\sname:\s.+", line) for line in cleanfilenames) | ||
| if api_ver and clst_tmpt and title and repo and group: | ||
| if gen_name != normal_name: | ||
| exit(0) | ||
| else: | ||
| print( | ||
| "generated_name and normal_name error, must have one of these not both" | ||
| ) | ||
| exit(1) | ||
| else: | ||
| print(f"""api_ver present?: {api_ver} | ||
| cluster template present?: {clst_tmpt} | ||
| title present?: {title} | ||
| repository present?: {repo} | ||
| group present?: {group}""") | ||
| exit(1) |
This file contains hidden or 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 @@ | ||
| #!/bin/bash | ||
| cd src/python_interface_to_workflows/templates | ||
| for file in * | ||
| do | ||
| argo lint "$file" --offline | ||
| SUCCESSFULLINT=$? | ||
| [ $SUCCESSFULLINT -ne 0 ] && exit 1 | ||
| done | ||
| exit 0 |
This file contains hidden or 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,8 @@ | ||
| #!/bin/bash | ||
| cd src/python_interface_to_workflows/workflow_definitions | ||
| for file in * | ||
| do | ||
| uv run "$file" | ||
| done | ||
| mv *.yaml ../templates/ | ||
| git add -u ../templates/ |
|
Matt-Carre marked this conversation as resolved.
|
This file contains hidden or 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,4 @@ | ||
| "HOST" = "https://argo-workflows.staging.workflows.diamond.ac.uk/" | ||
| "IMAGE" = "python:3.10" | ||
| "TOKEN" = "Token" | ||
| "NAMESPACE" = "ks10000-3" |
File renamed without changes.
This file contains hidden or 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
60 changes: 60 additions & 0 deletions
60
src/python_interface_to_workflows/templates/divisionyaml.yaml
This file contains hidden or 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,60 @@ | ||
| apiVersion: argoproj.io/v1alpha1 | ||
| kind: Workflow | ||
| metadata: | ||
| generateName: hera-division- | ||
| annotations: | ||
| workflows.argoproj.io/description: |- | ||
| Takes a numerical input and returns the | ||
| remainder, output float, and output string to a json file | ||
| workflows.argoproj.io/title: Division via hera test | ||
| workflows.diamond.ac.uk/repository: https://github.com/DiamondLightSource/python-interface-to-workflows | ||
| labels: | ||
| workflows.diamond.ac.uk/science-group-examples: 'true' | ||
| spec: | ||
| entrypoint: divide | ||
| templates: | ||
| - name: divide | ||
| steps: | ||
| - - name: first | ||
| template: do-division | ||
| arguments: | ||
| parameters: | ||
| - name: a | ||
| value: '2' | ||
| - name: b | ||
| value: '5' | ||
| - name: do-division | ||
| inputs: | ||
| parameters: | ||
| - name: a | ||
| - name: b | ||
| outputs: | ||
| artifacts: | ||
| - name: json-output | ||
| path: /output-dir/output.json | ||
| script: | ||
| image: None | ||
| source: |- | ||
| import os | ||
| import sys | ||
| sys.path.append(os.getcwd()) | ||
| import json | ||
| try: a = json.loads(r'''{{inputs.parameters.a}}''') | ||
| except: a = r'''{{inputs.parameters.a}}''' | ||
| try: b = json.loads(r'''{{inputs.parameters.b}}''') | ||
| except: b = r'''{{inputs.parameters.b}}''' | ||
|
|
||
| div = a / b | ||
| intdiv = a // b | ||
| remain = a % b | ||
| dictionary_of_results = {'divide': div, 'quotient': intdiv, 'remainder': remain} | ||
| with open('/output-dir/output.json', 'w') as otpt: | ||
| json.dump(dictionary_of_results, otpt) | ||
| command: | ||
| - python | ||
| volumeMounts: | ||
| - name: output-dir | ||
| mountPath: /output-dir/ | ||
| volumes: | ||
| - name: output-dir | ||
| emptyDir: {} |
59 changes: 59 additions & 0 deletions
59
src/python_interface_to_workflows/workflow_definitions/create_division_yaml.py
This file contains hidden or 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,59 @@ | ||
| import json | ||
| import os | ||
|
|
||
| from hera.shared import global_config | ||
| from hera.workflows import ( | ||
| Artifact, | ||
| EmptyDirVolume, | ||
| Steps, | ||
| Workflow, | ||
| script, # pyright: ignore[reportUnknownVariableType] | ||
| ) | ||
| from hera.workflows import models as m | ||
|
|
||
| global_config.host = os.environ.get("HOST") | ||
| global_config.image = str(os.environ.get("IMAGE")) | ||
| global_config.token = os.environ.get("TOKEN") | ||
|
|
||
|
|
||
| @script( | ||
| volume_mounts=[m.VolumeMount(name="output-dir", mount_path="/output-dir/")], | ||
|
Matt-Carre marked this conversation as resolved.
|
||
| outputs=Artifact(name="json-output", path="/output-dir/output.json"), | ||
| ) | ||
| def do_division(a: int, b: int): | ||
| div = a / b | ||
| intdiv = a // b | ||
| remain = a % b | ||
| dictionary_of_results = { | ||
| "divide": div, | ||
| "quotient": intdiv, | ||
| "remainder": remain, | ||
| } | ||
| with open("/output-dir/output.json", "w") as otpt: | ||
| json.dump(dictionary_of_results, otpt) | ||
|
|
||
|
|
||
| with Workflow( | ||
| generate_name="hera-division-", # when running on graphql this should be name | ||
| entrypoint="divide", | ||
| namespace=os.environ.get("NAMESPACE"), | ||
| api_version="argoproj.io/v1alpha1", | ||
| kind="Workflow", # ClusterWorkflowTemplate", when on graphql | ||
| labels={"workflows.diamond.ac.uk/science-group-examples": "true"}, | ||
| annotations={ | ||
| "workflows.argoproj.io/title": "Division via hera test", | ||
| "workflows.argoproj.io/description": """Takes a numerical input and returns the | ||
| remainder, output float, and output string to a json file""", | ||
| "workflows.diamond.ac.uk/repository": "https://github.com/DiamondLightSource/python-interface-to-workflows", | ||
| }, | ||
| volumes=EmptyDirVolume(name="output-dir", mount_path="/output-dir"), | ||
| ) as w: | ||
| with Steps(name="divide"): | ||
| do_division(name="first", arguments={"a": 2, "b": 5}) | ||
|
|
||
|
|
||
| with open("divisionyaml.yaml", "w") as div: | ||
| div.write(w.to_yaml()) # pyright: ignore[reportUnknownMemberType] | ||
|
|
||
|
|
||
| # w.create() | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.