From a1199d8a7ddad26e151682fdaf993d2a1714d1dc Mon Sep 17 00:00:00 2001 From: Pablo Prietz Date: Fri, 25 Feb 2022 13:46:30 +0100 Subject: [PATCH 1/3] Read package version using importlib --- pyproject.toml | 6 ------ setup.cfg | 2 ++ src/pupil_labs/project_name/__init__.py | 14 +++++++++++--- tests/test_api.py | 1 - 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 11006f5..c8b8cf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,12 +6,6 @@ build-backend = "setuptools.build_meta" skip-string-normalization = true [tool.setuptools_scm] -write_to = "src/pupil_labs/project_name/version.py" -write_to_template = """ -\"\"\" Version information \"\"\" -__version__ = "{version}" -__version_info__ = {version_tuple} -""" [pytest.enabler.black] addopts = "--black" diff --git a/setup.cfg b/setup.cfg index 1acbce4..732be02 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,6 +20,8 @@ classifiers = Programming Language :: Python :: 3.10 [options] +install_requires = + importlib-metadata;python_version<"3.8" packages = find_namespace: python_requires = >=3.7 include_package_data = true diff --git a/src/pupil_labs/project_name/__init__.py b/src/pupil_labs/project_name/__init__.py index b94cfaf..1551b7c 100644 --- a/src/pupil_labs/project_name/__init__.py +++ b/src/pupil_labs/project_name/__init__.py @@ -1,6 +1,14 @@ """Top-level entry-point for the package""" -# .version is generated on install via setuptools_scm, see pyproject.toml -from .version import __version__, __version_info__ +try: + from importlib.metadata import PackageNotFoundError, version +except ImportError: + from importlib_metadata import PackageNotFoundError, version -__all__ = ["__version__", "__version_info__"] +try: + __version__ = version("pupil_labs.project_name") +except PackageNotFoundError: + # package is not installed + pass + +__all__ = ["__version__"] diff --git a/tests/test_api.py b/tests/test_api.py index 24c0a5b..f7ef4bd 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -3,4 +3,3 @@ def test_package_metadata() -> None: assert hasattr(this_project, "__version__") - assert hasattr(this_project, "__version_info__") From f80824b178e10ee3ea7bea121933930b23336b5b Mon Sep 17 00:00:00 2001 From: Pablo Prietz Date: Fri, 25 Feb 2022 13:46:59 +0100 Subject: [PATCH 2/3] Do not check black format via pytest pre-commit takes care of that --- pyproject.toml | 3 --- setup.cfg | 1 - 2 files changed, 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c8b8cf5..95477f7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,9 +7,6 @@ skip-string-normalization = true [tool.setuptools_scm] -[pytest.enabler.black] -addopts = "--black" - [pytest.enabler.mypy] addopts = "--mypy" diff --git a/setup.cfg b/setup.cfg index 732be02..73df7ff 100644 --- a/setup.cfg +++ b/setup.cfg @@ -43,7 +43,6 @@ docs = sphinx<4.4 # 4.4 does not detect TypeVars correctly testing = pytest>=6 - pytest-black>=0.3.7 pytest-checkdocs>=2.4 pytest-cov pytest-enabler>=1.0.1 From d60e54ada02d0eb78b98aa73700a608f242943cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 25 Feb 2022 12:48:47 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 73df7ff..63a9877 100644 --- a/setup.cfg +++ b/setup.cfg @@ -20,9 +20,9 @@ classifiers = Programming Language :: Python :: 3.10 [options] +packages = find_namespace: install_requires = importlib-metadata;python_version<"3.8" -packages = find_namespace: python_requires = >=3.7 include_package_data = true package_dir =