Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/_dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ jobs:

- name: Test module --version works using the installed wheel
# If more than one module in src/ replace with module name to test
run: python -m $(ls --hide='*.egg-info' src | head -1) --version
run: python -m $(ls --hide='*.egg-info' --hide='copier_template' src | head -1) --version
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ lockfiles/

# environment variables file
*.env

# Python version
.python-version
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ repos:
entry: ruff check --force-exclude --fix
types: [python]
require_serial: true
exclude: ^src/copier_template/src/\{\{ project_name \}\}/

- id: create-workflow-templates
name: creates workflow templates
Expand All @@ -41,6 +42,13 @@ repos:
pass_filenames: true
require_serial: true

- id: update-copy-template
name: ensure copy template contains all templates
language: system
entry: bash scripts/makecopiercorrect.sh
pass_filenames: false
require_serial: true

- id: ruff-format
name: format with ruff
language: system
Expand Down
2 changes: 1 addition & 1 deletion catalog-info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Component
metadata:
name: python-interface-to-workflows
title: python-interface-to-workflows
description: Python alternative to creating and running argo workflows in the Data Analysis Platform
description: Python alternative to creating and running argo workflows in the Data Analysis Platform
spec:
type: service
lifecycle: experimental
Expand Down
40 changes: 40 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# questions
project_name:
type: str
help: What is the name for your project?
validator: >-
{% if not (project_name | regex_search('^[a-z_][a-z0-9_]*$')) %}
{{project_name}} is not a valid ruff-compatible python package name
{% endif %}

repo_name:
type: str
help: |
What is the name for your new repo?
Generally, use the package name with underscores replaced by dashes.
default: "{{ project_name | replace('_', '-') }}"
validator: >-
{% if not (repo_name | regex_search('^[a-zA-Z0-9](?:[a-zA-Z0-9_.-]*[a-zA-Z0-9])?$')) %}
{{ repo_name }} is not a valid repo name
{% endif %}
description:
type: str
help: Please provide a description of your project
placeholder: One line description of your module

github_org:
type: str
help: What is your github organisation?
default: DiamondLightSource

author_name:
type: str
help: What is your full name?
placeholder: FirstName LastName

author_email:
type: str
help: What is your email address?
placeholder: email@diamond.ac.uk

_subdirectory: "src/copier_template"
23 changes: 23 additions & 0 deletions scripts/makecopiercorrect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
cd "src/python_interface_to_workflows/workflow_definitions"

