Skip to content
This repository has been archived by the owner on Dec 31, 2023. It is now read-only.

Commit

Permalink
Calculate version number based on pyproject.toml
Browse files Browse the repository at this point in the history
During `poetry install`, Poetry installs the project as if it were a
package itself. You can then pull the version from the package metadata.
It's a little tricky to get `importlib_metadata` to work with Docker.
You have to remove `--no-root` from the _Dockerfile_ and add
`importlib-metadata` to prod dependencies, and you still might get
errors after that.

python-poetry/poetry#144
python-poetry/poetry#1036
  • Loading branch information
br3ndonland committed Jun 20, 2020
1 parent 54f1376 commit 227ab28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
17 changes: 16 additions & 1 deletion portfolio/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
__version__ = "0.2.0"
"""
Calculate version number based on pyproject.toml.
---
During `poetry install`, Poetry installs the project as if it were a package itself.
You can then pull from the package metadata.
It's a little tricky to get `importlib_metadata` to work with Docker builds.
You have to remove `--no-root` from the _Dockerfile_ and move `importlib-metadata`
to prod dependencies, and you still might get errors after that.
See [poetry#1036](https://github.com/python-poetry/poetry/issues/1036) and
[poetry#144](https://github.com/python-poetry/poetry/issues/144) for more info.
"""

from importlib_metadata import version

__version__ = version(__package__)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "portfolio"
version = "0.1.0"
version = "0.3.0"
description = "Getting Started Testing: pytest edition"
authors = ["Brendon Smith <br3ndonland@protonmail.com>"]
license = "MIT"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@


def test_version():
assert __version__ == "0.2.0"
"""Verify version number in __init__.py."""
assert __version__ == "0.3.0"

0 comments on commit 227ab28

Please sign in to comment.