[diffoscope] 01/01: diffoscope.__init__: Split out all remaining helper methods

Chris Lamb chris at chris-lamb.co.uk
Wed Dec 28 16:53:21 CET 2016


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 4e71b82458cf8b28b11f9b716a5c6a2a9e188bc7
Author: Chris Lamb <lamby at debian.org>
Date:   Wed Dec 28 15:49:06 2016 +0000

    diffoscope.__init__: Split out all remaining helper methods
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/__init__.py                     | 76 ------------------------------
 diffoscope/changes.py                      |  3 +-
 diffoscope/comparators/apk.py              |  3 +-
 diffoscope/comparators/ar.py               |  3 +-
 diffoscope/comparators/bzip2.py            |  3 +-
 diffoscope/comparators/cbfs.py             |  3 +-
 diffoscope/comparators/cpio.py             |  2 +-
 diffoscope/comparators/deb.py              |  2 +-
 diffoscope/comparators/debian.py           |  2 +-
 diffoscope/comparators/dex.py              |  3 +-
 diffoscope/comparators/directory.py        |  3 +-
 diffoscope/comparators/elf.py              |  3 +-
 diffoscope/comparators/fonts.py            |  2 +-
 diffoscope/comparators/fsimage.py          |  2 +-
 diffoscope/comparators/gettext.py          |  4 +-
 diffoscope/comparators/gzip.py             |  3 +-
 diffoscope/comparators/haskell.py          |  3 +-
 diffoscope/comparators/icc.py              |  2 +-
 diffoscope/comparators/image.py            |  2 +-
 diffoscope/comparators/iso9660.py          |  2 +-
 diffoscope/comparators/java.py             |  2 +-
 diffoscope/comparators/javascript.py       |  2 +-
 diffoscope/comparators/llvm.py             |  2 +-
 diffoscope/comparators/macho.py            |  2 +-
 diffoscope/comparators/missing_file.py     |  2 +-
 diffoscope/comparators/mono.py             |  2 +-
 diffoscope/comparators/openssh.py          |  2 +-
 diffoscope/comparators/pdf.py              |  2 +-
 diffoscope/comparators/png.py              |  2 +-
 diffoscope/comparators/ppu.py              |  3 +-
 diffoscope/comparators/ps.py               |  3 +-
 diffoscope/comparators/rpm.py              |  3 +-
 diffoscope/comparators/rust.py             |  3 +-
 diffoscope/comparators/sqlite.py           |  2 +-
 diffoscope/comparators/squashfs.py         |  3 +-
 diffoscope/comparators/symlink.py          |  2 +-
 diffoscope/comparators/utils/archive.py    |  2 +-
 diffoscope/comparators/utils/command.py    |  2 +-
 diffoscope/comparators/utils/compare.py    |  3 +-
 diffoscope/comparators/utils/container.py  |  2 +-
 diffoscope/comparators/utils/file.py       |  3 +-
 diffoscope/comparators/utils/fuzzy.py      |  2 +-
 diffoscope/comparators/utils/libarchive.py |  2 +-
 diffoscope/comparators/utils/specialize.py |  2 +-
 diffoscope/comparators/xz.py               |  3 +-
 diffoscope/comparators/zip.py              |  2 +-
 diffoscope/difference.py                   |  9 ++--
 diffoscope/exc.py                          |  4 +-
 tests/conftest.py => diffoscope/locale.py  | 22 +++++++--
 tests/conftest.py => diffoscope/logging.py | 15 ++++--
 diffoscope/main.py                         | 25 +++++-----
 diffoscope/presenters/html.py              |  8 ++--
 diffoscope/presenters/text.py              |  3 +-
 diffoscope/tempfiles.py                    |  2 +-
 diffoscope/{__init__.py => tools.py}       | 55 +++++----------------
 tests/comparators/test_binary.py           |  2 +-
 tests/conftest.py                          |  5 +-
 57 files changed, 136 insertions(+), 200 deletions(-)

