[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#733489: python-apt: Improve 'Dependency' and 'BaseDependency' to get target package versions that satisfy dependencies



On Thu, Jan 02, 2014 at 01:49:39PM +0100, Michael Schaller wrote:
> On 01/01/2014 05:44 PM, Michael Vogt wrote:
> >On Wed, Jan 01, 2014 at 12:30:16PM +0100, Michael Schaller wrote:
> >>A few comments on the patches:
> >
> >Thanks for your review and the points you raised.
> >
> You're welcome. I really like the idea to use Travis CI.

Cool, attached is a new patchset that should address your points and
Julians as well.
 
> Thanks. Could you include the detailed messages for the error codes?
> (taken from --show-pep8)
[..]

I added them.
 
> IMHO those should be fixed too because they increase the readability
> of the source code. You can try to fix those with autopep8.

Thanks! I will give autopep8 a try later.
 
[..]
> Thanks for the good explanation. ^^
> BTW: Don't you need a '-q' for 'sudo apt-get install build-essential
> $(gdebi -q --apt-line ./debian/control)', too?

Good catch, thanks! Updated that too.

The patchset includes your pep8/pyflakes patch as well to avoid
conflicts. Lets see if Julian has further feedback and if he is also
ok with the changes I will commit to the python-apt git upstream
branch. 

Cheers,
 Michael
>From e1baaccebb1adfe67ed031b3d293f4d036bf60cb Mon Sep 17 00:00:00 2001
From: Michael Vogt <mvo@debian.org>
Date: Tue, 31 Dec 2013 10:06:22 +0100
Subject: [PATCH 1/7] make pep8 test part of the unittests

---
 tests/test_pep8.py | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
 create mode 100755 tests/test_pep8.py

diff --git a/tests/test_pep8.py b/tests/test_pep8.py
new file mode 100755
index 0000000..e6a672c
--- /dev/null
+++ b/tests/test_pep8.py
@@ -0,0 +1,27 @@
+import os
+import subprocess
+import unittest
+
+
+class PackagePep8TestCase(unittest.TestCase):
+
+    def test_all_code(self):
+        res = 0
+        py_dir = os.path.join(os.path.dirname(__file__), "..")
+        res += subprocess.call(
+            ["pep8",
+             # disable for now:
+             # E125 continuation line does not distinguish itself from
+             #      next logical line
+             # E126 continuation line over-indented for hanging indent
+             # E127 continuation line over-indented for visual indent
+             # E128 continuation line under-indented for visual indent
+             "--ignore=E125,E126,E127,E128",
+             "--exclude", "build,tests/old",
+             "--repeat", py_dir])
+        if res != 0:
+            self.fail("pep8 failed with: %s" % res)
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.3.2

>From 9704f1c0bcf85468bc2e982c3971799a3a8b6a31 Mon Sep 17 00:00:00 2001
From: Michael Vogt <mvo@debian.org>
Date: Tue, 31 Dec 2013 21:36:26 +0100
Subject: [PATCH 2/7] add pyflakes test

---
 tests/test_pyflakes.py | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100644 tests/test_pyflakes.py

diff --git a/tests/test_pyflakes.py b/tests/test_pyflakes.py
new file mode 100644
index 0000000..9c17a40
--- /dev/null
+++ b/tests/test_pyflakes.py
@@ -0,0 +1,41 @@
+#!/usr/bin/python3
+# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
+
+import os
+import subprocess
+import unittest
+
+
+class TestPyflakesClean(unittest.TestCase):
+
+    EXCLUDES = ["build", "tests/old"]
+    TOPLEVEL = os.path.normpath(
+        os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
+
+    def is_excluded_path(self, path):
+        for exclude in self.EXCLUDES:
+            if path.startswith(os.path.join(self.TOPLEVEL, exclude)):
+                return True
+        return False
+
+    def get_py_files(self, toplevel):
+        files = []
+        for path, dirnames, filenames in os.walk(self.TOPLEVEL):
+            if self.is_excluded_path(path):
+                continue
+            for filename in filenames:
+                if os.path.splitext(filename)[1] == ".py":
+                    files.append(os.path.join(path, filename))
+        return files
+
+    def test_pyflakes_clean(self):
+        cmd = ["pyflakes"] + self.get_py_files(self.TOPLEVEL)
+        res = subprocess.call(cmd)
+        if res != 0:
+            self.fail("pyflakes failed with: %s" % res)
+
+
+if __name__ == "__main__":
+    import logging
+    logging.basicConfig(level=logging.DEBUG)
+    unittest.main()
-- 
1.8.3.2

>From 945c2b61fe4cb45d3cab62531e09dcfd4058c905 Mon Sep 17 00:00:00 2001
From: Michael Vogt <mvo@debian.org>
Date: Tue, 31 Dec 2013 22:34:54 +0100
Subject: [PATCH 3/7] add new pep8,pyflakes dependencies

---
 debian/control       | 4 +++-
 debian/tests/control | 2 +-
 po/python-apt.pot    | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/debian/control b/debian/control
index 8c2f2ce..f4f5211 100644
--- a/debian/control
+++ b/debian/control
@@ -18,7 +18,9 @@ Build-Depends: apt (>= 0.9.6),
                python-distutils-extra (>= 2.0),
                python-sphinx (>= 0.5),
                python-debian,
-	       python-unittest2
+	       python-unittest2,
+               pep8,
+               pyflakes
 Vcs-Git: git://anonscm.debian.org/apt/python-apt.git
 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=apt/python-apt.git
 XS-Testsuite: autopkgtest
diff --git a/debian/tests/control b/debian/tests/control
index 2ca0a40..bdca7d6 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -1,2 +1,2 @@
 Tests: run-tests
-Depends: @, apt-utils, python-debian, fakeroot, intltool
+Depends: @, apt-utils, python-debian, fakeroot, intltool, pep8, pyflakes
diff --git a/po/python-apt.pot b/po/python-apt.pot
index 15f78b4..2d4f825 100644
--- a/po/python-apt.pot
+++ b/po/python-apt.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-10-23 20:26+0200\n"
+"POT-Creation-Date: 2013-12-31 22:31+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -661,6 +661,6 @@ msgstr ""
 msgid "Please insert a Disc in the drive and press enter"
 msgstr ""
 
-#: ../apt/cache.py:160
+#: ../apt/cache.py:164
 msgid "Building data structures"
 msgstr ""
-- 
1.8.3.2

>From c6704b7283060fd904e17069dcc1d29977f2390a Mon Sep 17 00:00:00 2001
From: Michael Vogt <mvo@debian.org>
Date: Tue, 31 Dec 2013 21:55:40 +0100
Subject: [PATCH 4/7] add .travis.yml & update python3 dependency to 3.3

This patch adds support for the travis-ci.org CI system.

The "C" environment in .travis.yml is used to avoid having PPA
python versions installed in the travis chroot.

python3.3 is needed so that test_paths.py runs

The tests_paths.py will only work with python3.3 as it uses
the u"" prefix
---
 .travis.yml       | 19 +++++++++++++++++++
 debian/control    |  6 +++---
 po/python-apt.pot | 57 ++++++++++++++++++++++++++-----------------------------
 3 files changed, 49 insertions(+), 33 deletions(-)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..832b69e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,19 @@
+# This provides integration into the travis-ci.org CI system. For a overview
+# check http://about.travis-ci.org/docs/user/getting-started/
+# 
+# Some notes:
+# - language is "C" because the travis chroot for python installs a non-repo
+#   python3.3 from a PPA
+# - we need to add the current stable ubuntu (or even the current development
+#   ubuntu because we need a recent version of apt to build the python-apt
+# - we use ubuntu instead of debian because the travis chroot is ubuntu based
+# - ./debian/rules build-arch will build the package and run the tests
+language: c
+before_install:
+ - sudo apt-get update -q
+ - sudo apt-get install distro-info
+ - echo "deb http://archive.ubuntu.com/ubuntu $(distro-info --stable) main"|sudo tee -a /etc/apt/sources.list.d/added.list
+ - sudo apt-get update -q
+ - sudo apt-get install -q --no-install-recommends gdebi-core
+ - sudo apt-get install -q build-essential $(gdebi -q --apt-line ./debian/control)
+script: ./debian/rules build-arch
diff --git a/debian/control b/debian/control
index f4f5211..8fdb394 100644
--- a/debian/control
+++ b/debian/control
@@ -5,7 +5,7 @@ Maintainer: APT Development Team <deity@lists.debian.org>
 Uploaders: Michael Vogt <mvo@debian.org>, Julian Andres Klode <jak@debian.org>
 Standards-Version: 3.9.4
 XS-Python-Version: >= 2.6
-X-Python3-Version: >= 3.1
+X-Python3-Version: >= 3.3
 Build-Depends: apt (>= 0.9.6),
                apt-utils,
                debhelper (>= 9),
@@ -13,8 +13,8 @@ Build-Depends: apt (>= 0.9.6),
                libapt-pkg-dev (>= 0.8.11),
                python-all-dev (>= 2.6.6-3~),
                python-all-dbg,
-               python3-all-dev (>= 3.1.2-10~),
-               python3-all-dbg (>= 3.1.2-6~),
+               python3-all-dev (>= 3.3),
+               python3-all-dbg (>= 3.3),
                python-distutils-extra (>= 2.0),
                python-sphinx (>= 0.5),
                python-debian,
diff --git a/po/python-apt.pot b/po/python-apt.pot
index 2d4f825..8d8b126 100644
--- a/po/python-apt.pot
+++ b/po/python-apt.pot
@@ -8,7 +8,7 @@ msgid ""
 msgstr ""
 "Project-Id-Version: PACKAGE VERSION\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-12-31 22:31+0100\n"
+"POT-Creation-Date: 2014-01-01 09:20+0100\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
 "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
 "Language-Team: LANGUAGE <LL@li.org>\n"
@@ -465,7 +465,7 @@ msgid "Non-DFSG-compatible Software"
 msgstr ""
 
 #. TRANSLATORS: %s is a country
-#: ../aptsources/distro.py:211 ../aptsources/distro.py:441
+#: ../aptsources/distro.py:211 ../aptsources/distro.py:442
 #, python-format
 msgid "Server for %s"
 msgstr ""
@@ -505,16 +505,16 @@ msgstr ""
 msgid "Complete"
 msgstr ""
 
-#: ../apt/package.py:337
+#: ../apt/package.py:328
 #, python-format
 msgid "Invalid unicode in description for '%s' (%s). Please report."
 msgstr ""
 
-#: ../apt/package.py:910 ../apt/package.py:1016
+#: ../apt/package.py:901 ../apt/package.py:1007
 msgid "The list of changes is not available"
 msgstr ""
 
-#: ../apt/package.py:1022
+#: ../apt/package.py:1013
 #, python-format
 msgid ""
 "The list of changes is not available yet.\n"
@@ -523,94 +523,91 @@ msgid ""
 "until the changes become available or try again later."
 msgstr ""
 
-#: ../apt/package.py:1029
+#: ../apt/package.py:1020
 msgid ""
 "Failed to download the list of changes. \n"
 "Please check your Internet connection."
 msgstr ""
 
-#: ../apt/debfile.py:85
+#: ../apt/debfile.py:87
 #, python-format
 msgid "List of files for '%s' could not be read"
 msgstr ""
 
-#: ../apt/debfile.py:96
+#: ../apt/debfile.py:99
 #, python-format
 msgid "List of control files for '%s' could not be read"
 msgstr ""
 
-#: ../apt/debfile.py:217
+#: ../apt/debfile.py:224
 #, python-format
 msgid "Dependency is not satisfiable: %s\n"
 msgstr ""
 
-#: ../apt/debfile.py:238
+#: ../apt/debfile.py:247
 #, python-format
 msgid "Conflicts with the installed package '%s'"
 msgstr ""
 
-#. TRANSLATORS: the first '%s' is the package that breaks, the second the dependency that makes it break, the third the relation (e.g. >=) and the latest the version for the releation
-#: ../apt/debfile.py:379
+#: ../apt/debfile.py:394
 #, python-format
 msgid ""
 "Breaks existing package '%(pkgname)s' dependency %(depname)s "
 "(%(deprelation)s %(depversion)s)"
 msgstr ""
 
-#. TRANSLATORS: the first '%s' is the package that conflicts, the second the packagename that it conflicts with (so the name of the deb the user tries to install), the third is the relation (e.g. >=) and the last is the version for the relation
-#: ../apt/debfile.py:395
+#: ../apt/debfile.py:421
 #, python-format
 msgid ""
 "Breaks existing package '%(pkgname)s' conflict: %(targetpkg)s (%(comptype)s "
 "%(targetver)s)"
 msgstr ""
 
-#: ../apt/debfile.py:405
+#: ../apt/debfile.py:435
 #, python-format
 msgid ""
 "Breaks existing package '%(pkgname)s' that conflict: '%(targetpkg)s'. But "
 "the '%(debfile)s' provides it via: '%(provides)s'"
 msgstr ""
 
-#: ../apt/debfile.py:453
+#: ../apt/debfile.py:486
 msgid "No Architecture field in the package"
 msgstr ""
 
-#: ../apt/debfile.py:463
+#: ../apt/debfile.py:496
 #, python-format
 msgid "Wrong architecture '%s'"
 msgstr ""
 
-#. the deb is older than the installed
-#: ../apt/debfile.py:470
+#: ../apt/debfile.py:504
 msgid "A later version is already installed"
 msgstr ""
 
-#: ../apt/debfile.py:495
+#: ../apt/debfile.py:529
 msgid "Failed to satisfy all dependencies (broken cache)"
 msgstr ""
 
-#: ../apt/debfile.py:525
+#: ../apt/debfile.py:558
 #, python-format
 msgid "Cannot install '%s'"
 msgstr ""
 
-#: ../apt/debfile.py:599
+#: ../apt/debfile.py:634
 msgid ""
 "Automatically decompressed:\n"
 "\n"
 msgstr ""
 
-#: ../apt/debfile.py:605
+#: ../apt/debfile.py:640
 msgid "Automatically converted to printable ascii:\n"
 msgstr ""
 
-#: ../apt/debfile.py:695
+#: ../apt/debfile.py:731
 #, python-format
 msgid "Install Build-Dependencies for source package '%s' that builds %s\n"
 msgstr ""
 
-#: ../apt/debfile.py:706
+#: ../apt/debfile.py:742
 msgid "An essential package would be removed"
 msgstr ""
 
@@ -635,11 +632,11 @@ msgstr ""
 msgid "Get:"
 msgstr ""
 
-#: ../apt/progress/text.py:203
+#: ../apt/progress/text.py:204
 msgid " [Working]"
 msgstr ""
 
-#: ../apt/progress/text.py:214
+#: ../apt/progress/text.py:215
 #, python-format
 msgid ""
 "Media change: please insert the disc labeled\n"
@@ -648,16 +645,16 @@ msgid ""
 msgstr ""
 
 #. Trick for getting a translation from apt
-#: ../apt/progress/text.py:223
+#: ../apt/progress/text.py:224
 #, python-format
 msgid "Fetched %sB in %s (%sB/s)\n"
 msgstr ""
 
-#: ../apt/progress/text.py:239
+#: ../apt/progress/text.py:240
 msgid "Please provide a name for this Disc, such as 'Debian 2.1r1 Disk 1'"
 msgstr ""
 
-#: ../apt/progress/text.py:255
+#: ../apt/progress/text.py:256
 msgid "Please insert a Disc in the drive and press enter"
 msgstr ""
 
-- 
1.8.3.2

>From 0cc7dd984510ea60b9c14f04922a169c3be54d76 Mon Sep 17 00:00:00 2001
From: Michael Schaller <michael@5challer.de>
Date: Tue, 31 Dec 2013 13:55:09 +0100
Subject: [PATCH 5/7] apt/cache.py, apt/package.py: Fixed PEP8 and pyflakes
 issues

---
 apt/cache.py     | 53 +++++++++++++++++++++++++----------------------------
 apt/package.py   | 40 +++++++++++++++++++---------------------
 debian/changelog |  3 +++
 3 files changed, 47 insertions(+), 49 deletions(-)

diff --git a/apt/cache.py b/apt/cache.py
index 43fb55d..6b1e2bd 100644
--- a/apt/cache.py
+++ b/apt/cache.py
@@ -40,6 +40,7 @@ class FetchFailedException(IOError):
 class LockFailedException(IOError):
     """Exception that is thrown when locking fails."""
 
+
 class CacheClosedException(Exception):
     """Exception that is thrown when the cache is used after close()."""
 
@@ -53,7 +54,7 @@ class Cache(object):
     list of available packages.
 
     The cache can be used like a mapping from package names to Package
-    objects (although only getting items is supported). 
+    objects (although only getting items is supported).
 
     Keyword arguments:
     progress -- a OpProgress object
@@ -74,7 +75,7 @@ class Cache(object):
         self._fullnameset = set()
         self._changes_count = -1
         self._sorted_set = None
-        
+
         self.connect("cache_post_open", self._inc_changes_count)
         self.connect("cache_post_change", self._inc_changes_count)
         if memonly:
@@ -86,17 +87,17 @@ class Cache(object):
             apt_pkg.config.clear("APT")
             apt_pkg.config.set("Dir", rootdir)
             apt_pkg.init_config()
-            if os.path.exists(rootdir+"/etc/apt/apt.conf"):
+            if os.path.exists(rootdir + "/etc/apt/apt.conf"):
                 apt_pkg.read_config_file(apt_pkg.config,
-                                       rootdir + "/etc/apt/apt.conf")
-            if os.path.isdir(rootdir+"/etc/apt/apt.conf.d"):
+                                         rootdir + "/etc/apt/apt.conf")
+            if os.path.isdir(rootdir + "/etc/apt/apt.conf.d"):
                 apt_pkg.read_config_dir(apt_pkg.config,
-                                      rootdir + "/etc/apt/apt.conf.d")
+                                        rootdir + "/etc/apt/apt.conf.d")
             apt_pkg.config.set("Dir::State::status",
                                rootdir + "/var/lib/dpkg/status")
             # also set dpkg to the rootdir path so that its called for the
             # --print-foreign-architectures call
