mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 03:55:22 +00:00
Strip alias from import name for multiple imports on the same line. Fix for #13
This commit is contained in:
parent
a0c796bc6b
commit
b30777fb41
@ -27,7 +27,6 @@ REGEXP = [
|
|||||||
re.compile(r'^from ((?!\.+).*?) import (?:.*)$')
|
re.compile(r'^from ((?!\.+).*?) import (?:.*)$')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def get_all_imports(start_path):
|
def get_all_imports(start_path):
|
||||||
imports = []
|
imports = []
|
||||||
packages = []
|
packages = []
|
||||||
@ -52,11 +51,9 @@ def get_all_imports(start_path):
|
|||||||
for item in s.groups():
|
for item in s.groups():
|
||||||
if "," in item:
|
if "," in item:
|
||||||
for match in item.split(","):
|
for match in item.split(","):
|
||||||
imports.append(match.strip())
|
imports.append(get_import_name_without_alias(match))
|
||||||
else:
|
else:
|
||||||
to_append = item.partition(
|
imports.append(get_import_name_without_alias(item))
|
||||||
' as ')[0].partition('.')[0]
|
|
||||||
imports.append(to_append.strip())
|
|
||||||
third_party_packages = set(imports) - set(set(packages) & set(imports))
|
third_party_packages = set(imports) - set(set(packages) & set(imports))
|
||||||
logging.debug(
|
logging.debug(
|
||||||
'Found third-party packages: {0}'.format(third_party_packages))
|
'Found third-party packages: {0}'.format(third_party_packages))
|
||||||
@ -128,6 +125,8 @@ def get_pkg_names_from_import_names(pkgs):
|
|||||||
result.append(toappend)
|
result.append(toappend)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def get_import_name_without_alias(import_name):
|
||||||
|
return import_name.partition(' as ')[0].partition('.')[0].strip()
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
print("Looking for imports")
|
print("Looking for imports")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user