diff --git a/diffoscope/__init__.py b/diffoscope/__init__.py
index 5a2fe3b..514db1c 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/__init__.py
@@ -17,80 +17,4 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import os
-import shutil
-import logging
-import platform
-import functools
-import time
-
-from distutils.spawn import find_executable
-
-from diffoscope.profiling import profile
-
 VERSION = "66"
-
-logger = logging.getLogger("diffoscope")
-logger.setLevel(logging.WARNING)
-ch = logging.StreamHandler()
-ch.setLevel(logging.DEBUG)
-logger.addHandler(ch)
-formatter = logging.Formatter('%(created).3f %(levelname).1s: %(message)s')
-ch.setFormatter(formatter)
-
-OS_NAMES = {
-    'arch': 'Arch Linux',
-    'debian': 'Debian',
-    'FreeBSD': 'FreeBSD',
-}
-
-
-def get_current_os():
-    system = platform.system()
-    if system == "Linux":
-        # FIXME: Will break under Python 3.7, see:
-        # https://docs.python.org/3/library/platform.html#platform.linux_distribution
-        return platform.linux_distribution()[0]
-    return system
-
-
-# Memoize calls to ``distutils.spawn.find_executable`` to avoid excessive stat
-# calls
-find_executable = functools.lru_cache()(find_executable)
-
-def tool_required(command):
-    """
-    Decorator that checks if the specified tool is installed
-    """
-    if not hasattr(tool_required, 'all'):
-        tool_required.all = set()
-    tool_required.all.add(command)
-    def wrapper(original_function):
-        if find_executable(command):
-            @functools.wraps(original_function)
-            def tool_check(*args, **kwargs):
-                with profile('command', command):
-                    return original_function(*args, **kwargs)
-        else:
-            @functools.wraps(original_function)
-            def tool_check(*args, **kwargs):
-                from .exc import RequiredToolNotFound
-                raise RequiredToolNotFound(command)
-        return tool_check
-    return wrapper
-
-
-def set_locale():
-    """Normalize locale so external tool gives us stable and properly
-    encoded output"""
-
-    for var in ['LANGUAGE', 'LC_ALL']:
-        if var in os.environ:
-            del os.environ[var]
-    for var in ['LANG', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY',
-                'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS',
-                'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION']:
-        os.environ[var] = 'C'
-    os.environ['LC_CTYPE'] = 'C.UTF-8'
-    os.environ['TZ'] = 'UTC'
-    time.tzset()
diff --git a/diffoscope/changes.py b/diffoscope/changes.py
index 7e03b4d..3e5ee75 100644
--- a/diffoscope/changes.py
+++ b/diffoscope/changes.py
@@ -47,7 +47,8 @@ import subprocess
 
 from debian import deb822
 
-from diffoscope import logger, tool_required
+from .tools import tool_required
+from .logging import logger
 
 
 class ChangesFileException(Exception):
diff --git a/diffoscope/comparators/apk.py b/diffoscope/comparators/apk.py
index 786c3e1..9140fce 100644
--- a/diffoscope/comparators/apk.py
+++ b/diffoscope/comparators/apk.py
@@ -21,7 +21,8 @@ import re
 import os.path
 import subprocess
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.tempfiles import get_temporary_directory
 
 from .binary import File
diff --git a/diffoscope/comparators/ar.py b/diffoscope/comparators/ar.py
index aa36807..9c5f409 100644
--- a/diffoscope/comparators/ar.py
+++ b/diffoscope/comparators/ar.py
@@ -20,7 +20,8 @@
 
 import re
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/bzip2.py b/diffoscope/comparators/bzip2.py
index bcd269a..a4c99f9 100644
--- a/diffoscope/comparators/bzip2.py
+++ b/diffoscope/comparators/bzip2.py
@@ -22,7 +22,8 @@ import os.path
 import subprocess
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 
 from .utils.file import File
 from .utils.archive import Archive
