mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Implement --print to output list of requirements to stdout
This commit is contained in:
parent
345a275b3a
commit
f31ad89350
@ -16,6 +16,7 @@ Options:
|
||||
--ignore <dirs>... Ignore extra directories, each separated by a comma
|
||||
--encoding <charset> Use encoding parameter for file open
|
||||
--savepath <file> Save the list of requirements in the given file
|
||||
--print Output the list of requirements in the standard output
|
||||
--force Overwrite existing requirements.txt
|
||||
"""
|
||||
from __future__ import print_function, absolute_import
|
||||
@ -117,6 +118,14 @@ def generate_requirements_file(path, imports):
|
||||
out_file.write('\n'.join(fmt.format(**item) if item['version'] else '{name}'.format(**item)
|
||||
for item in imports) + '\n')
|
||||
|
||||
def output_requirements(imports):
|
||||
logging.debug('Writing {num} requirements: {imports} to stdout'.format(
|
||||
num=len(imports),
|
||||
imports=", ".join([x['name'] for x in imports])
|
||||
))
|
||||
fmt = '{name}=={version}'
|
||||
print('\n'.join(fmt.format(**item) if item['version'] else '{name}'.format(**item)
|
||||
for item in imports))
|
||||
|
||||
def get_imports_info(imports, pypi_server="https://pypi.python.org/pypi/", proxy=None):
|
||||
result = []
|
||||
@ -241,10 +250,14 @@ def init(args):
|
||||
path = (args["--savepath"] if args["--savepath"] else
|
||||
os.path.join(args['<path>'], "requirements.txt"))
|
||||
|
||||
if not args["--savepath"] and not args["--force"] and os.path.exists(path):
|
||||
if not args["--print"] and not args["--savepath"] and not args["--force"] and os.path.exists(path):
|
||||
logging.warning("Requirements.txt already exists, "
|
||||
"use --force to overwrite it")
|
||||
return
|
||||
if args["--print"]:
|
||||
output_requirements(imports)
|
||||
logging.info("Successfully output requirements")
|
||||
else:
|
||||
generate_requirements_file(path, imports)
|
||||
logging.info("Successfully saved requirements file in " + path)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user