-            apt_pkg.config.set("Dir::bin::dpkg", 
+            apt_pkg.config.set("Dir::bin::dpkg",
                                os.path.join(rootdir, "usr", "bin", "dpkg"))
             # create required dirs/files when run with special rootdir
             # automatically
@@ -105,7 +106,6 @@ class Cache(object):
             # recognized (LP: #320665)
             apt_pkg.init_system()
         self.open(progress)
-        
 
     def _inc_changes_count(self):
         """Increase the number of changes"""
@@ -118,12 +118,12 @@ class Cache(object):
         """
         files = ["/var/lib/dpkg/status",
                  "/etc/apt/sources.list",
-                ]
+                 ]
         dirs = ["/var/lib/dpkg",
                 "/etc/apt/",
                 "/var/cache/apt/archives/partial",
                 "/var/lib/apt/lists/partial",
-               ]
+                ]
         for d in dirs:
             if not os.path.exists(rootdir + d):
                 #print "creating: ", rootdir + d
@@ -165,8 +165,8 @@ class Cache(object):
         i = last = 0
         size = len(self._cache.packages)
         for pkg in self._cache.packages:
-            if progress is not None and last+100 < i:
-                progress.update(i/float(size)*100)
+            if progress is not None and last + 100 < i:
+                progress.update(i / float(size) * 100)
                 last = i
             # drop stuff with no versions (cruft)
             if pkg.has_versions:
@@ -259,7 +259,8 @@ class Cache(object):
     def required_download(self):
         """Get the size of the packages that are required to download."""
         if self._records is None:
-            raise CacheClosedException("Cache object used after close() called")
+            raise CacheClosedException(
+                "Cache object used after close() called")
         pm = apt_pkg.PackageManager(self._depcache)
         fetcher = apt_pkg.Acquire()
         pm.get_archives(fetcher, self._list, self._records)
@@ -289,16 +290,14 @@ class Cache(object):
 
         # now check the result (this is the code from apt-get.cc)
         failed = False
-        transient = False
         err_msg = ""
         for item in fetcher.items:
             if item.status == item.STAT_DONE:
                 continue
             if item.STAT_IDLE:
-                transient = True
                 continue
             err_msg += "Failed to fetch %s %s\n" % (item.desc_uri,
-                                                   item.error_text)
+                                                    item.error_text)
             failed = True
 
         # we raise a exception if the download failed or it was cancelt
@@ -311,7 +310,8 @@ class Cache(object):
     def _fetch_archives(self, fetcher, pm):
         """ fetch the needed archives """
         if self._records is None:
-            raise CacheClosedException("Cache object used after close() called")
+            raise CacheClosedException(
+                "Cache object used after close() called")
 
         # get lock
         lockfile = apt_pkg.config.find_dir("Dir::Cache::Archives") + "lock"
@@ -349,7 +349,6 @@ class Cache(object):
         if fetcher is None:
             fetcher = apt_pkg.Acquire(progress)
 
-        
         return self._fetch_archives(fetcher,
                                     apt_pkg.PackageManager(self._depcache))
 
@@ -362,12 +361,12 @@ class Cache(object):
         else:
             return bool(pkg.has_provides and not pkg.has_versions)
 
-    def get_providing_packages(self, pkgname, candidate_only=True, 
+    def get_providing_packages(self, pkgname, candidate_only=True,
                                include_nonvirtual=False):
         """Return a list of all packages providing a package.
-        
+
         Return a list of packages which provide the virtual package of the
-        specified name. 
+        specified name.
 
         If 'candidate_only' is False, return all packages with at
         least one version providing the virtual package. Otherwise,
@@ -378,7 +377,7 @@ class Cache(object):
         packages providing pkgname, even if pkgname is not itself
         a virtual pkg.
         """
-        
+
         providers = set()
         get_candidate_ver = self._depcache.get_candidate_ver
         try:
@@ -423,7 +422,8 @@ class Cache(object):
             old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
             old_sources_list_d = apt_pkg.config.find("Dir::Etc::sourceparts")
             old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
-            apt_pkg.config.set("Dir::Etc::sourcelist", os.path.abspath(sources_list))
+            apt_pkg.config.set("Dir::Etc::sourcelist",
+                               os.path.abspath(sources_list))
             apt_pkg.config.set("Dir::Etc::sourceparts", "xxx")
             apt_pkg.config.set("APT::List-Cleanup", "0")
             slist = apt_pkg.SourceList()
@@ -559,9 +559,9 @@ class Cache(object):
     @property
     def dpkg_journal_dirty(self):
         """Return True if the dpkg was interrupted
-        
+
         All dpkg operations will fail until this is fixed, the action to
-        fix the system if dpkg got interrupted is to run 
+        fix the system if dpkg got interrupted is to run
         'dpkg --configure -a' as root.
         """
         dpkg_status_dir = os.path.dirname(
@@ -711,7 +711,6 @@ class FilteredCache(object):
         #print "filterCachePostChange()"
         self._reapply_filter()
 
-
 #    def connect(self, name, callback):
 #        self.cache.connect(name, callback)
 
@@ -750,8 +749,6 @@ def _test():
     for pkg in changes:
         assert pkg.name
 
-
-
     # see if fetching works
     for dirname in ["/tmp/pytest", "/tmp/pytest/partial"]:
         if not os.path.exists(dirname):
diff --git a/apt/package.py b/apt/package.py
index 04d4ddd..79dac71 100644
--- a/apt/package.py
+++ b/apt/package.py
@@ -26,7 +26,6 @@ import re
 import socket
 import subprocess
 import urllib2
-import warnings
 try:
     from collections import Mapping, Sequence
 except ImportError:
@@ -335,7 +334,7 @@ class Version(object):
                 dsc = unicode(dsc, "utf-8")
         except UnicodeDecodeError as err:
             return _("Invalid unicode in description for '%s' (%s). "
-                  "Please report.") % (self.package.name, err)
+                     "Please report.") % (self.package.name, err)
 
         lines = iter(dsc.split("\n"))
         # Skip the first line, since its a duplication of the summary
@@ -416,8 +415,8 @@ class Version(object):
                     base_deps = []
                     for dep_or in dep_ver_list:
                         base_deps.append(BaseDependency(dep_or.target_pkg.name,
-                                        dep_or.comp_type, dep_or.target_ver,
-                                        (type_ == "PreDepends"),
+                                         dep_or.comp_type, dep_or.target_ver,
+                                         (type_ == "PreDepends"),
                                          rawtype=type_))
                     depends_list.append(Dependency(base_deps))
             except KeyError:
@@ -428,7 +427,7 @@ class Version(object):
     def provides(self):
         """ Return a list of names that this version provides."""
         return [p[0] for p in self._cand.provides_list]
-        
+
     @property
     def enhances(self):
         """Return the list of enhances for the package version."""
@@ -601,7 +600,7 @@ class Version(object):
         for item in acq.items:
             if item.status != item.STAT_DONE:
                 raise FetchError("The item %r could not be fetched: %s" %
-                                    (item.destfile, item.error_text))
+                                 (item.destfile, item.error_text))
 
         if unpack:
             outdir = src.package + '-' + apt_pkg.upstream_version(src.version)
@@ -633,8 +632,8 @@ class VersionList(Sequence):
     """
 
     def __init__(self, package, slice_=None):
-        self._package = package # apt.package.Package()
-        self._versions = package._pkg.version_list # [apt_pkg.Version(), ...]
+        self._package = package  # apt.package.Package()
+        self._versions = package._pkg.version_list  # [apt_pkg.Version(), ...]
         if slice_:
             self._versions = self._versions[slice_]
 
@@ -659,7 +658,7 @@ class VersionList(Sequence):
         return (Version(self._package, ver) for ver in self._versions)
 
     def __contains__(self, item):
-        if isinstance(item, Version): # Sequence interface
+        if isinstance(item, Version):  # Sequence interface
             item = item.version
         # Dictionary interface.
         for ver in self._versions:
@@ -702,8 +701,8 @@ class Package(object):
         self._changelog = ""            # Cached changelog
 
     def __repr__(self):
-        return '<Package: name:%r architecture=%r id:%r>' % (self._pkg.name,
-                 self._pkg.architecture, self._pkg.id)
+        return '<Package: name:%r architecture=%r id:%r>' % (
+            self._pkg.name, self._pkg.architecture, self._pkg.id)
 
     def __lt__(self, other):
         return self.name < other.name
@@ -917,10 +916,10 @@ class Package(object):
         src_section = "main"
         # use the section of the candidate as a starting point
         section = self.candidate.section
-        
+
         # get the source version
         src_ver = self.candidate.source_version
-                
+
         try:
             # try to get the source version of the pkg, this differs
             # for some (e.g. libnspr4 on ubuntu)
@@ -1006,7 +1005,7 @@ class Package(object):
                             changelog_ver = changelog_ver.split(":", 1)[1]
 
                         if (installed and apt_pkg.version_compare(
-                                          changelog_ver, installed) <= 0):
+                                changelog_ver, installed) <= 0):
                             break
                     # EOF (shouldn't really happen)
                     changelog += line