diff --git a/diffoscope/comparators/cbfs.py b/diffoscope/comparators/cbfs.py
index 0fa39c5..6671d06 100644
--- a/diffoscope/comparators/cbfs.py
+++ b/diffoscope/comparators/cbfs.py
@@ -23,7 +23,8 @@ import re
 import struct
 import subprocess
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/cpio.py b/diffoscope/comparators/cpio.py
index 7dac814..cb0f458 100644
--- a/diffoscope/comparators/cpio.py
+++ b/diffoscope/comparators/cpio.py
@@ -20,7 +20,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/deb.py b/diffoscope/comparators/deb.py
index e0207b7..fcf342b 100644
--- a/diffoscope/comparators/deb.py
+++ b/diffoscope/comparators/deb.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .tar import TarContainer
diff --git a/diffoscope/comparators/debian.py b/diffoscope/comparators/debian.py
index 7dde081..f7e44c7 100644
--- a/diffoscope/comparators/debian.py
+++ b/diffoscope/comparators/debian.py
@@ -25,7 +25,7 @@ import collections
 
 from debian.deb822 import Dsc
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.changes import Changes
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/dex.py b/diffoscope/comparators/dex.py
index d8222fe..c3dc122 100644
--- a/diffoscope/comparators/dex.py
+++ b/diffoscope/comparators/dex.py
@@ -22,7 +22,8 @@ import os.path
 import subprocess
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 
 from .binary import File
 from .utils.archive import Archive
diff --git a/diffoscope/comparators/directory.py b/diffoscope/comparators/directory.py
index 3aa2012..f6843a1 100644
--- a/diffoscope/comparators/directory.py
+++ b/diffoscope/comparators/directory.py
@@ -21,8 +21,9 @@ import os
 import re
 import subprocess
 
-from diffoscope import logger, tool_required
 from diffoscope.exc import RequiredToolNotFound
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.progress import Progress
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/elf.py b/diffoscope/comparators/elf.py
index f688933..699146d 100644
--- a/diffoscope/comparators/elf.py
+++ b/diffoscope/comparators/elf.py
@@ -22,8 +22,9 @@ import os.path
 import subprocess
 import collections
 
-from diffoscope import tool_required, logger
 from diffoscope.exc import OutputParsingError
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.tempfiles import get_named_temporary_file
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/fonts.py b/diffoscope/comparators/fonts.py
index 339383b..5fa4f81 100644
--- a/diffoscope/comparators/fonts.py
+++ b/diffoscope/comparators/fonts.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/fsimage.py b/diffoscope/comparators/fsimage.py
index 91ba8f8..5db035b 100644
--- a/diffoscope/comparators/fsimage.py
+++ b/diffoscope/comparators/fsimage.py
@@ -21,7 +21,7 @@ import re
 import os.path
 import collections
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/gettext.py b/diffoscope/comparators/gettext.py
index 4885b73..7bd34fd 100644
--- a/diffoscope/comparators/gettext.py
+++ b/diffoscope/comparators/gettext.py
@@ -20,8 +20,8 @@
 import io
 import re
 
-from diffoscope import logger
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/gzip.py b/diffoscope/comparators/gzip.py
index 61a812b..dde67e7 100644
--- a/diffoscope/comparators/gzip.py
+++ b/diffoscope/comparators/gzip.py
@@ -22,7 +22,8 @@ import os.path
 import subprocess
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .utils.archive import Archive
diff --git a/diffoscope/comparators/haskell.py b/diffoscope/comparators/haskell.py
index 8d154fa..c0360c8 100644
--- a/diffoscope/comparators/haskell.py
+++ b/diffoscope/comparators/haskell.py
@@ -22,7 +22,8 @@ import struct
 import platform
 import subprocess
 
