From d59c9a1e846e15ca78a266f9a10003d459610632 Mon Sep 17 00:00:00 2001 From: lord63 Date: Tue, 14 Jul 2015 19:56:14 +0800 Subject: [PATCH] Fix flake8 --- pipreqs/pipreqs.py | 15 +++++++++------ tests/_data/test.py | 14 ++++++++------ tests/test_pipreqs.py | 19 +++++++++++-------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 3d376e7..7ae6a0b 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -6,7 +6,7 @@ Usage: pipreqs [options] Options: - --use-local Use ONLY local package information instead of querying PyPI + --use-local Use ONLY local package info instead of querying PyPI --debug Print debug information --savepath Save the list of requirements in the given file --force Overwrite existing requirements.txt @@ -101,7 +101,8 @@ def get_locally_installed_packages(): except: continue for i_item in package_import: - if i_item not in ignore and package[0] not in ignore: + if ((i_item not in ignore) and + (package[0] not in ignore)): packages[i_item] = { 'version': package[1].replace(".dist", ""), 'name': package[0] @@ -157,14 +158,16 @@ def init(args): logging.debug("Getting packages information from Local/PyPI") local = get_import_local(candidates) # Get packages that were not found locally - difference = [x for x in candidates if x.lower() not in [z['name'].lower() - for z in local]] + difference = [x for x in candidates + if x.lower() not in [z['name'].lower() for z in local]] imports = local + get_imports_info(difference) - path = args["--savepath"] if args["--savepath"] else os.path.join(args[''], "requirements.txt") + path = (args["--savepath"] if args["--savepath"] else + os.path.join(args[''], "requirements.txt")) if not args["--savepath"] and not args["--force"] and os.path.exists(path): - logging.info("Requirements.txt already exists, use --force to overwrite it") + logging.info("Requirements.txt already exists, " + "use --force to overwrite it") return generate_requirements_file(path, imports) logging.info("Successfully saved requirements file in " + path) diff --git a/tests/_data/test.py b/tests/_data/test.py index b1843bc..2ea6692 100644 --- a/tests/_data/test.py +++ b/tests/_data/test.py @@ -7,8 +7,8 @@ from sys import argv as test2 # [unused-import] from sys import flags # [unused-import] # +1:[unused-import,unused-import] from collections import deque, OrderedDict, Counter -# All imports above should be ignored -import requests # [unused-import] +# All imports above should be ignored +import requests # [unused-import] # setuptools import zipimport # command/easy_install.py @@ -24,8 +24,9 @@ import importlib # html/notebookapp.py from IPython.utils.importstring import import_item # Many files -# pyflakes -from pyflakes.test.test_imports import Test as TestImports # test/test_doctests.py +# pyflakes +# test/test_doctests.py +from pyflakes.test.test_imports import Test as TestImports # Nose from nose.importer import Importer, add_path, remove_path # loader.py @@ -44,7 +45,7 @@ import bs4 import nonexistendmodule import boto as b, import peewee as p, # import django -import flask.ext.somext # # # +import flask.ext.somext # # # from sqlalchemy import model try: import ujson as json @@ -53,7 +54,8 @@ except ImportError: import models + def main(): - pass + pass import after_method_should_be_ignored diff --git a/tests/test_pipreqs.py b/tests/test_pipreqs.py index b60380d..38b3fe8 100755 --- a/tests/test_pipreqs.py +++ b/tests/test_pipreqs.py @@ -18,7 +18,8 @@ class TestPipreqs(unittest.TestCase): def setUp(self): self.modules = ['flask', 'requests', 'sqlalchemy', - 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'peewee', 'ujson', 'nonexistendmodule', 'bs4', ] + 'docopt', 'boto', 'ipython', 'pyflakes', 'nose', + 'peewee', 'ujson', 'nonexistendmodule', 'bs4', ] self.modules2 = ['beautifulsoup4'] self.local = ["docopt", "requests", "nose"] self.project = os.path.join(os.path.dirname(__file__), "_data") @@ -45,8 +46,9 @@ class TestPipreqs(unittest.TestCase): # Should contain only 5 Elements without the "nonexistendmodule" self.assertEqual(len(with_info), 10) for item in with_info: - self.assertTrue(item['name'].lower( - ) in self.modules, "Import item appears to be missing " + item['name']) + self.assertTrue( + item['name'].lower() in self.modules, + "Import item appears to be missing " + item['name']) def test_get_use_local_only(self): # should find only docopt and requests @@ -55,8 +57,8 @@ class TestPipreqs(unittest.TestCase): self.assertTrue(item['name'].lower() in self.local) def test_init(self): - pipreqs.init( - {'': self.project, '--savepath': None, '--use-local': None, '--force': True}) + pipreqs.init({'': self.project, '--savepath': None, + '--use-local': None, '--force': True}) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.read().lower() @@ -64,8 +66,8 @@ class TestPipreqs(unittest.TestCase): self.assertTrue(item.lower() in data) def test_init_local_only(self): - pipreqs.init( - {'': self.project, '--savepath': None, '--use-local': True, '--force': True}) + pipreqs.init({'': self.project, '--savepath': None, + '--use-local': True, '--force': True}) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.readlines() @@ -87,7 +89,8 @@ class TestPipreqs(unittest.TestCase): def test_init_overwrite(self): with open(self.requirements_path, "w") as f: f.write("should_not_be_overwritten") - pipreqs.init({'': self.project, '--savepath': None, '--use-local': None, '--force': None}) + pipreqs.init({'': self.project, '--savepath': None, + '--use-local': None, '--force': None}) assert os.path.exists(self.requirements_path) == 1 with open(self.requirements_path, "r") as f: data = f.read().lower()