Skip to content

Commit 7ae1f8e

Browse files
committed
support static version in pyproject.toml
1 parent b056c1e commit 7ae1f8e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

jupyter_releaser/tests/test_functions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def test_get_version_python(py_package):
3131
assert util.get_version() == "0.0.2a0"
3232

3333

34+
def test_get_version_pyproject(py_package):
35+
os.unlink("setup.py")
36+
assert util.get_version() == "0.0.1"
37+
38+
3439
def test_get_version_multipython(py_multipackage):
3540
prev_dir = os.getcwd()
3641
for package in py_multipackage:

jupyter_releaser/tests/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def pyproject_template(sub_packages=[]):
8585
[build-system]
8686
requires = ["setuptools>=40.8.0", "wheel"]
8787
build-backend = "setuptools.build_meta"
88+
89+
[project]
90+
version = "0.0.1"
8891
"""
8992
if sub_packages:
9093
res += f"""

jupyter_releaser/util.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ def get_version():
136136
"""Get the current package version"""
137137
if SETUP_PY.exists():
138138
return run("python setup.py --version").split("\n")[-1]
139+
elif PYPROJECT.exists():
140+
text = PYPROJECT.read_text(encoding="utf-8")
141+
data = toml.loads(text)
142+
project = data.get('project', {})
143+
version = project.get('version')
144+
if not version: # pragma: no cover
145+
raise ValueError("No version identifier could be found!")
146+
return version
139147
elif PACKAGE_JSON.exists():
140148
return json.loads(PACKAGE_JSON.read_text(encoding="utf-8")).get("version", "")
141149
else: # pragma: no cover

0 commit comments

Comments
 (0)