Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate sct_testing_data to a pip package #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Template for packaging spinalcordtoolbox datasets in pip.
  • Loading branch information
kousu committed Apr 6, 2021
commit 4b8e242bd1cf43ccbf8373a9bd90de6383eac8c0
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__
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='neuropoly@googlegroups.com',
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 >