Skip to content

Commit 5bea3f1

Browse files
authored
MNT: Infrastructure updates (#351)
Bringing smriprep build infrastructure into 2023. This: * Drops setuptools/versioneer, adopts hatch/hatch-vcs. * Uses the current Dockerfile+env.yml+requirements.txt approach used in fMRIPrep * Adds a precommit configuration * Updates .gitignore using standard approach introduced elsewhere in nipreps
1 parent b174172 commit 5bea3f1

20 files changed

+932
-3401
lines changed

.circleci/config.yml

Lines changed: 71 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -84,98 +84,85 @@ aliases:
8484
jobs:
8585
build:
8686
<<: *machine_defaults
87+
environment:
88+
DOCKER_BUILDKIT: 1
8789
steps:
8890
- checkout:
8991
path: *src
9092
- restore_cache:
9193
keys:
92-
- build-v0-{{ .Branch }}-{{ .Revision }}
93-
- build-v0--{{ .Revision }}
94-
- build-v0-{{ .Branch }}-
95-
- build-v0-master-
96-
- build-v0-
94+
- build-v1-{{ .Branch }}-{{ .Revision }}
95+
- build-v1--{{ .Revision }}
96+
- build-v1-{{ .Branch }}-
97+
- build-v1-master-
98+
- build-v1-
9799
paths:
98100
- /tmp/docker
99101
- /tmp/images
100102
- docker/install-docker-credential-helper
101103
- run: *docker_auth
102104
- run: *setup_docker_registry
103105
- run:
104-
name: Save docker registry
105-
command: |
106-
if [[ ! -f /tmp/images/registry.tar.gz ]]; then
107-
mkdir -p /tmp/images
108-
docker save registry:2 | gzip > /tmp/images/registry.tar.gz
109-
fi
110-
- run:
111-
name: Pull Ubuntu/jammy image
112-
command: |
113-
set +e
114-
docker pull localhost:5000/ubuntu
115-
success=$?
116-
set -e
117-
if [[ "$success" = "0" ]]; then
118-
echo "Pulling from local registry"
119-
docker tag localhost:5000/ubuntu ubuntu:jammy-20221130
120-
else
121-
echo "Pulling from Docker Hub"
122-
docker pull ubuntu:jammy-20221130
123-
docker tag ubuntu:jammy-20221130 localhost:5000/ubuntu
124-
docker push localhost:5000/ubuntu
125-
fi
126-
- run:
127-
name: Pull sMRIPrep Docker image
128-
command: |
129-
set +e
130-
docker pull localhost:5000/smriprep
131-
success=$?
132-
set -e
133-
if [[ "$success" = "0" ]]; then
134-
echo "Pulled from local registry"
135-
docker tag localhost:5000/smriprep nipreps/smriprep:latest
136-
docker tag localhost:5000/smriprep nipreps/smriprep
137-
else
138-
echo "Pulling from Docker Hub"
139-
docker pull nipreps/smriprep:latest
140-
fi
106+
name: Create named builder
107+
command: docker buildx create --use --name=builder --driver=docker-container
141108
- run:
142109
name: Build Docker image
143110
no_output_timeout: 60m
144111
command: |
145112
export PY3=$( pyenv versions | awk '/^\* 3/ { print $2 }' )
146113
pyenv local $PY3
114+
pip install hatch
147115
# Get version, update files.
148-
THISVERSION=$( python3 get_version.py )
116+
THISVERSION=$( hatch version )
149117
if [[ ${THISVERSION:0:1} == "0" ]] ; then
150118
echo "WARNING: latest git tag could not be found"
151119
echo "Please, make sure you fetch all tags from upstream with"
152120
echo "the command ``git fetch --tags --verbose`` and push"
153121
echo "them to your fork with ``git push origin --tags``"
154122
fi
155123
# Build docker image
156-
e=1 && for i in {1..5}; do
157-
docker build --rm \
158-
--cache-from=nipreps/smriprep \
124+
docker buildx build --load --builder builder \
125+
--cache-from localhost:5000/smriprep \
126+
--cache-from nipreps/smriprep:latest \
159127
-t nipreps/smriprep:latest \
160128
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
161129
--build-arg VCS_REF=`git rev-parse --short HEAD` \
162-
--build-arg VERSION="${CIRCLE_TAG:-$THISVERSION}" . \
163-
&& e=0 && break || sleep 15
164-
done && [ "$e" -eq "0" ]
130+
--build-arg VERSION="${CIRCLE_TAG:-$THISVERSION}" .
165131
- run:
166132
name: Check Docker image
167133
command: |
168134
export PY3=$( pyenv versions | awk '/^\* 3/ { print $2 }' )
169135
pyenv local $PY3
170136
# Get version, update files.
171-
THISVERSION=$( python3 get_version.py )
137+
THISVERSION=$( hatch version )
172138
BUILT_VERSION=$( docker run --rm nipreps/smriprep:latest --version )
173139
BUILT_VERSION=${BUILT_VERSION%$'\r'}
174140
BUILT_VERSION=${BUILT_VERSION#*"smriprep v"}
175141
echo "VERSION: \"$THISVERSION\""
176142
echo "BUILT: \"$BUILT_VERSION\""
177143
set -e
178144
test "$BUILT_VERSION" = "$THISVERSION"
145+
- run:
146+
name: Docker push to local registry
147+
no_output_timeout: 40m
148+
command: |
149+
docker tag nipreps/smriprep:latest localhost:5000/smriprep
150+
docker push localhost:5000/smriprep
151+
- run:
152+
name: Docker registry garbage collection
153+
command: |
154+
docker exec -it registry /bin/registry garbage-collect --delete-untagged \
155+
/etc/docker/registry/config.yml
156+
157+
- persist_to_workspace:
158+
root: /tmp
159+
paths:
160+
- src/smriprep
161+
- save_cache:
162+
key: build-v1-{{ .Branch }}-{{ .Revision }}
163+
paths:
164+
- /tmp/docker
165+
- /tmp/images
179166

180167
- run:
181168
name: Docker push to local registry
@@ -189,7 +176,7 @@ jobs:
189176
docker exec -it registry /bin/registry garbage-collect --delete-untagged \
190177
/etc/docker/registry/config.yml
191178
- save_cache:
192-
key: build-v0-{{ .Branch }}-{{ .Revision }}
179+
key: build-v1-{{ .Branch }}-{{ .Revision }}
193180
paths:
194181
- /tmp/docker
195182
- /tmp/images
@@ -300,7 +287,7 @@ jobs:
300287
at: /tmp
301288
- restore_cache:
302289
keys:
303-
- build-v0-{{ .Branch }}-{{ .Revision }}
290+
- build-v1-{{ .Branch }}-{{ .Revision }}
304291
paths:
305292
- /tmp/docker
306293
- /tmp/images
@@ -337,35 +324,31 @@ jobs:
337324
338325
test_deploy_pypi:
339326
<<: *python_defaults
340-
working_directory: /tmp/src/smriprep
341327
steps:
342328
- checkout
329+
- run:
330+
name: Update build tools
331+
command: pip install --upgrade build twine hatch
343332
- run:
344333
name: Build sMRIPrep
345-
command: |
346-
pip install --user twine # For use in checking distributions
347-
THISVERSION=$( python get_version.py )
348-
THISVERSION=${THISVERSION%.dirty*}
349-
THISVERSION=${CIRCLE_TAG:-$THISVERSION}
350-
virtualenv --python=python build
351-
source build/bin/activate
352-
pip install --upgrade "pip>=19.1" numpy
353-
echo "${CIRCLE_TAG:-$THISVERSION}" > smriprep/VERSION
354-
python setup.py sdist
355-
pip wheel --no-deps -w dist/ .
334+
command: python -m build
335+
- run:
336+
name: Twine check smriprep
337+
command: twine check dist/*
338+
- run:
339+
name: Pre-run hatch version
340+
command: hatch version
356341
- store_artifacts:
357342
path: /tmp/src/smriprep/dist
358343
- run:
359344
name: Check sdist distribution
360345
command: |
361-
THISVERSION=$( python get_version.py )
362-
THISVERSION=${THISVERSION%.dirty*}
346+
THISVERSION=$( hatch version )
363347
THISVERSION=${CIRCLE_TAG:-$THISVERSION}
364-
twine check dist/smriprep*.tar.gz
365348
virtualenv --python=python sdist
366349
source sdist/bin/activate
367-
pip install --upgrade "pip>=19.1" numpy
368-
pip install dist/smriprep*.tar.gz
350+
python -m pip install --upgrade pip
351+
python -m pip install dist/smriprep*.tar.gz
369352
which smriprep | grep sdist\\/bin
370353
INSTALLED_VERSION=$(smriprep --version)
371354
INSTALLED_VERSION=${INSTALLED_VERSION%$'\r'}
@@ -376,13 +359,11 @@ jobs:
376359
- run:
377360
name: Check wheel distribution
378361
command: |
379-
THISVERSION=$( python get_version.py )
380-
THISVERSION=${THISVERSION%.dirty*}
362+
THISVERSION=$( hatch version )
381363
THISVERSION=${CIRCLE_TAG:-$THISVERSION}
382-
twine check dist/smriprep*.whl
383364
virtualenv --python=python wheel
384365
source wheel/bin/activate
385-
pip install dist/smriprep*.whl
366+
python -m pip install dist/smriprep*.whl
386367
which smriprep | grep wheel\\/bin
387368
INSTALLED_VERSION=$(smriprep --version)
388369
INSTALLED_VERSION=${INSTALLED_VERSION%$'\r'}
@@ -392,28 +373,10 @@ jobs:
392373
test "$INSTALLED_VERSION" = "$THISVERSION"
393374
- run:
394375
name: Build smriprep-docker
395-
command: |
396-
THISVERSION=$( python get_version.py )
397-
THISVERSION=${THISVERSION%.dirty*}
398-
cd wrapper
399-
virtualenv --python=python build
400-
source build/bin/activate
401-
pip install --upgrade "pip>=19.1"
402-
sed -i -E "s/(__version__ = )\"[A-Za-z0-9.-]+\"/\1\"${CIRCLE_TAG:-$THISVERSION}\"/" smriprep_docker.py
403-
python setup.py sdist
404-
twine check dist/smriprep*.tar.gz
405-
pip wheel --no-deps -w dist/ .
406-
twine check dist/smriprep*.whl
407-
pip install dist/smriprep*.whl
408-
set +e
409-
INSTALLED_VERSION=$(yes n | smriprep-docker --version)
410-
set -e
411-
INSTALLED_VERSION=${INSTALLED_VERSION%$'\r'}
412-
INSTALLED_VERSION=${INSTALLED_VERSION#*"smriprep wrapper "}
413-
INSTALLED_VERSION=$( echo ${INSTALLED_VERSION} | cut -f1 -d" ")
414-
echo "VERSION: \"$THISVERSION\""
415-
echo "INSTALLED: \"$INSTALLED_VERSION\""
416-
test "$INSTALLED_VERSION" = "$THISVERSION"
376+
command: python -m build wrapper
377+
- run:
378+
name: Twine check wrapper
379+
command: twine check wrapper/dist/*
417380
- store_artifacts:
418381
path: /tmp/src/smriprep/wrapper/dist
419382

@@ -435,7 +398,7 @@ jobs:
435398
fi
436399
- restore_cache:
437400
keys:
438-
- build-v0-{{ .Branch }}-{{ .Revision }}
401+
- build-v1-{{ .Branch }}-{{ .Revision }}
439402
paths:
440403
- /tmp/docker
441404
- /tmp/images
@@ -566,7 +529,7 @@ jobs:
566529
fi
567530
- restore_cache:
568531
keys:
569-
- build-v0-{{ .Branch }}-{{ .Revision }}
532+
- build-v1-{{ .Branch }}-{{ .Revision }}
570533
paths:
571534
- /tmp/docker
572535
- /tmp/images
@@ -688,8 +651,8 @@ jobs:
688651
name: Update pip
689652
command: pip install --upgrade pip
690653
- run:
691-
name: Install deps
692-
command: pip install -r docs/requirements.txt
654+
name: Install deps and package
655+
command: pip install -r docs/requirements.txt .
693656
- run:
694657
name: Build only this commit
695658
no_output_timeout: 30m
@@ -734,35 +697,20 @@ jobs:
734697

735698
deploy_pypi:
736699
<<: *python_defaults
737-
working_directory: /tmp/src/smriprep
738700
steps:
739701
- checkout
702+
- run:
703+
name: Update build tools
704+
command: pip install --upgrade build twine
740705
- run:
741706
name: Build sMRIPrep
742-
command: |
743-
THISVERSION=$( python get_version.py )
744-
virtualenv --python=python build
745-
source build/bin/activate
746-
pip install --upgrade "pip>=19.1"
747-
echo "${CIRCLE_TAG:-$THISVERSION}" > smriprep/VERSION
748-
python setup.py sdist
749-
pip wheel --no-deps -w dist/ .
707+
command: python -m build
750708
- run:
751709
name: Build smriprep-docker
752-
command: |
753-
THISVERSION=$( python get_version.py )
754-
cd wrapper
755-
virtualenv --python=python build
756-
source build/bin/activate
757-
pip install --upgrade "pip>=19.1"
758-
sed -i -E "s/(__version__ = )\"[A-Za-z0-9.-]+\"/\1\"${CIRCLE_TAG:-$THISVERSION}\"/" smriprep_docker.py
759-
python setup.py sdist
760-
pip wheel --no-deps -w dist/ .
710+
command: python -m build wrapper/
761711
- run:
762712
name: Upload packages to PyPI
763-
command: |
764-
pip install --user twine
765-
twine upload dist/smriprep* wrapper/dist/smriprep*
713+
command: python -m twine upload dist/smriprep* wrapper/dist/smriprep*
766714

767715
deploy_docker:
768716
<<: *machine_defaults
@@ -777,9 +725,9 @@ jobs:
777725
fi
778726
- restore_cache:
779727
keys:
780-
- build-v0-{{ .Branch }}-{{ epoch }}
781-
- build-v0-{{ .Branch }}-
782-
- build-v0-master-
728+
- build-v1-{{ .Branch }}-{{ epoch }}
729+
- build-v1-{{ .Branch }}-
730+
- build-v1-master-
783731
paths:
784732
- /tmp/docker
785733
- /tmp/images

.flake8

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[flake8]
2+
max-line-length = 99
3+
doctests = False
4+
exclude=*build/
5+
ignore =
6+
W503
7+
per-file-ignores =
8+
**/__init__.py : F401
9+
docs/conf.py : E265

.git_archival.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node: $Format:%H$
2+
node-date: $Format:%cI$
3+
describe-name: $Format:%(describe:tags=true,match=*[0-9]*)$
4+
ref-names: $Format:%D$

0 commit comments

Comments
 (0)