[jhbuild] Remove uprint/uencode/udecode from builtins
- From: Christoph Reiter <creiter src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [jhbuild] Remove uprint/uencode/udecode from builtins
- Date: Sun, 22 Sep 2019 18:50:14 +0000 (UTC)
commit 1fec35e3dd7bbdf5da6a520ca7e09d667240b460
Author: Christoph Reiter <reiter christoph gmail com>
Date: Sat Sep 21 21:12:59 2019 +0200
Remove uprint/uencode/udecode from builtins
Import them explicitly everywhere. Less magic.
.flake8 | 2 +-
jhbuild/commands/__init__.py | 2 +-
jhbuild/commands/base.py | 2 +-
jhbuild/commands/checkbranches.py | 1 +
jhbuild/commands/info.py | 1 +
jhbuild/commands/rdepends.py | 1 +
jhbuild/commands/sanitycheck.py | 2 +-
jhbuild/frontends/terminal.py | 1 +
jhbuild/main.py | 43 +--------------------------------------
jhbuild/utils/__init__.py | 2 +-
jhbuild/utils/misc.py | 43 ++++++++++++++++++++++++++++++++++++++-
tests/test_main.py | 19 -----------------
12 files changed, 52 insertions(+), 67 deletions(-)
---
diff --git a/.flake8 b/.flake8
index f0e47686..bde382f0 100644
--- a/.flake8
+++ b/.flake8
@@ -1,5 +1,5 @@
[flake8]
ignore=E122,E402,E126,E128,F401,E401,W504,W503,E201,E302,E305,E251,E203,E124,E231,W293,E261,E221,E211,E502,E722,W391,E301,E202,E225,E227,W291,E303,E226,E131,E123,E241,W292
max-line-length=160
-builtins=SRCDIR,_,N_,uencode,uprint,PKGDATADIR,DATADIR,udecode
+builtins=SRCDIR,_,N_,PKGDATADIR,DATADIR
exclude=jhbuild/modtypes/linux.py
\ No newline at end of file
diff --git a/jhbuild/commands/__init__.py b/jhbuild/commands/__init__.py
index a911aa7e..0fdcfc01 100644
--- a/jhbuild/commands/__init__.py
+++ b/jhbuild/commands/__init__.py
@@ -31,7 +31,7 @@ import sys
import os
from jhbuild.errors import UsageError, FatalError
-from jhbuild.utils import try_import_module
+from jhbuild.utils import try_import_module, uprint, uencode
class OptionParser(optparse.OptionParser):
diff --git a/jhbuild/commands/base.py b/jhbuild/commands/base.py
index 3f00b144..2fdf0a3c 100644
--- a/jhbuild/commands/base.py
+++ b/jhbuild/commands/base.py
@@ -30,7 +30,7 @@ import jhbuild.moduleset
import jhbuild.frontends
from jhbuild.errors import UsageError, FatalError, CommandError
from jhbuild.commands import Command, BuildCommand, register_command
-
+from jhbuild.utils import uprint
from jhbuild.config import parse_relative_time
diff --git a/jhbuild/commands/checkbranches.py b/jhbuild/commands/checkbranches.py
index 7920434e..366b071c 100644
--- a/jhbuild/commands/checkbranches.py
+++ b/jhbuild/commands/checkbranches.py
@@ -22,6 +22,7 @@ from optparse import make_option
import jhbuild.moduleset
from jhbuild.commands import Command, register_command
from jhbuild.utils.cmds import get_output
+from jhbuild.utils import uprint
from jhbuild.errors import CommandError
class cmd_checkbranches(Command):
diff --git a/jhbuild/commands/info.py b/jhbuild/commands/info.py
index f52b9227..1347e1a3 100644
--- a/jhbuild/commands/info.py
+++ b/jhbuild/commands/info.py
@@ -24,6 +24,7 @@ from optparse import make_option
import jhbuild.moduleset
import jhbuild.frontends
+from jhbuild.utils import uprint
from jhbuild.errors import FatalError
from jhbuild.commands import Command, register_command
from jhbuild.modtypes import MetaModule
diff --git a/jhbuild/commands/rdepends.py b/jhbuild/commands/rdepends.py
index 87fb3691..4faa2b4d 100644
--- a/jhbuild/commands/rdepends.py
+++ b/jhbuild/commands/rdepends.py
@@ -22,6 +22,7 @@ from optparse import make_option
import jhbuild.moduleset
from jhbuild.commands import Command, register_command
from jhbuild.errors import UsageError, FatalError, CommandError
+from jhbuild.utils import uprint
class cmd_rdepends(Command):
diff --git a/jhbuild/commands/sanitycheck.py b/jhbuild/commands/sanitycheck.py
index e8597c89..be6b95f1 100644
--- a/jhbuild/commands/sanitycheck.py
+++ b/jhbuild/commands/sanitycheck.py
@@ -23,7 +23,7 @@ import re
from jhbuild.commands import Command, register_command
from jhbuild.utils.cmds import get_output, check_version
-from jhbuild.utils import inpath
+from jhbuild.utils import inpath, uprint
from jhbuild.errors import UsageError, CommandError
def get_aclocal_path():
diff --git a/jhbuild/frontends/terminal.py b/jhbuild/frontends/terminal.py
index 2c896dbd..e2f0bf01 100644
--- a/jhbuild/frontends/terminal.py
+++ b/jhbuild/frontends/terminal.py
@@ -31,6 +31,7 @@ from jhbuild.frontends import buildscript
from jhbuild.utils import cmds
from jhbuild.utils import trayicon
from jhbuild.utils import notify
+from jhbuild.utils import uprint, uencode, udecode
from jhbuild.errors import CommandError, FatalError
from jhbuild.utils.compat import input, string_types
diff --git a/jhbuild/main.py b/jhbuild/main.py
index 418e397e..5285e6b8 100644
--- a/jhbuild/main.py
+++ b/jhbuild/main.py
@@ -23,7 +23,6 @@ import sys, os, errno
import optparse
import traceback
import logging
-import locale
import gettext
import __builtin__
@@ -33,50 +32,10 @@ import jhbuild.config
import jhbuild.commands
from jhbuild.errors import UsageError, FatalError
from jhbuild.utils.cmds import get_output
+from jhbuild.utils import uprint, _encoding
from jhbuild.moduleset import warn_local_modulesets
-from jhbuild.utils.compat import text_type
-def _get_encoding():
- try:
- encoding = locale.getpreferredencoding()
- except locale.Error:
- encoding = ""
- if not encoding:
- # work around locale.getpreferredencoding() returning an empty string in
- # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650
- if sys.platform == "darwin":
- encoding = "utf-8"
- else:
- encoding = "ascii"
- return encoding
-
-_encoding = _get_encoding()
-
-
-def uencode(s):
- if isinstance(s, text_type):
- return s.encode(_encoding, 'replace')
- else:
- return s
-
-def udecode(s):
- if not isinstance(s, text_type):
- return s.decode(_encoding, 'replace')
- else:
- return s
-
-def uprint(*args):
- '''Print Unicode string encoded for the terminal'''
- for s in args[:-1]:
- print(uencode(s), end=' ')
- s = args[-1]
- print(uencode(s))
-
-__builtin__.__dict__['uprint'] = uprint
-__builtin__.__dict__['uencode'] = uencode
-__builtin__.__dict__['udecode'] = udecode
-
class LoggingFormatter(logging.Formatter):
def __init__(self):
logging.Formatter.__init__(self, '%(level_name_initial)s: %(message)s')
diff --git a/jhbuild/utils/__init__.py b/jhbuild/utils/__init__.py
index 56596733..4cdbda43 100644
--- a/jhbuild/utils/__init__.py
+++ b/jhbuild/utils/__init__.py
@@ -17,4 +17,4 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from .misc import inpath, try_import_module
\ No newline at end of file
+from .misc import inpath, try_import_module, uencode, udecode, uprint, _encoding
\ No newline at end of file
diff --git a/jhbuild/utils/misc.py b/jhbuild/utils/misc.py
index dfca0014..fbd1b439 100644
--- a/jhbuild/utils/misc.py
+++ b/jhbuild/utils/misc.py
@@ -12,11 +12,15 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from __future__ import print_function
+
import os
import sys
import importlib
import pkgutil
+import locale
+from .compat import text_type
def inpath(filename, path):
for dir in path:
@@ -33,4 +37,41 @@ def try_import_module(module_name):
if pkgutil.get_loader(module_name) is None:
return
- return importlib.import_module(module_name)
\ No newline at end of file
+ return importlib.import_module(module_name)
+
+
+def _get_encoding():
+ try:
+ encoding = locale.getpreferredencoding()
+ except locale.Error:
+ encoding = ""
+ if not encoding:
+ # work around locale.getpreferredencoding() returning an empty string in
+ # Mac OS X, see http://bugzilla.gnome.org/show_bug.cgi?id=534650
+ if sys.platform == "darwin":
+ encoding = "utf-8"
+ else:
+ encoding = "ascii"
+ return encoding
+
+_encoding = _get_encoding()
+
+
+def uencode(s):
+ if isinstance(s, text_type):
+ return s.encode(_encoding, 'replace')
+ else:
+ return s
+
+def udecode(s):
+ if not isinstance(s, text_type):
+ return s.decode(_encoding, 'replace')
+ else:
+ return s
+
+def uprint(*args):
+ '''Print Unicode string encoded for the terminal'''
+ for s in args[:-1]:
+ print(uencode(s), end=' ')
+ s = args[-1]
+ print(uencode(s))
\ No newline at end of file
diff --git a/tests/test_main.py b/tests/test_main.py
index bcab1525..9bc9c46b 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -51,30 +51,11 @@ from jhbuild.errors import UsageError, CommandError
from jhbuild.modtypes import Package
from jhbuild.modtypes.autotools import AutogenModule
from jhbuild.modtypes.distutils import DistutilsModule
-from jhbuild.utils.compat import text_type
import jhbuild.config
import jhbuild.frontends.terminal
import jhbuild.moduleset
import jhbuild.utils.cmds
import jhbuild.versioncontrol.tarball
-from jhbuild.main import _encoding
-
-
-def uencode(s):
- if isinstance(s, text_type):
- return s.encode(_encoding, 'replace')
- else:
- return s
-
-def uprint(*args):
- '''Print Unicode string encoded for the terminal'''
- for s in args[:-1]:
- print(uencode(s), end=' ')
- s = args[-1]
- print(uencode(s))
-__builtin__.__dict__['uprint'] = uprint
-__builtin__.__dict__['uencode'] = uencode
-
import mock
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]