mirror of
https://github.com/bndr/pipreqs.git
synced 2025-06-06 03:25:21 +00:00
Add and implement function diff, improve inline comments in function parse_requirements
This commit is contained in:
parent
a78203dc2b
commit
7549b1c416
@ -18,6 +18,7 @@ Options:
|
||||
--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
|
||||
--diff <file> Compare modules in requirements.txt to project imports.
|
||||
"""
|
||||
from __future__ import print_function, absolute_import
|
||||
import os
|
||||
@ -289,6 +290,14 @@ def compare_modules(file_, imports):
|
||||
return modules_not_imported
|
||||
|
||||
|
||||
def diff(file_, imports):
|
||||
"""Display the difference between modules in file a and imported modules."""
|
||||
modules_not_imported = compare_modules(file_, imports)
|
||||
|
||||
logging.info("The following modules are in {} but do not seem to be imported: "
|
||||
"{}".format(file_, ", ".join(x for x in modules_not_imported)))
|
||||
|
||||
|
||||
def init(args):
|
||||
encoding = args.get('--encoding')
|
||||
extra_ignore_dirs = args.get('--ignore')
|
||||
@ -326,6 +335,10 @@ def init(args):
|
||||
path = (args["--savepath"] if args["--savepath"] else
|
||||
os.path.join(args['<path>'], "requirements.txt"))
|
||||
|
||||
if args["--diff"]:
|
||||
diff(args["--diff"], imports)
|
||||
return
|
||||
|
||||
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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user