-from diffoscope import tool_required, logger
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/icc.py b/diffoscope/comparators/icc.py
index 028b241..180d809 100644
--- a/diffoscope/comparators/icc.py
+++ b/diffoscope/comparators/icc.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/image.py b/diffoscope/comparators/image.py
index e7ed8d2..293887c 100644
--- a/diffoscope/comparators/image.py
+++ b/diffoscope/comparators/image.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/iso9660.py b/diffoscope/comparators/iso9660.py
index 82f0da9..22756c0 100644
--- a/diffoscope/comparators/iso9660.py
+++ b/diffoscope/comparators/iso9660.py
@@ -20,7 +20,7 @@
 import re
 import subprocess
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/java.py b/diffoscope/comparators/java.py
index b01e6b5..af39306 100644
--- a/diffoscope/comparators/java.py
+++ b/diffoscope/comparators/java.py
@@ -21,7 +21,7 @@
 import re
 import os.path
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/javascript.py b/diffoscope/comparators/javascript.py
index 875d54a..645dc9b 100644
--- a/diffoscope/comparators/javascript.py
+++ b/diffoscope/comparators/javascript.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .utils.file import File
diff --git a/diffoscope/comparators/llvm.py b/diffoscope/comparators/llvm.py
index 759d383..bc44844 100644
--- a/diffoscope/comparators/llvm.py
+++ b/diffoscope/comparators/llvm.py
@@ -18,7 +18,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/macho.py b/diffoscope/comparators/macho.py
index e5dbe52..d3b0db3 100644
--- a/diffoscope/comparators/macho.py
+++ b/diffoscope/comparators/macho.py
@@ -21,7 +21,7 @@
 import re
 import subprocess
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/missing_file.py b/diffoscope/comparators/missing_file.py
index 89712ad..3ca40d7 100644
--- a/diffoscope/comparators/missing_file.py
+++ b/diffoscope/comparators/missing_file.py
@@ -19,8 +19,8 @@
 
 import os
 
-from diffoscope import logger
 from diffoscope.config import Config
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import FilesystemFile
diff --git a/diffoscope/comparators/mono.py b/diffoscope/comparators/mono.py
index 333eb4c..4236de0 100644
--- a/diffoscope/comparators/mono.py
+++ b/diffoscope/comparators/mono.py
@@ -20,7 +20,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/openssh.py b/diffoscope/comparators/openssh.py
index 522b0d0..8bb3df0 100644
--- a/diffoscope/comparators/openssh.py
+++ b/diffoscope/comparators/openssh.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/pdf.py b/diffoscope/comparators/pdf.py
index ceb4da4..a400e43 100644
--- a/diffoscope/comparators/pdf.py
+++ b/diffoscope/comparators/pdf.py
@@ -19,7 +19,7 @@
 
 import re
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/png.py b/diffoscope/comparators/png.py
index 33b1e8e..d51fa17 100644
--- a/diffoscope/comparators/png.py
+++ b/diffoscope/comparators/png.py
@@ -20,7 +20,7 @@
 import re
 import functools
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/ppu.py b/diffoscope/comparators/ppu.py
index 340d1ef..ab6a057 100644
--- a/diffoscope/comparators/ppu.py
+++ b/diffoscope/comparators/ppu.py
@@ -23,7 +23,8 @@ import os
 import re
 import subprocess
 
-from diffoscope import tool_required, logger
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/ps.py b/diffoscope/comparators/ps.py
index 5c64e80..43a1df6 100644
--- a/diffoscope/comparators/ps.py
+++ b/diffoscope/comparators/ps.py
@@ -19,8 +19,9 @@
 
 import re
 
