Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 61c2434

Browse files
committed
Merge branch 'skeleton-merge-branch'
2 parents 8062874 + 4a29f75 commit 61c2434

36 files changed

+686
-374
lines changed

.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/python3-pip-skeleton-cli/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/python3-pip-skeleton-cli/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/python3-pip-skeleton-cli/main/developer/how-to/contribute.html

.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(name=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()

.github/workflows/code.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ jobs:
139139
uses: actions/upload-artifact@v3
140140
with:
141141
name: dist
142-
path: dist/*
142+
path: dist
143143

144144
sdist:
145145
needs: container
@@ -171,8 +171,7 @@ jobs:
171171
uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5 # v0.1.14
172172
with:
173173
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
174-
files: |
175-
dist/*
174+
files: dist/*
176175
generate_release_notes: true
177176
env:
178177
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/docs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ jobs:
4343

4444
- name: Move to versioned directory
4545
# e.g. main or 0.1.2
46-
run: mv build/html ".github/pages/${GITHUB_REF##*/}"
46+
run: mv build/html ".github/pages/${{ github.ref_name }}"
4747

48-
- name: Write versions.txt
49-
run: sphinx_rtd_theme_github_versions .github/pages
48+
- name: Write switcher.json
49+
run: python .github/pages/make_switcher.py --add "${{ github.ref_name }}" ${{ github.repository }} .github/pages/switcher.json
5050

5151
- name: Publish Docs to gh-pages
5252
if: github.event_name == 'push'

.github/workflows/docs_clean.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ jobs:
3232

3333
- name: update index and push changes
3434
run: |
35-
echo removing redundant documentation version ${{ env.remove_me }}
3635
rm -r ${{ env.remove_me }}
37-
sed -i /${{ env.remove_me }}/d versions.txt
36+
python make_switcher.py --remove ${{ env.remove_me }} ${{ github.repository }} switcher.json
3837
git config --global user.name 'GitHub Actions Docs Cleanup CI'
39-
git config --global user.email 'GithubActionsCleanup@users.noreply.github.com'
40-
git commit -am"removing redundant docs version ${{ env.remove_me }}"
38+
git config --global user.email '[email protected]'
39+
git commit -am"removing redundant docs version ${{ env.remove_me }}"
4140
git push

.vscode/extensions.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"recommendations": [
3-
"ms-vscode-remote.remote-containers"
3+
"ms-vscode-remote.remote-containers",
44
"ms-python.vscode-pylance",
55
"ms-python.python",
66
"ryanluker.vscode-coverage-gutters"
77
]
8-
}
8+
}

CONTRIBUTING.rst

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

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is for use as a devcontainer and a runtime container
2-
#
3-
# The devcontainer should use the build target and run as root with podman
2+
#
3+
# The devcontainer should use the build target and run as root with podman
44
# or docker with user namespaces.
55
#
66
FROM python:3.10 as build
@@ -26,6 +26,7 @@ RUN cd /project && \
2626

2727
RUN python -m venv /venv
2828
ENV PATH=/venv/bin:$PATH
29+
ENV TOX_DIRECT=1
2930

3031
RUN cd /project && \
3132
pip install --upgrade pip && \
@@ -43,5 +44,5 @@ COPY --from=build /venv/ /venv/
4344
ENV PATH=/venv/bin:$PATH
4445

4546
# change this entrypoint if it is not the same as the repo
46-
ENTRYPOINT ["python3-pip-skeleton"]
47+
ENTRYPOINT ["python3-pip-skeleton-cli"]
4748
CMD ["--version"]

0 commit comments

Comments
 (0)