mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-07 12:05:33 +00:00
Merge pull request #7 from cclauss/patch-2
str.partition() simplifies the logic, tighten up write()
This commit is contained in:
commit
843f6b66f8
@ -51,11 +51,8 @@ def get_all_imports(start_path):
|
|||||||
if "," in item:
|
if "," in item:
|
||||||
for match in item.split(","):
|
for match in item.split(","):
|
||||||
imports.append(match.strip())
|
imports.append(match.strip())
|
||||||
elif " as " in item:
|
|
||||||
to_append = item.split(" as ")[0]
|
|
||||||
imports.append(to_append.strip())
|
|
||||||
else:
|
else:
|
||||||
to_append = item if "." not in item else item.split(".")[0]
|
to_append = item.partition(' as ')[0].partition('.')[0]
|
||||||
imports.append(to_append.strip())
|
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('Found third-party packages: %s', third_party_packages)
|
logging.debug('Found third-party packages: %s', third_party_packages)
|
||||||
@ -65,11 +62,10 @@ def get_all_imports(start_path):
|
|||||||
|
|
||||||
|
|
||||||
def generate_requirements_file(path, imports):
|
def generate_requirements_file(path, imports):
|
||||||
with open(path, "w") as ff:
|
with open(path, "w") as out_file:
|
||||||
logging.debug('Writing requirements to file %s', path)
|
logging.debug('Writing %d requirements to file %s', (len(imports), path))
|
||||||
for item in imports:
|
fmt = '{name} == {version}'
|
||||||
ff.write(item['name'] + "==" + item['version'])
|
out_file.write('\n'.join(fmt.format(**item) for item in imports) + '\n')
|
||||||
ff.write("\n")
|
|
||||||
|
|
||||||
|
|
||||||
def get_imports_info(imports):
|
def get_imports_info(imports):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user