Skip to content

Commit 5358059

Browse files
author
Nathan Hammond
committed
update readme and names, add tests, add github actino for pip install test
1 parent ec7cfe1 commit 5358059

File tree

9 files changed

+124
-9
lines changed

9 files changed

+124
-9
lines changed
File renamed without changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Test pip install
2+
3+
on:
4+
push:
5+
branches:
6+
- "*"
7+
pull_request:
8+
branches:
9+
- "*"
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Python 3.10
22+
uses: actions/setup-python@v3
23+
with:
24+
python-version: "3.10"
25+
26+
- name: Install package
27+
run: |
28+
python -m pip install --upgrade pip
29+
python -m pip install .
30+
31+
- name: Test with unittest
32+
run: |
33+
python -m unittest discover

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# For setuptools-scm automatic versioning, do not check in auto-generated _version.py file
2+
_version.py
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ RUN echo "REF_NAME: $REF_NAME"
4545
RUN pip install --upgrade pip setuptools && \
4646
pip install /src/${PROJECT}
4747

48-
ENTRYPOINT ["python3", "-m", "napari"]
48+
RUN python3 -m unittest discover
49+
50+
ENTRYPOINT ["python3", "-m", "napari"]

README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,66 @@ conda env create --file compmicro-ndutils-env/environment.yml
1515
```
1616

1717
### Docker
18+
A docker image is automatically built using GitHub actions whenever a version tag is pushed. See the GitHub-hosted [compmicro-ndutils-env](https://github.com/czbiohub-sf/compmicro-ndutils-env/pkgs/container/compmicro-ndutils-env) Docker repository.
19+
20+
To pull and run a Docker image:
21+
```
22+
docker run ghcr.io/czbiohub-sf/compmicro-ndutils-env:${VERSION}
23+
```
24+
25+
To build a Docker image manually:
1826
```
1927
git clone [email protected]:czbiohub-sf/compmicro-ndutils-env.git
2028
cd compmicro-ndutils-env
2129
docker build .
2230
```
2331

32+
## Apptainer
33+
To run an Apptainer container created from the Docker image:
34+
```
35+
apptainer run docker://ghcr.io/czbiohub-sf/compmicro-ndutils-env:${VERSION}
36+
```
37+
38+
Or to run a bash shell in Apptainer:
39+
```
40+
apptainer exec docker://ghcr.io/czbiohub-sf/compmicro-ndutils-env:${VERSION} bash
41+
```
42+
2443
## Checking the installed version
25-
You can check the version of the installed ndutils environment using the ndutils_version command or with "pip list"
44+
You can check the version of the installed ndutils environment using the env_version command or with "pip list" or "pip show".
45+
2646
```
27-
$ ndutils_version
28-
0.2.0.dev2
47+
$ env_version
48+
ndutils 0.2.0.dev3
2949
3050
$ pip list | grep ndutils
31-
compmicro-ndutils-env 0.2.0.dev2
51+
ndutils 0.2.0.dev3
52+
53+
$ pip show ndutils
54+
Name: ndutils
55+
Version: 0.2.0.dev3
56+
Summary: ndutils compute environment for computational microscopy at CZBiohub SF
57+
...
3258
```
59+
60+
## Creating a new release
61+
To update this environment:
62+
* Check out the git repo and make edits
63+
* Update Python dependencies by editing requirements.txt (which is used by Conda, Docker, and Pip install methods)
64+
* Update Python version by editing both environment.yml (for Conda) and Dockerfile
65+
* Commit and push/merge changes to the *main* branch
66+
* Tag the commit with a version identifier (`git tag x.y.z`)
67+
* Push the tag with `git push --tags` (warning this pushes ALL local tags)
68+
* Monitor [GitHub actions](https://github.com/czbiohub-sf/compmicro-ndutils-env/actions) to confirm the build succeeds
69+
* If needed, deploy the new environment to your infrastructure (e.g. by running "conda update ...".) Deployment documentation is not included here as it varies between sites.
70+
71+
## Creating a new environment
72+
If you want to use the code in this repo as a template for creating a new environment, you will need to make the following changes:
73+
* Create a new repo in GitHub. (Defining multiple environments in one GitHub repo is to be avoided because it complicates versioning and automatically building each environment separately.)
74+
* When copying files into the new repo, be sure to include the hidden ".github/" directory and ".gitignore" file, but exclude the ".git/" directory. (A fresh ".git" directory will be creating either by `git init` or by cloning a clean repo created in GitHub.)
75+
* Edit the following files and directories to update references to the git repo name (compmicro-ndutils-env), Python package name and conda environment name (ndutils), environment name. (You may want to grep to make sure there are not any others.)
76+
* README.md
77+
* pyproject.toml
78+
* ndutils/
79+
* Edit the Dockerfile to ensure an appropriate ENTRYPOINT is used, if any, for the new environment.
80+
* Commit, tag, and push the updated code as described in "Creating a new release".

ndutils/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

ndutils/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
from . import _version
22

3+
34
# The "_version.py" file is generated by setuptools_scm on installation
45

5-
def version():
6-
print(f"{__name__}: {_version.version}")
6+
7+
def env_version():
8+
package, version = _env_version_tuple()
9+
print(f"{package}\t{version}")
10+
11+
12+
def _env_version_tuple():
13+
package = __name__
14+
return (package, _version.version)

ndutils/test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from unittest import TestCase
2+
from unittest.mock import patch
3+
from io import StringIO
4+
5+
from . import env_version, _env_version_tuple
6+
7+
8+
class TestEnvVersion(TestCase):
9+
10+
@patch('sys.stdout', new_callable=StringIO)
11+
def test_env_version(self, mock_stdout):
12+
# Confirm non-empty stdout when calling env_version
13+
# Excpected value is "${package_name}\t${version}"
14+
env_version()
15+
self.assertTrue(len(mock_stdout.getvalue()) > 0)
16+
17+
def test_env_version_tuple(self):
18+
# Confirm non-empty strings for package and version
19+
(package, version) = _env_version_tuple()
20+
self.assertTrue(len(package) > 0)
21+
self.assertTrue(len(version) > 0)
22+

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ classifiers = [
2828
]
2929

3030
[project.scripts]
31-
ndutils_version = "ndutils:version"
31+
env_version = "ndutils:env_version"
3232

3333
[project.urls]
3434
"Homepage" = "https://github.com/czbiohub-sf/compmicro-ndutils-env"

0 commit comments

Comments
 (0)