diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..93e519a --- /dev/null +++ b/.github/workflows/build.yml @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e6b1fa3 --- /dev/null +++ b/.github/workflows/release.yml @@ -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/ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92148bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +dist/ +build/ + +*.whl +*.egg-info +__pycache__ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..1ce1d64 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +# this ensures builds are done reliably +[build-system] +requires = ["setuptools>=40.8.0", "setuptools_scm[toml]", "wheel"] diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..93edf6b --- /dev/null +++ b/setup.py @@ -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-deepseg_gm_models', + description='Part of https://github.com/neuropoly/spinalcordtoolbox', + long_description=(here / 'README.txt').read_text(encoding='utf-8'), + long_description_content_type='text/plain', + author='Neuropoly', + author_email='neuropoly@googlegroups.com', + url='https://spinalcordtoolbox.com/', + project_urls={ + 'Source': 'https://github.com/sct-data/deepseg_gm_models', + #'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 +) + diff --git a/src/spinalcordtoolbox/data/deepseg/gm/__init__.py b/src/spinalcordtoolbox/data/deepseg/gm/__init__.py new file mode 100644 index 0000000..ead4c67 --- /dev/null +++ b/src/spinalcordtoolbox/data/deepseg/gm/__init__.py @@ -0,0 +1,2 @@ +# empty __init__.py to enable importlib.resources +# see < TODO > diff --git a/challenge_model.hdf5 b/src/spinalcordtoolbox/data/deepseg/gm/challenge_model.hdf5 similarity index 100% rename from challenge_model.hdf5 rename to src/spinalcordtoolbox/data/deepseg/gm/challenge_model.hdf5 diff --git a/challenge_model.json b/src/spinalcordtoolbox/data/deepseg/gm/challenge_model.json similarity index 100% rename from challenge_model.json rename to src/spinalcordtoolbox/data/deepseg/gm/challenge_model.json diff --git a/large_model.hdf5 b/src/spinalcordtoolbox/data/deepseg/gm/large_model.hdf5 similarity index 100% rename from large_model.hdf5 rename to src/spinalcordtoolbox/data/deepseg/gm/large_model.hdf5 diff --git a/large_model.json b/src/spinalcordtoolbox/data/deepseg/gm/large_model.json similarity index 100% rename from large_model.json rename to src/spinalcordtoolbox/data/deepseg/gm/large_model.json