@@ -1020,14 +1019,14 @@ class Package(object):
 
             except urllib2.HTTPError:
                 res = _("The list of changes is not available yet.\n\n"
-                         "Please use http://launchpad.net/ubuntu/+source/%s/";
-                         "%s/+changelog\n"
-                         "until the changes become available or try again "
-                         "later.") % (src_pkg, src_ver)
+                        "Please use http://launchpad.net/ubuntu/+source/%s/";
+                        "%s/+changelog\n"
+                        "until the changes become available or try again "
+                        "later.") % (src_pkg, src_ver)
                 return res if isinstance(res, unicode) else res.decode("utf-8")
             except (IOError, httplib.BadStatusLine):
                 res = _("Failed to download the list of changes. \nPlease "
-                         "check your Internet connection.")
+                        "check your Internet connection.")
                 return res if isinstance(res, unicode) else res.decode("utf-8")
         finally:
             socket.setdefaulttimeout(timeout)
@@ -1168,12 +1167,11 @@ def _test():
     print "Recommends: %s" % pkg.installed.recommends
     for dep in pkg.candidate.dependencies:
         print ",".join("%s (%s) (%s) (%s)" % (o.name, o.version, o.relation,
-                        o.pre_depend) for o in dep.or_dependencies)
+                       o.pre_depend) for o in dep.or_dependencies)
     print "arch: %s" % pkg.candidate.architecture
     print "homepage: %s" % pkg.candidate.homepage
     print "rec: ", pkg.candidate.record
 
