Skip to content

Commit 62093d9

Browse files
authored
Merge pull request Duke-GCB#177 from fabricebrito/calrissian-172
Addresses issue Duke-GCB#172 introducing hatch and pyproject.toml
2 parents 4ee2108 + 98af45d commit 62093d9

16 files changed

+328
-324
lines changed

Diff for: .github/workflows/build-and-test.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
4+
name: Build & Tests
5+
on: [push, pull_request]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python 3.10
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: "3.10"
20+
cache: "pip"
21+
- name: Install dependencies
22+
run: |
23+
# python -m pip install --upgrade pip
24+
pip install hatch
25+
- name: Cache Hatch
26+
id: cache-hatch
27+
uses: actions/cache@v3
28+
with:
29+
path: /home/runner/.local/share/hatch/env/virtual/
30+
key: ${{ runner.os }}-hatch
31+
- name: Build
32+
run: hatch build
33+
- name: Test
34+
run: |
35+
hatch -e test run nose2 --verbose

Diff for: .github/workflows/build.yaml

-27
This file was deleted.

Diff for: .github/workflows/package.yaml

+30-50
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,45 @@
1-
name: package
1+
name: Publish to PyPI
2+
23
on:
34
release:
45
types: [created]
56

7+
permissions:
8+
contents: read
9+
610
jobs:
11+
deploy:
712

8-
version:
913
runs-on: ubuntu-latest
10-
outputs:
11-
app-version: ${{ steps.set-version.outputs.version }}
12-
steps:
13-
- uses: actions/checkout@v4
14-
- run: echo "APP_VERSION=$(python setup.py --version)" >> $GITHUB_ENV
15-
- run: echo app version is $APP_VERSION
16-
- id: set-version
17-
run: echo "::set-output name=version::$APP_VERSION"
1814

