Skip to content

Commit 1684e68

Browse files
committed
fix[shuffle-tools-fork]: Making dynamic imports possible
1 parent bb43d09 commit 1684e68

File tree

1 file changed

+8
-5
lines changed
  • shuffle-tools-fork/1.0.0/src

1 file changed

+8
-5
lines changed

shuffle-tools-fork/1.0.0/src/app.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import tempfile
1010
import zipfile
1111
import base64
12+
import importlib
1213
import ipaddress
1314
import hashlib
1415
import shufflepy
@@ -58,6 +59,11 @@ def __init__(self, redis, logger, console_logger=None):
5859
"""
5960
super().__init__(redis, logger, console_logger)
6061

62+
def dynamic_import(package_name: str):
63+
"""Import a package and return the module"""
64+
return importlib.import_module(package_name.split('==')[0].split('>=')[0].split('<=')[0].split('>')[0].split('<')[0])
65+
66+
6167
def get_missing_packages(required_packages: list) -> list:
6268
"""
6369
Returns a list of packages that aren't currently installed.
@@ -103,11 +109,8 @@ def execute_python(self, code, packages=[]) -> dict:
103109
if packages:
104110
if allow_package_install:
105111
self.install_packages(packages)
106-
else:
107-
return {
108-
"success": False,
109-
"message": "Package installation is disabled in this environment",
110-
}
112+
self.dynamic_import(packages)
113+
111114

112115
if len(code) == 36 and "-" in code:
113116
filedata = self.get_file(code)

0 commit comments

Comments
 (0)