From 496b729309d7539ad5acca1d0951577f39c6e91f Mon Sep 17 00:00:00 2001 From: Vadim Kravcenko Date: Mon, 11 May 2015 19:18:05 +0200 Subject: [PATCH] fix(pipreqs): line parsing with comments on the same line --- pipreqs/pipreqs.py | 2 +- tests/_data/test.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index cc4145c..3582ce9 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -38,7 +38,7 @@ def get_all_imports(path): candidates += [os.path.splitext(fn)[0] for fn in files] for file_name in files: with open(os.path.join(root, file_name), "r") as f: - lines = filter(filter_line, map(lambda l: l.strip(), f)) + lines = filter(filter_line, map(lambda l: l.partition("#")[0].strip(), f)) for line in lines: if "(" in line: break diff --git a/tests/_data/test.py b/tests/_data/test.py index 0c8dfb9..9809a0d 100644 --- a/tests/_data/test.py +++ b/tests/_data/test.py @@ -1,3 +1,15 @@ +"""unused import""" +# pylint: disable=undefined-all-variable, import-error, no-absolute-import, too-few-public-methods, missing-docstring +import xml.etree # [unused-import] +import xml.sax # [unused-import] +import os.path as test # [unused-import] +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 atexit from __future__ import print_function from docopt import docopt @@ -9,11 +21,10 @@ import time import sys import signal import bs4 -import requests import nonexistendmodule import boto as b, import peewee as p, # import django -import flask.ext.somext +import flask.ext.somext # # # from sqlalchemy import model try: import ujson as json