fix(pipreqs): ignore word "import" in package names

This commit is contained in:
Vadim Kravcenko 2015-05-11 21:46:33 +02:00
parent 8c77afd7fb
commit 0f622de27c
4 changed files with 29 additions and 7 deletions

View File

@ -261,6 +261,7 @@ socketio:gevent_socketio
socketserver:pies2overrides
sockjs:sockjs_tornado
socks:SocksiPy_branch
IPython:ipython
solr:solrpy
solution:Solution
sorl:sorl_thumbnail

View File

@ -126,8 +126,10 @@ def get_pkg_names(pkgs):
def get_name_without_alias(name):
if "import" in name:
name = REGEXP[0].match(name.strip()).groups(0)[0]
if "import " in name:
match = REGEXP[0].match(name.strip())
if match:
name = match.groups(0)[0]
return name.partition(' as ')[0].partition('.')[0].strip()

View File

@ -7,8 +7,28 @@ 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
import requests # [unused-import]
# All imports above should be ignored
import requests # [unused-import]
# setuptools
import zipimport # command/easy_install.py
# twisted
from importlib import invalidate_caches # python/test/test_deprecate.py
# astroid
import zipimport # manager.py
# IPython
from importlib.machinery import all_suffixes # core/completerlib.py
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
# Nose
from nose.importer import Importer, add_path, remove_path # loader.py
import atexit
from __future__ import print_function

View File

@ -18,7 +18,7 @@ class TestPipreqs(unittest.TestCase):
def setUp(self):
self.modules = ['flask', 'requests', 'sqlalchemy',
'docopt', 'boto', 'peewee', 'ujson', 'nonexistendmodule', 'bs4',]
'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'peewee', 'ujson', 'nonexistendmodule', 'bs4',]
self.modules2 = ['beautifulsoup4']
self.project = os.path.join(os.path.dirname(__file__), "_data")
self.requirements_path = os.path.join(self.project, "requirements.txt")
@ -27,7 +27,7 @@ class TestPipreqs(unittest.TestCase):
def test_get_all_imports(self):
imports = pipreqs.get_all_imports(self.project)
self.assertEqual(len(imports), 9)
self.assertEqual(len(imports), 12)
for item in imports:
self.assertTrue(
item.lower() in self.modules, "Import is missing: " + item)
@ -42,8 +42,7 @@ class TestPipreqs(unittest.TestCase):
imports = pipreqs.get_all_imports(self.project)
with_info = pipreqs.get_imports_info(imports)
# Should contain only 5 Elements without the "nonexistendmodule"
self.assertEqual(
len(with_info), 7)
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'])