Skip to content

Commit 6e80bb0

Browse files
updated files to latest skeleton (#198)
* updated files to latest skeleton * added main.py because versioning makes sense * ignoring _version.py file and excluding it from black checks * got rid of reference to requirements.txt in Dockerfile * removed now redundant _version_git.py, changed dockerfile to inspect github CI build * modified code to not use _version_git.py * investigating docker error * container is just listing its directory now * Add experimental ls to debug ci * Restore Docker build behavoir * Remove dockerignore * changed main file to take version arg * added arg PIP_OPTIONS to be overwritten by code container CI job * changed CMD to ENTRYPOINT in dockerfile * removed container yml job as it is a duplication of an existing job in code yml workflow * updated pyproject toml to look at correct version of diffcalc-core * modified test --------- Co-authored-by: Callum Forrester <[email protected]>
1 parent f093cfc commit 6e80bb0

Some content is hidden

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

61 files changed

+1417
-788
lines changed

.devcontainer/Dockerfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3/.devcontainer/base.Dockerfile
2+
# FROM ubuntu:latest
3+
# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
4+
ARG VARIANT="3.10-bullseye"
5+
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
6+
7+
# # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
8+
ARG NODE_VERSION="none"
9+
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
10+
11+
# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
12+
# COPY requirements.txt /tmp/pip-tmp/
13+
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
14+
# && rm -rf /tmp/pip-tmp
15+
16+
# [Optional] Uncomment this section to install additional OS packages.
17+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
18+
# && apt-get -y install --no-install-recommends <your-package-list-here>
19+
20+
# [Optional] Uncomment this line to install global node packages.
21+
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

.devcontainer/devcontainer.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/python-3
3+
{
4+
"name": "Python 3",
5+
"runArgs": [
6+
"--net",
7+
"host"
8+
],
9+
"build": {
10+
"dockerfile": "Dockerfile",
11+
"context": "..",
12+
"args": {
13+
// Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
14+
// Append -bullseye or -buster to pin to an OS version.
15+
// Use -bullseye variants on local on arm64/Apple Silicon.
16+
"VARIANT": "3.11",
17+
// Options
18+
"NODE_VERSION": "none"
19+
}
20+
},
21+
// Configure tool-specific properties.
22+
"customizations": {
23+
// Configure properties specific to VS Code.
24+
"vscode": {
25+
// Set *default* container specific settings.json values on container create.
26+
"settings": {
27+
"python.defaultInterpreterPath": "/usr/local/bin/python",
28+
"python.linting.enabled": true,
29+
"python.linting.pylintEnabled": true,
30+
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
31+
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
32+
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
33+
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
34+
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
35+
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
36+
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
37+
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
38+
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
39+
},
40+
// Add the IDs of extensions you want installed when the container is created.
41+
"extensions": [
42+
"ms-python.python",
43+
"ms-python.vscode-pylance"
44+
]
45+
}
46+
},
47+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
48+
// Use 'postCreateCommand' to run commands after the container is created.
49+
// "postCreateCommand": "pip3 install --user -r requirements.txt",
50+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
51+
"remoteUser": "root"
52+
}

.github/CONTRIBUTING.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Contributing to the project
2+
===========================
3+
4+
Contributions and issues are most welcome! All issues and pull requests are
5+
handled through GitHub_. Also, please check for any existing issues before
6+
filing a new one. If you have a great idea but it involves big changes, please
7+
file a ticket before making a pull request! We want to make sure you don't spend
8+
your time coding something that might not fit the scope of the project.
9+
10+
.. _GitHub: https://github.com/DiamondLightSource/diffcalc-api/issues
11+
12+
Issue or Discussion?
13+
--------------------
14+
15+
Github also offers discussions_ as a place to ask questions and share ideas. If
16+
your issue is open ended and it is not obvious when it can be "closed", please
17+
raise it as a discussion instead.
18+
19+
.. _discussions: https://github.com/DiamondLightSource/diffcalc-api/discussions
20+
21+
Code coverage
22+
-------------
23+
24+
While 100% code coverage does not make a library bug-free, it significantly
25+
reduces the number of easily caught bugs! Please make sure coverage remains the
26+
same or is improved by a pull request!
27+
28+
Developer guide
29+
---------------
30+
31+
The `Developer Guide`_ contains information on setting up a development
32+
environment, running the tests and what standards the code and documentation
33+
should follow.
34+
35+
.. _Developer Guide: https://diamondlightsource.github.io/diffcalc-api/master/developer/how-to/contribute.html
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Install requirements
2+
description: Run pip install with requirements and upload resulting requirements
3+
inputs:
4+
requirements_file:
5+
description: Name of requirements file to use and upload
6+
required: true
7+
install_options:
8+
description: Parameters to pass to pip install
9+
required: true
10+
python_version:
11+
description: Python version to install
12+
default: "3.x"
13+
14+
runs:
15+
using: composite
16+
17+
steps:
18+
- name: Setup python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ inputs.python_version }}
22+
23+
- name: Pip install
24+
run: |
25+
touch ${{ inputs.requirements_file }}
26+
# -c uses requirements.txt as constraints, see 'Validate requirements file'
27+
pip install -c ${{ inputs.requirements_file }} ${{ inputs.install_options }}
28+
shell: bash
29+
30+
- name: Create lockfile
31+
run: |
32+
mkdir -p lockfiles
33+
pip freeze --exclude-editable > lockfiles/${{ inputs.requirements_file }}
34+
# delete the self referencing line and make sure it isn't blank
35+
sed -i '/file:/d' lockfiles/${{ inputs.requirements_file }}
36+
shell: bash
37+
38+
- name: Upload lockfiles
39+
uses: actions/upload-artifact@v3
40+
with:
41+
name: lockfiles
42+
path: lockfiles
43+
44+
# This eliminates the class of problems where the requirements being given no
45+
# longer match what the packages themselves dictate. E.g. In the rare instance
46+
# where I install some-package which used to depend on vulnerable-dependency
47+
# but now uses good-dependency (despite being nominally the same version)
48+
# pip will install both if given a requirements file with -r
49+
- name: If requirements file exists, check it matches pip installed packages
50+
run: |
51+
if [ -s ${{ inputs.requirements_file }} ]; then
52+
if ! diff -u ${{ inputs.requirements_file }} lockfiles/${{ inputs.requirements_file }}; then
53+
echo "Error: ${{ inputs.requirements_file }} need the above changes to be exhaustive"
54+
exit 1
55+
fi
56+
fi
57+
shell: bash
58+

.github/pages/make_switcher.py

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

0 commit comments

Comments
 (0)