[Reproducible-commits] [diffoscope] 03/05: Make python-debian optional
Jérémy Bobbio
lunar at moszumanska.debian.org
Fri Nov 13 11:26:06 UTC 2015
This is an automated email from the git hooks/post-receive script.
lunar pushed a commit to branch master
in repository diffoscope.
commit 5469acae2c66e7509904a1c32ec377a230915dda
Author: Jérémy Bobbio <lunar at debian.org>
Date: Fri Nov 13 11:59:26 2015 +0100
Make python-debian optional
This will help packaging diffoscope in other distributions.
---
README.rst | 3 +-
debian/rules | 2 +-
diffoscope/comparators/__init__.py | 7 ++++-
diffoscope/comparators/debian_fallback.py | 49 +++++++++++++++++++++++++++++++
setup.py | 2 --
tests/comparators/test_debian.py | 14 ++++++++-
6 files changed, 71 insertions(+), 6 deletions(-)
diff --git a/README.rst b/README.rst
index 86e75e5..4e10920 100644
--- a/README.rst
+++ b/README.rst
@@ -41,7 +41,6 @@ External dependencies
diffoscope requires Python 3 and the following modules available on PyPI:
`libarchive-c <https://pypi.python.org/pypi/libarchive-c>`_,
-`python-debian <https://pypi.python.org/pypi/python-debian>`_,
`python-magic <https://pypi.python.org/pypi/python-debian>`_.
Optionally, the following modules will enhance it:
@@ -50,6 +49,8 @@ Optionally, the following modules will enhance it:
It is build from `tlsh source
<https://github.com/trendmicro/tlsh>`_.
Available on Debian as ``python3-tlsh``.
+* ``python-debian`` is used to inspect Debian control files.
+ It is available on `PyPI <https://pypi.python.org/pypi/python-debian>`_.
* ``rpm-python`` is used to inspect RPM files.
It is built from `rpm
<http://rpm.org/>`_.
diff --git a/debian/rules b/debian/rules
index 34d40ae..9f507c3 100755
--- a/debian/rules
+++ b/debian/rules
@@ -13,7 +13,7 @@ override_dh_auto_build:
dh_auto_build -O--buildsystem=pybuild
override_dh_python3:
- dh_python3 --recommends=rpm-python --recommends=tlsh
+ dh_python3 --recommends=python-debian --recommends=rpm-python --recommends=tlsh
override_dh_gencontrol:
TOOLS="$$(bin/diffoscope --list-tools | tail -n 1 | \
diff --git a/diffoscope/comparators/__init__.py b/diffoscope/comparators/__init__.py
index 4d63f8c..4c111b9 100644
--- a/diffoscope/comparators/__init__.py
+++ b/diffoscope/comparators/__init__.py
@@ -37,7 +37,12 @@ from diffoscope.comparators.java import ClassFile
from diffoscope.comparators.cbfs import CbfsFile
from diffoscope.comparators.cpio import CpioFile
from diffoscope.comparators.deb import DebFile, Md5sumsFile, DebDataTarFile
-from diffoscope.comparators.debian import DotChangesFile, DotDscFile
+try:
+ from diffoscope.comparators.debian import DotChangesFile, DotDscFile
+except ImportError as ex:
+ if hasattr(ex, 'msg') and not ex.msg.startswith("No module named 'debian"):
+ raise
+ from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile
from diffoscope.comparators.device import Device
from diffoscope.comparators.directory import Directory, compare_directories
from diffoscope.comparators.elf import ElfFile, StaticLibFile
diff --git a/diffoscope/comparators/debian_fallback.py b/diffoscope/comparators/debian_fallback.py
new file mode 100644
index 0000000..0f44e6f
--- /dev/null
+++ b/diffoscope/comparators/debian_fallback.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+#
+# diffoscope: in-depth comparison of files, archives, and directories
+#
+# Copyright © 2015 Jérémy Bobbio <lunar 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
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# diffoscope 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 diffoscope. If not, see <http://www.gnu.org/licenses/>.
+
+import re
+from diffoscope.comparators.text import TextFile
+
+class DotChangesFile(TextFile):
+ RE_FILE_EXTENSION = re.compile(r'\.changes$')
+
+ @staticmethod
+ def recognizes(file):
+ return DotChangesFile.RE_FILE_EXTENSION.search(file.name)
+
+ def compare(self, other, source=None):
+ difference = super().compare(other)
+ if not difference:
+ return None
+ difference.add_comment('Unable to find Python debian module. Falling back to text comparison.')
+ return difference
+
+class DotDscFile(TextFile):
+ RE_FILE_EXTENSION = re.compile(r'\.dsc$')
+
+ @staticmethod
+ def recognizes(file):
+ return DotDscFile.RE_FILE_EXTENSION.search(file.name)
+
+ def compare(self, other, source=None):
+ difference = super().compare(other)
+ if not difference:
+ return None
+ difference.add_comment('Unable to find Python debian module. Falling back to text comparison.')
+ return difference
diff --git a/setup.py b/setup.py
index c59c35d..41d318c 100644
--- a/setup.py
+++ b/setup.py
@@ -38,8 +38,6 @@ setup(name='diffoscope',
],
},
install_requires=[
- 'python-debian',
- 'chardet', # hidden dependency of python-debian
'python-magic',
'libarchive-c',
],
diff --git a/tests/comparators/test_debian.py b/tests/comparators/test_debian.py
index c248879..f839930 100644
--- a/tests/comparators/test_debian.py
+++ b/tests/comparators/test_debian.py
@@ -22,7 +22,12 @@ import shutil
import pytest
from diffoscope.comparators import specialize
from diffoscope.comparators.binary import FilesystemFile, NonExistingFile
-from diffoscope.comparators.debian import DotChangesFile, DotDscFile
+try:
+ from diffoscope.comparators.debian import DotChangesFile, DotDscFile
+ miss_debian_module = False
+except ImportError:
+ from diffoscope.comparators.debian_fallback import DotChangesFile, DotDscFile
+ miss_debian_module = True
from diffoscope.config import Config
from diffoscope.presenters.text import output_text
@@ -50,6 +55,7 @@ def dot_changes2(tmpdir):
def test_dot_changes_identification(dot_changes1):
assert isinstance(dot_changes1, DotChangesFile)
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_invalid(tmpdir):
tmpdir.mkdir('a')
dot_changes_path = str(tmpdir.join('a/test_1.changes'))
@@ -68,14 +74,17 @@ def dot_changes_differences(dot_changes1, dot_changes2):
output_text(difference, print_func=print)
return difference.details
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_description(dot_changes_differences):
assert dot_changes_differences[0]
expected_diff = open(os.path.join(os.path.dirname(__file__), '../data/dot_changes_description_expected_diff')).read()
assert dot_changes_differences[0].unified_diff == expected_diff
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_internal_diff(dot_changes_differences):
assert dot_changes_differences[2].source1 == 'test_1_all.deb'
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_changes_compare_non_existing(monkeypatch, dot_changes1):
monkeypatch.setattr(Config.general, 'new_file', True)
difference = dot_changes1.compare(NonExistingFile('/nonexisting', dot_changes1))
@@ -107,6 +116,7 @@ def dot_dsc2(tmpdir):
def test_dot_dsc_identification(dot_dsc1):
assert isinstance(dot_dsc1, DotDscFile)
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_dsc_invalid(tmpdir, dot_dsc2):
tmpdir.mkdir('a')
dot_dsc_path = str(tmpdir.join('a/test_1.dsc'))
@@ -125,9 +135,11 @@ def dot_dsc_differences(dot_dsc1, dot_dsc2):
output_text(difference, print_func=print)
return difference.details
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_dsc_internal_diff(dot_dsc_differences):
assert dot_dsc_differences[1].source1 == 'test_1.tar.gz'
+ at pytest.mark.skipif(miss_debian_module, reason='debian module is not installed')
def test_dot_dsc_compare_non_existing(monkeypatch, dot_dsc1):
monkeypatch.setattr(Config.general, 'new_file', True)
difference = dot_dsc1.compare(NonExistingFile('/nonexisting', dot_dsc1))
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list