Skip to content

Commit 4ab0a5c

Browse files
authored
Merge pull request #1 from JunAishima/prefect3-pixi-upgrade
Prefect3 pixi upgrade
2 parents b85b8fc + 78de7ce commit 4ab0a5c

16 files changed

+6724
-99
lines changed

.github/workflows/linting.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-python@v2
14-
- uses: pre-commit/action@v2.0.3
12+
- uses: actions/checkout@v4.3.0
13+
- uses: actions/setup-python@v5.6.0
14+
- uses: pre-commit/action@v3.0.1

.github/workflows/publish-ghcr.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
push:
7+
branches: ["main"]
8+
9+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
15+
jobs:
16+
build-and-push-image:
17+
runs-on: ubuntu-latest
18+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
19+
permissions:
20+
contents: read
21+
packages: write
22+
attestations: write
23+
id-token: write
24+
#
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v5
28+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
29+
- name: Log in to the Container registry
30+
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
42+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
43+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
44+
- name: Build and push Docker image
45+
id: push
46+
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
47+
with:
48+
context: .
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
53+
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
54+
- name: Generate artifact attestation
55+
uses: actions/attest-build-provenance@v3
56+
with:
57+
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
58+
subject-digest: ${{ steps.push.outputs.digest }}
59+
push-to-registry: true

.pre-commit-config.yaml

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,92 @@
1-
# See https://pre-commit.com for more information
2-
# See https://pre-commit.com/hooks.html for more hooks
1+
ci:
2+
autoupdate_commit_msg: "chore: update pre-commit hooks"
3+
autofix_commit_msg: "style: pre-commit fixes"
4+
5+
exclude: ^.cruft.json|.copier-answers.yml$
6+
37
repos:
8+
- repo: https://github.com/adamchainz/blacken-docs
9+
rev: "1.19.1"
10+
hooks:
11+
- id: blacken-docs
12+
additional_dependencies: [black==24.*]
13+
414
- repo: https://github.com/pre-commit/pre-commit-hooks
5-
rev: v4.0.1
15+
rev: "v5.0.0"
616
hooks:
7-
- id: trailing-whitespace
8-
- id: end-of-file-fixer
9-
- id: check-ast
17+
- id: check-added-large-files
1018
- id: check-case-conflict
1119
- id: check-merge-conflict
1220
- id: check-symlinks
1321
- id: check-yaml
1422
- id: debug-statements
23+
- id: end-of-file-fixer
24+
- id: mixed-line-ending
25+
- id: name-tests-test
26+
args: ["--pytest-test-first"]
27+
- id: requirements-txt-fixer
28+
- id: trailing-whitespace
29+
30+
- repo: https://github.com/pre-commit/pygrep-hooks
31+
rev: "v1.10.0"
32+
hooks:
33+
- id: rst-backticks
34+
- id: rst-directive-colons
35+
- id: rst-inline-touching-normal
36+
37+
- repo: https://github.com/rbubley/mirrors-prettier
38+
rev: "v3.5.3"
39+
hooks:
40+
- id: prettier
41+
types_or: [yaml, markdown, html, css, scss, javascript, json]
42+
args: [--prose-wrap=always]
43+
44+
- repo: https://github.com/astral-sh/ruff-pre-commit
45+
rev: "v0.11.11"
46+
hooks:
47+
- id: ruff
48+
args: ["--fix", "--show-fixes"]
49+
- id: ruff-format
50+
51+
- repo: https://github.com/pre-commit/mirrors-mypy
52+
rev: "v1.15.0"
53+
hooks:
54+
- id: mypy
55+
files: src|tests
56+
args: []
57+
additional_dependencies:
58+
- pytest
59+
60+
- repo: https://github.com/codespell-project/codespell
61+
rev: "v2.4.1"
62+
hooks:
63+
- id: codespell
64+
additional_dependencies:
65+
- tomli; python_version<'3.11'
66+
exclude: "pixi.*"
67+
68+
- repo: https://github.com/shellcheck-py/shellcheck-py
69+
rev: "v0.10.0.1"
70+
hooks:
71+
- id: shellcheck
72+
73+
- repo: local
74+
hooks:
75+
- id: disallow-caps
76+
name: Disallow improper capitalization
77+
language: pygrep
78+
entry: PyBind|Numpy|Cmake|CCache|Github|PyTest
79+
exclude: .pre-commit-config.yaml
1580

16-
- repo: https://github.com/timothycrosley/isort
17-
rev: 5.9.3
81+
- repo: https://github.com/abravalheri/validate-pyproject
82+
rev: "v0.24.1"
1883
hooks:
19-
- id: isort
84+
- id: validate-pyproject
85+
additional_dependencies: ["validate-pyproject-schema-store[all]"]
2086

21-
- repo: https://github.com/psf/black
22-
rev: 22.3.0
87+
- repo: https://github.com/python-jsonschema/check-jsonschema
88+
rev: "0.33.0"
2389
hooks:
24-
- id: black
90+
- id: check-dependabot
91+
- id: check-github-workflows
92+
- id: check-readthedocs

Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM ghcr.io/prefix-dev/pixi:latest
2+
3+
ENV TZ="America/New_York"
4+
5+
RUN apt-get -y update && \
6+
apt-get -y install git
7+
8+
COPY pixi.toml .
9+
COPY pixi.lock .
10+
# use `--locked` to ensure the lockfile is up to date with pixi.toml
11+
RUN pixi install --locked
12+
# create the shell-hook bash script to activate the environment
13+
RUN pixi shell-hook -s bash > /shell-hook
14+
15+
ENV PYTHONUNBUFFERED=1
16+
17+
COPY test.py .
18+
19+
RUN mkdir /etc/tiled
20+
RUN mkdir /.prefect -m 0777
21+
RUN mkdir /repo -m 0777
22+
23+
RUN /bin/bash /shell-hook
24+
25+
#now reapply deployment to push the image that is being created
26+
ENTRYPOINT ["pixi", "run"]
27+
CMD ["python", "-m", "test", "arg"]

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# ucal Workflows
22

