Skip to content

Commit

Permalink
ci: Adds multiple build CI jobs (#223)
Browse files Browse the repository at this point in the history
* chore: Bumps numpy

* ci: Adds new build jobs

* style: Fixes mypy

* ci: Fixes conda job

* ci: Debug conda

* ci: Debug

* ci: Debug

* ci: Debug

* ci: Debug

* ci: Fixing conda

* ci: Fixes publish job
  • Loading branch information
frgfm authored Oct 19, 2023
1 parent 97f91b5 commit 88eb30f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 33 deletions.
6 changes: 3 additions & 3 deletions .conda/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# {% set urls = pyproject.get('project', {}).get('urls') %}
package:
name: torchcam
version: "{{ environ.get('BUILD_VERSION') }}"
version: "{{ environ.get('BUILD_VERSION', '0.4.0.dev0') }}"

source:
fn: torchcam-{{ environ.get('BUILD_VERSION') }}.tar.gz
url: ../dist/torchcam-{{ environ.get('BUILD_VERSION') }}.tar.gz
fn: torchcam-{{ environ.get('BUILD_VERSION', '0.4.0.dev0') }}.tar.gz
url: ../dist/torchcam-{{ environ.get('BUILD_VERSION', '0.4.0.dev0') }}.tar.gz

build:
noarch: python
Expand Down
44 changes: 43 additions & 1 deletion .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python: [3.8, 3.9]
python: [3.8, 3.9, '3.10', 3.11]
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -32,3 +32,45 @@ jobs:
pip install -e . --upgrade
- name: Import package
run: python -c "import torchcam; print(torchcam.__version__)"

pypi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
architecture: x64
- name: Cache python modules
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-python-${{ matrix.python }}-${{ hashFiles('pyproject.toml') }}-build
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine --upgrade
- run: |
python setup.py sdist bdist_wheel
twine check dist/*
conda:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.9"
- name: Install dependencies
shell: bash -el {0}
run: conda install -y conda-build conda-verify
- name: Build conda
shell: bash -el {0}
run: |
python setup.py sdist
mkdir conda-dist
conda env list
conda build .conda/ -c pytorch --output-folder conda-dist
ls -l conda-dist/noarch/*tar.bz2
42 changes: 16 additions & 26 deletions .github/workflows/release.yml → .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: release
name: publish

on:
release:
types: [published]

jobs:
pypi-publish:
pypi:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: 3.9
architecture: x64
Expand All @@ -24,24 +23,20 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine --upgrade
- name: Get release tag
id: release_tag
run: |
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
VERSION: ${{ steps.release_tag.outputs.VERSION }}
run: |
BUILD_VERSION=${VERSION:1} python setup.py sdist bdist_wheel
echo "BUILD_VERSION=${GITHUB_REF#refs/*/}" | cut -c 2- >> $GITHUB_ENV
python setup.py sdist bdist_wheel
twine check dist/*
twine upload dist/*
pypi-check:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest
needs: pypi-publish
needs: pypi
steps:
- uses: actions/checkout@v2
- name: Set up Python
Expand All @@ -55,7 +50,7 @@ jobs:
pip install torchcam
python -c "import torchcam; print(torchcam.__version__)"
conda-publish:
conda:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest
steps:
Expand All @@ -65,37 +60,32 @@ jobs:
with:
auto-update-conda: true
python-version: 3.9
auto-activate-base: true
- name: Install dependencies
run: |
conda install -y conda-build conda-verify anaconda-client
- name: Get release tag
id: release_tag
run: |
echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
shell: bash -el {0}
run: conda install -y conda-build conda-verify anaconda-client
- name: Build and publish
shell: bash -el {0}
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }}
VERSION: ${{ steps.release_tag.outputs.VERSION }}
run: |
BUILD_VERSION=${VERSION:1} python setup.py sdist
echo "BUILD_VERSION=${GITHUB_REF#refs/*/}" | cut -c 2- >> $GITHUB_ENV
python setup.py sdist
mkdir conda-dist
conda-build .conda/ -c pytorch --output-folder conda-dist
conda build .conda/ -c pytorch --output-folder conda-dist
ls -l conda-dist/noarch/*tar.bz2
anaconda upload conda-dist/noarch/*tar.bz2
conda-check:
if: "!github.event.release.prerelease"
runs-on: ubuntu-latest
needs: conda-publish
needs: conda
steps:
- name: Miniconda setup
uses: conda-incubator/setup-miniconda@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: 3.9
auto-activate-base: true
- name: Install package
shell: bash -el {0}
run: |
conda install -c frgfm torchcam
python -c "import torchcam; print(torchcam.__version__)"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dynamic = ["version"]
dependencies = [
# cf. https://github.com/frgfm/torch-cam/discussions/148
"torch>=2.0.0,<3.0.0",
"numpy>=1.14.0,<2.0.0",
"numpy>=1.17.2,<2.0.0",
# cf. https://github.com/advisories/GHSA-98vv-pw6r-q6q4
# cf. https://github.com/pytorch/vision/issues/4934
# https://github.com/frgfm/Holocron/security/dependabot/5
Expand Down
4 changes: 2 additions & 2 deletions torchcam/methods/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from abc import abstractmethod
from functools import partial
from types import TracebackType
from typing import Any, List, Optional, Tuple, Type, Union, cast
from typing import Any, List, Optional, Tuple, Type, Union

import torch
import torch.nn.functional as F
Expand Down Expand Up @@ -261,4 +261,4 @@ def _fuse_cams(cams: List[Tensor], target_shape: Tuple[int, int]) -> Tensor:
]

# Fuse them
return cast(Tensor, torch.stack(scaled_cams).max(dim=0).values.squeeze(1))
return torch.stack(scaled_cams).max(dim=0).values.squeeze(1)

0 comments on commit 88eb30f

Please sign in to comment.