cp *.py "../../copier_template/src/{{ project_name }}/workflow_definitions"
cp ../templates/*.yaml "../../copier_template/src/{{ project_name }}/templates"

for file in "../../copier_template/src/{{ project_name }}/workflow_definitions"/*
do
[[ $file == *.jinja ]] && continue
sed -i 's/python-interface-to-workflows/{{repo_name}}/g' "$file"
sed -i 's/DiamondLightSource/{{github_org}}/g' "$file"
mv "$file" "$file.jinja"
done

for file in "../../copier_template/src/{{ project_name }}/templates"/*
do
[[ $file == *.jinja ]] && continue
sed -i 's/python-interface-to-workflows/{{repo_name}}/g' "$file"
sed -i 's/DiamondLightSource/{{github_org}}/g' "$file"
mv "$file" "$file.jinja"
done
git add "../../copier_template/src/{{ project_name }}/workflow_definitions"/*
git add "../../copier_template/src/{{ project_name }}/templates"/*
75 changes: 75 additions & 0 deletions src/copier_template/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// For format details, see https://containers.dev/implementors/json_reference/
{
"name": "Python 3 Developer Container",
"build": {
"dockerfile": "../Dockerfile",
"target": "developer"
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}",
// Put things that allow it in the persistent cache
"PRE_COMMIT_HOME": "/cache/pre-commit",
"UV_CACHE_DIR": "/cache/uv",
"UV_PYTHON_CACHE_DIR": "/cache/uv-python",
// Make a venv that is specific for this workspace path as the cache is shared
"UV_PROJECT_ENVIRONMENT": "/cache/venv-for${localWorkspaceFolder}",
// Do the equivalent of "activate" the venv so we don't have to "uv run" everything
"VIRTUAL_ENV": "/cache/venv-for${localWorkspaceFolder}",
"PATH": "/cache/venv-for${localWorkspaceFolder}/bin:${containerEnv:PATH}"
},
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
// Use the container's python by default
"python.defaultInterpreterPath": "/cache/venv-for${localWorkspaceFolder}/bin/python",
// Don't activate the venv as it is already in the PATH
"python.terminal.activateEnvInCurrentTerminal": false,
"python.terminal.activateEnvironment": false,
// Workaround to prevent garbled python REPL in the terminal
// https://github.com/microsoft/vscode-python/issues/25505
"python.terminal.shellIntegration.enabled": false
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"github.vscode-github-actions",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"charliermarsh.ruff",
"ms-azuretools.vscode-docker"
]
}
},
// Create the config folder for the bash-config feature and uv cache
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/terminal-config",
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
// "--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
"--security-opt=label=disable"
],
"forwardPorts": [
5173
],
"mounts": [
// Mount in the user terminal config folder so it can be edited
{
"source": "${localEnv:HOME}/.config/terminal-config",
"target": "/user-terminal-config",
"type": "bind"
},
// Keep a persistent cross container cache for uv, pre-commit, and the venvs
{
"source": "devcontainer-shared-cache",
"target": "/cache",
"type": "volume"
}
],
// Mount the parent as /workspaces so we can pip install peers as editable
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, recreate the venv then make pre-commit first run faster
"postCreateCommand": "uv venv --clear && uv sync && pre-commit install --install-hooks"
}
27 changes: 27 additions & 0 deletions src/copier_template/.github/CONTRIBUTING.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Contribute to the project

Contributions and issues are most welcome! All issues and pull requests are
handled through [GitHub](https://github.com/{{github_org}}/{{repo_name}}/issues). Also, please check for any existing issues before
filing a new one. If you have a great idea but it involves big changes, please
file a ticket before making a pull request! We want to make sure you don't spend
your time coding something that might not fit the scope of the project.

## Issue or Discussion?

Github also offers [discussions](https://github.com/{{github_org}}/{{repo_name}}/discussions) as a place to ask questions and share ideas. If
your issue is open ended and it is not obvious when it can be "closed", please
raise it as a discussion instead.

## Code Coverage

While 100% code coverage does not make a library bug-free, it significantly
reduces the number of easily caught bugs! Please make sure coverage remains the
same or is improved by a pull request!

## Developer Information

It is recommended that developers use a [vscode devcontainer](https://code.visualstudio.com/docs/devcontainers/containers). This repository contains configuration to set up a containerized development environment that suits its own needs.

This project was created using the [Diamond Light Source Workflow Copier Template](https://github.com/DiamondLightSource/python-interface-to-workflows) for Python projects.

For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/5.1.0/how-to.html).
21 changes: 21 additions & 0 deletions src/copier_template/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Bug Report
about: The template to use for reporting bugs and usability issues
title: " "
labels: 'bug'
assignees: ''

---

Describe the bug, including a clear and concise description of the expected behaviour, the actual behavior and the context in which you encountered it (ideally include details of your environment).

## Steps To Reproduce
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error


## Acceptance Criteria
- Specific criteria that will be used to judge if the issue is fixed
13 changes: 13 additions & 0 deletions src/copier_template/.github/ISSUE_TEMPLATE/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: Issue
about: The standard template to use for feature requests, design discussions and tasks
title: " "
labels: ''
assignees: ''

---

A brief description of the issue, including specific stakeholders and the business case where appropriate

## Acceptance Criteria
- Specific criteria that will be used to judge if the issue is fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Fixes #ISSUE

### Instructions to reviewer on how to test:
1. Do thing x
2. Confirm thing y happens

### Checks for reviewer
- [ ] Would the PR title make sense to a user on a set of release notes
11 changes: 11 additions & 0 deletions src/copier_template/.github/pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>

<head>
<title>Redirecting to main branch</title>
<meta charset="utf-8">
<meta http-equiv="refresh" content="0; url=./main/index.html">
<link rel="canonical" href="main/index.html">
</head>

</html>
96 changes: 96 additions & 0 deletions src/copier_template/.github/pages/make_switcher.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""Make switcher.json to allow docs to switch between different versions."""

import json
import logging
from argparse import ArgumentParser
from pathlib import Path
from subprocess import CalledProcessError, check_output


def report_output(stdout: bytes, label: str) -> list[str]:
"""Print and return something received frm stdout."""
ret = stdout.decode().strip().split("\n")
print(f"{label}: {ret}")
return ret


def get_branch_contents(ref: str) -> list[str]:
"""Get the list of directories in a branch."""
stdout = check_output(["git", "ls-tree", "-d", "--name-only", ref])
return report_output(stdout, "Branch contents")


def get_sorted_tags_list() -> list[str]:
"""Get a list of sorted tags in descending order from the repository."""
stdout = check_output(["git", "tag", "-l", "--sort=-v:refname"])
return report_output(stdout, "Tags list")


def get_versions(ref: str, add: str | None) -> list[str]:
"""Generate the file containing the list of all GitHub Pages builds."""
# Get the directories (i.e. builds) from the GitHub Pages branch
try:
builds = set(get_branch_contents(ref))
except CalledProcessError:
builds = set()
logging.warning(f"Cannot get {ref} contents")

# Add and remove from the list of builds
if add:
builds.add(add)

# Get a sorted list of tags
tags = get_sorted_tags_list()

# Make the sorted versions list from main branches and tags
versions: list[str] = []
for version in ["master", "main"] + tags:
if version in builds:
versions.append(version)
builds.remove(version)

# Add in anything that is left to the bottom
versions += sorted(builds)
print(f"Sorted versions: {versions}")
return versions


def write_json(path: Path, repository: str, versions: list[str]):
"""Write the JSON switcher to path."""
org, repo_name = repository.split("/")
struct = [
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
for version in versions
]
text = json.dumps(struct, indent=2)
print(f"JSON switcher:\n{text}")
path.write_text(text, encoding="utf-8")


def main(args=None):
"""Parse args and write switcher."""
parser = ArgumentParser(
description="Make a versions.json file from gh-pages directories"
)
parser.add_argument(
"--add",
help="Add this directory to the list of existing directories",
)
parser.add_argument(
"repository",
help="The GitHub org and repository name: ORG/REPO",
)
parser.add_argument(
"output",
type=Path,
help="Path of write switcher.json to",
)
args = parser.parse_args(args)

# Write the versions file
versions = get_versions("origin/gh-pages", args.add)
write_json(args.output, args.repository, versions)


if __name__ == "__main__":
main()
18 changes: 18 additions & 0 deletions src/copier_template/.github/workflows/_commit_msg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: commit-lint

on:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Lint Commit Messages
uses: wagoid/commitlint-github-action@v6.2.1
with:
failonWarnings: true
Loading