Skip to content

Commit

Permalink
MAINT: Add version number from git tag using setuptools scm (shap#3402)
Browse files Browse the repository at this point in the history
* Add setuptools-scm

* Ignore _version.py, sort .gitignore

* Disable routine pushing to TestPyPI

* Specify fetch-tags true in build

* Enable TestPyPI on manual trigger

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add MANIFEST.in

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
connortann and pre-commit-ci[bot] authored Dec 6, 2023
1 parent ce770fd commit 287e751
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 36 deletions.
37 changes: 32 additions & 5 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Ensure all git tags are present so version number is extracted
# See https://github.com/actions/checkout/issues/1471
fetch-depth: 100
fetch-tags: true


- name: Set up QEMU
if: runner.os == 'Linux'
Expand All @@ -68,7 +74,12 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Check out the repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# Ensure all git tags are present so version number is extracted
# See https://github.com/actions/checkout/issues/1471
fetch-depth: 100
fetch-tags: true

- name: Set up Python 3.11
uses: actions/setup-python@v4
Expand All @@ -85,11 +96,10 @@ jobs:
name: sdist_files
path: dist/*.tar.gz

publish_wheels:
name: Publish wheels on pypi
publish_test_pypi:
name: Publish wheels to TestPyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/download-artifact@v3
with:
Expand All @@ -107,6 +117,23 @@ jobs:
password: ${{ secrets.TEST_PYPI_TOKEN }}
repository-url: https://test.pypi.org/legacy/

publish_pypi:
name: Publish wheels to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# Only publish tagged releases to PyPI
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/download-artifact@v3
with:
name: bdist_files
path: dist

- uses: actions/download-artifact@v3
with:
name: sdist_files
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
42 changes: 21 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,30 @@ env.bak/
venv.bak/

# shap/shap
node_modules
__pycache__
shap.egg-info
*.pyc
/build
/dist
/shap/cached_data
notebooks/local_scratch
docs/local
docs/_build
docs/generated/
.ipynb_checkpoints
.DS_Store
.eggs
.idea
.ipynb_checkpoints
.ruff_cache
javascript/build/*
.vscode
.DS_Store
/notebooks/deep_explainer/mnist_data
/data/CRIC*
*.pyc
**/.coverage*
/build
/data/*
/dist
/docs/_build
/docs/artwork/local
shap/_cext*
.idea
/docs/generated/
/docs/local
/javascript/build/*
/notebooks/deep_explainer/mnist_data
/notebooks/local_scratch
/shap.egg-info
/shap/_cext*
/shap/_version.py
/shap/cached_data
/tests/local_scratch.py
/tests/mnist_data
catboost_info
tests/local_scratch.py
tests/mnist_data
data/*
**/.coverage*
node_modules
14 changes: 14 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file controls what files are included in the source distribution.

# Note: setuptools-scm will by default include everything managed by git,
# so we need to manually exclude things that we don't wish to include.
# See: https://github.com/pypa/setuptools_scm/issues/190

prune .github
prune appveyor
prune data
prune docs
prune javascript
prune notebooks
exclude .git-blame-ignore-revs .gitattributes .gitignore .pre-commit-config.yaml .readthedocs.yml
exclude CONTRIBUTING.md requirements.txt MANIFEST.in
12 changes: 5 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools>=61.0", "oldest-supported-numpy", "packaging>20.9"]
requires = ["setuptools>=61.0", "setuptools-scm>=8.0", "oldest-supported-numpy", "packaging>20.9"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -96,13 +96,11 @@ packages = [
'shap.actions',
'shap.models'
]
zip-safe = false

[tool.setuptools.dynamic]
version = {attr = "shap.__version__"}

[tool.setuptools.package-data]
shap = ["plots/resources/*", "cext/*"]
[tool.setuptools_scm]
version_file = "shap/_version.py"
# Use "no-local-version" so dev releases are compatibile with PyPI
local_scheme = "no-local-version"

[tool.pytest.ini_options]
addopts = "--mpl"
Expand Down
10 changes: 7 additions & 3 deletions shap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@

__version__ = "0.43.0"

from ._explanation import Cohorts, Explanation

# explainers
Expand All @@ -18,6 +15,13 @@
from .explainers._sampling import SamplingExplainer
from .explainers._tree import TreeExplainer

try:
# Version from setuptools-scm
from ._version import version as __version__
except ImportError:
# Expected when running locally without build
__version__ = "0.0.0-not-built"

_no_matplotlib_warning = "matplotlib is not installed so plotting is not available! Run `pip install matplotlib` " \
"to fix this."

Expand Down

0 comments on commit 287e751

Please sign in to comment.