-from diffoscope import tool_required, logger
 from diffoscope.exc import RequiredToolNotFound
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .text import TextFile
diff --git a/diffoscope/comparators/rpm.py b/diffoscope/comparators/rpm.py
index 746dd01..66c8549 100644
--- a/diffoscope/comparators/rpm.py
+++ b/diffoscope/comparators/rpm.py
@@ -24,7 +24,8 @@ import os.path
 import binascii
 import subprocess
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.tempfiles import get_temporary_directory
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/rust.py b/diffoscope/comparators/rust.py
index d1accf2..98c9613 100644
--- a/diffoscope/comparators/rust.py
+++ b/diffoscope/comparators/rust.py
@@ -22,7 +22,8 @@ import zlib
 import os.path
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .utils.archive import Archive
diff --git a/diffoscope/comparators/sqlite.py b/diffoscope/comparators/sqlite.py
index 42d8c2a..eb9823c 100644
--- a/diffoscope/comparators/sqlite.py
+++ b/diffoscope/comparators/sqlite.py
@@ -17,7 +17,7 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/squashfs.py b/diffoscope/comparators/squashfs.py
index d5c3d54..a5ba6f7 100644
--- a/diffoscope/comparators/squashfs.py
+++ b/diffoscope/comparators/squashfs.py
@@ -23,7 +23,8 @@ import stat
 import subprocess
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/comparators/symlink.py b/diffoscope/comparators/symlink.py
index 7528ec1..1e6d2e1 100644
--- a/diffoscope/comparators/symlink.py
+++ b/diffoscope/comparators/symlink.py
@@ -19,7 +19,7 @@
 
 import os
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.tempfiles import get_named_temporary_file
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/utils/archive.py b/diffoscope/comparators/utils/archive.py
index 25dd61f..142b1ad 100644
--- a/diffoscope/comparators/utils/archive.py
+++ b/diffoscope/comparators/utils/archive.py
@@ -19,7 +19,7 @@
 
 import abc
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.profiling import profile
 from diffoscope.tempfiles import get_temporary_directory
 
diff --git a/diffoscope/comparators/utils/command.py b/diffoscope/comparators/utils/command.py
index 89c839b..97ceeb5 100644
--- a/diffoscope/comparators/utils/command.py
+++ b/diffoscope/comparators/utils/command.py
@@ -22,7 +22,7 @@ import abc
 import subprocess
 import threading
 
-from diffoscope import logger
+from diffoscope.logging import logger
 
 
 class Command(object, metaclass=abc.ABCMeta):
diff --git a/diffoscope/comparators/utils/compare.py b/diffoscope/comparators/utils/compare.py
index f6316d9..c968c4b 100644
--- a/diffoscope/comparators/utils/compare.py
+++ b/diffoscope/comparators/utils/compare.py
@@ -22,7 +22,8 @@ import os
 import sys
 import binascii
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.exc import RequiredToolNotFound
 from diffoscope.config import Config
 from diffoscope.profiling import profile
diff --git a/diffoscope/comparators/utils/container.py b/diffoscope/comparators/utils/container.py
index d2e8d9a..93b30cd 100644
--- a/diffoscope/comparators/utils/container.py
+++ b/diffoscope/comparators/utils/container.py
@@ -21,8 +21,8 @@ import abc
 import itertools
 import collections
 
-from diffoscope import logger
 from diffoscope.config import Config
+from diffoscope.logging import logger
 from diffoscope.progress import Progress
 
 from ..missing_file import MissingFile
diff --git a/diffoscope/comparators/utils/file.py b/diffoscope/comparators/utils/file.py
index 310db8a..cceed47 100644
--- a/diffoscope/comparators/utils/file.py
+++ b/diffoscope/comparators/utils/file.py
@@ -23,8 +23,9 @@ import abc
 import magic
 import subprocess
 
-from diffoscope import tool_required, logger
 from diffoscope.exc import RequiredToolNotFound, OutputParsingError
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.profiling import profile
 from diffoscope.difference import Difference
 
diff --git a/diffoscope/comparators/utils/fuzzy.py b/diffoscope/comparators/utils/fuzzy.py
index 16e224c..648eae4 100644
--- a/diffoscope/comparators/utils/fuzzy.py
+++ b/diffoscope/comparators/utils/fuzzy.py
@@ -19,8 +19,8 @@
 
 import operator
 
-from diffoscope import logger
 from diffoscope.config import Config