-
     print cache["2vcard"].get_changelog()
     for i in True, False:
         print "Running install on random upgradable pkgs with AutoFix: %s " % i
diff --git a/debian/changelog b/debian/changelog
index 52a1000..a7b037d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,9 @@ python-apt (0.9.2) UNRELEASED; urgency=low
   * apt/cache.py:
     - when using apt.Cache(rootdir=/some/dir) only read the APT
       configuration from this rootdir instead of /etc (closes: #728274)
+    - Fixed PEP8 and pyflakes issues
+  * apt/package.py:
+    - Fixed PEP8 and pyflakes issues
 
  -- Michael Vogt <michael.vogt@ubuntu.com>  Sat, 23 Nov 2013 08:49:51 +0100
 
-- 
1.8.3.2

>From 3b023a188e085d2cb894a0b8210c8e0ff0a55159 Mon Sep 17 00:00:00 2001
From: Michael Vogt <mvo@debian.org>
Date: Tue, 31 Dec 2013 23:18:43 +0100
Subject: [PATCH 6/7] make pyflakes clean

---
 apt/__init__.py                     |  2 ++
 apt/auth.py                         |  1 -
 apt/debfile.py                      |  1 +
 apt/progress/__init__.py            |  1 -
 doc/examples/acquire.py             |  3 ++-
 doc/examples/progress.py            |  1 +
 doc/source/conf.py                  |  1 +
 tests/test_aptsources.py            |  2 --
 tests/test_aptsources_ports.py      |  1 -
 tests/test_cache_invocation.py      |  1 +
 tests/test_debfile.py               | 11 ++---------
 tests/test_debfile_multiarch.py     |  2 --
 tests/test_lp659438.py              |  2 +-
 tests/test_paths.py                 |  1 -
 tests/test_progress.py              |  2 +-
 tests/test_utils.py                 |  4 ----
 utils/get_ubuntu_mirrors.py         |  2 --
 utils/get_ubuntu_mirrors_from_lp.py |  1 -
 18 files changed, 12 insertions(+), 27 deletions(-)

diff --git a/apt/__init__.py b/apt/__init__.py
index 7b04bef..c4e78ba 100644
--- a/apt/__init__.py
+++ b/apt/__init__.py
@@ -23,6 +23,8 @@ import apt_pkg
 # import some fancy classes
 from apt.package import Package
 from apt.cache import Cache, ProblemResolver
+Cache  # pyflakes
+ProblemResolver  # pyflakes
 from apt.cdrom import Cdrom
 
 # init the package system, but do not re-initialize config
diff --git a/apt/auth.py b/apt/auth.py
index c1b8da2..d5a66b4 100644
--- a/apt/auth.py
+++ b/apt/auth.py
@@ -24,7 +24,6 @@
 #  USA
 """Handle GnuPG keys used to trust signed repositories."""
 
-import atexit
 import os
 import os.path
 import shutil
diff --git a/apt/debfile.py b/apt/debfile.py
index 7f9cf9f..c845b1f 100644
--- a/apt/debfile.py
+++ b/apt/debfile.py
@@ -508,6 +508,7 @@ class DebPackage(object):
         # turn off MarkAndSweep via a action group (if available)
         try:
             _actiongroup = apt_pkg.ActionGroup(self._cache._depcache)
+            _actiongroup  # pyflakes
         except AttributeError:
             pass
         # check depends
diff --git a/apt/progress/__init__.py b/apt/progress/__init__.py
index 00dc768..776a703 100644
--- a/apt/progress/__init__.py
+++ b/apt/progress/__init__.py
@@ -22,7 +22,6 @@ This package provides progress reporting for the python-apt package. The module
 'base' provides classes with no output, the module 'gtk2' provides classes for
 GTK+ applications, and the module 'text' provides classes for terminals, etc.
 """
-import apt_pkg
 
 
 __all__ = []
diff --git a/doc/examples/acquire.py b/doc/examples/acquire.py
index c2db832..7381ad6 100644
--- a/doc/examples/acquire.py
+++ b/doc/examples/acquire.py
@@ -9,6 +9,7 @@ def get_file(fetcher, uri, destfile):
     # get the file
     af = apt_pkg.AcquireFile(fetcher, uri=uri, descr="sample descr",
                                destfile=destfile)
+    print "desc_uri: %s -> %s" % (af.desc_uri, af.destfile)
     res = fetcher.run()
     if res != fetcher.RESULT_CONTINUE:
         return False
@@ -45,7 +46,7 @@ except OSError:
     pass
 apt_pkg.config.set("Dir::Cache::archives", "/tmp/pyapt-test")
 
-pkg = cache["3ddesktop"]
+pkg = cache["2vcard"]
 depcache.mark_install(pkg)
 
 progress = apt.progress.text.AcquireProgress()
diff --git a/doc/examples/progress.py b/doc/examples/progress.py
index 77985a5..d7c4fad 100644
--- a/doc/examples/progress.py
+++ b/doc/examples/progress.py
@@ -98,6 +98,7 @@ class TextCdromProgress(apt.progress.base.CdromProgress):
     def change_cdrom(self):
         print "Please insert cdrom and press <ENTER>"
         answer = sys.stdin.readline()
+        print answer
         return True
 
 
diff --git a/doc/source/conf.py b/doc/source/conf.py
index bdf0579..163f507 100644
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -26,6 +26,7 @@ if os.path.exists("../../build"):
         sys.path.insert(0, os.path.abspath(os.path.dirname(apt_pkg_path)))
         try:
             import apt_pkg
+            apt_pkg  # pyflakes
         except ImportError as exc:
             # Not the correct version
             sys.stderr.write('W: Ignoring error %s\n' % exc)
diff --git a/tests/test_aptsources.py b/tests/test_aptsources.py
index 5a174f3..0b74cb7 100644
--- a/tests/test_aptsources.py
+++ b/tests/test_aptsources.py
@@ -140,7 +140,6 @@ class TestAptSources(unittest.TestCase):
         distro = aptsources.distro.get_distro(id="Ubuntu")
         distro.get_sources(sources)
         # test if all suits of the current distro were detected correctly
-        dist_templates = set()
         for s in sources:
             if not s.template:
                 self.fail("source entry '%s' has no matcher" % s)
@@ -178,7 +177,6 @@ class TestAptSources(unittest.TestCase):
         assert sources.list[9].line.strip() == str(sources.list[9])
 
     def test_enable_component(self):
-        from subprocess import Popen, PIPE
         target = "./data/aptsources/sources.list.enable_comps"
         line = "deb http://archive.ubuntu.com/ubuntu lucid main\n"
         with open(target, "w") as target_file:
diff --git a/tests/test_aptsources_ports.py b/tests/test_aptsources_ports.py
index 67c21b9..b625b8c 100644
--- a/tests/test_aptsources_ports.py
+++ b/tests/test_aptsources_ports.py
@@ -31,7 +31,6 @@ class TestAptSourcesPorts(unittest.TestCase):
                                               "8.04")
         distro.get_sources(sources)
         # test if all suits of the current distro were detected correctly
-        dist_templates = set()
         for s in sources:
             if not s.line.strip() or s.line.startswith("#"):
                 continue
diff --git a/tests/test_cache_invocation.py b/tests/test_cache_invocation.py
index a89ef55..4bba081 100644
--- a/tests/test_cache_invocation.py
+++ b/tests/test_cache_invocation.py
@@ -25,6 +25,7 @@ class TestCache(unittest.TestCase):
         """cache_invocation: Test correct invocation."""
         apt_cache = apt_pkg.Cache(progress=None)
         apt_depcache = apt_pkg.DepCache(apt_cache)
+        self.assertNotEqual(apt_depcache, None)
 
 if __name__ == "__main__":
     unittest.main()
diff --git a/tests/test_debfile.py b/tests/test_debfile.py
index 3e93394..9379884 100644
--- a/tests/test_debfile.py
+++ b/tests/test_debfile.py
@@ -123,15 +123,8 @@ Description: testpackage for gdebi - contains usr/bin/binary for file reading
         deb.missing_deps
 
     def test_no_supported_data_tar(self):
-        # ensure that a unknown data.tar.xxx raises a exception
-        raised = False
-        try:
-            deb = apt.debfile.DebPackage("./data/test_debs/data-tar-broken.deb")
-        except SystemError:
-            raised = True
-	# with self.assertRaises(SystemError): is more elegant above, but
-	# we need to support python2.6
-        self.assertTrue(raised)
+        with self.assertRaises(SystemError):
+            apt.debfile.DebPackage("./data/test_debs/data-tar-broken.deb")
 
     def test_contains(self):
         deb = apt.debfile.DebPackage("./data/test_debs/data-tar-xz.deb")
diff --git a/tests/test_debfile_multiarch.py b/tests/test_debfile_multiarch.py
index bbf6201..cf6479b 100644
--- a/tests/test_debfile_multiarch.py
+++ b/tests/test_debfile_multiarch.py
@@ -7,8 +7,6 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 """Unit tests for verifying the correctness of DebPackage in apt.debfile."""
-import os
-import logging
 import unittest
 
 from test_all import get_library_dir
diff --git a/tests/test_lp659438.py b/tests/test_lp659438.py
index b9a837b..334f574 100644
--- a/tests/test_lp659438.py
+++ b/tests/test_lp659438.py
@@ -63,7 +63,7 @@ Architecture: all""")
     def tearDown(self):
         # this resets the rootdir apt_pkg.config to ensure it does not
         # "pollute" the later tests
