mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Fix flake8
This commit is contained in:
parent
9671b53ff3
commit
d59c9a1e84
@ -6,7 +6,7 @@ Usage:
|
||||
pipreqs [options] <path>
|
||||
|
||||
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 <file> 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['<path>'], "requirements.txt")
|
||||
path = (args["--savepath"] if args["--savepath"] else
|
||||
os.path.join(args['<path>'], "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)
|
||||
|
@ -8,7 +8,7 @@ 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]
|
||||
import requests # [unused-import]
|
||||
|
||||
# setuptools
|
||||
import zipimport # command/easy_install.py
|
||||
@ -25,7 +25,8 @@ 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
|
||||
# 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
|
||||
|
@ -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(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': None, '--force': True})
|
||||
pipreqs.init({'<path>': 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(
|
||||
{'<path>': self.project, '--savepath': None, '--use-local': True, '--force': True})
|
||||
pipreqs.init({'<path>': 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({'<path>': self.project, '--savepath': None, '--use-local': None, '--force': None})
|
||||
pipreqs.init({'<path>': 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user