diff --git a/poetry.lock b/poetry.lock index c13169c..df13c2b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -4375,6 +4375,18 @@ webencodings = ">=0.4" doc = ["sphinx", "sphinx_rtd_theme"] test = ["pytest", "ruff"] +[[package]] +name = "toml" +version = "0.10.2" +description = "Python Library for Tom's Obvious, Minimal Language" +category = "main" +optional = false +python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*" +files = [ + {file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"}, + {file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"}, +] + [[package]] name = "tomli" version = "2.0.2" @@ -4688,4 +4700,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.13" -content-hash = "d3f1a9b775ba6ad7e56d90fbcfc819f339d89abf16d11c070a6d43c0c05f978b" +content-hash = "daca350144de1d307720245b6aadb229b24c7705d62584584608d96a7478c6d9" diff --git a/pyproject.toml b/pyproject.toml index 7eaedc4..428e0ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ scipy = "^1.13.1" cloudpickle = "^3.0.0" nptyping = "^2.5.0" librosa = "^0.10.2.post1" +toml = "^0.10.2" [tool.poetry.group.docs.dependencies] diff --git a/src/new_fave/__init__.py b/src/new_fave/__init__.py index 8871cc1..c8fe4b1 100644 --- a/src/new_fave/__init__.py +++ b/src/new_fave/__init__.py @@ -10,8 +10,17 @@ from importlib.metadata import version -# this is bugged for testing -#__version__ = version("new_fave") +from pathlib import Path +import toml + +__version__ = "unknown" +# adopt path to your pyproject.toml +pyproject_toml_file = Path(__file__).parent.parent.parent / "pyproject.toml" +if pyproject_toml_file.exists() and pyproject_toml_file.is_file(): + data = toml.load(pyproject_toml_file) + # check project.version + if "tool" in data and "poetry" in data["tool"] and "version" in data["tool"]["poetry"]: + __version__ = data["tool"]["poetry"]["version"] __all__ = [ "VowelMeasurement", diff --git a/src/new_fave/extract.py b/src/new_fave/extract.py index c6009b4..10c1fb2 100644 --- a/src/new_fave/extract.py +++ b/src/new_fave/extract.py @@ -52,7 +52,7 @@ def ask(message: str) -> bool: response = click.confirm( f"{message}", - default=True + default=False ) return response diff --git a/tests/test_version.py b/tests/test_version.py new file mode 100644 index 0000000..feb847f --- /dev/null +++ b/tests/test_version.py @@ -0,0 +1,18 @@ +from pathlib import Path +import toml +import new_fave + +def test_version(): + pyproject_toml_file = Path(__file__).parent.parent / "pyproject.toml" + toml_v = "unknown" + if pyproject_toml_file.exists() and pyproject_toml_file.is_file(): + data = toml.load(pyproject_toml_file) + # check project.version + if "project" in data and "version" in data["project"]: + toml_v = data["project"]["version"] + # check tool.poetry.version + elif "tool" in data and "poetry" in data["tool"] and "version" in data["tool"]["poetry"]: + toml_v = data["tool"]["poetry"]["version"] + + assert new_fave.__version__ == toml_v + \ No newline at end of file