Skip to content

Commit 3c35ec4

Browse files
committed
feat: support pyproject.toml dynamic version from attribute
1 parent 97aec8f commit 3c35ec4

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

test/test_local_git_version.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""Tests of local_git_version module."""
2+
3+
import logging
4+
5+
import unittest
6+
7+
8+
from version_query.local_git_version import QUERIED, PREDICTED
9+
10+
_LOG = logging.getLogger(__name__)
11+
12+
13+
class Tests(unittest.TestCase):
14+
15+
def test_queried(self):
16+
_LOG.debug('QUERIED: %s', QUERIED)
17+
self.assertIsInstance(QUERIED, str)
18+
19+
def test_predicted(self):
20+
_LOG.debug('PREDICTED: %s', PREDICTED)
21+
self.assertIsInstance(PREDICTED, str)

version_query/local_git_version.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Use this module when reading the version from an attribute is needed without Python code.
2+
3+
For example, when using setuptools in pyproject.toml,
4+
one can set the version dynamically as follows:
5+
6+
[project]
7+
dynamic = ["version"]
8+
...
9+
10+
[tool.setuptools.dynamic]
11+
version = {attr = "version_query.local_git_version.PREDICTED"}
12+
"""
13+
14+
import os
15+
import pathlib
16+
17+
from .git_query import query_git_repo, predict_git_repo
18+
19+
_CURRENT_FOLDER: pathlib.Path = pathlib.Path()
20+
_PROJECT_FOLDER: pathlib.Path = pathlib.Path(os.environ.get('PROJECT_FOLDER', _CURRENT_FOLDER))
21+
QUERIED: str = query_git_repo(_PROJECT_FOLDER).to_str()
22+
PREDICTED: str = predict_git_repo(_PROJECT_FOLDER).to_str()

0 commit comments

Comments
 (0)