diff --git a/.readthedocs.yml b/.readthedocs.yml index 0604945f9e..8b1cff2d5d 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -13,6 +13,7 @@ build: python: install: - requirements: docs-requirements.txt + - path: . sphinx: fail_on_warning: true diff --git a/docs/source/conf.py b/docs/source/conf.py index fb8e60cdc5..275aee0a54 100755 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -315,9 +315,9 @@ def add_mapping( # built documents. # # The short X.Y version. -import trio +import importlib.metadata -version = trio.__version__ +version = importlib.metadata.version("trio") # The full version, including alpha/beta/rc tags. release = version diff --git a/newsfragments/3190.deprecated.rst b/newsfragments/3190.deprecated.rst new file mode 100644 index 0000000000..0658da9a10 --- /dev/null +++ b/newsfragments/3190.deprecated.rst @@ -0,0 +1 @@ +Deprecate ``trio.__version__`` in favor of `importlib.metadata.version`. diff --git a/src/trio/__init__.py b/src/trio/__init__.py index 0b675ce473..ebd7e4fb12 100644 --- a/src/trio/__init__.py +++ b/src/trio/__init__.py @@ -115,7 +115,14 @@ _deprecate.enable_attribute_deprecations(__name__) -__deprecated_attributes__: dict[str, _deprecate.DeprecatedAttribute] = {} +__deprecated_attributes__: dict[str, _deprecate.DeprecatedAttribute] = { + "__version__": _deprecate.DeprecatedAttribute( + __version__, "0.29.0", issue=None, instead='importlib.metadata.version("trio")' + ) +} + +if not TYPE_CHECKING: + del __version__ # Having the public path in .__module__ attributes is important for: # - exception names in printed tracebacks diff --git a/src/trio/_tests/test_trio.py b/src/trio/_tests/test_trio.py index 65d4ce34f2..aa88ac682c 100644 --- a/src/trio/_tests/test_trio.py +++ b/src/trio/_tests/test_trio.py @@ -6,3 +6,12 @@ def test_trio_import() -> None: del sys.modules[module] import trio # noqa: F401 + + +def test_trio_version_deprecated() -> None: + import pytest + + import trio + + with pytest.warns(DeprecationWarning, match="^trio.__version__ is deprecated"): + _ = trio.__version__ diff --git a/src/trio/_tests/type_tests/trio_version.py b/src/trio/_tests/type_tests/trio_version.py new file mode 100644 index 0000000000..2441b1b336 --- /dev/null +++ b/src/trio/_tests/type_tests/trio_version.py @@ -0,0 +1,4 @@ +import trio +from typing_extensions import assert_type + +assert_type(trio.__version__, str)