-        cache = apt.cache.Cache(rootdir="/")
+        apt.cache.Cache(rootdir="/")
         shutil.rmtree(self.chroot_path)
 
     def test_survive_reqreinst(self):
diff --git a/tests/test_paths.py b/tests/test_paths.py
index 17f562d..48f86c5 100644
--- a/tests/test_paths.py
+++ b/tests/test_paths.py
@@ -3,7 +3,6 @@
 #
 import os
 import shutil
-import tempfile
 import unittest
 
 import apt_inst
diff --git a/tests/test_progress.py b/tests/test_progress.py
index e4a5fa3..508da7d 100644
--- a/tests/test_progress.py
+++ b/tests/test_progress.py
@@ -44,7 +44,7 @@ class TestProgress(unittest.TestCase):
     def test_acquire_progress(self):
         progress = TestAcquireProgress()
         cache = apt.Cache()
-        res = cache.update(progress)
+        cache.update(progress)
         self.assertTrue(progress.pulsed)
 
 if __name__ == "__main__":
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 2676bb9..35c0a46 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -8,12 +8,8 @@
 
 import datetime
 import os
-import sys
 import unittest
 
-import apt_pkg
-import apt.utils
-
 from apt.utils import (
     get_maintenance_end_date,
     get_release_date_from_release_file,
diff --git a/utils/get_ubuntu_mirrors.py b/utils/get_ubuntu_mirrors.py
index ddd1e36..cf50908 100755
--- a/utils/get_ubuntu_mirrors.py
+++ b/utils/get_ubuntu_mirrors.py
@@ -26,8 +26,6 @@
 
 import urllib2
 import re
-import os
-import commands
 import sys
 
 # the list of official Ubuntu servers
diff --git a/utils/get_ubuntu_mirrors_from_lp.py b/utils/get_ubuntu_mirrors_from_lp.py
index 7c4d383..6ff2d88 100755
--- a/utils/get_ubuntu_mirrors_from_lp.py
+++ b/utils/get_ubuntu_mirrors_from_lp.py
@@ -25,7 +25,6 @@
 #  USA
 
 import feedparser
-import sys
 
 d = feedparser.parse("https://launchpad.net/ubuntu/+archivemirrors-rss";)
 #d = feedparser.parse(open("+archivemirrors-rss"))
-- 
1.8.3.2

Attachment: 0007-make-test_pep8.py-pass.patch.gz
Description: Binary data


Reply to: