mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
fix(pipreqs): ignore word "import" in package names
This commit is contained in:
parent
8c77afd7fb
commit
0f622de27c
@ -261,6 +261,7 @@ socketio:gevent_socketio
|
|||||||
socketserver:pies2overrides
|
socketserver:pies2overrides
|
||||||
sockjs:sockjs_tornado
|
sockjs:sockjs_tornado
|
||||||
socks:SocksiPy_branch
|
socks:SocksiPy_branch
|
||||||
|
IPython:ipython
|
||||||
solr:solrpy
|
solr:solrpy
|
||||||
solution:Solution
|
solution:Solution
|
||||||
sorl:sorl_thumbnail
|
sorl:sorl_thumbnail
|
||||||
|
@ -126,8 +126,10 @@ def get_pkg_names(pkgs):
|
|||||||
|
|
||||||
|
|
||||||
def get_name_without_alias(name):
|
def get_name_without_alias(name):
|
||||||
if "import" in name:
|
if "import " in name:
|
||||||
name = REGEXP[0].match(name.strip()).groups(0)[0]
|
match = REGEXP[0].match(name.strip())
|
||||||
|
if match:
|
||||||
|
name = match.groups(0)[0]
|
||||||
return name.partition(' as ')[0].partition('.')[0].strip()
|
return name.partition(' as ')[0].partition('.')[0].strip()
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,28 @@ from sys import argv as test2 # [unused-import]
|
|||||||
from sys import flags # [unused-import]
|
from sys import flags # [unused-import]
|
||||||
# +1:[unused-import,unused-import]
|
# +1:[unused-import,unused-import]
|
||||||
from collections import deque, OrderedDict, Counter
|
from collections import deque, OrderedDict, Counter
|
||||||
import requests # [unused-import]
|
|
||||||
# All imports above should be ignored
|
# 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
|
import atexit
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
@ -18,7 +18,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.modules = ['flask', 'requests', 'sqlalchemy',
|
self.modules = ['flask', 'requests', 'sqlalchemy',
|
||||||
'docopt', 'boto', 'peewee', 'ujson', 'nonexistendmodule', 'bs4',]
|
'docopt', 'boto', 'ipython', 'pyflakes', 'nose', 'peewee', 'ujson', 'nonexistendmodule', 'bs4',]
|
||||||
self.modules2 = ['beautifulsoup4']
|
self.modules2 = ['beautifulsoup4']
|
||||||
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
self.project = os.path.join(os.path.dirname(__file__), "_data")
|
||||||
self.requirements_path = os.path.join(self.project, "requirements.txt")
|
self.requirements_path = os.path.join(self.project, "requirements.txt")
|
||||||
@ -27,7 +27,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_all_imports(self):
|
def test_get_all_imports(self):
|
||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
self.assertEqual(len(imports), 9)
|
self.assertEqual(len(imports), 12)
|
||||||
for item in imports:
|
for item in imports:
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
item.lower() in self.modules, "Import is missing: " + item)
|
item.lower() in self.modules, "Import is missing: " + item)
|
||||||
@ -42,8 +42,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
with_info = pipreqs.get_imports_info(imports)
|
with_info = pipreqs.get_imports_info(imports)
|
||||||
# Should contain only 5 Elements without the "nonexistendmodule"
|
# Should contain only 5 Elements without the "nonexistendmodule"
|
||||||
self.assertEqual(
|
self.assertEqual(len(with_info), 10)
|
||||||
len(with_info), 7)
|
|
||||||
for item in with_info:
|
for item in with_info:
|
||||||
self.assertTrue(item['name'].lower(
|
self.assertTrue(item['name'].lower(
|
||||||
) in self.modules, "Import item appears to be missing " + item['name'])
|
) in self.modules, "Import item appears to be missing " + item['name'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user