Skip to content

Commit

Permalink
fix[shuffle-tools-fork]: Making dynamic imports possible
Browse files Browse the repository at this point in the history
  • Loading branch information
0x0elliot committed Nov 29, 2024
1 parent bb43d09 commit 1684e68
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions shuffle-tools-fork/1.0.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tempfile
import zipfile
import base64
import importlib
import ipaddress
import hashlib
import shufflepy
Expand Down Expand Up @@ -58,6 +59,11 @@ def __init__(self, redis, logger, console_logger=None):
"""
super().__init__(redis, logger, console_logger)

def dynamic_import(package_name: str):
"""Import a package and return the module"""
return importlib.import_module(package_name.split('==')[0].split('>=')[0].split('<=')[0].split('>')[0].split('<')[0])


def get_missing_packages(required_packages: list) -> list:
"""
Returns a list of packages that aren't currently installed.
Expand Down Expand Up @@ -103,11 +109,8 @@ def execute_python(self, code, packages=[]) -> dict:
if packages:
if allow_package_install:
self.install_packages(packages)
else:
return {
"success": False,
"message": "Package installation is disabled in this environment",
}
self.dynamic_import(packages)


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

0 comments on commit 1684e68

Please sign in to comment.