Skip to content

Commit

Permalink
Using importlib instead of pkg_resources for version handling
Browse files Browse the repository at this point in the history
  • Loading branch information
reinout committed Apr 18, 2024
1 parent f357c41 commit 89e0b50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Changelog for zest.releaser
9.1.4 (unreleased)
------------------

- Nothing changed yet.
- Fixed version handling documentation to use ``importlib`` instead of
``pkg_resources``.
[reinout]


9.1.3 (2024-02-07)
Expand Down
9 changes: 4 additions & 5 deletions doc/source/versions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,13 @@ discussion.
- The version in the ``setup.py`` is the real version.

- Add a ``__version__`` attribute in your main module. Often this will be an
``__init__.py``. Set this version attribute with ``pkg_resources``, which is
automatically installed as part of setuptools/distribute. Here's `the code
<https://github.com/zestsoftware/zest.releaser/blob/master/zest/releaser/__init__.py>`_
``__init__.py``. Set this version attribute with ``importlib.metadata``. Here's `the
code <https://github.com/zestsoftware/zest.releaser/blob/master/zest/releaser/__init__.py>`_
from ``zest/releaser/__init__.py``::

import pkg_resources
from importlib.metadata import version

__version__ = pkg_resources.get_distribution("zest.releaser").version
__version__ = version("zest.releaser")

This way you can do::

Expand Down
5 changes: 2 additions & 3 deletions zest/releaser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from colorama import init

import pkg_resources
from importlib.metadata import version


# Initialize colorized output. Set it to reset after each print, so
Expand All @@ -9,4 +8,4 @@
# but it looks like it already does that itself.
init(autoreset=True)

__version__ = pkg_resources.get_distribution("zest.releaser").version
__version__ = version("zest.releaser")

0 comments on commit 89e0b50

Please sign in to comment.