Changeset - 1f8eaa4c1dff
[Not reviewed]
default
1 2 1
Mads Kiilerich (mads) - 5 years ago 2020-10-28 21:24:13
mads@kiilerich.com
Grafted from: deb7c57f11be
lib: move locale.py to locales.py to avoid shadowing of standard module

"Fix" spurious problem, seen for example as:

$ python kallithea/lib/annotate.py
Traceback (most recent call last):
File ".../lib64/python3.8/site-packages/mercurial/encoding.py", line 107, in <module>
encoding = locale.getpreferredencoding().encode('ascii') or b'ascii'
AttributeError: module 'locale' has no attribute 'getpreferredencoding'

That happened when something in some other module tried to import stdlib locale
... but somehow would pick up the kallithea locale module and things would
fail.

Stay out of that kind of trouble by using a name that doesn't collide.
3 files changed with 4 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/bin/kallithea_cli_config.py
Show inline comments
 
@@ -12,25 +12,25 @@
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import os
 
import sys
 
import uuid
 
from collections import defaultdict
 

	
 
import click
 
import mako.exceptions
 

	
 
import kallithea.bin.kallithea_cli_base as cli_base
 
import kallithea.lib.locale
 
import kallithea.lib.locales
 
from kallithea.lib import inifile
 

	
 

	
 
def show_defaults(ctx, param, value):
 
    # Following construct is taken from the Click documentation:
 
    # https://click.palletsprojects.com/en/7.x/options/#callbacks-and-eager-options
 
    # "The resilient_parsing flag is applied to the context if Click wants to
 
    # parse the command line without any destructive behavior that would change
 
    # the execution flow. In this case, because we would exit the program, we
 
    # instead do nothing."
 
    if not value or ctx.resilient_parsing:
 
        return
 
@@ -57,25 +57,25 @@ def config_create(config_file, key_value
 
    on the command line as key=value arguments.
 

	
 
    Additional key=value arguments will be patched/inserted in the [app:main]
 
    section ... until another section name specifies where any following values
 
    should go.
 
    """
 

	
 
    mako_variable_values = {
 
        'version': kallithea.__version__,
 
        'git_hook_interpreter': sys.executable,
 
        'user_home_path': os.path.expanduser('~'),
 
        'kallithea_cli_path': cli_base.kallithea_cli_path,
 
        'ssh_locale': kallithea.lib.locale.get_current_locale(),
 
        'ssh_locale': kallithea.lib.locales.get_current_locale(),
 
    }
 
    ini_settings = defaultdict(dict)
 

	
 
    section_name = None
 
    for parameter in key_value_pairs:
 
        parts = parameter.split('=', 1)
 
        if len(parts) == 1 and parameter.startswith('[') and parameter.endswith(']'):
 
            section_name = parameter
 
        elif len(parts) == 2:
 
            key, value = parts
 
            if section_name is None and key in inifile.default_variables:
 
                mako_variable_values[key] = value
kallithea/config/app_cfg.py
Show inline comments
 
@@ -21,25 +21,25 @@ import logging
 
import os
 
import platform
 
import sys
 

	
 
import alembic.config
 
import mercurial
 
import tg
 
from alembic.migration import MigrationContext
 
from alembic.script.base import ScriptDirectory
 
from sqlalchemy import create_engine
 
from tg import FullStackApplicationConfigurator
 

	
 
import kallithea.lib.locale
 
import kallithea.lib.locales
 
import kallithea.model.base
 
import kallithea.model.meta
 
from kallithea.lib import celerypylons
 
from kallithea.lib.utils import check_git_version, load_extensions, set_app_settings, set_indexer_config, set_vcs_config
 
from kallithea.lib.utils2 import asbool
 
from kallithea.model import db
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
base_config = FullStackApplicationConfigurator()
 
@@ -90,25 +90,25 @@ try:
 
    from tgext.debugbar import enable_debugbar
 
    assert kajiki
 
except ImportError:
 
    pass
 
else:
 
    base_config.get_blueprint_value('renderers').append('kajiki')
 
    enable_debugbar(base_config)
 

	
 

	
 
def setup_configuration(app):
 
    config = app.config
 

	
 
    if not kallithea.lib.locale.current_locale_is_valid():
 
    if not kallithea.lib.locales.current_locale_is_valid():
 
        log.error("Terminating ...")
 
        sys.exit(1)
 

	
 
    # Mercurial sets encoding at module import time, so we have to monkey patch it
 
    hgencoding = config.get('hgencoding')
 
    if hgencoding:
 
        mercurial.encoding.encoding = hgencoding
 

	
 
    if config.get('ignore_alembic_revision', False):
 
        log.warning('database alembic revision checking is disabled')
 
    else:
 
        dbconf = config['sqlalchemy.url']
kallithea/lib/locales.py
Show inline comments
 
file renamed from kallithea/lib/locale.py to kallithea/lib/locales.py
0 comments (0 inline, 0 general)