changeset 8668:2ff983214ea0

imports: always import the whole kallithea module to use top level kallithea variables This is slightly more lazy and might avoid some depeendency issues.
author Mads Kiilerich <mads@kiilerich.com>
date Sun, 11 Oct 2020 01:07:51 +0200
parents 072c0352dd36
children 07cb7b42057e
files docs/conf.py kallithea/lib/base.py kallithea/lib/hooks.py kallithea/lib/utils2.py kallithea/model/forms.py kallithea/model/scm.py
diffstat 6 files changed, 23 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/docs/conf.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/docs/conf.py	Sun Oct 11 01:07:51 2020 +0200
@@ -14,7 +14,7 @@
 import os
 import sys
 
-from kallithea import __version__
+import kallithea
 
 
 # If extensions (or modules to document with autodoc) are in another directory,
@@ -56,9 +56,9 @@
 # The short X.Y version.
 root = os.path.dirname(os.path.dirname(__file__))
 sys.path.append(root)
-version = __version__
+version = kallithea.__version__
 # The full version, including alpha/beta/rc tags.
-release = __version__
+release = kallithea.__version__
 
 # The language for content autogenerated by Sphinx. Refer to documentation
 # for a list of supported languages.
--- a/kallithea/lib/base.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/kallithea/lib/base.py	Sun Oct 11 01:07:51 2020 +0200
@@ -43,7 +43,7 @@
 from tg import tmpl_context as c
 from tg.i18n import ugettext as _
 
-from kallithea import BACKENDS, __version__
+import kallithea
 from kallithea.config.routing import url
 from kallithea.lib import auth_modules, ext_json
 from kallithea.lib.auth import AuthUser, HasPermissionAnyMiddleware
@@ -368,7 +368,7 @@
                 log.error('CSRF check failed')
                 raise webob.exc.HTTPForbidden()
 
-        c.kallithea_version = __version__
+        c.kallithea_version = kallithea.__version__
         rc_config = Setting.get_app_settings()
 
         # Visual options
@@ -413,7 +413,7 @@
         # END CONFIG VARS
 
         c.repo_name = get_repo_slug(request)  # can be empty
-        c.backends = list(BACKENDS)
+        c.backends = list(kallithea.BACKENDS)
 
         self.cut_off_limit = safe_int(config.get('cut_off_limit'))
 
--- a/kallithea/lib/hooks.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/kallithea/lib/hooks.py	Sun Oct 11 01:07:51 2020 +0200
@@ -31,6 +31,7 @@
 
 import mercurial.scmutil
 
+import kallithea
 from kallithea.lib import helpers as h
 from kallithea.lib.exceptions import UserCreationError
 from kallithea.lib.utils import action_logger, make_ui
@@ -94,8 +95,7 @@
     action = 'pull'
     action_logger(user, action, ex.repository, ex.ip, commit=True)
     # extension hook call
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'PULL_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'PULL_HOOK', None)
     if callable(callback):
         kw = {}
         kw.update(ex)
@@ -133,8 +133,7 @@
     ScmModel().mark_for_invalidation(ex.repository)
 
     # extension hook call
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'PUSH_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'PUSH_HOOK', None)
     if callable(callback):
         kw = {'pushed_revs': revs}
         kw.update(ex)
@@ -164,8 +163,7 @@
      'repo_name'
 
     """
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'CREATE_REPO_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'CREATE_REPO_HOOK', None)
     if callable(callback):
         kw = {}
         kw.update(repository_dict)
@@ -176,8 +174,7 @@
 
 def check_allowed_create_user(user_dict, created_by, **kwargs):
     # pre create hooks
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'PRE_CREATE_USER_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'PRE_CREATE_USER_HOOK', None)
     if callable(callback):
         allowed, reason = callback(created_by=created_by, **user_dict)
         if not allowed:
@@ -212,8 +209,7 @@
      'emails',
 
     """
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'CREATE_USER_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'CREATE_USER_HOOK', None)
     if callable(callback):
         callback(created_by=created_by, **user_dict)
 
