diff --git a/CHANGELOG.md b/CHANGELOG.md index 60704731..0857ae30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Prospector Changelog ======= +## Version 0.8.2 +* [#82](https://github.com/landscapeio/prospector/issues/82) resolves regression in adapter library detection raising, ``ValueError: too many values to unpack``. provided by [@jquast](https://github.com/jquast) +* [#83](https://github.com/landscapeio/prospector/issues/83) resolves regression when adapter library detects django, ``TypeError: '_sre.SRE_Pattern' object is not iterable``. provided by [@jquast](https://github.com/jquast) + ## Version 0.8.1 * Strictness now also changes which pep257 messages are output * pep257 and vulture messages are now combined and 'blended' with other tools diff --git a/prospector/autodetect.py b/prospector/autodetect.py index 4deb7aa5..be6a8a28 100644 --- a/prospector/autodetect.py +++ b/prospector/autodetect.py @@ -13,7 +13,7 @@ _FROM_IMPORT_REGEX = re.compile(r'^\s*from ([\._a-zA-Z0-9]+) import .*$') _IMPORT_REGEX = re.compile(r'^\s*import ([\._a-zA-Z0-9]+)$') _IMPORT_MULTIPLE_REGEX = re.compile(r'^\s*import ([\._a-zA-Z0-9]+(, ){1})+') -_CODING_REGEX = "coding[:=]\s*([-\w.]+)" +_CODING_REGEX = re.compile(r'coding[:=]\s*([-\w.]+)') def detect_by_bom(path): @@ -28,8 +28,8 @@ def detect_by_bom(path): raw = fin.read(4) for enc, boms in ( ('utf-8-sig', (codecs.BOM_UTF8,)), - ('utf-16', (codecs.BOM_UTF16_LE,codecs.BOM_UTF16_BE)), - ('utf-32', (codecs.BOM_UTF32_LE,codecs.BOM_UTF32_BE))): + ('utf-16', (codecs.BOM_UTF16_LE, codecs.BOM_UTF16_BE)), + ('utf-32', (codecs.BOM_UTF32_LE, codecs.BOM_UTF32_BE))): if any(raw.startswith(bom) for bom in boms): return enc @@ -117,8 +117,8 @@ def find_from_requirements(path): reqs = find_requirements(path) names = [] for requirement in reqs: - if requirement.name is not None \ - and requirement.name.lower() in POSSIBLE_LIBRARIES: + if (requirement.name is not None + and requirement.name.lower() in POSSIBLE_LIBRARIES): names.append(requirement.name.lower()) return names diff --git a/prospector/config/__init__.py b/prospector/config/__init__.py index e43b6681..0a2bb89f 100644 --- a/prospector/config/__init__.py +++ b/prospector/config/__init__.py @@ -137,8 +137,7 @@ def _find_used_libraries(self, config): # Bring in adaptors that we automatically detect are needed if config.autodetect: - for name, adaptor in autodetect_libraries(self.workdir): - libraries.append(name) + map(libraries.append, autodetect_libraries(self.workdir)) # Bring in adaptors for the specified libraries for name in config.uses: @@ -200,7 +199,9 @@ def _determine_ignores(self, config, profile, libraries): # some libraries have further automatic ignores if 'django' in libraries: - ignores += re.compile('(^|/)(south_)?migrations(/|$)') + ignores += [ + re.compile('(^|/)(south_)?migrations(/|$)') + ] return ignores @@ -258,4 +259,4 @@ def max_line_length(self): @property def loquacious_pylint(self): - return self.config.loquacious_pylint \ No newline at end of file + return self.config.loquacious_pylint diff --git a/tests/test_autodetect.py b/tests/test_autodetect.py index 1a3cc2d6..092f0de9 100644 --- a/tests/test_autodetect.py +++ b/tests/test_autodetect.py @@ -6,8 +6,17 @@ import tempfile import contextlib from unittest import TestCase - -from prospector.autodetect import find_from_imports, find_from_path +try: + from unittest.util import safe_repr +except ImportError: + # python2.6 + safe_repr = repr + +from prospector.autodetect import ( + autodetect_libraries, + find_from_imports, + find_from_path, +) class FindFromImportsTest(TestCase): @@ -35,12 +44,15 @@ def test_multiple_imports(self): def test_indented_imports(self): """ django is discovered from function-local import statements. """ - self._test('def lala(self):\n from django.db import models\n return models.Model', 'django') + self._test('def lala(self):\n' + 'from django.db import models\n' + 'return models.Model', 'django') def test_same_line_two_imports(self): """ importing two modules of interest on same line are discovered. """ self._test('import django, celery', 'django', 'celery') + class ImportCodingsTest(TestCase): def SetUp(self): @@ -51,7 +63,7 @@ def tearDown(self): warnings.resetwarnings() TestCase.tearDown(self) - if sys.version_info < (2,7): + if sys.version_info < (2, 7): # backport assertGreaterEqual and assertIn for python2.6. def assertGreaterEqual(self, a, b, msg=None): @@ -67,7 +79,6 @@ def assertIn(self, member, container, msg=None): safe_repr(container)) self.fail(self._formatMessage(msg, standardMsg)) - @contextlib.contextmanager def make_pypath(self, bindata): tmp_folder = tempfile.mkdtemp(prefix='prospector-') @@ -81,7 +92,6 @@ def make_pypath(self, bindata): os.unlink(tmp_file) os.rmdir(tmp_folder) - def test_latin1_coding_line2(self): """ File containing latin1 at line 2 with 'coding' declaration at line 1. @@ -98,7 +108,6 @@ def test_latin1_coding_line2(self): # verify. self.assertEqual(set(expected_names), names) - def test_negative_latin1(self): """ Negative test: file containing latin1 without 'coding' declaration. """ # given, @@ -112,7 +121,6 @@ def test_negative_latin1(self): self.assertGreaterEqual(len(warned), 1) self.assertIn(ImportWarning, [_w.category for _w in warned]) - def test_negative_lookuperror(self): """ File declares an unknown coding. """ # given, @@ -126,7 +134,6 @@ def test_negative_lookuperror(self): self.assertGreaterEqual(len(warned), 1) self.assertIn(ImportWarning, [_w.category for _w in warned]) - def test_bom_encoded_filepath(self): """ File containing only a UTF32_BE byte order mark still decodes. """ # given, @@ -141,7 +148,6 @@ def test_bom_encoded_filepath(self): # verify. self.assertEqual(set(expected_names), names) - def test_negative_misleading_bom(self): """ Negative test: file containing BOM that is not the correct encoding. """ # given, @@ -157,6 +163,22 @@ def test_negative_misleading_bom(self): self.assertIn(ImportWarning, [_w.category for _w in warned]) +class AdaptersTest(TestCase): + + """ Adapters detection requires a true project, we just use only our own. """ + + def test_autodetect_adapters_of_prospector(self): + """ Use prospector's base proj. folder, discovers nothing. """ + # Given + tgt_path = os.path.join(os.path.dirname(__file__), os.path.pardir) + + # Exercise + detected = autodetect_libraries(tgt_path) + + # Verify + self.assertEqual(set(), detected) + + if __name__ == '__main__': import unittest unittest.main() diff --git a/tox.ini b/tox.ini index a792267f..a07d2a8a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,11 @@ [tox] -envlist = py26,py27,py33 +envlist = py27,py33,py34 + +skip_missing_interpreters = true [testenv] deps = nose Django -commands = nosetests +commands = nosetests tests