mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +00:00
- Pre-filter python files only and remove empty lines in file.
- Exclude local packages import.
This commit is contained in:
parent
1dee19e3f5
commit
a438406f68
@ -34,9 +34,11 @@ def get_all_imports(start_path):
|
|||||||
for root, dirs, files in os.walk(start_path):
|
for root, dirs, files in os.walk(start_path):
|
||||||
packages.append(os.path.basename(root))
|
packages.append(os.path.basename(root))
|
||||||
files = filter(lambda fn:os.path.splitext(fn)[1] == ".py", files)
|
files = filter(lambda fn:os.path.splitext(fn)[1] == ".py", files)
|
||||||
|
packages += map(lambda fn:os.path.splitext(fn)[0], files)
|
||||||
for file_name in files:
|
for file_name in files:
|
||||||
with open(os.path.join(root, file_name), "r") as file_object:
|
with open(os.path.join(root, file_name), "r") as file_object:
|
||||||
for line in file_object:
|
lines = filter(lambda l:len(l) > 0, map(lambda l:l.strip(), file_object))
|
||||||
|
for line in lines:
|
||||||
if line[0] == "#":
|
if line[0] == "#":
|
||||||
continue
|
continue
|
||||||
if "(" in line:
|
if "(" in line:
|
||||||
|
@ -13,7 +13,12 @@ import nonexistendmodule
|
|||||||
# import django
|
# import django
|
||||||
import flask.ext.somext
|
import flask.ext.somext
|
||||||
from sqlalchemy import model
|
from sqlalchemy import model
|
||||||
import ujson as json
|
try:
|
||||||
|
import ujson as json
|
||||||
|
except ImportError:
|
||||||
|
import json
|
||||||
|
|
||||||
|
import models
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pass
|
pass
|
||||||
|
@ -29,6 +29,7 @@ class TestPipreqs(unittest.TestCase):
|
|||||||
self.assertFalse("curses" in imports)
|
self.assertFalse("curses" in imports)
|
||||||
self.assertFalse("__future__" in imports)
|
self.assertFalse("__future__" in imports)
|
||||||
self.assertFalse("django" in imports)
|
self.assertFalse("django" in imports)
|
||||||
|
self.assertFalse("models" in imports)
|
||||||
|
|
||||||
def test_get_imports_info(self):
|
def test_get_imports_info(self):
|
||||||
imports = pipreqs.get_all_imports(self.project)
|
imports = pipreqs.get_all_imports(self.project)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user