mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +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):
|
||||
packages.append(os.path.basename(root))
|
||||
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:
|
||||
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] == "#":
|
||||
continue
|
||||
if "(" in line:
|
||||
|
@ -13,7 +13,12 @@ import nonexistendmodule
|
||||
# import django
|
||||
import flask.ext.somext
|
||||
from sqlalchemy import model
|
||||
import ujson as json
|
||||
try:
|
||||
import ujson as json
|
||||
except ImportError:
|
||||
import json
|
||||
|
||||
import models
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
@ -29,6 +29,7 @@ class TestPipreqs(unittest.TestCase):
|
||||
self.assertFalse("curses" in imports)
|
||||
self.assertFalse("__future__" in imports)
|
||||
self.assertFalse("django" in imports)
|
||||
self.assertFalse("models" in imports)
|
||||
|
||||
def test_get_imports_info(self):
|
||||
imports = pipreqs.get_all_imports(self.project)
|
||||
|
Loading…
x
Reference in New Issue
Block a user