Skip to content

Commit

Permalink
Template for packaging spinalcordtoolbox datasets in pip.
Browse files Browse the repository at this point in the history
  • Loading branch information
kousu committed Apr 6, 2021
1 parent 13be1fe commit b66e6b3
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Test the Build

on:
# test on PRs and double-test on merges to master, or manually.
pull_request:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
- name: Build tools
run: |
python -m pip install --upgrade pip
pip install build
- name: Build
run: |
python -m build --wheel --sdist
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Publish

on:
# publish from the Releases page:
release:
types: [published]
# publish from the Actions page:
workflow_dispatch:
inputs:
version:
description: 'Version (e.g. 2.0.3)'
required: true

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
- name: Build tools
run: |
python -m pip install --upgrade pip
pip install build
- name: Build
run: |
python -m build --wheel --sdist
### TODO: can the uploads be parallelized?
- name: Publish to Github
uses: softprops/action-gh-release@v1
with:
files: 'dist/*'
fail_on_unmatched_files: true
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.
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
#password: ${{ secrets.PYPI_PASSWORD }}
# DEBUG:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dist/
build/

*.whl
*.egg-info
__pycache__
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# PAM50

PAM50 template. For more details see [De Leener et al. Neuroimage 2018](https://pubmed.ncbi.nlm.nih.gov/29061527/)

Part of [`spinalcordtoolbox`](https://github.com/neuropoly/spinalcordtoolbox).
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this ensures builds are done reliably
[build-system]
requires = ["setuptools>=40.8.0", "setuptools_scm[toml]", "wheel"]
44 changes: 44 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from setuptools import setup, find_packages, find_namespace_packages
import pathlib

here = pathlib.Path(__file__).parent.resolve()

# workaround a bug introduced by pyproject.toml
# https://github.com/pypa/pip/issues/7953#issuecomment-645133255
import site, sys; site.ENABLE_USER_SITE = True

setup(
name='spinalcordtoolbox-data-<dataset>',
description='Part of https://github.com/neuropoly/spinalcordtoolbox',
long_description=(here / 'README.md').read_text(encoding='utf-8'),
long_description_content_type='text/markdown',
author='Neuropoly',
author_email='[email protected]',
url='https://spinalcordtoolbox.com/',
project_urls={
'Source': 'https://github.com/sct-data/<dataset>',
#'Documentation': '',
},
#license='CC-BY-NC', ??
#license_files=[ ... ] # TODO?

packages=find_namespace_packages('src/'),
package_dir={"":"src/"},

# with setuptools_scm, means it includes non-python files if they're under git
include_package_data=True,

# with setuptools_scm, get the version out of the most recent git tag.
# the tags must be formatted as semver.
use_scm_version=True,

# pyproject.toml::build-system.requires is supposed to supersede this, but it's still very new so we duplicate it.
setup_requires=[
'setuptools',
'setuptools_scm[toml]',
'wheel',
],

zip_safe=False, # guarantees that importlib.resources.path() is safe
)

2 changes: 2 additions & 0 deletions src/spinalcordtoolbox/data/dataset/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# empty __init__.py to enable importlib.resources
# see < TODO >

0 comments on commit b66e6b3

Please sign in to comment.