DemocracyClub / dc_django_utils

Shared helpers and utility functions for DC websites
MIT License
0 stars 2 forks source link

Specify version number once #89

Closed chris48s closed 2 months ago

chris48s commented 2 months ago

Currently this has to be bumped in two places https://github.com/DemocracyClub/dc_django_utils/commit/43ec52d2846b1b28cfaabd036841456c5f9a4466

For a "normal" package that you build and push to a registry, the way to do this would be to tell setuptools to get the version from __version__ at build time, like this:

diff --git a/pyproject.toml b/pyproject.toml
index 11d0a9c..876aa01 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,5 @@
 [project]
 name = "dc_django_utils"
-version = "6.1.0"
 description = "This is a package to provide some common utilities for Django projects at Democracy Club."
 readme = "README.md"
 authors = [{name = "Sym Roe"}, {name = "Virginia Dooley"}]
@@ -17,6 +16,9 @@ dependencies = [
 ]

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

 [project.urls]
 Homepage = "https://github.com/DemocracyClub/dc_django_utils"

and then you can just bump the __version__.

I guess the reason you're not doing that on this project is because you don't build this package and push it to a registry. You just consume it as a VCS dependency. One thing you could do would be to actually build the package. If you want to stick with it being a VCS dependency, you could also drop the __version__ property. Or if you really want to keep it, you could go the other way and populate the __version__ property based on the version in pyproject.toml.

So

import tomllib

with open("../pyproject.toml", "rb") as f:
    pyproject = tomllib.load(f)

__version__ = pyproject['project']['version']

or whatever (not tested, but I reckon that should work).

Whichever way we go, it would be desirable to have one source of truth for the package version.

chris48s commented 2 months ago

That said, over on https://github.com/DemocracyClub/dc_logging/ you're doing https://github.com/DemocracyClub/dc_logging/blob/main/setup.cfg#L3 (which is the setup.cfg-land version of my first proposal) so maybe the fact you're not building doesn't matter because the package manager will build a wheel on install and you're relying on using tagged tarballs to make sure it always considers a new release a "different" URL? (implying we could just do the first suggestion)

chris48s commented 2 months ago

done in https://github.com/DemocracyClub/dc_django_utils/pull/88