Skip to content

Commit 7d4dc94

Browse files
authored
Merge pull request #275 from blink1073/fix-get-version
2 parents b056c1e + 328d563 commit 7d4dc94

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
repos:
22
- repo: https://github.com/asottile/reorder_python_imports
3-
rev: v1.9.0
3+
rev: v3.0.1
44
hooks:
55
- id: reorder-python-imports
66
- repo: https://github.com/psf/black
7-
rev: 20.8b1
7+
rev: 22.3.0
88
hooks:
99
- id: black
1010
- repo: https://github.com/pre-commit/mirrors-prettier
11-
rev: v2.2.1
11+
rev: v2.6.1
1212
hooks:
1313
- id: prettier
1414
- repo: https://gitlab.com/pycqa/flake8
15-
rev: "3.8.4"
15+
rev: "3.9.2"
1616
hooks:
1717
- id: flake8
1818
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v3.4.0
19+
rev: v4.1.0
2020
hooks:
2121
- id: end-of-file-fixer
2222
- id: check-case-conflict
2323
- id: check-executables-have-shebangs
2424
- id: requirements-txt-fixer
2525
- repo: https://github.com/pre-commit/mirrors-pylint
26-
rev: v3.0.0a3
26+
rev: v3.0.0a4
2727
hooks:
2828
- id: pylint
2929
args: [--disable=all, --enable=unused-import]

jupyter_releaser/tee.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
from subprocess import list2cmdline as join # pylint: disable=ungrouped-imports
4646

4747

48-
STREAM_LIMIT = 2 ** 23 # 8MB instead of default 64kb, override it if you need
48+
STREAM_LIMIT = 2**23 # 8MB instead of default 64kb, override it if you need
4949

5050

5151
async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> None:

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)