# HG changeset patch # User RhodeCode Admin # Date 2023-05-18 12:23:39 # Node ID bb0b5a8e5b9bcf2515fe8aeb5d13230f1e3408b9 # Parent 170035d4c35d5792c75a1cd145f1a97f509a277b ruff: code-cleanups diff --git a/vcsserver/config/settings_maker.py b/vcsserver/config/settings_maker.py --- a/vcsserver/config/settings_maker.py +++ b/vcsserver/config/settings_maker.py @@ -164,7 +164,7 @@ class SettingsMaker(object): 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf) return - with open(logging_conf, 'rb') as f: + with open(logging_conf, 'rt') as f: ini_template = textwrap.dedent(f.read()) ini_template = string.Template(ini_template).safe_substitute( RC_LOGGING_LEVEL=os.environ.get('RC_LOGGING_LEVEL', '') or level, diff --git a/vcsserver/lib/exc_tracking.py b/vcsserver/lib/exc_tracking.py --- a/vcsserver/lib/exc_tracking.py +++ b/vcsserver/lib/exc_tracking.py @@ -75,6 +75,7 @@ def _store_exception(exc_id, exc_info, p detailed_tb = getattr(exc_value, '_org_exc_tb', None) if detailed_tb: + remote_tb = detailed_tb if isinstance(detailed_tb, str): remote_tb = [detailed_tb] diff --git a/vcsserver/lib/rc_cache/__init__.py b/vcsserver/lib/rc_cache/__init__.py --- a/vcsserver/lib/rc_cache/__init__.py +++ b/vcsserver/lib/rc_cache/__init__.py @@ -16,7 +16,9 @@ # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA import logging + from dogpile.cache import register_backend + module_name = 'vcsserver' register_backend( @@ -40,8 +42,12 @@ log = logging.getLogger(__name__) from . import region_meta from .utils import ( - get_default_cache_settings, backend_key_generator, get_or_create_region, - clear_cache_namespace, make_region) + backend_key_generator, + clear_cache_namespace, + get_default_cache_settings, + get_or_create_region, + make_region, +) def configure_dogpile_cache(settings): diff --git a/vcsserver/lib/rc_cache/backends.py b/vcsserver/lib/rc_cache/backends.py --- a/vcsserver/lib/rc_cache/backends.py +++ b/vcsserver/lib/rc_cache/backends.py @@ -15,30 +15,29 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +import errno +import fcntl +import functools +import logging +import pickle import time -import errno -import logging -import functools import msgpack import redis -import pickle -import fcntl + flock_org = fcntl.flock from typing import Union +from dogpile.cache.api import Deserializer, Serializer +from dogpile.cache.backends import file as file_backend from dogpile.cache.backends import memory as memory_backend -from dogpile.cache.backends import file as file_backend from dogpile.cache.backends import redis as redis_backend from dogpile.cache.backends.file import FileLock from dogpile.cache.util import memoized_property -from dogpile.cache.api import Serializer, Deserializer - from pyramid.settings import asbool from vcsserver.lib.memory_lru_dict import LRUDict, LRUDictDebug -from vcsserver.str_utils import safe_str, safe_bytes - +from vcsserver.str_utils import safe_bytes, safe_str _default_max_size = 1024 diff --git a/vcsserver/lib/rc_cache/utils.py b/vcsserver/lib/rc_cache/utils.py --- a/vcsserver/lib/rc_cache/utils.py +++ b/vcsserver/lib/rc_cache/utils.py @@ -15,17 +15,17 @@ # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +import functools +import logging import os import time -import logging -import functools + import decorator - from dogpile.cache import CacheRegion +from vcsserver.lib.rc_cache import region_meta from vcsserver.str_utils import safe_bytes from vcsserver.utils import sha1 -from vcsserver.lib.rc_cache import region_meta log = logging.getLogger(__name__) @@ -41,7 +41,7 @@ class RhodeCodeCacheRegion(CacheRegion): condition=True): """ Custom conditional decorator, that will not touch any dogpile internals if - condition isn't meet. This works a bit different than should_cache_fn + condition isn't meet. This works a bit different from should_cache_fn And it's faster in cases we don't ever want to compute cached values """ expiration_time_is_callable = callable(expiration_time) @@ -150,7 +150,7 @@ def key_generator(backend, namespace, fn backend_prefix = getattr(backend, 'key_prefix', None) or 'backend_prefix' namespace_pref = namespace or 'default_namespace' arg_key = compute_key_from_params(*args) - final_key = "{}:{}:{}_{}".format(backend_prefix, namespace_pref, fname, arg_key) + final_key = f"{backend_prefix}:{namespace_pref}:{fname}_{arg_key}" return final_key diff --git a/vcsserver/lib/statsd_client.py b/vcsserver/lib/statsd_client.py --- a/vcsserver/lib/statsd_client.py +++ b/vcsserver/lib/statsd_client.py @@ -1,3 +1,20 @@ +# RhodeCode VCSServer provides access to different vcs backends via network. +# Copyright (C) 2014-2020 RhodeCode GmbH +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + from vcsserver.lib._vendor.statsd import client_from_config diff --git a/vcsserver/remote/git.py b/vcsserver/remote/git.py --- a/vcsserver/remote/git.py +++ b/vcsserver/remote/git.py @@ -70,7 +70,7 @@ def reraise_safe_exceptions(func): exc = exceptions.VcsException(org_exc=e) raise exc(safe_str(e)) except Exception as e: - # NOTE(marcink): becuase of how dulwich handles some exceptions + # NOTE(marcink): because of how dulwich handles some exceptions # (KeyError on empty repos), we cannot track this and catch all # exceptions, it's an exceptions from other handlers #if not hasattr(e, '_vcs_kind'): @@ -422,6 +422,7 @@ class GitRemote(RemoteBase): def branch(self, wire, commit_id): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _branch(_context_uid, _repo_id, _commit_id): regex = re.compile('^refs/heads') @@ -438,6 +439,7 @@ class GitRemote(RemoteBase): def commit_branches(self, wire, commit_id): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _commit_branches(_context_uid, _repo_id, _commit_id): repo_init = self._factory.repo_libgit2(wire) @@ -658,7 +660,7 @@ class GitRemote(RemoteBase): repo[HEAD_MARKER] = remote_refs[refs[-1]] if update_after: - # we want to checkout HEAD + # we want to check out HEAD repo[HEAD_MARKER] = remote_refs[HEAD_MARKER] index.build_index_from_tree(repo.path, repo.index_path(), repo.object_store, repo[HEAD_MARKER].tree) @@ -944,6 +946,7 @@ class GitRemote(RemoteBase): def message(self, wire, commit_id): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _message(_repo_id, _commit_id): repo_init = self._factory.repo_libgit2(wire) @@ -1183,7 +1186,7 @@ class GitRemote(RemoteBase): @reraise_safe_exceptions def node_annotate_legacy(self, wire, commit_id, path): - #note: replaced by pygit2 impelementation + # note: replaced by pygit2 implementation cmd = ['blame', '-l', '--root', '-r', commit_id, '--', path] # -l ==> outputs long shas (and we need all 40 characters) # --root ==> doesn't put '^' character for boundaries diff --git a/vcsserver/remote/svn.py b/vcsserver/remote/svn.py --- a/vcsserver/remote/svn.py +++ b/vcsserver/remote/svn.py @@ -28,12 +28,13 @@ import urllib.parse import urllib.error import traceback -import svn.client -import svn.core -import svn.delta -import svn.diff -import svn.fs -import svn.repos + +import svn.client # noqa +import svn.core # noqa +import svn.delta # noqa +import svn.diff # noqa +import svn.fs # noqa +import svn.repos # noqa from vcsserver import svn_diff, exceptions, subprocessio, settings from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, archive_repo, BinaryEnvelope @@ -274,6 +275,7 @@ class SvnRemote(RemoteBase): def node_properties(self, wire, path, revision): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _node_properties(_repo_id, _path, _revision): repo = self._factory.repo(wire) @@ -313,6 +315,7 @@ class SvnRemote(RemoteBase): cache_on, context_uid, repo_id = self._cache_on(wire) region = self._region(wire) + @region.conditional_cache_on_arguments(condition=cache_on) def _get_node_type(_repo_id, _path, _revision): repo = self._factory.repo(wire)