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
|
--ignore <dirs>... Ignore extra directories, each separated by a comma
|
||||||
--encoding <charset> Use encoding parameter for file open
|
--encoding <charset> Use encoding parameter for file open
|
||||||
--savepath <file> Save the list of requirements in the given file
|
--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
|
--force Overwrite existing requirements.txt
|
||||||
"""
|
"""
|
||||||
from __future__ import print_function, absolute_import
|
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)
|
out_file.write('\n'.join(fmt.format(**item) if item['version'] else '{name}'.format(**item)
|
||||||
for item in imports) + '\n')
|
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):
|
def get_imports_info(imports, pypi_server="https://pypi.python.org/pypi/", proxy=None):
|
||||||
result = []
|
result = []
|
||||||
@ -241,12 +250,16 @@ def init(args):
|
|||||||
path = (args["--savepath"] if args["--savepath"] else
|
path = (args["--savepath"] if args["--savepath"] else
|
||||||
os.path.join(args['<path>'], "requirements.txt"))
|
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, "
|
logging.warning("Requirements.txt already exists, "
|
||||||
"use --force to overwrite it")
|
"use --force to overwrite it")
|
||||||
return
|
return
|
||||||
generate_requirements_file(path, imports)
|
if args["--print"]:
|
||||||
logging.info("Successfully saved requirements file in " + path)
|
output_requirements(imports)
|
||||||
|
logging.info("Successfully output requirements")
|
||||||
|
else:
|
||||||
|
generate_requirements_file(path, imports)
|
||||||
|
logging.info("Successfully saved requirements file in " + path)
|
||||||
|
|
||||||
|
|
||||||
def main(): # pragma: no cover
|
def main(): # pragma: no cover
|
||||||
|
Loading…
x
Reference in New Issue
Block a user