From f3e1cb226bd49e279855fccc8d2ec7dad8b027ed Mon Sep 17 00:00:00 2001 From: Jun <164005568@qq.com> Date: Thu, 19 Mar 2026 17:03:18 +0800 Subject: [PATCH 1/2] fix: replace pkg_resources with importlib.metadata for setuptools 82+ Fixes #285 --- vpython/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vpython/__init__.py b/vpython/__init__.py index 1c17f05..9060bfd 100644 --- a/vpython/__init__.py +++ b/vpython/__init__.py @@ -1,4 +1,4 @@ -from pkg_resources import get_distribution, DistributionNotFound +from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound from .gs_version import glowscript_version From 9cc2b6db79b73fdf5483521f4656c5e748862b05 Mon Sep 17 00:00:00 2001 From: Jun <164005568@qq.com> Date: Sat, 21 Mar 2026 02:00:27 +0800 Subject: [PATCH 2/2] simplify: use version(__name__) directly Address maintainer review feedback: use version() directly instead of aliasing to get_distribution(), and update exception name to PackageNotFoundError. Fixes #286 --- vpython/__init__.py | 98 ++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/vpython/__init__.py b/vpython/__init__.py index 9060bfd..c3d0271 100644 --- a/vpython/__init__.py +++ b/vpython/__init__.py @@ -1,49 +1,49 @@ -from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound - -from .gs_version import glowscript_version - -try: - __version__ = get_distribution(__name__).version -except DistributionNotFound: - # package is not installed - pass -__gs_version__ = glowscript_version() - -del glowscript_version -del get_distribution -del DistributionNotFound - -# Keep the remaining imports later to ensure that __version__ and -# __gs_version__ exist before importing vpython, which itself imports -# both of those. - -from ._notebook_helpers import __is_spyder - -from .vpython import canvas - -# Need to initialize canvas before user does anything and before -scene = canvas() - -from .vpython import * -from .shapespaths import * -from ._vector_import_helper import * -from .rate_control import rate - -# vpython is showing up in the -# namespace, so delete them -del vpython - -# cyvector may be in the namespace. Get rid of it -try: - del cyvector -except NameError: - pass - -# import for backwards compatibility -from math import * -from numpy import arange -from random import random - -if __is_spyder(): - from ._notebook_helpers import _warn_if_spyder_settings_wrong - _warn_if_spyder_settings_wrong() +from importlib.metadata import version, PackageNotFoundError + +from .gs_version import glowscript_version + +try: + __version__ = version(__name__) +except PackageNotFoundError: + # package is not installed + pass +__gs_version__ = glowscript_version() + +del glowscript_version +del version +del PackageNotFoundError + +# Keep the remaining imports later to ensure that __version__ and +# __gs_version__ exist before importing vpython, which itself imports +# both of those. + +from ._notebook_helpers import __is_spyder + +from .vpython import canvas + +# Need to initialize canvas before user does anything and before +scene = canvas() + +from .vpython import * +from .shapespaths import * +from ._vector_import_helper import * +from .rate_control import rate + +# vpython is showing up in the +# namespace, so delete them +del vpython + +# cyvector may be in the namespace. Get rid of it +try: + del cyvector +except NameError: + pass + +# import for backwards compatibility +from math import * +from numpy import arange +from random import random + +if __is_spyder(): + from ._notebook_helpers import _warn_if_spyder_settings_wrong + _warn_if_spyder_settings_wrong()