# HG changeset patch # User RhodeCode Admin # Date 2024-04-22 12:54:33 # Node ID f90791c09c2835fc5a5a20a95c93d305c38386f3 # Parent 7bfb02ec6478ffa5f43452408288ba146ae3870a shell: remove module level imports diff --git a/rhodecode/lib/paster_commands/ishell.py b/rhodecode/lib/paster_commands/ishell.py --- a/rhodecode/lib/paster_commands/ishell.py +++ b/rhodecode/lib/paster_commands/ishell.py @@ -54,8 +54,13 @@ class Command(BasePasterCommand): parser = BasePasterCommand.standard_parser(verbose=True) summary = "Interactive shell" + def import_all_from_module(self, module_name): + import importlib + module = importlib.import_module(module_name) + globals().update({k: v for k, v in module.__dict__.items() if not k.startswith('_')}) + def command(self): - #get SqlAlchemy session + # get SqlAlchemy session self._init_session() # imports, used in ipython shell @@ -64,7 +69,7 @@ class Command(BasePasterCommand): import time import shutil import datetime - from rhodecode.model.db import * + self.import_all_from_module('rhodecode.model.db') try: from IPython import embed diff --git a/rhodecode/lib/pyramid_shell/__init__.py b/rhodecode/lib/pyramid_shell/__init__.py --- a/rhodecode/lib/pyramid_shell/__init__.py +++ b/rhodecode/lib/pyramid_shell/__init__.py @@ -41,6 +41,12 @@ or reset some user/system settings. """ +def import_all_from_module(module_name): + import importlib + module = importlib.import_module(module_name) + globals().update({k: v for k, v in module.__dict__.items() if not k.startswith('_')}) + + def ipython_shell_runner(env, help): # imports, used in ipython shell @@ -50,7 +56,7 @@ def ipython_shell_runner(env, help): import shutil import datetime from rhodecode.model import user, user_group, repo, repo_group - from rhodecode.model.db import * + import_all_from_module('rhodecode.model.db') try: import IPython