Skip to content

Commit

Permalink
Merge pull request #5 from pupil-labs/importlib
Browse files Browse the repository at this point in the history
Use importlib to read version instead of writing it to a file
  • Loading branch information
papr authored Feb 25, 2022
2 parents fa620c0 + d60e54a commit 6ee9eaf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +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"

[pytest.enabler.mypy]
addopts = "--mypy"
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ classifiers =

[options]
packages = find_namespace:
install_requires =
importlib-metadata;python_version<"3.8"
python_requires = >=3.7
include_package_data = true
package_dir =
Expand All @@ -41,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
Expand Down
14 changes: 11 additions & 3 deletions src/pupil_labs/project_name/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
"""Top-level entry-point for the <project_name> 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__"]
1 change: 0 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

def test_package_metadata() -> None:
assert hasattr(this_project, "__version__")
assert hasattr(this_project, "__version_info__")

0 comments on commit 6ee9eaf

Please sign in to comment.