diff --git a/.conda/meta.yaml b/.conda/meta.yaml index 6f5e932..265e1ff 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -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 diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index 459e9c9..dd57e3c 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/publish.yml similarity index 68% rename from .github/workflows/release.yml rename to .github/workflows/publish.yml index dd799de..2df19ca 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/publish.yml @@ -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 @@ -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 @@ -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: @@ -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__)" diff --git a/pyproject.toml b/pyproject.toml index b5e52f3..b929f91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/torchcam/methods/core.py b/torchcam/methods/core.py index e89979e..107d190 100644 --- a/torchcam/methods/core.py +++ b/torchcam/methods/core.py @@ -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 @@ -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)