@@ -224,8 +220,7 @@
 
     :param pullrequest_dict: dict dump of pull request object
     """
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'CREATE_PULLREQUEST_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'CREATE_PULLREQUEST_HOOK', None)
     if callable(callback):
         return callback(created_by=created_by, **pullrequest_dict)
 
@@ -254,8 +249,7 @@
      'repo_name'
 
     """
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'DELETE_REPO_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'DELETE_REPO_HOOK', None)
     if callable(callback):
         kw = {}
         kw.update(repository_dict)
@@ -293,8 +287,7 @@
      'emails',
 
     """
-    from kallithea import EXTENSIONS
-    callback = getattr(EXTENSIONS, 'DELETE_USER_HOOK', None)
+    callback = getattr(kallithea.EXTENSIONS, 'DELETE_USER_HOOK', None)
     if callable(callback):
         callback(deleted_by=deleted_by, **user_dict)
 
--- a/kallithea/lib/utils2.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/kallithea/lib/utils2.py	Sun Oct 11 01:07:51 2020 +0200
@@ -41,6 +41,7 @@
 from tg.support.converters import asbool, aslist
 from webhelpers2.text import collapse, remove_formatting, strip_tags
 
+import kallithea
 from kallithea.lib.vcs.utils import ascii_bytes, ascii_str, safe_bytes, safe_str  # re-export
 from kallithea.lib.vcs.utils.lazy import LazyProperty
 
@@ -442,14 +443,13 @@
 
     Must always be called before anything with hooks are invoked.
     """
-    from kallithea import CONFIG
     extras = {
         'ip': ip_addr, # used in log_push/pull_action action_logger
         'username': username,
         'action': action or 'push_local', # used in log_push_action_raw_ids action_logger
         'repository': repo_name,
         'scm': repo_alias, # used to pick hack in log_push_action_raw_ids
-        'config': CONFIG['__file__'], # used by git hook to read config
+        'config': kallithea.CONFIG['__file__'], # used by git hook to read config
     }
     os.environ['KALLITHEA_EXTRAS'] = json.dumps(extras)
 
--- a/kallithea/model/forms.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/kallithea/model/forms.py	Sun Oct 11 01:07:51 2020 +0200
@@ -39,7 +39,7 @@
 from formencode import All
 from tg.i18n import ugettext as _
 
-from kallithea import BACKENDS
+import kallithea
 from kallithea.model import validators as v
 
 
@@ -238,7 +238,7 @@
     return _PasswordResetConfirmationForm
 
 
-def RepoForm(edit=False, old_data=None, supported_backends=BACKENDS,
+def RepoForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS,
              repo_groups=None, landing_revs=None):
     old_data = old_data or {}
     repo_groups = repo_groups or []
@@ -315,7 +315,7 @@
     return _RepoFieldForm
 
 
-def RepoForkForm(edit=False, old_data=None, supported_backends=BACKENDS,
+def RepoForkForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS,
                  repo_groups=None, landing_revs=None):
     old_data = old_data or {}
     repo_groups = repo_groups or []
@@ -431,7 +431,7 @@
     return _CustomDefaultPermissionsForm
 
 
-def DefaultsForm(edit=False, old_data=None, supported_backends=BACKENDS):
+def DefaultsForm(edit=False, old_data=None, supported_backends=kallithea.BACKENDS):
     class _DefaultsForm(formencode.Schema):
         allow_extra_fields = True
         filter_extra_fields = True
--- a/kallithea/model/scm.py	Sun Oct 11 01:02:46 2020 +0200
+++ b/kallithea/model/scm.py	Sun Oct 11 01:07:51 2020 +0200
@@ -36,7 +36,6 @@
 from tg.i18n import ugettext as _
 
 import kallithea
-from kallithea import BACKENDS
 from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoPermissionLevel, HasUserGroupPermissionLevel
 from kallithea.lib.exceptions import IMCCommitError, NonRelativePathError
 from kallithea.lib.hooks import process_pushed_raw_ids
@@ -188,10 +187,10 @@
 
                     klass = get_backend(path[0])
 
-                    if path[0] == 'hg' and path[0] in BACKENDS:
+                    if path[0] == 'hg' and path[0] in kallithea.BACKENDS:
                         repos[name] = klass(path[1], baseui=baseui)
 
-                    if path[0] == 'git' and path[0] in BACKENDS:
+                    if path[0] == 'git' and path[0] in kallithea.BACKENDS:
                         repos[name] = klass(path[1])
             except OSError:
                 continue