Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use importlib.metadata for version info if >py37 #3187

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/3187.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use ``importlib.metadata`` for version info if python>=3.8
1 change: 1 addition & 0 deletions newsfragments/3187.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add basic import and version tests for the ``web3`` module
5 changes: 5 additions & 0 deletions tests/core/web3-module/test_import_and_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def test_import_and_version():
import web3

version = web3.__version__
assert isinstance(version, str)
15 changes: 12 additions & 3 deletions web3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
from eth_account import Account # noqa: E402,
import pkg_resources
from eth_account import Account # noqa: E402
import sys

if sys.version_info.major == 3 and sys.version_info.minor < 8:
import pkg_resources

__version__ = pkg_resources.get_distribution("web3").version
else:
from importlib.metadata import version

__version__ = version("web3")


from web3.main import (
AsyncWeb3,
Expand All @@ -22,7 +32,6 @@
WebsocketProviderV2,
)

__version__ = pkg_resources.get_distribution("web3").version

__all__ = [
"__version__",
Expand Down