Skip to content

Commit 9cc2b6d

Browse files
committed
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
1 parent f3e1cb2 commit 9cc2b6d

1 file changed

Lines changed: 49 additions & 49 deletions

File tree

vpython/__init__.py

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound
2-
3-
from .gs_version import glowscript_version
4-
5-
try:
6-
__version__ = get_distribution(__name__).version
7-
except DistributionNotFound:
8-
# package is not installed
9-
pass
10-
__gs_version__ = glowscript_version()
11-
12-
del glowscript_version
13-
del get_distribution
14-
del DistributionNotFound
15-
16-
# Keep the remaining imports later to ensure that __version__ and
17-
# __gs_version__ exist before importing vpython, which itself imports
18-
# both of those.
19-
20-
from ._notebook_helpers import __is_spyder
21-
22-
from .vpython import canvas
23-
24-
# Need to initialize canvas before user does anything and before
25-
scene = canvas()
26-
27-
from .vpython import *
28-
from .shapespaths import *
29-
from ._vector_import_helper import *
30-
from .rate_control import rate
31-
32-
# vpython is showing up in the
33-
# namespace, so delete them
34-
del vpython
35-
36-
# cyvector may be in the namespace. Get rid of it
37-
try:
38-
del cyvector
39-
except NameError:
40-
pass
41-
42-
# import for backwards compatibility
43-
from math import *
44-
from numpy import arange
45-
from random import random
46-
47-
if __is_spyder():
48-
from ._notebook_helpers import _warn_if_spyder_settings_wrong
49-
_warn_if_spyder_settings_wrong()
1+
from importlib.metadata import version, PackageNotFoundError
2+
3+
from .gs_version import glowscript_version
4+
5+
try:
6+
__version__ = version(__name__)
7+
except PackageNotFoundError:
8+
# package is not installed
9+
pass
10+
__gs_version__ = glowscript_version()
11+
12+
del glowscript_version
13+
del version
14+
del PackageNotFoundError
15+
16+
# Keep the remaining imports later to ensure that __version__ and
17+
# __gs_version__ exist before importing vpython, which itself imports
18+
# both of those.
19+
20+
from ._notebook_helpers import __is_spyder
21+
22+
from .vpython import canvas
23+
24+
# Need to initialize canvas before user does anything and before
25+
scene = canvas()
26+
27+
from .vpython import *
28+
from .shapespaths import *
29+
from ._vector_import_helper import *
30+
from .rate_control import rate
31+
32+
# vpython is showing up in the
33+
# namespace, so delete them
34+
del vpython
35+
36+
# cyvector may be in the namespace. Get rid of it
37+
try:
38+
del cyvector
39+
except NameError:
40+
pass
41+
42+
# import for backwards compatibility
43+
from math import *
44+
from numpy import arange
45+
from random import random
46+
47+
if __is_spyder():
48+
from ._notebook_helpers import _warn_if_spyder_settings_wrong
49+
_warn_if_spyder_settings_wrong()

0 commit comments

Comments
 (0)