+from diffoscope.logging import logger
 
 try:
     import tlsh
diff --git a/diffoscope/comparators/utils/libarchive.py b/diffoscope/comparators/utils/libarchive.py
index e9a788a..bae2f71 100644
--- a/diffoscope/comparators/utils/libarchive.py
+++ b/diffoscope/comparators/utils/libarchive.py
@@ -23,7 +23,7 @@ import os.path
 import ctypes
 import libarchive
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.tempfiles import get_temporary_directory
 
 from ..device import Device
diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index b3db931..0e7d2d9 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -19,7 +19,7 @@
 
 import importlib
 
-from diffoscope import logger
+from diffoscope.logging import logger
 from diffoscope.profiling import profile
 
 from .. import COMPARATORS
diff --git a/diffoscope/comparators/xz.py b/diffoscope/comparators/xz.py
index efb5b4b..67e2d81 100644
--- a/diffoscope/comparators/xz.py
+++ b/diffoscope/comparators/xz.py
@@ -22,7 +22,8 @@ import os.path
 import subprocess
 import collections
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 
 from .binary import File
 from .utils.archive import Archive
diff --git a/diffoscope/comparators/zip.py b/diffoscope/comparators/zip.py
index 85d5ac2..ec8b6fd 100644
--- a/diffoscope/comparators/zip.py
+++ b/diffoscope/comparators/zip.py
@@ -24,7 +24,7 @@ import os.path
 import zipfile
 import contextlib
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.difference import Difference
 
 from .binary import File
diff --git a/diffoscope/difference.py b/diffoscope/difference.py
index 2634b55..073b2f7 100644
--- a/diffoscope/difference.py
+++ b/diffoscope/difference.py
@@ -29,10 +29,11 @@ import tempfile
 
 from multiprocessing.dummy import Queue
 
-from diffoscope import logger, tool_required
-from diffoscope.exc import RequiredToolNotFound
-from diffoscope.config import Config
-from diffoscope.profiling import profile
+from .exc import RequiredToolNotFound
+from .tools import tool_required
+from .config import Config
+from .logging import logger
+from .profiling import profile
 
 
 class DiffParser(object):
diff --git a/diffoscope/exc.py b/diffoscope/exc.py
index e65ec3c..ea8d0a7 100644
--- a/diffoscope/exc.py
+++ b/diffoscope/exc.py
@@ -18,6 +18,9 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
+from .tools import get_current_os
+
+
 class OutputParsingError(Exception):
     def __init__(self, command, object):
         self.command = command
@@ -213,7 +216,6 @@ class RequiredToolNotFound(Exception):
         self.command = command
 
     def get_package(self):
-        from . import get_current_os
 
         try:
             providers = RequiredToolNotFound.PROVIDERS[self.command]
diff --git a/tests/conftest.py b/diffoscope/locale.py
similarity index 54%
copy from tests/conftest.py
copy to diffoscope/locale.py
index 2d283a0..0131ef5 100644
--- a/tests/conftest.py
+++ b/diffoscope/locale.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016 Brett Smith <debbug at brettcsmith.org>
+# Copyright © 2016 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,9 +17,21 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import pytest
-import diffoscope
+import os
+import time
 
 
-# Ensure set_locale fixture runs before all tests.
-set_locale = pytest.fixture(autouse=True, scope='session')(diffoscope.set_locale)
+def set_locale():
+    """Normalize locale so external tool gives us stable and properly
+    encoded output"""
+
+    for var in ['LANGUAGE', 'LC_ALL']:
+        if var in os.environ:
+            del os.environ[var]
+    for var in ['LANG', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY',
+                'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS',
+                'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION']:
+        os.environ[var] = 'C'
+    os.environ['LC_CTYPE'] = 'C.UTF-8'
+    os.environ['TZ'] = 'UTC'
+    time.tzset()
diff --git a/tests/conftest.py b/diffoscope/logging.py
similarity index 69%
copy from tests/conftest.py
copy to diffoscope/logging.py
index 2d283a0..3ec3c01 100644
--- a/tests/conftest.py
+++ b/diffoscope/logging.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2016 Brett Smith <debbug at brettcsmith.org>
+# Copyright © 2016 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,9 +17,14 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import pytest
-import diffoscope
+import logging
 
