From dd335a80c7c51ceb62e0ab1c83a25b199b7a5990 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Tue, 19 Mar 2024 12:29:31 +0100 Subject: [PATCH 1/4] TST: update public API test/listing to reflect actual 2.0.x state --- numpy/tests/test_public_api.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/numpy/tests/test_public_api.py b/numpy/tests/test_public_api.py index 780e1fccb79e..618223705937 100644 --- a/numpy/tests/test_public_api.py +++ b/numpy/tests/test_public_api.py @@ -114,14 +114,14 @@ def test_NPY_NO_EXPORT(): "f2py", "fft", "lib", - "lib.format", # was this meant to be public? + "lib.array_utils", + "lib.format", + "lib.introspect", "lib.mixins", - "lib.recfunctions", + "lib.npyio", + "lib.recfunctions", # note: still needs cleaning, was forgotten for 2.0 "lib.scimath", "lib.stride_tricks", - "lib.npyio", - "lib.introspect", - "lib.array_utils", "linalg", "ma", "ma.extras", @@ -134,11 +134,12 @@ def test_NPY_NO_EXPORT(): "polynomial.legendre", "polynomial.polynomial", "random", + "strings", "testing", "testing.overrides", "typing", "typing.mypy_plugin", - "version" # Should be removed for NumPy 2.0 + "version", ]] if sys.version_info < (3, 12): PUBLIC_MODULES += [ @@ -158,7 +159,6 @@ def test_NPY_NO_EXPORT(): "numpy.char", "numpy.emath", "numpy.rec", - "numpy.strings", ] @@ -535,7 +535,7 @@ def test_core_shims_coherence(): # no need to add it to np.core if ( member_name.startswith("_") - or member_name == "tests" + or member_name in ["tests", "strings"] or f"numpy.{member_name}" in PUBLIC_ALIASED_MODULES ): continue From 523daf7f239d0ebd4a64b89a85800f0fd9d31690 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 29 Mar 2024 17:23:39 +0100 Subject: [PATCH 2/4] DOC: document the ``numpy.version`` submodule - officially public now --- doc/source/reference/module_structure.rst | 2 ++ doc/source/reference/routines.version.rst | 38 +++++++++++++++++++++++ numpy/_build_utils/gitversion.py | 3 ++ 3 files changed, 43 insertions(+) create mode 100644 doc/source/reference/routines.version.rst diff --git a/doc/source/reference/module_structure.rst b/doc/source/reference/module_structure.rst index 2db9de7f03a8..01a5bcff7fbc 100644 --- a/doc/source/reference/module_structure.rst +++ b/doc/source/reference/module_structure.rst @@ -35,6 +35,7 @@ Special-purpose namespaces - :ref:`numpy.emath ` - mathematical functions with automatic domain - :ref:`numpy.lib ` - utilities & functionality which do not fit the main namespace - :ref:`numpy.rec ` - record arrays (largely superseded by dataframe libraries) +- :ref:`numpy.version ` - small module with more detailed version info Legacy namespaces ================= @@ -67,6 +68,7 @@ and/or this code is deprecated or isn't reliable. numpy.emath numpy.lib numpy.rec + numpy.version numpy.char numpy.distutils numpy.f2py <../f2py/index> diff --git a/doc/source/reference/routines.version.rst b/doc/source/reference/routines.version.rst new file mode 100644 index 000000000000..84f3c3ef1175 --- /dev/null +++ b/doc/source/reference/routines.version.rst @@ -0,0 +1,38 @@ +.. currentmodule:: numpy.version + +.. _routines.version: + +******************* +Version information +******************* + +The ``numpy.version`` submodule includes several constants that expose more +detailed information about the exact version of the installed ``numpy`` +package: + +.. data:: version + + Version string for the installed package - matches ``numpy.__version__``. + +.. data:: full_version + + Version string - the same as ``numpy.version.version``. + +.. data:: short_version + + Version string without any local build identifiers. + + .. rubric:: Examples + + >>> np.__version__ + '2.1.0.dev0+git20240319.2ea7ce0' # may vary + >>> np.version.short_version + '2.1.0.dev0' + +.. data:: git_revision + + String containing the git hash of the commit from which ``numpy`` was built. + +.. data:: release + + ``True`` if this version is a ``numpy`` release, ``False`` if a dev version. diff --git a/numpy/_build_utils/gitversion.py b/numpy/_build_utils/gitversion.py index 4ee6e00bbd65..defc704c41eb 100644 --- a/numpy/_build_utils/gitversion.py +++ b/numpy/_build_utils/gitversion.py @@ -70,6 +70,9 @@ def git_version(version): # For NumPy 2.0, this should only have one field: `version` template = textwrap.dedent(f''' + """ + Module to expose more detailed version info for the installed `numpy` + """ version = "{version}" __version__ = version full_version = version From 0b37ada684839b8df1fe78c5404cad42dc3e5596 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Fri, 29 Mar 2024 17:29:19 +0100 Subject: [PATCH 3/4] TST: add a test that the `np.version` public content is as expected [skip azp] [skip cirrus] --- numpy/tests/test_numpy_version.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/numpy/tests/test_numpy_version.py b/numpy/tests/test_numpy_version.py index 61643426c8d7..d3abcb92c1c3 100644 --- a/numpy/tests/test_numpy_version.py +++ b/numpy/tests/test_numpy_version.py @@ -39,3 +39,16 @@ def test_short_version(): else: assert_(np.__version__.split("+")[0] == np.version.short_version, "short_version mismatch in development version") + + +def test_version_module(): + contents = set([s for s in dir(np.version) if not s.startswith('_')]) + expected = set([ + 'full_version', + 'git_revision', + 'release', + 'short_version', + 'version', + ]) + + assert contents == expected From 589390a91fd59922fa9d785f034950f9a27a6484 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Fri, 29 Mar 2024 12:58:53 -0600 Subject: [PATCH 4/4] MAINT: Fix failing example --- doc/source/reference/routines.version.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/reference/routines.version.rst b/doc/source/reference/routines.version.rst index 84f3c3ef1175..72c48a752cf6 100644 --- a/doc/source/reference/routines.version.rst +++ b/doc/source/reference/routines.version.rst @@ -27,7 +27,7 @@ package: >>> np.__version__ '2.1.0.dev0+git20240319.2ea7ce0' # may vary >>> np.version.short_version - '2.1.0.dev0' + '2.1.0.dev0' # may vary .. data:: git_revision