19-
deploy:
20-
runs-on: ubuntu-latest
21-
15+
environment: release
16+
permissions:
17+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
18+
2219
steps:
2320
- uses: actions/checkout@v4
2421
- name: Set up Python
2522
uses: actions/setup-python@v4
2623
with:
27-
python-version: "3.10"
24+
python-version: '3.10'
25+
cache: 'pip'
2826
- name: Install dependencies
2927
run: |
30-
python -m pip install --upgrade pip
31-
python3 -m venv venv
32-
. venv/bin/activate
33-
pip install setuptools wheel twine
34-
pip install -r requirements.txt
35-
- name: verify git tag vs. version
36-
run: |
37-
python3 -m venv venv
38-
. venv/bin/activate
39-
python setup.py verify
40-
- name: Build
41-
run: |
42-
. venv/bin/activate
43-
python setup.py bdist_wheel --universal
44-
- name: Publish
45-
env:
46-
TWINE_USERNAME: __token__
47-
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
48-
run: |
49-
. venv/bin/activate
50-
twine upload dist/*
51-
52-
container-build:
53-
needs: version
54-
runs-on: ubuntu-latest
55-
steps:
56-
- uses: actions/checkout@v4
57-
- run: echo version ${{needs.version.outputs.app-version}}
58-
- run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
59-
- name: build & push image
60-
run: |
61-
IMAGE_ID=ghcr.io/duke-gcb/calrissian/calrissian
62-
docker build . --file Dockerfile --tag calrissian
63-
docker tag calrissian $IMAGE_ID:${{needs.version.outputs.app-version}}
64-
docker push $IMAGE_ID:${{needs.version.outputs.app-version}}
65-
28+
# python -m pip install --upgrade pip
29+
pip install hatch
30+
- name: Build package
31+
run: hatch build
32+
- name: Test package
33+
run: hatch -e test run nose2 --verbose
34+
- name: Publish package distributions to Test PyPI
35+
if: github.ref != 'refs/heads/main'
36+
uses: pypa/gh-action-pypi-publish@release/v1
37+
with:
38+
skip-existing: true
39+
repository-url: https://test.pypi.org/legacy/
40+
- name: Publish package distributions to PyPI
41+
if: github.ref == 'refs/heads/main'
42+
uses: pypa/gh-action-pypi-publish@release/v1
43+
with:
44+
skip-existing: true
45+
repository-url: https://upload.pypi.org/legacy/

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ build
1111
*.whl
1212
*.zip
1313
env-calrissian*
14+
*.tar.gz

Diff for: CHANGELOG.md

+27
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
66
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
77

8+
## [v0.18.0] - 2024-12-13
9+
10+
### Changes
11+
12+
- Drop setup.py and requirements.txt in favour of PEP 517 and 518 by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/177
13+
14+
## [v0.17.2] - 2024-05-02
15+
16+
### Changes
17+
18+
- calls `setup_kubernetes` before `_setup` to set `cudaDeviceCount` by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/170
19+
20+
## [v0.17.1] - 2024-05-02
21+
22+
### Changes
23+
24+
## [v0.17.0] - 2024-05-02
25+
26+
- broken release
27+
28+
### Changes
29+
30+
- Create codemeta.json by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/163
31+
- Conformance 1.2.1 by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/164
32+
- Update README.md by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/165
33+
- adds `cudaVersionMin`, `cudaComputeCapability` in `CUDARequirement` by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/168
34+
835
## [v0.16.0] - 2023-11-23
936

1037
### Changes

Diff for: Dockerfile

+48-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,56 @@
1-
FROM python:3.10.0-slim-buster
2-
LABEL maintainer="[email protected]"
1+
# Stage 1: Build stage
2+
FROM rockylinux:9.3-minimal AS build
33

4-
# cwltool requires nodejs
5-
RUN apt-get update && apt-get install -y nodejs
4+
# Install necessary build tools
5+
RUN microdnf install -y curl tar
66

7-
RUN mkdir -p /app
8-
COPY . /app
9-
RUN pip install /app
10-
WORKDIR /app
7+
# Download the hatch tar.gz file from GitHub
8+
RUN curl -L https://github.com/pypa/hatch/releases/latest/download/hatch-x86_64-unknown-linux-gnu.tar.gz -o /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz
9+
10+
# Extract the hatch binary
11+
RUN tar -xzf /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz -C /tmp/
12+
13+
# Stage 2: Final stage
14+
FROM rockylinux:9.3-minimal
15+
16+
# Install runtime dependencies
17+
RUN microdnf install -y --nodocs nodejs && \
18+
microdnf clean all
1119

12-
# Create a default user and home directory
20+
# Set up a default user and home directory
1321
ENV HOME=/home/calrissian
14-
# home dir is created by useradd with group (g=0) to comply with
15-
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines
22+
23+
# Create a user with UID 1001, group root, and a home directory
1624
RUN useradd -u 1001 -r -g 0 -m -d ${HOME} -s /sbin/nologin \
17-
-c "Default Calrissian User" calrissian && \
18-
chown -R 1001:0 /app && \
19-
chmod g+rwx ${HOME}
25+
-c "Default Calrissian User" calrissian && \
26+
mkdir -p /app && \
27+
mkdir -p /prod && \
28+
chown -R 1001:0 /app && \
29+
chmod g+rwx ${HOME} /app
30+
31+
# Copy the hatch binary from the build stage
32+
COPY --from=build /tmp/hatch /usr/bin/hatch
33+
34+
# Ensure the hatch binary is executable
35+
RUN chmod +x /usr/bin/hatch
2036

37+
# Switch to the non-root user
2138
USER calrissian
39+
40+
# Copy the application files into the /app directory
41+
COPY --chown=1001:0 . /tmp
42+
WORKDIR /tmp
43+
44+
# Set up virtual environment paths
45+
ENV VIRTUAL_ENV=/app/envs/calrissian
46+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
47+
48+
# Prune any existing environments and create a new production environment
49+
RUN cd /tmp && hatch env prune && \
50+
hatch env create prod && \
51+
rm -fr /tmp/* /tmp/.git /tmp/.pytest_cache
52+
53+
WORKDIR /app
54+
55+
# Set the default command to run when the container starts
2256
CMD ["calrissian"]

Diff for: README.md

+42
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,45 @@ When encountering a Kubernetes API exception, Calrissian uses a library to retry
6363
- `RETRY_MIN`: Default `5`. Minimum interval between retries.
6464
- `RETRY_MAX`: Default `1200`. Maximum interval between retries.
6565
- `RETRY_ATTEMPTS`: Default `10`. Max number of retries before giving up.
66+
67+
## For developers
68+
69+
### Installing for Development
70+
71+
Note that for development you can just use [Hatch] directly as described below.
72+
73+
### Installing Hatch
74+
75+
The main tool that is used for development is [Hatch]. It manages dependencies (in a virtualenv that is created on the fly) and is also the command runner.
76+
77+
So first, [install it][install Hatch]. Ideally in an isolated way with **`pipx install hatch`** (after [installing `pipx`]), or just `pip install hatch` as a more well-known way.
78+
79+
### Running tests
80+
81+
```
82+
hatch run test:test
83+
```
84+
85+
Verbose:
86+
87+
```
88+
hatch run test:testv
89+
```
90+
91+
### Running test coverage
92+
93+
```
94+
hatch run test:cov
95+
```
96+
97+
### Running calrissian
98+
99+
```
100+
hatch run calrissian
101+
```
102+
103+
### Serve the documentation
104+
105+
```
106+
hatch run docs:serve
107+
```

Diff for: calrissian/__about__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version="0.18.0"

0 commit comments

Comments
 (0)