forked from DiamondLightSource/mx-bluesky
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from olliesilvester/merge_in_hyperion
Merge in hyperion
- Loading branch information
Showing
329 changed files
with
28,154 additions
and
293 deletions.
There are no files selected for viewing
This file contains 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,18 @@ | ||
[run] | ||
omit = | ||
*/test_* | ||
**/conftest.py | ||
data_file = /tmp/hyperion.coverage | ||
|
||
[report] | ||
exclude_also = | ||
if TYPE_CHECKING: | ||
def __repr__ | ||
raise NotImplementedError | ||
@(abc\.)?abstractmethod | ||
|
||
[paths] | ||
# Tests are run from installed location, map back to the src directory | ||
source = | ||
src | ||
**/site-packages/ |
This file contains 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 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 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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
Fixes #ISSUE | ||
|
||
Link to dodal PR (if required): #XXX | ||
(remember to update `setup.cfg` with the dodal commit tag if you need it for tests to pass!) | ||
|
||
### 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 |
This file contains 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,3 @@ | ||
FROM ghcr.io/githubgphl/imginfo:main | ||
COPY entrypoint.sh /entrypoint.sh | ||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains 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,18 @@ | ||
name: "Verify nexus" | ||
description: "Verify nexus files against imginfo" | ||
inputs: | ||
filename: | ||
description: "nexus file to verify" | ||
required: true | ||
outputs: | ||
imginfo_stdout: | ||
description: "imginfo output" | ||
imginfo_stderr: | ||
description: "imginfo error output" | ||
imginfo_exit_code: | ||
description: "imginfo exit code" | ||
runs: | ||
using: "docker" | ||
image: "Dockerfile" | ||
args: | ||
- ${{ inputs.filename }} |
This file contains 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,25 @@ | ||
#!/bin/sh -l | ||
echo "Contents of /github/workspace:" | ||
ls /github/workspace | ||
echo "current dir: $(pwd)" | ||
echo "Running imginfo on $1" | ||
/imginfo/imginfo $1 >> imginfo_out_file 2>> imginfo_err_file | ||
{ echo "imginfo_output<<EOF" | ||
cat imginfo_out_file | ||
echo EOF | ||
} >> "$GITHUB_OUTPUT" | ||
{ echo "imginfo_output<<EOF" | ||
cat imginfo_err_file | ||
echo EOF | ||
} >> "$GITHUB_OUTPUT" | ||
echo "imginfo_exit_code=$?" >> "$GITHUB_OUTPUT" | ||
echo "------------- IMGINFO STDOUT -------------" | ||
cat imginfo_out_file | ||
echo "------------- IMGINFO STDERR -------------" | ||
cat imginfo_err_file | ||
echo "------------------------------------------" | ||
if [ -s imginfo_err_file ]; then | ||
echo "ERRORS IN IMGINFO PROCESSING!" | ||
exit 1 | ||
fi | ||
echo "VALIDATED SUCCESSFULLY!" |
This file contains 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 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 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,136 @@ | ||
#!/usr/bin/env python3 | ||
import argparse | ||
import locale | ||
import os | ||
import re | ||
import subprocess | ||
from functools import partial | ||
from sys import stderr, stdout | ||
|
||
SETUP_CFG_PATTERN = re.compile("(.*?\\S)\\s*(@(.*))?$") | ||
SETUP_UNPINNED_PATTERN = re.compile("(.*?\\S)\\s*([<>=]+(.*))?$") | ||
PIP = "pip" | ||
|
||
|
||
def rename_original(suffix): | ||
os.rename("setup.cfg", "setup.cfg" + suffix) | ||
|
||
|
||
def normalize(package_name: str): | ||
return re.sub(r"[-_.]+", "-", package_name).lower() | ||
|
||
|
||
def fetch_pin_versions() -> dict[str, str]: | ||
process = run_pip_freeze() | ||
if process.returncode == 0: | ||
output = process.stdout | ||
lines = output.split("\n") | ||
pin_versions = {} | ||
for line in lines: | ||
kvpair = line.split("==") | ||
if len(kvpair) != 2: | ||
stderr.write(f"Unable to parse {line} - ignored\n") | ||
else: | ||
pin_versions[normalize(kvpair[0]).strip()] = kvpair[1].strip() | ||
return pin_versions | ||
else: | ||
stderr.write(f"pip freeze failed with error code {process.returncode}\n") | ||
stderr.write(process.stderr) | ||
exit(1) | ||
|
||
|
||
def run_pip_freeze(): | ||
process = subprocess.run( | ||
[PIP, "freeze"], capture_output=True, encoding=locale.getpreferredencoding() | ||
) | ||
return process | ||
|
||
|
||
def process_setup_cfg(input_fname, output_fname, dependency_processor): | ||
with open(input_fname) as input_file: | ||
with open(output_fname, "w") as output_file: | ||
process_files(input_file, output_file, dependency_processor) | ||
|
||
|
||
def process_files(input_file, output_file, dependency_processor): | ||
while line := input_file.readline(): | ||
output_file.write(line) | ||
if line.startswith("install_requires"): | ||
break | ||
while (line := input_file.readline()) and not line.startswith("["): | ||
if line.isspace(): | ||
output_file.write(line) | ||
else: | ||
dependency_processor(line, output_file) | ||
output_file.write(line) | ||
while line := input_file.readline(): | ||
output_file.write(line) | ||
|
||
|
||
def strip_comment(line: str): | ||
split = line.rstrip("\n").split("#", 1) | ||
return split[0], (split[1] if len(split) > 1 else None) | ||
|
||
|
||
def write_with_comment(comment, text, output_file): | ||
output_file.write(text) | ||
if comment: | ||
output_file.write(" #" + comment) | ||
output_file.write("\n") | ||
|
||
|
||
def update_setup_cfg_line(version_map: dict[str, str], line, output_file): | ||
stripped_line, comment = strip_comment(line) | ||
if match := SETUP_UNPINNED_PATTERN.match(stripped_line): | ||
normalized_name = normalize(match[1].strip()) | ||
if normalized_name not in version_map: | ||
stderr.write( | ||
f"Unable to find {normalized_name} in installed python packages\n" | ||
) | ||
exit(1) | ||
|
||
write_with_comment( | ||
comment, | ||
f" {normalized_name} == {version_map[normalized_name]}", | ||
output_file, | ||
) | ||
else: | ||
output_file.write(line) | ||
|
||
|
||
def write_commit_message(pinned_versions: dict[str, str]): | ||
message = f"Pin dependencies prior to release. Dodal {pinned_versions['dls-dodal']}, nexgen {pinned_versions['nexgen']}" | ||
stdout.write(message) | ||
|
||
|
||
def unpin_versions(line, output_file): | ||
stripped_line, comment = strip_comment(line) | ||
if match := SETUP_CFG_PATTERN.match(stripped_line): | ||
if match[3] and match[3].strip().startswith("git+"): | ||
write_with_comment(comment, match[1], output_file) | ||
return | ||
|
||
output_file.write(line) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Pin dependency versions in setup.cfg") | ||
parser.add_argument( | ||
"--unpin", | ||
help="remove pinned hashes from setup.cfg prior to pip installing latest", | ||
action="store_true", | ||
) | ||
args = parser.parse_args() | ||
|
||
if args.unpin: | ||
rename_original(".orig") | ||
process_setup_cfg("setup.cfg.orig", "setup.cfg", unpin_versions) | ||
else: | ||
rename_original(".unpinned") | ||
installed_versions = fetch_pin_versions() | ||
process_setup_cfg( | ||
"setup.cfg.unpinned", | ||
"setup.cfg", | ||
partial(update_setup_cfg_line, installed_versions), | ||
) | ||
write_commit_message(installed_versions) |
This file contains 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,48 @@ | ||
name: pre_release_workflow | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
tagName: | ||
description: 'Tag to create' | ||
required: true | ||
type: string | ||
default: 'vX.Y.Z' | ||
jobs: | ||
pin_dependency_versions: | ||
runs-on: ubuntu-latest | ||
env: | ||
GH_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
steps: | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
architecture: x64 | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
- name: Reset pinned hash versions | ||
run: .github/workflows/pin_versions.py --unpin | ||
- name: Install with latest dependencies | ||
run: pip install -e .[dev] | ||
- id: pin_versions | ||
name: Pin Versions | ||
run: | | ||
MSG=$(.github/workflows/pin_versions.py) | ||
echo "COMMIT_MESSAGE=\"$MSG\"" >> "$GITHUB_OUTPUT" | ||
- name: Add setup.cfg | ||
run: | | ||
git add setup.cfg | ||
- name: Commit changes | ||
run: | | ||
git config --global user.name "${{ github.actor }}" | ||
git config --global user.email "${{ github.actor }}@users.noreply.github.com" | ||
git commit -m ${{steps.pin_versions.outputs.COMMIT_MESSAGE}} | ||
git tag ${{inputs.tagName}} | ||
git push origin ${{inputs.tagName}} | ||
- name: Create Release | ||
run: gh release create --generate-notes --draft ${{inputs.tagName}} | ||
- name: Edit Release Notes | ||
run: | | ||
echo -e "${{ steps.pin_versions.outputs.COMMIT_MESSAGE }}\n\n" > "$RUNNER_TEMP/relnotes.txt" | ||
gh release view ${{ inputs.tagName }} | sed '0,/^--$/d' >> "$RUNNER_TEMP/relnotes.txt" | ||
gh release edit ${{ inputs.tagName }} --notes-file "$RUNNER_TEMP/relnotes.txt" |
Oops, something went wrong.