# HG changeset patch # User Mads Kiilerich # Date 1595700505 -7200 # Node ID 68eee0e7f4f535eaf06c84bac3a04512e3441e14 # Parent eb486c0c3114e74bf7f912ef5ff7cca1612859e7 isort: upgrade to 5.1.2 The changes to non-top-level imports seem nice. diff -r eb486c0c3114 -r 68eee0e7f4f5 dev_requirements.txt --- a/dev_requirements.txt Mon Jul 20 19:46:30 2020 +0200 +++ b/dev_requirements.txt Sat Jul 25 20:08:25 2020 +0200 @@ -5,5 +5,5 @@ mock >= 3.0.0, < 4.1 Sphinx >= 1.8.0, < 3.1 WebTest >= 2.0.6, < 2.1 -isort == 4.3.21 +isort == 5.1.2 pyflakes == 2.2.0 diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/config/app_cfg.py --- a/kallithea/config/app_cfg.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/config/app_cfg.py Sat Jul 25 20:08:25 2020 +0200 @@ -86,8 +86,8 @@ # 'debug = true' (not in production!) # See the Kallithea documentation for more information. try: + import kajiki # only to check its existence from tgext.debugbar import enable_debugbar - import kajiki # only to check its existence assert kajiki except ImportError: pass diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/controllers/compare.py --- a/kallithea/controllers/compare.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/controllers/compare.py Sat Jul 25 20:08:25 2020 +0200 @@ -130,8 +130,8 @@ elif alias == 'git': if org_repo != other_repo: + from dulwich.client import SubprocessGitClient from dulwich.repo import Repo - from dulwich.client import SubprocessGitClient gitrepo = Repo(org_repo.path) SubprocessGitClient(thin_packs=False).fetch(other_repo.path, gitrepo) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/celerylib/tasks.py --- a/kallithea/lib/celerylib/tasks.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/celerylib/tasks.py Sat Jul 25 20:08:25 2020 +0200 @@ -323,8 +323,8 @@ @celerylib.task @celerylib.dbsession def create_repo(form_data, cur_user): + from kallithea.model.db import Setting from kallithea.model.repo import RepoModel - from kallithea.model.db import Setting DBS = celerylib.get_session() diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/db_manage.py Sat Jul 25 20:08:25 2020 +0200 @@ -163,11 +163,9 @@ self.create_user(username, password, email, True) else: log.info('creating admin and regular test users') - from kallithea.tests.base import TEST_USER_ADMIN_LOGIN, \ - TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, \ - TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, \ - TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR2_LOGIN, \ - TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL + from kallithea.tests.base import (TEST_USER_ADMIN_EMAIL, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_REGULAR2_EMAIL, + TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR_LOGIN, + TEST_USER_REGULAR_PASS) self.create_user(TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_ADMIN_EMAIL, True) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/helpers.py --- a/kallithea/lib/helpers.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/helpers.py Sat Jul 25 20:08:25 2020 +0200 @@ -632,6 +632,7 @@ """Find the user identified by 'author', return one of the users attributes, default to the username attribute, None if there is no user""" from kallithea.model.db import User + # if author is already an instance use it for extraction if isinstance(author, User): return getattr(author, show_attr) @@ -646,6 +647,7 @@ def person_by_id(id_, show_attr="username"): from kallithea.model.db import User + # maybe it's an ID ? if str(id_).isdigit() or isinstance(id_, int): id_ = int(id_) @@ -974,10 +976,8 @@ def gravatar_url(email_address, size=30, default=''): - # doh, we need to re-import those to mock it later - from kallithea.config.routing import url - from kallithea.model.db import User from tg import tmpl_context as c + if not c.visual.use_gravatar: return "" @@ -987,6 +987,10 @@ if email_address == _def: return default + # re-import url so tests can mock it + from kallithea.config.routing import url + from kallithea.model.db import User + parsed_url = urllib.parse.urlparse(url.current(qualified=True)) url = (c.visual.gravatar_url or User.DEFAULT_GRAVATAR_URL) \ .replace('{email}', email_address) \ @@ -1022,8 +1026,7 @@ :param stats: two element list of added/deleted lines of code """ - from kallithea.lib.diffs import NEW_FILENODE, DEL_FILENODE, \ - MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE + from kallithea.lib.diffs import BIN_FILENODE, CHMOD_FILENODE, DEL_FILENODE, MOD_FILENODE, NEW_FILENODE, RENAMED_FILENODE a, d = stats['added'], stats['deleted'] width = 100 diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/hooks.py --- a/kallithea/lib/hooks.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/hooks.py Sat Jul 25 20:08:25 2020 +0200 @@ -307,6 +307,7 @@ connect to the database. """ import paste.deploy + import kallithea.config.application extras = get_hook_environment() diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/middleware/pygrack.py --- a/kallithea/lib/middleware/pygrack.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/middleware/pygrack.py Sat Jul 25 20:08:25 2020 +0200 @@ -168,8 +168,9 @@ if git_command in ['git-receive-pack']: # updating refs manually after each push. # Needed for pre-1.7.0.4 git clients using regular HTTP mode. + from dulwich.server import update_server_info + from kallithea.lib.vcs import get_repo - from dulwich.server import update_server_info repo = get_repo(self.content_path) if repo: update_server_info(repo._repo) @@ -223,6 +224,6 @@ def make_wsgi_app(repo_name, repo_root): - from dulwich.web import LimitedInputFilter, GunzipFilter + from dulwich.web import GunzipFilter, LimitedInputFilter app = GitDirectory(repo_root, repo_name) return GunzipFilter(LimitedInputFilter(app)) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/utils2.py Sat Jul 25 20:08:25 2020 +0200 @@ -331,9 +331,8 @@ :param repo: :param rev: """ - from kallithea.lib.vcs.backends.base import BaseRepository + from kallithea.lib.vcs.backends.base import BaseRepository, EmptyChangeset from kallithea.lib.vcs.exceptions import RepositoryError - from kallithea.lib.vcs.backends.base import EmptyChangeset if not isinstance(repo, BaseRepository): raise Exception('You must pass an Repository ' 'object as first argument got %s' % type(repo)) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/lib/vcs/utils/helpers.py --- a/kallithea/lib/vcs/utils/helpers.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/lib/vcs/utils/helpers.py Sat Jul 25 20:08:25 2020 +0200 @@ -108,8 +108,8 @@ except ImportError: return code from pygments import highlight - from pygments.lexers import guess_lexer_for_filename, ClassNotFound from pygments.formatters import TerminalFormatter + from pygments.lexers import ClassNotFound, guess_lexer_for_filename try: lexer = guess_lexer_for_filename(name, code) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/model/db.py --- a/kallithea/model/db.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/model/db.py Sat Jul 25 20:08:25 2020 +0200 @@ -307,8 +307,10 @@ @classmethod def get_server_info(cls): + import platform + import pkg_resources - import platform + from kallithea.lib.utils import check_git_version mods = [(p.project_name, p.version) for p in pkg_resources.working_set] info = { @@ -595,7 +597,8 @@ :param author: """ - from kallithea.lib.helpers import email, author_name + from kallithea.lib.helpers import author_name, email + # Valid email in the attribute passed, see if they're in the system _email = email(author) if _email: diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/model/repo.py --- a/kallithea/model/repo.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/model/repo.py Sat Jul 25 20:08:25 2020 +0200 @@ -109,7 +109,8 @@ @classmethod def _render_datatable(cls, tmpl, *args, **kwargs): - from tg import tmpl_context as c, request, app_globals + from tg import app_globals, request + from tg import tmpl_context as c from tg.i18n import ugettext as _ _tmpl_lookup = app_globals.mako_lookup @@ -128,7 +129,9 @@ admin: return data for action column. """ _render = self._render_datatable - from tg import tmpl_context as c, request + from tg import request + from tg import tmpl_context as c + from kallithea.model.scm import ScmModel def repo_lnk(name, rtype, rstate, private, fork_of): diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/model/repo_group.py --- a/kallithea/model/repo_group.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/model/repo_group.py Sat Jul 25 20:08:25 2020 +0200 @@ -189,8 +189,8 @@ def _update_permissions(self, repo_group, perms_new=None, perms_updates=None, recursive=None, check_perms=True): + from kallithea.lib.auth import HasUserGroupPermissionLevel from kallithea.model.repo import RepoModel - from kallithea.lib.auth import HasUserGroupPermissionLevel if not perms_new: perms_new = [] diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/model/user.py --- a/kallithea/model/user.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/model/user.py Sat Jul 25 20:08:25 2020 +0200 @@ -59,8 +59,7 @@ if not cur_user: cur_user = getattr(get_current_authuser(), 'username', None) - from kallithea.lib.hooks import log_create_user, \ - check_allowed_create_user + from kallithea.lib.hooks import check_allowed_create_user, log_create_user _fd = form_data user_data = { 'username': _fd['username'], @@ -111,9 +110,8 @@ if not cur_user: cur_user = getattr(get_current_authuser(), 'username', None) - from kallithea.lib.auth import get_crypt_password, check_password - from kallithea.lib.hooks import log_create_user, \ - check_allowed_create_user + from kallithea.lib.auth import check_password, get_crypt_password + from kallithea.lib.hooks import check_allowed_create_user, log_create_user user_data = { 'username': username, 'password': password, 'email': email, 'firstname': firstname, 'lastname': lastname, @@ -168,8 +166,8 @@ raise def create_registration(self, form_data): + import kallithea.lib.helpers as h from kallithea.model.notification import NotificationModel - import kallithea.lib.helpers as h form_data['admin'] = False form_data['extern_type'] = User.DEFAULT_AUTH_TYPE @@ -317,9 +315,9 @@ allowing users to copy-paste or manually enter the token from the email. """ + import kallithea.lib.helpers as h from kallithea.lib.celerylib import tasks from kallithea.model.notification import EmailNotificationModel - import kallithea.lib.helpers as h user_email = data['email'] user = User.get_by_email(user_email) @@ -386,8 +384,8 @@ return expected_token == token def reset_password(self, user_email, new_passwd): + from kallithea.lib import auth from kallithea.lib.celerylib import tasks - from kallithea.lib import auth user = User.get_by_email(user_email) if user is not None: if not self.can_change_password(user): diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/tests/api/api_base.py Sat Jul 25 20:08:25 2020 +0200 @@ -145,7 +145,7 @@ assert 'trololo' == Optional.extract('trololo') def test_Optional_OAttr(self): - from kallithea.controllers.api.api import Optional, OAttr + from kallithea.controllers.api.api import OAttr, Optional option1 = Optional(OAttr('apiuser')) assert 'apiuser' == Optional.extract(option1) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/tests/other/test_libs.py --- a/kallithea/tests/other/test_libs.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/tests/other/test_libs.py Sat Jul 25 20:08:25 2020 +0200 @@ -156,8 +156,9 @@ (dict(years= -3, months= -2), '3 years and 2 months ago'), ]) def test_age(self, age_args, expected): + from dateutil import relativedelta + from kallithea.lib.utils2 import age - from dateutil import relativedelta with test_context(self.app): n = datetime.datetime(year=2012, month=5, day=17) delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) @@ -181,8 +182,9 @@ (dict(years= -4, months= -8), '5 years ago'), ]) def test_age_short(self, age_args, expected): + from dateutil import relativedelta + from kallithea.lib.utils2 import age - from dateutil import relativedelta with test_context(self.app): n = datetime.datetime(year=2012, month=5, day=17) delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) @@ -200,8 +202,9 @@ (dict(years=1, months=1), 'in 1 year and 1 month') ]) def test_age_in_future(self, age_args, expected): + from dateutil import relativedelta + from kallithea.lib.utils2 import age - from dateutil import relativedelta with test_context(self.app): n = datetime.datetime(year=2012, month=5, day=17) delt = lambda *args, **kwargs: relativedelta.relativedelta(*args, **kwargs) @@ -297,6 +300,7 @@ :param text: """ import re + # quickly change expected url[] into a link url_pattern = re.compile(r'(?:url\[)(.+?)(?:\])') @@ -570,11 +574,11 @@ ('http://www.example.org/kallithea/repos/', 'abc/xyz/', 'http://www.example.org/kallithea/repos/abc/xyz/'), ]) def test_canonical_url(self, canonical, test, expected): - from kallithea.lib.helpers import canonical_url + # setup url(), used by canonical_url + import routes from tg import request - # setup url(), used by canonical_url - import routes + from kallithea.lib.helpers import canonical_url m = routes.Mapper() m.connect('about', '/about-page') url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'}) @@ -594,11 +598,12 @@ ('http://www.example.org/kallithea/repos/', 'www.example.org'), ]) def test_canonical_hostname(self, canonical, expected): - from kallithea.lib.helpers import canonical_hostname + import routes from tg import request + from kallithea.lib.helpers import canonical_hostname + # setup url(), used by canonical_hostname - import routes m = routes.Mapper() url = routes.URLGenerator(m, {'HTTP_HOST': 'http_host.example.org'}) diff -r eb486c0c3114 -r 68eee0e7f4f5 kallithea/tests/vcs/test_workdirs.py --- a/kallithea/tests/vcs/test_workdirs.py Mon Jul 20 19:46:30 2020 +0200 +++ b/kallithea/tests/vcs/test_workdirs.py Sat Jul 25 20:08:25 2020 +0200 @@ -68,6 +68,7 @@ def test_checkout_branch(self): from kallithea.lib.vcs.exceptions import BranchDoesNotExistError + # first, 'foobranch' does not exist. with pytest.raises(BranchDoesNotExistError): self.repo.workdir.checkout_branch(branch='foobranch') diff -r eb486c0c3114 -r 68eee0e7f4f5 scripts/i18n --- a/scripts/i18n Mon Jul 20 19:46:30 2020 +0200 +++ b/scripts/i18n Sat Jul 25 20:08:25 2020 +0200 @@ -19,7 +19,6 @@ import sys import click - import i18n_utils @@ -90,11 +89,8 @@ and then invoke merge/rebase/graft with the additional argument '--tool i18n'. """ - from mercurial import ( - context, - simplemerge, - ui as uimod, - ) + from mercurial import context, simplemerge + from mercurial import ui as uimod print('i18n normalized-merge: normalizing and merging %s' % output)