Skip to content

Commit e1bbc8e

Browse files
authored
chore: Update pyproject.toml to work with Poetry 2.x (#241)
* update pre-commit config * Pin the ruff version used in Actions * Update to latest dev.sh script * Update pyproject.toml to new format Update poetry.lock with updated dependencies Update project to require Python >= 3.9 * Move container files to product-agnostic file names Update README Add .containerignore file Update to a more standard Containerfile * move from green to pytest for unit testing
1 parent 3af0dac commit e1bbc8e

13 files changed

+557
-1294
lines changed

.containerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.[a-z]*
2+
.venv/*
3+
*.sh
4+
*.xml
5+
CHANGELOG.md
6+
Dockerfile
7+
tests/*
8+
tmp/*

.github/workflows/checks.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ jobs:
1212
linting:
1313
uses: broadinstitute/shared-workflows/.github/workflows/[email protected]
1414
with:
15+
ruff_version: '0.8.6'
1516
use_pylama: false
1617
use_ruff: true
1718
unit-tests:
1819
uses: broadinstitute/shared-workflows/.github/workflows/[email protected]
1920
with:
2021
python_package_name: cert_manager
22+
run_coverage: false
23+
test_runner: pytest

.green

-2
This file was deleted.

.pre-commit-config.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.5.0
4+
rev: v5.0.0
55
hooks:
66
- id: check-added-large-files
77
- id: check-ast
@@ -28,12 +28,12 @@ repos:
2828
- id: trailing-whitespace
2929
- repo: https://github.com/astral-sh/ruff-pre-commit
3030
# Ruff version.
31-
rev: v0.1.14
31+
rev: v0.8.6
3232
hooks:
3333
- id: ruff
3434
args: [--fix, --exit-non-zero-on-fix]
3535
- repo: https://github.com/adrienverge/yamllint.git
36-
rev: v1.33.0
36+
rev: v1.35.1
3737
hooks:
3838
- id: yamllint
3939
args:

Containerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM docker.io/node:bookworm AS prettier-install
2+
RUN yarn add prettier@3
3+
4+
FROM python:3.11-slim-bookworm
5+
6+
ARG LOCAL_BIN=/root/.local/bin
7+
ENV PATH=$LOCAL_BIN:$PATH
8+
9+
# Install prettier
10+
RUN mkdir -p $LOCAL_BIN
11+
COPY --from=prettier-install /usr/local/bin/node $LOCAL_BIN
12+
COPY --from=prettier-install /node_modules/prettier /prettier
13+
RUN ln -s /prettier/bin/prettier.cjs $LOCAL_BIN/prettier
14+
15+
COPY . /working/
16+
17+
WORKDIR /working
18+
19+
RUN apt-get update \
20+
&& apt-get upgrade -y \
21+
&& apt-get install -yq --no-install-recommends curl make \
22+
&& curl -sSL https://install.python-poetry.org | python3 - \
23+
&& poetry install \
24+
&& rm -rf /tmp/* \
25+
&& rm -rf /var/cache/apt/* \
26+
&& rm -rf /var/tmp/*
27+
28+
ENTRYPOINT ["poetry", "run"]
29+
30+
CMD ["bash"]

Dockerfile

-20
This file was deleted.

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This library provides a [Python][1] interface to the [Sectigo][2] Certificate Ma
66

77
## Basics
88

9-
`cert_manager` runs on [Python][1] >= 3.7
9+
`cert_manager` runs on [Python][1] >= 3.9
1010

1111
## Features
1212

@@ -109,15 +109,15 @@ Pull requests to add functionality and fix bugs are always welcome. Please chec
109109

110110
### Testing
111111

112-
We try to have a high level of test coverage on the code. Therefore, when adding anything to the repo, tests should be written to test a new feature or to test a bug fix so that there won't be a regression. This library is setup to be pretty simple to build a working development environment using [Docker][4]. Therefore, it is suggested that you have [Docker][4] installed where you clone this repository to make development easier.
112+
We try to have a high level of test coverage on the code. Therefore, when adding anything to the repo, tests should be written to test a new feature or to test a bug fix so that there won't be a regression. This library is setup to be pretty simple to build a working development environment using [Docker][4]. Therefore, it is suggested that you have [Docker][4] installed where you clone this repository to make development easier.
113113

114-
To start a development environment, you should be able to just run the `dev.sh` script. This script will use the `Dockerfile` in this repository to build a [Docker][4] container with all the dependencies for development installed using [Pipenv][3].
114+
To start a development environment, you should be able to just run the `dev.bash` script. This script will use the `Containerfile` in this repository to build a [Docker][4] container with all the dependencies for development installed using [Poetry][3].
115115

116116
```sh
117-
./dev.sh
117+
./dev.bash
118118
```
119119

120-
The first time you run the script, it should build the [Docker][4] image and then drop you into the container's shell. The directory where you cloned this repository should be volume mounted in to `/usr/src`, which should also be the current working directory. From there, you can make changes as you see fit. Tests can be run from the `/usr/src` directory by simply typing `green` as [green][5] has been setup to with the correct parameters.
120+
The first time you run the script, it should build the [Docker][4] image and then drop you into the container's shell. The directory where you cloned this repository should be volume mounted in to `/working`, which should also be the current working directory. From there, you can make changes as you see fit. Tests can be run from the `/working` directory by simply typing `pytest` as [pytest][5] has been setup to with the correct parameters.
121121

122122
## Changelog
123123

@@ -162,7 +162,7 @@ git push --tags
162162

163163
[1]: https://www.python.org/ "Python"
164164
[2]: https://sectigo.com/ "Sectigo"
165-
[3]: https://pipenv.readthedocs.io/en/latest/ "Pipenv"
165+
[3]: https://python-poetry.org/ "Poetry"
166166
[4]: https://www.docker.com/ "Docker"
167-
[5]: https://github.com/CleanCut/green "green"
167+
[5]: https://docs.pytest.org/en/stable/ "pytest"
168168
[6]: https://pypi.org/project/bump2version/ "bump2version"

dev.bash

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
3+
declare -g CHECKSUM_APP
4+
declare -g CONTAINER_APP
5+
declare -g CONTAINER_IMAGE='cert_manager:dev'
6+
declare -g LABEL_PREFIX='org.broadinstitute.cert-manager'
7+
declare -g SCRIPT_DIR
8+
declare -ga TRACK_FILES=( Containerfile poetry.lock pyproject.toml )
9+
declare -ga SUDO
10+
declare -ag TTY
11+
12+
SCRIPT_DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13+
14+
if hash sha256sum 2>/dev/null; then
15+
CHECKSUM_APP='sha256sum'
16+
elif hash shasum 2>/dev/null; then
17+
CHECKSUM_APP='shasum -a 256'
18+
elif hash md5sum 2>/dev/null; then
19+
CHECKSUM_APP='md5sum'
20+
else
21+
echo 'Could not find a checksumming program. Exiting!'
22+
exit 1
23+
fi
24+
25+
if hash docker 2>/dev/null; then
26+
CONTAINER_APP='docker'
27+
elif hash podman 2>/dev/null; then
28+
CONTAINER_APP='podman'
29+
else
30+
echo 'Container environment cannot be found. Exiting!'
31+
exit 2
32+
fi
33+
34+
if [[ "${TERM}" != 'dumb' ]]; then
35+
TTY=( -it )
36+
fi
37+
38+
if [[ "${CONTAINER_APP}" = 'docker' ]] && [[ "$( uname -s )" != 'Darwin' ]]; then
39+
if [[ ! -w "${DOCKER_SOCKET}" ]]; then
40+
SUDO=( sudo )
41+
fi
42+
fi
43+
44+
function build() {
45+
if [[ -z "$1" ]]; then
46+
echo 'Image name not provided to build. Exiting!'
47+
exit 1
48+
fi
49+
CONTAINER_IMAGE=$1
50+
51+
if ! git diff --quiet; then
52+
echo 'Branch is dirty. The build can only happen on an unmodified branch.'
53+
exit 2
54+
fi
55+
56+
local -a labels
57+
for tfile in "${TRACK_FILES[@]}"; do
58+
label="$( "${CHECKSUM_APP}" "${tfile}" | awk -v PREFIX="${LABEL_PREFIX}" '{print PREFIX"."$2"="$1}' )"
59+
labels+=( --label "${label}" )
60+
done
61+
62+
"${SUDO[@]}" "${CONTAINER_APP}" build --pull -t "${CONTAINER_IMAGE}" "${labels[@]}" .
63+
}
64+
65+
pushd "${SCRIPT_DIR}" >/dev/null || exit 1
66+
if ! "${SUDO[@]}" "${CONTAINER_APP}" image ls | awk '{print $1":"$2}' | grep --quiet -E "^(localhost\/)*${CONTAINER_IMAGE}"; then
67+
build "${CONTAINER_IMAGE}"
68+
fi
69+
70+
rebuild='0'
71+
for tfile in "${TRACK_FILES[@]}"; do
72+
current="$( "${CHECKSUM_APP}" "${tfile}" | cut -d' ' -f1 )"
73+
stored="$( "${CONTAINER_APP}" image inspect --format="{{index .Config.Labels \"${LABEL_PREFIX}.${tfile}\"}}" "${CONTAINER_IMAGE}" )"
74+
75+
if [[ "${current}" != "${stored}" ]]; then
76+
echo "${tfile} changed. Rebuilding."
77+
rebuild='1'
78+
fi
79+
done
80+
81+
if [[ "${rebuild}" == '1' ]]; then
82+
build "${CONTAINER_IMAGE}"
83+
fi
84+
85+
"${SUDO[@]}" "${CONTAINER_APP}" run "${TTY[@]}" --rm \
86+
-v "${SCRIPT_DIR}:/working" \
87+
"${CONTAINER_IMAGE}" "$@"
88+
89+
popd >/dev/null || exit 1

dev.sh

-26
This file was deleted.

0 commit comments

Comments
 (0)