From 1ee081454b8e7b83b6deeb90be5e4433a63a07a1 Mon Sep 17 00:00:00 2001 From: Vadim Kravcenko Date: Fri, 4 Dec 2015 20:40:38 +0100 Subject: [PATCH] fix(pipreqs.py): remove ''' and """ comments before going through imports --- pipreqs/pipreqs.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index b1a0e97..02ec8f4 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -53,8 +53,11 @@ def get_all_imports(path, encoding=None): candidates += [os.path.splitext(fn)[0] for fn in files] for file_name in files: with open_func(os.path.join(root, file_name), "r", encoding=encoding) as f: + contents = re.sub(re.compile("'''.+?'''", re.DOTALL), '', f.read()) + contents = re.sub(re.compile('""".+"""', re.DOTALL), "", contents) + lines = contents.split("\n") lines = filter( - filter_line, map(lambda l: l.partition("#")[0].strip(), f)) + filter_line, map(lambda l: l.partition("#")[0].strip(), lines)) for line in lines: if "(" in line: break