Skip to content

Commit 9c632b2

Browse files
authored
Merge pull request #2 from DiamondLightSource/copier
Update to Copier Template
2 parents e868f36 + 20176a7 commit 9c632b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1640
-460
lines changed

.copier-answers.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changes here will be overwritten by Copier
2+
_commit: 4.2.0
3+
_src_path: https://github.com/diamondlightsource/python-copier-template
4+
author_email: [email protected]
5+
author_name: Giles Knap
6+
component_lifecycle: production
7+
component_owner: group:default/controls
8+
component_type: service
9+
description: A Diamond Light Source specific developer container
10+
distribution_name: dev-c7
11+
docker: true
12+
docker_debug: false
13+
docs_type: sphinx
14+
git_platform: github.com
15+
github_org: DiamondLightSource
16+
package_name: dev_c7
17+
pypi: false
18+
repo_name: dev-c7
19+
strict_typing: false
20+
type_checker: pyright

.devcontainer/devcontainer.json

Lines changed: 0 additions & 43 deletions
This file was deleted.

.github/CONTRIBUTING.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Contribute to the project
2+
3+
Contributions and issues are most welcome! All issues and pull requests are
4+
handled through [GitHub](https://github.com/DiamondLightSource/dev-c7/issues). Also, please check for any existing issues before
5+
filing a new one. If you have a great idea but it involves big changes, please
6+
file a ticket before making a pull request! We want to make sure you don't spend
7+
your time coding something that might not fit the scope of the project.
8+
9+
## Issue or Discussion?
10+
11+
Github also offers [discussions](https://github.com/DiamondLightSource/dev-c7/discussions) as a place to ask questions and share ideas. If
12+
your issue is open ended and it is not obvious when it can be "closed", please
13+
raise it as a discussion instead.
14+
15+
## Code Coverage
16+
17+
While 100% code coverage does not make a library bug-free, it significantly
18+
reduces the number of easily caught bugs! Please make sure coverage remains the
19+
same or is improved by a pull request!
20+
21+
## Developer Information
22+
23+
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.
24+
25+
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
26+
27+
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/4.2.0/how-to.html).
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
name: Bug Report
3+
about: The template to use for reporting bugs and usability issues
4+
title: " "
5+
labels: 'bug'
6+
assignees: ''
7+
8+
---
9+
10+
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).
11+
12+
## Steps To Reproduce
13+
Steps to reproduce the behavior:
14+
1. Go to '...'
15+
2. Click on '....'
16+
3. Scroll down to '....'
17+
4. See error
18+
19+
20+
## Acceptance Criteria
21+
- Specific criteria that will be used to judge if the issue is fixed

.github/ISSUE_TEMPLATE/issue.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: Issue
3+
about: The standard template to use for feature requests, design discussions and tasks
4+
title: " "
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
A brief description of the issue, including specific stakeholders and the business case where appropriate
11+
12+
## Acceptance Criteria
13+
- Specific criteria that will be used to judge if the issue is fixed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Fixes #ISSUE
2+
3+
### Instructions to reviewer on how to test:
4+
1. Do thing x
5+
2. Confirm thing y happens
6+
7+
### Checks for reviewer
8+
- [ ] Would the PR title make sense to a user on a set of release notes
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Install requirements
2+
description: Install a version of python then call pip install and report what was installed
3+
inputs:
4+
python-version:
5+
description: Python version to install, default is from Dockerfile
6+
default: "dev"
7+
pip-install:
8+
description: Parameters to pass to pip install
9+
default: "$([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e .[dev]"
10+
11+
runs:
12+
using: composite
13+
steps:
14+
- name: Get version of python
15+
run: |
16+
PYTHON_VERSION="${{ inputs.python-version }}"
17+
if [ $PYTHON_VERSION == "dev" ]; then
18+
# python version from Dockerfile, removing potential pinned sha
19+
PYTHON_VERSION=$(sed -Ene "s/ARG PYTHON_VERSION=([0-9\.]+).*/\1/p" Dockerfile)
20+
fi
21+
echo "PYTHON_VERSION=$PYTHON_VERSION" >> "$GITHUB_ENV"
22+
shell: bash
23+
24+
- name: Setup python
25+
uses: actions/setup-python@v5
26+
with:
27+
python-version: ${{ env.PYTHON_VERSION }}
28+
29+
- name: Install packages
30+
run: pip install ${{ inputs.pip-install }}
31+
shell: bash
32+
33+
- name: Report what was installed
34+
run: pip freeze
35+
shell: bash

