Skip to content

Commit b66e6b3

Browse files
committed
Template for packaging spinalcordtoolbox datasets in pip.
1 parent 13be1fe commit b66e6b3

File tree

7 files changed

+125
-0
lines changed

7 files changed

+125
-0
lines changed

.github/workflows/build.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Test the Build
2+
3+
on:
4+
# test on PRs and double-test on merges to master, or manually.
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
workflow_dispatch:
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Set up Python
17+
uses: actions/setup-python@v1
18+
- name: Build tools
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install build
22+
- name: Build
23+
run: |
24+
python -m build --wheel --sdist

.github/workflows/release.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish
2+
3+
on:
4+
# publish from the Releases page:
5+
release:
6+
types: [published]
7+
# publish from the Actions page:
8+
workflow_dispatch:
9+
inputs:
10+
version:
11+
description: 'Version (e.g. 2.0.3)'
12+
required: true
13+
14+
jobs:
15+
publish:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python
20+
uses: actions/setup-python@v1
21+
- name: Build tools
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install build
25+
- name: Build
26+
run: |
27+
python -m build --wheel --sdist
28+
### TODO: can the uploads be parallelized?
29+
- name: Publish to Github
30+
uses: softprops/action-gh-release@v1
31+
with:
32+
files: 'dist/*'
33+
fail_on_unmatched_files: true
34+
tag_name: ${{ github.event.inputs.version }} # in the workflow_dispatch case, make a new tag from the given input; in the published release case, this will be empty and will fall back to updating that release.
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
- name: Publish to PyPI
38+
uses: pypa/gh-action-pypi-publish@release/v1
39+
with:
40+
user: __token__
41+
#password: ${{ secrets.PYPI_PASSWORD }}
42+
# DEBUG:
43+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
44+
repository_url: https://test.pypi.org/legacy/

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
dist/
2+
build/
3+
4+
*.whl
5+
*.egg-info
6+
__pycache__

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# PAM50
22

33
PAM50 template. For more details see [De Leener et al. Neuroimage 2018](https://pubmed.ncbi.nlm.nih.gov/29061527/)
4+
5+
Part of [`spinalcordtoolbox`](https://github.com/neuropoly/spinalcordtoolbox).

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this ensures builds are done reliably
2+
[build-system]
3+
requires = ["setuptools>=40.8.0", "setuptools_scm[toml]", "wheel"]

setup.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from setuptools import setup, find_packages, find_namespace_packages
2+
import pathlib
3+
4+
here = pathlib.Path(__file__).parent.resolve()
5+
6+
# workaround a bug introduced by pyproject.toml
7+
# https://github.com/pypa/pip/issues/7953#issuecomment-645133255
8+
import site, sys; site.ENABLE_USER_SITE = True
9+
10+
setup(
11+
name='spinalcordtoolbox-data-<dataset>',
12+
description='Part of https://github.com/neuropoly/spinalcordtoolbox',
13+
long_description=(here / 'README.md').read_text(encoding='utf-8'),
14+
long_description_content_type='text/markdown',
15+
author='Neuropoly',
16+
author_email='neuropoly@googlegroups.com',
17+
url='https://spinalcordtoolbox.com/',
18+
project_urls={
19+
'Source': 'https://github.com/sct-data/<dataset>',
20+
#'Documentation': '',
21+
},
22+
#license='CC-BY-NC', ??
23+
#license_files=[ ... ] # TODO?
24+
25+
packages=find_namespace_packages('src/'),
26+
package_dir={"":"src/"},
27+
28+
# with setuptools_scm, means it includes non-python files if they're under git
29+
include_package_data=True,
30+
31+
# with setuptools_scm, get the version out of the most recent git tag.
32+
# the tags must be formatted as semver.
33+
use_scm_version=True,
34+
35+
# pyproject.toml::build-system.requires is supposed to supersede this, but it's still very new so we duplicate it.
36+
setup_requires=[
37+
'setuptools',
38+
'setuptools_scm[toml]',
39+
'wheel',
40+
],
41+
42+
zip_safe=False, # guarantees that importlib.resources.path() is safe
43+
)
44+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# empty __init__.py to enable importlib.resources
2+
# see < TODO >

0 commit comments

Comments
 (0)