Skip to content

Commit 857c114

Browse files
committed
fix import for protobuf package and other known packages when the name of the package is different from its module
1 parent 98dac2d commit 857c114

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

graalpython/lib-graalpython/modules/ginstall.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,25 @@
4848
import sys
4949

5050

51+
def get_module_name(package_name):
52+
non_standard_packages = {
53+
'pyyaml':'pyaml',
54+
'protobuf':'google.protobuf',
55+
'python-dateutil':'dateutil',
56+
'websocket-client':'websocket',
57+
}
58+
module_name = non_standard_packages.get(package_name, package_name)
59+
return module_name.replace('-', '_')
60+
61+
5162
def pip_package(name=None):
5263
def decorator(func):
5364
def wrapper(*args, **kwargs):
5465
_name = name if name else func.__name__
5566
try:
56-
importlib.import_module(_name)
57-
del sys.modules[_name]
67+
module_name = get_module_name(_name)
68+
importlib.import_module(module_name)
69+
del sys.modules[module_name]
5870
except ImportError:
5971
print("Installing required dependency: {}".format(_name))
6072
func(*args, **kwargs)

0 commit comments

Comments
 (0)