Skip to content

Commit

Permalink
Merge pull request #275 from blink1073/fix-get-version
Browse files Browse the repository at this point in the history
  • Loading branch information
blink1073 authored Mar 31, 2022
2 parents b056c1e + 328d563 commit 7d4dc94
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
repos:
- repo: https://github.com/asottile/reorder_python_imports
rev: v1.9.0
rev: v3.0.1
hooks:
- id: reorder-python-imports
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.3.0
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.2.1
rev: v2.6.1
hooks:
- id: prettier
- repo: https://gitlab.com/pycqa/flake8
rev: "3.8.4"
rev: "3.9.2"
hooks:
- id: flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.1.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
- repo: https://github.com/pre-commit/mirrors-pylint
rev: v3.0.0a3
rev: v3.0.0a4
hooks:
- id: pylint
args: [--disable=all, --enable=unused-import]
2 changes: 1 addition & 1 deletion jupyter_releaser/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from subprocess import list2cmdline as join # pylint: disable=ungrouped-imports


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


async def _read_stream(stream: StreamReader, callback: Callable[..., Any]) -> None:
Expand Down
5 changes: 5 additions & 0 deletions jupyter_releaser/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def test_get_version_python(py_package):
assert util.get_version() == "0.0.2a0"


def test_get_version_pyproject(py_package):
os.unlink("setup.py")
assert util.get_version() == "0.0.1"


def test_get_version_multipython(py_multipackage):
prev_dir = os.getcwd()
for package in py_multipackage:
Expand Down
3 changes: 3 additions & 0 deletions jupyter_releaser/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def pyproject_template(sub_packages=[]):
[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
version = "0.0.1"
"""
if sub_packages:
res += f"""
Expand Down
8 changes: 8 additions & 0 deletions jupyter_releaser/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def get_version():
"""Get the current package version"""
if SETUP_PY.exists():
return run("python setup.py --version").split("\n")[-1]
elif PYPROJECT.exists():
text = PYPROJECT.read_text(encoding="utf-8")
data = toml.loads(text)
project = data.get("project", {})
version = project.get("version")
if not version: # pragma: no cover
raise ValueError("No version identifier could be found!")
return version
elif PACKAGE_JSON.exists():
return json.loads(PACKAGE_JSON.read_text(encoding="utf-8")).get("version", "")
else: # pragma: no cover
Expand Down

0 comments on commit 7d4dc94

Please sign in to comment.