Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
balbasty committed Apr 18, 2024
2 parents 5188464 + 038bf4d commit dd81448
Show file tree
Hide file tree
Showing 12 changed files with 313 additions and 64 deletions.
33 changes: 33 additions & 0 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{% set name = "torch-distmap" %}
{% set version = "0.1.0" %}

package:
name: "{{ name|lower }}"
version: "{{ version }}"

source:
url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
sha256: dbc57eaa42d037bc31ff2d8702928bcc05de44cfaf7b57b2ba784551e91a244a

build:
number: 0
script: {{ PYTHON }} -m pip install . -vv
noarch: python

requirements:
host:
- python >=3.6
- pip
run:
- python >=3.6
- pytorch >=1.3

test:
imports:
- distmap

about:
home: https://github.com/balbasty/torch-distmap
license: MIT
summary: Euclidean distance transform in PyTorch
dev_url: https://github.com/balbasty/torch-distmap
89 changes: 89 additions & 0 deletions .github/actions/conda/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: conda
description: Publish to Anaconda
inputs:
tag:
description: 'Commit / Branch / Tag / SHA to checkout'
required: false
default: ''
platforms:
description: 'Platforms [all noarch osx-64 osx-arm64 linux-32 linux-ppc64 linux-ppc64le linux-s390x linux-armv6l linux-armv7l linux-aarch64 win-32 win-64]'
required: false
default: 'noarch'
python-version:
description: 'One or multiple python versions'
required: false
default: 3.7
dry-run:
description: 'Dry run'
required: false
default: false
override:
description: 'Override'
required: false
default: true
password:
required: true
runs:
using: "composite"
steps:
- shell: bash
env:
TAG: ${{ inputs.tag }}
PLATFORMS: ${{ inputs.platforms }}
DRYRUN: ${{ inputs.dry-run }}
OVERRIDE: ${{ inputs.override }}
run: echo "$TAG // $PLATFORMS // $DRYRUN // $OVERRIDE"
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.tag }}
- uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
activate-environment: build
- name: Install boa / anaconda
shell: bash -el {0}
run: |
mamba install boa anaconda-client
- name: Build
shell: bash -el {0}
env:
PY: ${{ inputs.python-version }}
run: |
PY=($PY)
OPT=""
for V in "${PY[@]}"; do
OPT+=",${V}"
done
OPT="{python: [${OPT:1}]}"
conda mambabuild --variants "$OPT" -c pytorch --croot . .conda
- name: Convert
shell: bash -el {0}
env:
PLATFORMS: ${{ inputs.platforms }}
run: |
for PLATFORM in osx-64 osx-arm64 linux-32 linux-64 linux-ppc64 linux-s390x linux-armv6l linux-armv7l linux-aarch64 win-32 win-64
do
if [[ $PLATFORMS == *"all"* || $PLATFORMS == *"${PLATFORM}"* ]]; then
conda convert -p $PLATFORM linux-64/*.tar.bz2
fi
done
- name: "Publish (dry run: ${{ inputs.dry-run }})"
if: inputs.dry-run == 'false'
shell: bash -el {0}
env:
OVERRIDE: ${{ inputs.override }}
PLATFORMS: ${{ inputs.platforms }}
ANACONDA_API_TOKEN: ${{ inputs.password }}
run: |
export ANACONDA_API_TOKEN
[[ "${OVERRIDE}" == "true" ]] && FORCE="--force" || FORCE=""
for PLATFORM in noarch osx-64 osx-arm64 linux-32 linux-64 linux-ppc64 linux-s390x linux-armv6l linux-armv7l linux-aarch64 win-32 win-64
do
if [[ $PLATFORMS == *"all"* || $PLATFORMS == *"${PLATFORM}"* ]]; then
anaconda upload ${FORCE} --label main ${PLATFORM}/*.tar.bz2
fi
done
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to PyPi
name: pypi
description: Publish to PyPi
inputs:
python-version:
Expand All @@ -13,23 +13,20 @@ inputs:
description: 'Publish'
required: false
default: 'test+pypi'
# {pypi, test, test+pypi, auto}
# auto is an alias for test+pypi
password-pypi:
description: 'PyPi password'
# {pypi, test, test+pypi}
pypi-password:
required: true
password-test:
description: 'Test PyPi password'
test-password:
required: true
runs:
using: "composite"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.tag }}
- name: Setup Python ${{ inputs.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.python-version }}
- name: Install dependencies for building package
Expand All @@ -42,20 +39,14 @@ runs:
python setup.py sdist bdist_wheel
shell: bash
- name: Publish distribution 📦 to Test PyPI
if: |
inputs.publish == 'test' ||
inputs.publish == 'test+pypi' ||
inputs.publish == 'auto'
if: ${{ contains(inputs.publish, 'test') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ inputs.password-test }}
password: ${{ inputs.test-password }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: |
inputs.publish == 'pypi' ||
inputs.publish == 'test+pypi' ||
inputs.publish == 'auto'
if: ${{ contains(inputs.publish, 'pypi') }}
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ inputs.password-pypi }}
password: ${{ inputs.pypi-password }}
repository_url: https://upload.pypi.org/legacy/
38 changes: 38 additions & 0 deletions .github/actions/test/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Run tests
description: Run tests
inputs:
tag:
description: 'Commit / Branch / Tag / SHA to checkout'
required: false
default: ''
python-version:
description: 'Python version'
required: true
default: '3.6'
pytorch-version:
description: 'PyTorch version'
required: true
default: '1.8'
runs:
using: "composite"
steps:
- uses: actions/checkout@v3
with:
ref: ${{ inputs.tag }}
- uses: conda-incubator/setup-miniconda@v2
with:
mamba-version: "*"
python-version: ${{ inputs.python-version }}
channels: conda-forge,pytorch,defaults
activate-environment: test-env
- name: Install dependencies
shell: bash -el {0}
env:
PYTORCH_VERSION: ${{ inputs.pytorch-version }}
run: |
mamba install pytorch=${PYTORCH_VERSION} pytest
- name: Test with pytest
shell: bash -el {0}
run: |
pip install .
pytest pytest --pyargs distmap
44 changes: 0 additions & 44 deletions .github/workflows/publish.yaml

This file was deleted.

104 changes: 104 additions & 0 deletions .github/workflows/test-and-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Test package and publish

on:
workflow_dispatch:
inputs:
tag:
description: 'Commit / Branch / Tag / SHA to checkout'
required: false
default: ''
test:
description: 'Run tests'
required: false
default: true
type: boolean
publish:
description: 'Publish'
required: false
default: 'none'
type: choice
options:
- 'none'
- 'pypi'
- 'test'
- 'conda'
- 'dryconda'
- 'test+pypi'
- 'pypi+conda'
- 'test+pypi+conda'
python-version:
description: 'Python version'
required: false
default: '3.7'
conda-platforms:
description: 'Target platforms'
required: false
default: 'noarch'

jobs:
test:
if: inputs.test
runs-on: ubuntu-latest
strategy:
matrix:
include:
- python-version: "3.7"
pytorch-version: "1.4"
- python-version: "3.7"
pytorch-version: "1.8"
- python-version: "3.9"
pytorch-version: "1.11"
- python-version: "3.11"
pytorch-version: "2.0"
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/test
with:
python-version: ${{ matrix.python-version }}
pytorch-version: ${{ matrix.pytorch-version }}
tag: ${{ inputs.tag }}

publish:
if: inputs.test && inputs.publish != 'none'
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/pypi
if: |
contains(inputs.publish, 'pypi') || contains(inputs.publish, 'test')
with:
python-version: ${{ inputs.python-version }}
publish: ${{ inputs.publish }}
tag: ${{ inputs.tag }}
pypi-password: ${{ secrets.PYPI_TOKEN }}
test-password: ${{ secrets.TEST_PYPI_TOKEN }}
- uses: ./.github/actions/conda
if: contains(inputs.publish, 'conda')
with:
tag: ${{ inputs.tag }}
platforms: ${{ inputs.conda-platforms }}
dry_run: ${{ contains(inputs.publish, 'dry') }}
password: ${{ secrets.ANACONDA_TOKEN }}

publish-only:
if: (!inputs.test) && inputs.publish != 'none'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/pypi
if: |
contains(inputs.publish, 'pypi') || contains(inputs.publish, 'test')
with:
python-version: ${{ inputs.python-version }}
publish: ${{ inputs.publish }}
tag: ${{ inputs.tag }}
pypi-password: ${{ secrets.PYPI_TOKEN }}
test-password: ${{ secrets.TEST_PYPI_TOKEN }}
- uses: ./.github/actions/conda
if: contains(inputs.publish, 'conda')
with:
tag: ${{ inputs.tag }}
platforms: ${{ inputs.conda-platforms }}
dry-run: ${{ contains(inputs.publish, 'dry') }}
password: ${{ secrets.ANACONDA_TOKEN }}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,20 @@ and therefore does not allow backpropagation.

## Installation

### Dependency

- `torch >= 1.3`

### Conda

```shell
conda install torch-distmap -c balbasty -c pytorch
```

### Pip

```shell
pip install git+https://github.com/balbasty/torch-distmap
pip install torch-distmap
```

## API
Expand Down
Loading

0 comments on commit dd81448

Please sign in to comment.