[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 Tue, Dec 31, 2013 at 01:09:39PM +0100, Michael Schaller wrote:
> Hi Michael,
Hi Michael,
 
> From my experience PEP8 and pyflakes are great tools with nearly no
> false positives - especially compared to pylint - and by now they
> are available for Python 2 and 3.

Indeed, I tend to use this combo (pep8 and pyflakes) in my projects as
well, works great!

> I personally like to add a lint command to setup.py to my projects.
> Maybe this would be beneficial for python-apt too. Please let me
> know if you would like to see a patch for that.

Indeed, I attached (this time for real :) patches to include them as
part of the tests. I like it this way as a CI system (like travis) can
alert me if I accidentally break pep8/pyflakes with a commit.

It also adds a .travis.yml file that runs the tests. Next step is
to actually make the pep8/pylakes test to pass :)

Cheers,
 Michael
>From f84aaa308f0f79d4a1407d8fd5cd849de8d50263 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/4] make pep8 test part of the unittests

---
 tests/test_pep8.py | 20 ++++++++++++++++++++
 1 file changed, 20 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..f72a2ea
--- /dev/null
+++ b/tests/test_pep8.py
@@ -0,0 +1,20 @@
+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",
+             "--ignore=E121,E123,E124,E125,E126,E127,E128",
+             "--exclude", "build,tests/old",
+             "--repeat", py_dir])
+        self.assertEqual(res, 0)
+
+
+if __name__ == "__main__":
+    unittest.main()
-- 
1.8.3.2

>From e751078fb9a532a3e8ef411e88d95adbe05ea0a5 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/4] add pyflakes test

---
 tests/test_pyflakes.py | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 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..7404987
--- /dev/null
+++ b/tests/test_pyflakes.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python3
+# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
+
+# Partly based on a script from Review Board, MIT license; but modified to
+# act as a unit test.
+
+from __future__ import print_function
+
+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 f8fb88aadc908fbabacc89169dc7dce197e71a51 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/4] 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 6043e3d03101305f14c240774373713d4b1499db 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/4] add .travis.yml

---
 .travis.yml | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 .travis.yml

diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..c859327
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,12 @@
+language: python
+before_install:
+ - sudo apt-get update -q
+ - sudo apt-get install distro-info
+ - echo "deb http://archive.ubuntu.com/ubuntu $(distro-info --devel) main"|sudo tee -a /etc/apt/sources.list.d/trusty.list
+ - sudo apt-get update -q
+ - sudo apt-get install apt libapt-pkg-dev
+ - sudo rm /etc/apt/sources.list.d/trusty.list
+ - sudo apt-get update -q
+ - sudo apt-get install -q --no-install-recommends gdebi-core
+ - sudo apt-get install $(gdebi -q --apt-line ./debian/control)
+script: ./debian/rules binary
-- 
1.8.3.2


Reply to: