Skip to content

Commit

Permalink
Add automatic versioning (#744)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomicapretto authored Oct 26, 2023
1 parent 64c21d8 commit 281fa1e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 23 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ jobs:
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: python3 -m twine upload dist/*
run: python3 -m twine upload dist/*

# See documentation on accesing the tag from the release
# Look for 'github.ref' and 'github.ref_name' in https://docs.github.com/en/actions/learn-github-actions/contexts
# On October, 2023 it says "For workflows triggered by release, this is the release tag created"
# So 'github.ref_name' should be the version number of the release we're making.
4 changes: 3 additions & 1 deletion bambi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logging

from importlib.metadata import version

from pymc import math

from .backend import PyMCModel
Expand All @@ -8,9 +10,9 @@
from .formula import Formula
from .models import Model
from .priors import Prior
from .version import __version__
from . import interpret

__version__ = version("bambi")

__all__ = [
"Model",
Expand Down
10 changes: 7 additions & 3 deletions bambi/backend/pymc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import logging
import traceback


from copy import deepcopy
from importlib.metadata import version

import numpy as np
import pymc as pm
Expand All @@ -11,15 +13,16 @@
from pytensor.tensor.special import softmax


from bambi import version

from bambi.backend.links import cloglog, identity, inverse_squared, logit, probit, arctan_2
from bambi.backend.model_components import ConstantComponent, DistributionalComponent
from bambi.utils import get_aliased_name

_log = logging.getLogger("bambi")


__version__ = version("bambi")


class PyMCModel:
"""PyMC model-fitting backend."""

Expand Down Expand Up @@ -238,8 +241,9 @@ def _run_mcmc(

def _clean_results(self, idata, omit_offsets, include_mean):
for group in idata.groups():

getattr(idata, group).attrs["modeling_interface"] = "bambi"
getattr(idata, group).attrs["modeling_interface_version"] = version.__version__
getattr(idata, group).attrs["modeling_interface_version"] = __version__

if omit_offsets:
offset_vars = [var for var in idata.posterior.data_vars if var.endswith("_offset")]
Expand Down
4 changes: 3 additions & 1 deletion bambi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import warnings

from copy import deepcopy
from importlib.metadata import version

import formulae as fm
import pymc as pm
Expand All @@ -27,12 +28,13 @@
remove_common_intercept,
wrapify,
)
from bambi.version import __version__

_log = logging.getLogger("bambi")

ORDINAL_FAMILIES = (univariate.Cumulative, univariate.StoppingRatio)

__version__ = version("bambi")


class Model:
"""Specification of model class.
Expand Down
12 changes: 0 additions & 12 deletions bambi/version.py

This file was deleted.

1 change: 0 additions & 1 deletion bambi/version.txt

This file was deleted.

7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=61.0"]
requires = ["setuptools>=61.0", "setuptools_scm>=8"]

[tool.setuptools_scm]

[project]
name = "bambi"
Expand Down Expand Up @@ -58,9 +60,6 @@ packages = [
"bambi.terms",
]

[tool.setuptools.dynamic]
version = {file = "bambi/version.txt"}

[tool.black]
line-length = 100
target-version = ["py39", "py310"]

0 comments on commit 281fa1e

Please sign in to comment.