3-
Repository of Prefect workflows for the micro calorimetry endstation at the SST beamline.
3+
Repository of Prefect workflows for the micro calorimetry endstation at the SST
4+
beamline.

end_of_run_export.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
def get_export_path(run):
1111
proposal_path = get_proposal_path(run)
1212

13-
visit_date = datetime.datetime.fromisoformat(run.start.get("start_datetime", datetime.datetime.today().isoformat()))
13+
visit_date = datetime.datetime.fromisoformat(
14+
run.start.get("start_datetime", datetime.datetime.today().isoformat())
15+
)
1416
visit_dir = visit_date.strftime("%Y%m%d_export")
1517

1618
export_path = join(proposal_path, visit_dir)

export_to_athena.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from os.path import exists, join
2+
from os.path import join
33
from export_tools import add_comment_to_lines, get_header_and_data
44
from prefect import get_run_logger
55

@@ -12,12 +12,12 @@ def exportToAthena(
1212
c2="",
1313
headerUpdates={},
1414
strict=False,
15-
verbose=True
15+
verbose=True,
1616
):
1717
"""Exports to Graham's ASCII SSRL data format
1818
1919
:param folder: Export folder (filename will be auto-generated)
20-
:param data: Numpy array with data of dimensions (npts, ncols)
20+
:param data: NumPy array with data of dimensions (npts, ncols)
2121
:param header: Dictionary with 'scaninfo', 'motors', 'channelinfo' sub-dictionaries
2222
:param namefmt: Python format string that will be filled with info from 'scaninfo' dictionary
2323
:param c1: Comment string 1
@@ -59,7 +59,7 @@ def exportToAthena(
5959
metadata["c1"] = c1
6060
metadata["c2"] = c2
6161

62-
headerstring = """NSLS
62+
headerstring = """NSLS
6363
{date}
6464
PTS:{npts:11d} COLS: {ncols:11d}
6565
Sample: {sample} loadid: {loadid}
@@ -71,9 +71,7 @@ def exportToAthena(
7171
{c1}
7272
{c2}
7373
-------------------------------------------------------------------------------
74-
{cols}""".format(
75-
**metadata, **motors
76-
)
74+
{cols}""".format(**metadata, **motors)
7775
headerstring = add_comment_to_lines(headerstring, "#")
7876
logger.info(f"Writing Athena to {filename}")
7977
with open(filename, "w") as f:

export_to_hdf5.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ def exportToHDF5(folder, run, header_updates={}):
1414
"""
1515

1616
if "primary" not in run:
17-
print(f"HDF5 Export does not support streams other than Primary, skipping {run.start['scan_id']}")
17+
print(
18+
f"HDF5 Export does not support streams other than Primary, skipping {run.start['scan_id']}"
19+
)
1820
return False
1921
metadata = get_xdi_run_header(run, header_updates)
2022
print("Got XDI Metadata")
2123
filename = make_filename(folder, metadata, "hdf5")
2224
print(f"Exporting HDF5 to {filename}")
2325

24-
columns, run_data, metadata = get_xdi_normalized_data(run, metadata, omit_array_keys=False)
26+
columns, run_data, metadata = get_xdi_normalized_data(
27+
run, metadata, omit_array_keys=False
28+
)
2529

2630
with h5py.File(filename, "w") as f:
2731
for name, data in zip(columns, run_data):

export_to_tiled.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from export_to_xdi import get_xdi_normalized_data, get_xdi_run_header, make_filename
1+
from export_to_xdi import get_xdi_normalized_data, get_xdi_run_header
22
import xarray as xr
33

44

@@ -28,20 +28,27 @@ def export_to_tiled(run, header_updates={}):
2828
"""
2929

3030
if "primary" not in run:
31-
print(f"Tiled Export does not support streams other than Primary, skipping {run.start['scan_id']}")
31+
print(
32+
f"Tiled Export does not support streams other than Primary, skipping {run.start['scan_id']}"
33+
)
3234
return False
3335
metadata = get_xdi_run_header(run, header_updates)
3436
print("Got XDI Metadata")
3537

36-
columns, run_data, metadata = get_xdi_normalized_data(run, metadata, omit_array_keys=False)
38+
columns, run_data, metadata = get_xdi_normalized_data(
39+
run, metadata, omit_array_keys=False
40+
)
3741

3842
da_dict = {}
3943
for name, data in zip(columns, run_data):
4044
if name == "rixs":
4145
if len(data) == 3:
4246
counts, mono_grid, energy_grid = data
4347
rixs = xr.DataArray(
44-
counts.T, coords={"emission": energy_grid[:, 0]}, dims=("time", "emission"), name=name
48+
counts.T,
49+
coords={"emission": energy_grid[:, 0]},
50+
dims=("time", "emission"),
51+
name=name,
4552
)
4653
else:
4754
rixs = xr.DataArray(data, dims=("time", "emission"), name=name)

0 commit comments

Comments
 (0)