+logger = logging.getLogger("diffoscope")
+logger.setLevel(logging.WARNING)
 
-# Ensure set_locale fixture runs before all tests.
-set_locale = pytest.fixture(autouse=True, scope='session')(diffoscope.set_locale)
+ch = logging.StreamHandler()
+ch.setLevel(logging.DEBUG)
+logger.addHandler(ch)
+
+formatter = logging.Formatter('%(created).3f %(levelname).1s: %(message)s')
+ch.setFormatter(formatter)
diff --git a/diffoscope/main.py b/diffoscope/main.py
index 4dd40bd..a827e47 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -28,17 +28,20 @@ import argparse
 import traceback
 import contextlib
 
-from diffoscope import logger, VERSION, set_locale
-from diffoscope.exc import RequiredToolNotFound
-from diffoscope.config import Config
-from diffoscope.progress import ProgressManager, Progress
-from diffoscope.tempfiles import clean_all_temp_files
-from diffoscope.profiling import ProfileManager, profile
-from diffoscope.difference import Difference
-from diffoscope.presenters.html import output_html, output_html_directory, \
+from . import VERSION
+from .exc import RequiredToolNotFound
+from .tools import tool_required, OS_NAMES, get_current_os
+from .config import Config
+from .locale import set_locale
+from .logging import logger
+from .progress import ProgressManager, Progress
+from .tempfiles import clean_all_temp_files
+from .profiling import ProfileManager, profile
+from .difference import Difference
+from .presenters.html import output_html, output_html_directory, \
     JQUERY_SYSTEM_LOCATIONS
-from diffoscope.presenters.text import output_text
-from diffoscope.comparators.utils.compare import compare_root_paths
+from .presenters.text import output_text
+from .comparators.utils.compare import compare_root_paths
 
 try:
     import tlsh
@@ -192,8 +195,6 @@ class RangeCompleter(object):
 
 class ListToolsAction(argparse.Action):
     def __call__(self, parser, namespace, os_override, option_string=None):
-        from diffoscope import tool_required, OS_NAMES, get_current_os
-
         print("External-Tools-Required: ", end='')
         print(', '.join(sorted(tool_required.all)))
         if os_override:
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 29f6895..a3349ed 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -40,9 +40,11 @@ import codecs
 import hashlib
 import contextlib
 
-from diffoscope import logger, VERSION
-from diffoscope.config import Config
-from diffoscope.presenters.icon import FAVICON_BASE64
+from .. import VERSION
+from ..config import Config
+from ..logging import logger
+
+from .icon import FAVICON_BASE64
 
 
 # minimum line size, we add a zero-sized breakable space every
diff --git a/diffoscope/presenters/text.py b/diffoscope/presenters/text.py
index cd943d6..3a21254 100644
--- a/diffoscope/presenters/text.py
+++ b/diffoscope/presenters/text.py
@@ -21,7 +21,8 @@
 import subprocess
 import sys
 
-from diffoscope import logger, tool_required
+from diffoscope.tools import tool_required
+from diffoscope.logging import logger
 from diffoscope.difference import color_unified_diff
 
 
diff --git a/diffoscope/tempfiles.py b/diffoscope/tempfiles.py
index 6c38931..d0ddff5 100644
--- a/diffoscope/tempfiles.py
+++ b/diffoscope/tempfiles.py
@@ -20,7 +20,7 @@
 import os
 import tempfile
 
-from diffoscope import logger
+from .logging import logger
 
 _DIRS, _FILES = [], []
 
