From c888100470da507c6762c05f8d22306468828de8 Mon Sep 17 00:00:00 2001 From: nrhine1 Date: Fri, 5 Feb 2016 10:57:26 -0500 Subject: [PATCH] added ignore option --- pipreqs/pipreqs.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index a3dd64f..a8e4d4c 100755 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -13,6 +13,7 @@ Options: $ export HTTP_PROXY="http://10.10.1.10:3128" $ export HTTPS_PROXY="https://10.10.1.10:1080" --debug Print debug information + --ignore ... Ignore extra directories --encoding Use encoding parameter for file open --savepath Save the list of requirements in the given file --force Overwrite existing requirements.txt @@ -43,12 +44,13 @@ else: open_func = codecs.open -def get_all_imports(path, encoding=None): +def get_all_imports(path, encoding=None, extra_ignore_dirs = []): imports = set() raw_imports = set() candidates = [] ignore_errors = False ignore_dirs = [".hg", ".svn", ".git", "__pycache__", "env", "venv"] + ignore_dirs.extend(extra_ignore_dirs) for root, dirs, files in os.walk(path): dirs[:] = [d for d in dirs if d not in ignore_dirs] @@ -193,7 +195,11 @@ def join(f): def init(args): encoding = args.get('--encoding') - candidates = get_all_imports(args[''], encoding=encoding) + extra_ignore_dirs = args.get('--ignore', []) + + candidates = get_all_imports(args[''], + encoding=encoding, + extra_ignore_dirs = extra_ignore_dirs) candidates = get_pkg_names(candidates) logging.debug("Found imports: " + ", ".join(candidates)) pypi_server = "https://pypi.python.org/pypi/"