Mercurial > kallithea
changeset 8725:6a9e5841cc51
lib: consistently import helpers the same way
Make it easier to grep for any remaining potential layering-violating use of
helpers.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Thu, 29 Oct 2020 11:28:36 +0100 |
parents | 7e7489e1672d |
children | 905cab5f971d |
files | kallithea/controllers/admin/repo_groups.py kallithea/controllers/admin/user_groups.py kallithea/controllers/admin/users.py kallithea/controllers/compare.py kallithea/controllers/feed.py kallithea/controllers/files.py kallithea/controllers/home.py kallithea/lib/celerylib/tasks.py kallithea/tests/functional/test_files.py kallithea/tests/models/test_notifications.py kallithea/tests/other/test_libs.py |
diffstat | 11 files changed, 27 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/repo_groups.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/admin/repo_groups.py Thu Oct 29 11:28:36 2020 +0100 @@ -36,7 +36,7 @@ from tg.i18n import ungettext from webob.exc import HTTPForbidden, HTTPFound, HTTPInternalServerError, HTTPNotFound -from kallithea.lib import helpers as h +import kallithea.lib.helpers as h from kallithea.lib import webutils from kallithea.lib.auth import HasPermissionAny, HasRepoGroupPermissionLevel, HasRepoGroupPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseController, render
--- a/kallithea/controllers/admin/user_groups.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/admin/user_groups.py Thu Oct 29 11:28:36 2020 +0100 @@ -37,7 +37,7 @@ from tg.i18n import ugettext as _ from webob.exc import HTTPFound, HTTPInternalServerError -from kallithea.lib import helpers as h +import kallithea.lib.helpers as h from kallithea.lib import webutils from kallithea.lib.auth import HasPermissionAnyDecorator, HasUserGroupPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseController, render
--- a/kallithea/controllers/admin/users.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/admin/users.py Thu Oct 29 11:28:36 2020 +0100 @@ -37,9 +37,8 @@ from webob.exc import HTTPFound, HTTPNotFound import kallithea -from kallithea.lib import auth_modules -from kallithea.lib import helpers as h -from kallithea.lib import webutils +import kallithea.lib.helpers as h +from kallithea.lib import auth_modules, webutils from kallithea.lib.auth import AuthUser, HasPermissionAnyDecorator, LoginRequired from kallithea.lib.base import BaseController, IfSshEnabled, render from kallithea.lib.exceptions import DefaultUserException, UserCreationError, UserOwnsReposException
--- a/kallithea/controllers/compare.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/compare.py Thu Oct 29 11:28:36 2020 +0100 @@ -34,9 +34,8 @@ from tg.i18n import ugettext as _ from webob.exc import HTTPBadRequest, HTTPFound, HTTPNotFound -from kallithea.lib import diffs -from kallithea.lib import helpers as h -from kallithea.lib import webutils +import kallithea.lib.helpers as h +from kallithea.lib import diffs, webutils from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseRepoController, render from kallithea.lib.graphmod import graph_data
--- a/kallithea/controllers/feed.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/feed.py Thu Oct 29 11:28:36 2020 +0100 @@ -34,9 +34,8 @@ from tg.i18n import ugettext as _ import kallithea -from kallithea.lib import feeds -from kallithea.lib import helpers as h -from kallithea.lib import webutils +import kallithea.lib.helpers as h +from kallithea.lib import feeds, webutils from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseRepoController from kallithea.lib.diffs import DiffProcessor
--- a/kallithea/controllers/files.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/files.py Thu Oct 29 11:28:36 2020 +0100 @@ -39,9 +39,8 @@ from webob.exc import HTTPFound, HTTPNotFound import kallithea -from kallithea.lib import diffs -from kallithea.lib import helpers as h -from kallithea.lib import webutils +import kallithea.lib.helpers as h +from kallithea.lib import diffs, webutils from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseRepoController, jsonify, render from kallithea.lib.exceptions import NonRelativePathError
--- a/kallithea/controllers/home.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/controllers/home.py Thu Oct 29 11:28:36 2020 +0100 @@ -34,7 +34,7 @@ from tg.i18n import ugettext as _ from webob.exc import HTTPBadRequest -from kallithea.lib import helpers as h +import kallithea.lib.helpers as h from kallithea.lib.auth import HasRepoPermissionLevelDecorator, LoginRequired from kallithea.lib.base import BaseController, jsonify, render from kallithea.lib.utils2 import safe_str
--- a/kallithea/lib/celerylib/tasks.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/lib/celerylib/tasks.py Thu Oct 29 11:28:36 2020 +0100 @@ -41,8 +41,8 @@ from tg import config import kallithea +import kallithea.lib.helpers as h from kallithea.lib import celerylib, conf, ext_json -from kallithea.lib.helpers import person from kallithea.lib.hooks import log_create_repository from kallithea.lib.indexers.daemon import WhooshIndexingDaemon from kallithea.lib.utils import action_logger @@ -72,7 +72,7 @@ # for js data compatibility cleans the key for person from ' def akc(k): - return person(k).replace('"', '') + return h.person(k).replace('"', '') @celerylib.task
--- a/kallithea/tests/functional/test_files.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/tests/functional/test_files.py Thu Oct 29 11:28:36 2020 +0100 @@ -3,6 +3,7 @@ import mimetypes import posixpath +import kallithea.lib.helpers from kallithea.model import db, meta from kallithea.tests import base from kallithea.tests.fixture import Fixture @@ -95,7 +96,6 @@ def test_file_source(self): # Force the global cache to be populated now when we know the right .ini has been loaded. # (Without this, the test would fail.) - import kallithea.lib.helpers kallithea.lib.helpers._urlify_issues_f = None self.log_user() response = self.app.get(base.url(controller='files', action='index',
--- a/kallithea/tests/models/test_notifications.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/tests/models/test_notifications.py Thu Oct 29 11:28:36 2020 +0100 @@ -6,7 +6,7 @@ import kallithea.lib.celerylib import kallithea.lib.celerylib.tasks -from kallithea.lib import helpers as h +import kallithea.lib.helpers as h from kallithea.model import db, meta from kallithea.model.notification import EmailNotificationModel, NotificationModel from kallithea.model.user import UserModel
--- a/kallithea/tests/other/test_libs.py Fri Oct 30 00:50:38 2020 +0100 +++ b/kallithea/tests/other/test_libs.py Thu Oct 29 11:28:36 2020 +0100 @@ -31,6 +31,7 @@ import mock from tg.util.webtest import test_context +import kallithea.lib.helpers as h from kallithea.lib import webutils from kallithea.lib.utils2 import AttributeDict, safe_bytes from kallithea.model import db @@ -198,8 +199,7 @@ "[requires => url] [lang => python] [just a tag]" "[,d] [ => ULR ] [obsolete] [desc]]" ) - from kallithea.lib.helpers import urlify_text - res = urlify_text(sample, stylize=True) + res = h.urlify_text(sample, stylize=True) assert '<div class="label label-meta" data-tag="tag">tag</div>' in res assert '<div class="label label-meta" data-tag="obsolete">obsolete</div>' in res assert '<div class="label label-meta" data-tag="stale">stale</div>' in res @@ -208,7 +208,6 @@ assert '<div class="label label-meta" data-tag="tag">tag</div>' in res def test_alternative_gravatar(self): - from kallithea.lib.helpers import gravatar_url _md5 = lambda s: hashlib.md5(safe_bytes(s)).hexdigest() # mock tg.tmpl_context @@ -225,30 +224,30 @@ with mock.patch('tg.tmpl_context', fake): from kallithea.lib.webutils import url assert url.current() == 'https://example.com' - grav = gravatar_url(email_address='test@example.com', size=24) + grav = h.gravatar_url(email_address='test@example.com', size=24) assert grav == 'http://example.com/test@example.com' fake = fake_tmpl_context(_url='http://example.com/{email}') with mock.patch('tg.tmpl_context', fake): - grav = gravatar_url(email_address='test@example.com', size=24) + grav = h.gravatar_url(email_address='test@example.com', size=24) assert grav == 'http://example.com/test@example.com' fake = fake_tmpl_context(_url='http://example.com/{md5email}') with mock.patch('tg.tmpl_context', fake): em = 'test@example.com' - grav = gravatar_url(email_address=em, size=24) + grav = h.gravatar_url(email_address=em, size=24) assert grav == 'http://example.com/%s' % (_md5(em)) fake = fake_tmpl_context(_url='http://example.com/{md5email}/{size}') with mock.patch('tg.tmpl_context', fake): em = 'test@example.com' - grav = gravatar_url(email_address=em, size=24) + grav = h.gravatar_url(email_address=em, size=24) assert grav == 'http://example.com/%s/%s' % (_md5(em), 24) fake = fake_tmpl_context(_url='{scheme}://{netloc}/{md5email}/{size}') with mock.patch('tg.tmpl_context', fake): em = 'test@example.com' - grav = gravatar_url(email_address=em, size=24) + grav = h.gravatar_url(email_address=em, size=24) assert grav == 'https://example.com/%s/%s' % (_md5(em), 24) @base.parametrize('clone_uri_tmpl,repo_name,username,prefix,expected', [ @@ -322,8 +321,7 @@ with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__', lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs, ): - from kallithea.lib.helpers import urlify_text - assert urlify_text(sample, 'repo_name') == expected + assert h.urlify_text(sample, 'repo_name') == expected @base.parametrize('sample,expected,url_', [ ("", @@ -378,8 +376,7 @@ with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__', lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs, ): - from kallithea.lib.helpers import urlify_text - assert urlify_text(sample, 'repo_name', stylize=True) == expected + assert h.urlify_text(sample, 'repo_name', stylize=True) == expected @base.parametrize('sample,expected', [ ("deadbeefcafe @mention, and http://foo.bar/ yo", @@ -392,8 +389,7 @@ with mock.patch('kallithea.lib.webutils.UrlGenerator.__call__', lambda self, name, **kwargs: dict(changeset_home='/%(repo_name)s/changeset/%(revision)s')[name] % kwargs, ): - from kallithea.lib.helpers import urlify_text - assert urlify_text(sample, 'repo_name', link_='#the-link') == expected + assert h.urlify_text(sample, 'repo_name', link_='#the-link') == expected @base.parametrize('issue_pat,issue_server,issue_sub,sample,expected', [ (r'#(\d+)', 'http://foo/{repo}/issue/\\1', '#\\1', @@ -474,7 +470,6 @@ """<a class="issue-tracker-link" href="http://foo/BRU/pullrequest/747/">PR-BRU-747</a>"""), ]) def test_urlify_issues(self, issue_pat, issue_server, issue_sub, sample, expected): - from kallithea.lib.helpers import urlify_text config_stub = { 'sqlalchemy.url': 'foo', 'issue_pat': issue_pat, @@ -484,7 +479,7 @@ # force recreation of lazy function with mock.patch('kallithea.lib.helpers._urlify_issues_f', None): with mock.patch('kallithea.CONFIG', config_stub): - assert urlify_text(sample, 'repo_name') == expected + assert h.urlify_text(sample, 'repo_name') == expected @base.parametrize('sample,expected', [ ('abc X5', 'abc <a class="issue-tracker-link" href="http://main/repo_name/main/5/">#5</a>'), @@ -496,7 +491,6 @@ ('issue FAILMORE89', 'issue FAILMORE89'), # no match because absent prefix ]) def test_urlify_issues_multiple_issue_patterns(self, sample, expected): - from kallithea.lib.helpers import urlify_text config_stub = { 'sqlalchemy.url': r'foo', 'issue_pat': r'X(\d+)', @@ -517,7 +511,7 @@ # force recreation of lazy function with mock.patch('kallithea.lib.helpers._urlify_issues_f', None): with mock.patch('kallithea.CONFIG', config_stub): - assert urlify_text(sample, 'repo_name') == expected + assert h.urlify_text(sample, 'repo_name') == expected @base.parametrize('test,expected', [ ("", None),