diff --git a/diffoscope/__init__.py b/diffoscope/tools.py
similarity index 68%
copy from diffoscope/__init__.py
copy to diffoscope/tools.py
index 5a2fe3b..8393284 100644
--- a/diffoscope/__init__.py
+++ b/diffoscope/tools.py
@@ -2,7 +2,7 @@
 #
 # diffoscope: in-depth comparison of files, archives, and directories
 #
-# Copyright © 2014-2015 Jérémy Bobbio <lunar at debian.org>
+# Copyright © 2016 Chris Lamb <lamby at debian.org>
 #
 # diffoscope is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -17,26 +17,16 @@
 # You should have received a copy of the GNU General Public License
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
-import os
-import shutil
-import logging
 import platform
 import functools
-import time
 
 from distutils.spawn import find_executable
 
-from diffoscope.profiling import profile
+from .profiling import profile
 
-VERSION = "66"
-
-logger = logging.getLogger("diffoscope")
-logger.setLevel(logging.WARNING)
-ch = logging.StreamHandler()
-ch.setLevel(logging.DEBUG)
-logger.addHandler(ch)
-formatter = logging.Formatter('%(created).3f %(levelname).1s: %(message)s')
-ch.setFormatter(formatter)
+# Memoize calls to ``distutils.spawn.find_executable`` to avoid excessive stat
+# calls
+find_executable = functools.lru_cache()(find_executable)
 
 OS_NAMES = {
     'arch': 'Arch Linux',
@@ -45,19 +35,6 @@ OS_NAMES = {
 }
 
 
-def get_current_os():
-    system = platform.system()
-    if system == "Linux":
-        # FIXME: Will break under Python 3.7, see:
-        # https://docs.python.org/3/library/platform.html#platform.linux_distribution
-        return platform.linux_distribution()[0]
-    return system
-
-
-# Memoize calls to ``distutils.spawn.find_executable`` to avoid excessive stat
-# calls
-find_executable = functools.lru_cache()(find_executable)
-
 def tool_required(command):
     """
     Decorator that checks if the specified tool is installed
@@ -79,18 +56,10 @@ def tool_required(command):
         return tool_check
     return wrapper
 
-
-def set_locale():
-    """Normalize locale so external tool gives us stable and properly
-    encoded output"""
-
-    for var in ['LANGUAGE', 'LC_ALL']:
-        if var in os.environ:
-            del os.environ[var]
-    for var in ['LANG', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY',
-                'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS',
-                'LC_TELEPHONE', 'LC_MEASUREMENT', 'LC_IDENTIFICATION']:
-        os.environ[var] = 'C'
-    os.environ['LC_CTYPE'] = 'C.UTF-8'
-    os.environ['TZ'] = 'UTC'
-    time.tzset()
+def get_current_os():
+    system = platform.system()
+    if system == "Linux":
+        # FIXME: Will break under Python 3.7, see:
+        # https://docs.python.org/3/library/platform.html#platform.linux_distribution
+        return platform.linux_distribution()[0]
+    return system
diff --git a/tests/comparators/test_binary.py b/tests/comparators/test_binary.py
index f009dbb..dbd09d2 100644
--- a/tests/comparators/test_binary.py
+++ b/tests/comparators/test_binary.py
@@ -20,7 +20,7 @@
 import pytest
 import subprocess
 
-from diffoscope import tool_required
+from diffoscope.tools import tool_required
 from diffoscope.exc import RequiredToolNotFound
 from diffoscope.difference import Difference
 from diffoscope.comparators.binary import FilesystemFile
diff --git a/tests/conftest.py b/tests/conftest.py
index 2d283a0..36a2f52 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -18,8 +18,9 @@
 # along with diffoscope.  If not, see <https://www.gnu.org/licenses/>.
 
 import pytest
-import diffoscope
+
+from diffoscope.locale import set_locale
 
 
 # Ensure set_locale fixture runs before all tests.
-set_locale = pytest.fixture(autouse=True, scope='session')(diffoscope.set_locale)
+set_locale = pytest.fixture(autouse=True, scope='session')(set_locale)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list