.github/dependabot.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "github-actions"
9+
directory: "/"
10+
schedule:
11+
interval: "weekly"
12+
groups:
13+
actions:
14+
patterns:
15+
- "*"
16+
commit-message:
17+
prefix: "chore"
18+
19+
- package-ecosystem: "pip"
20+
directory: "/"
21+
schedule:
22+
interval: "weekly"
23+
groups:
24+
dev-dependencies:
25+
patterns:
26+
- "*"
27+
commit-message:
28+
prefix: "chore"

.github/pages/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
<link rel="canonical" href="main/index.html">
99
</head>
1010

11-
</html>
11+
</html>

.github/pages/make_switcher.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""Make switcher.json to allow docs to switch between different versions."""
2+
3+
import json
4+
import logging
5+
from argparse import ArgumentParser
6+
from pathlib import Path
7+
from subprocess import CalledProcessError, check_output
8+
9+
10+
def report_output(stdout: bytes, label: str) -> list[str]:
11+
"""Print and return something received frm stdout."""
12+
ret = stdout.decode().strip().split("\n")
13+
print(f"{label}: {ret}")
14+
return ret
15+
16+
17+
def get_branch_contents(ref: str) -> list[str]:
18+
"""Get the list of directories in a branch."""
19+
stdout = check_output(["git", "ls-tree", "-d", "--name-only", ref])
20+
return report_output(stdout, "Branch contents")
21+
22+
23+
def get_sorted_tags_list() -> list[str]:
24+
"""Get a list of sorted tags in descending order from the repository."""
25+
stdout = check_output(["git", "tag", "-l", "--sort=-v:refname"])
26+
return report_output(stdout, "Tags list")
27+
28+
29+
def get_versions(ref: str, add: str | None) -> list[str]:
30+
"""Generate the file containing the list of all GitHub Pages builds."""
31+
# Get the directories (i.e. builds) from the GitHub Pages branch
32+
try:
33+
builds = set(get_branch_contents(ref))
34+
except CalledProcessError:
35+
builds = set()
36+
logging.warning(f"Cannot get {ref} contents")
37+
38+
# Add and remove from the list of builds
39+
if add:
40+
builds.add(add)
41+
42+
# Get a sorted list of tags
43+
tags = get_sorted_tags_list()
44+
45+
# Make the sorted versions list from main branches and tags
46+
versions: list[str] = []
47+
for version in ["master", "main"] + tags:
48+
if version in builds:
49+
versions.append(version)
50+
builds.remove(version)
51+
52+
# Add in anything that is left to the bottom
53+
versions += sorted(builds)
54+
print(f"Sorted versions: {versions}")
55+
return versions
56+
57+
58+
def write_json(path: Path, repository: str, versions: list[str]):
59+
"""Write the JSON switcher to path."""
60+
org, repo_name = repository.split("/")
61+
struct = [
62+
{"version": version, "url": f"https://{org}.github.io/{repo_name}/{version}/"}
63+
for version in versions
64+
]
65+
text = json.dumps(struct, indent=2)
66+
print(f"JSON switcher:\n{text}")
67+
path.write_text(text, encoding="utf-8")
68+
69+
70+
def main(args=None):
71+
"""Parse args and write switcher."""
72+
parser = ArgumentParser(
73+
description="Make a versions.json file from gh-pages directories"
74+
)
75+
parser.add_argument(
76+
"--add",
77+
help="Add this directory to the list of existing directories",
78+
)
79+
parser.add_argument(
80+
"repository",
81+
help="The GitHub org and repository name: ORG/REPO",
82+
)
83+
parser.add_argument(
84+
"output",
85+
type=Path,
86+
help="Path of write switcher.json to",
87+
)
88+
args = parser.parse_args(args)
89+
90+
# Write the versions file
91+
versions = get_versions("origin/gh-pages", args.add)
92+
write_json(args.output, args.repository, versions)
93+
94+
95+
if __name__ == "__main__":
96+
main()

0 commit comments

Comments
 (0)