diff --git a/.gitignore b/.gitignore index 45a067a..57eefd5 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ Session.vim *~ /pipreqs/*.bak +.vscode/ diff --git a/README.rst b/README.rst index fd4b363..e224999 100644 --- a/README.rst +++ b/README.rst @@ -45,6 +45,8 @@ Usage environments parameter in your terminal: $ export HTTP_PROXY="http://10.10.1.10:3128" $ export HTTPS_PROXY="https://10.10.1.10:1080" + --trusted-host Ignore SSL warnings, recommended using with + enterprise proxy. --debug Print debug information --ignore ... Ignore extra directories, each separated by a comma --no-follow-links Do not follow symbolic links in the project diff --git a/pipreqs/pipreqs.py b/pipreqs/pipreqs.py index 24eeeb7..7175320 100644 --- a/pipreqs/pipreqs.py +++ b/pipreqs/pipreqs.py @@ -18,6 +18,8 @@ Options: parameter in your terminal: $ export HTTP_PROXY="http://10.10.1.10:3128" $ export HTTPS_PROXY="https://10.10.1.10:1080" + --trusted-host Ignore SSL warnings, recommended using with + enterprise proxy. --debug Print debug information --ignore ... Ignore extra directories, each separated by a comma --no-follow-links Do not follow symbolic links in the project @@ -47,6 +49,8 @@ from docopt import docopt import requests from yarg import json2package from yarg.exceptions import HTTPError +from urllib3 import disable_warnings +from urllib3.exceptions import InsecureRequestWarning from pipreqs import __version__ @@ -171,13 +175,15 @@ def output_requirements(imports, symbol): def get_imports_info( - imports, pypi_server="https://pypi.python.org/pypi/", proxy=None): + imports, pypi_server="https://pypi.python.org/pypi/", proxy=None, + verify_ssl=True): result = [] for item in imports: try: response = requests.get( - "{0}{1}/json".format(pypi_server, item), proxies=proxy) + "{0}{1}/json".format(pypi_server, item), proxies=proxy, + verify=verify_ssl) if response.status_code == 200: if hasattr(response.content, 'decode'): data = json2package(response.content.decode()) @@ -405,6 +411,7 @@ def init(args): encoding = args.get('--encoding') extra_ignore_dirs = args.get('--ignore') follow_links = not args.get('--no-follow-links') + verify_ssl = not args.get('--trusted-host') input_path = args[''] if input_path is None: input_path = os.path.abspath(os.curdir) @@ -412,6 +419,9 @@ def init(args): if extra_ignore_dirs: extra_ignore_dirs = extra_ignore_dirs.split(',') + if not verify_ssl: + disable_warnings(InsecureRequestWarning) + candidates = get_all_imports(input_path, encoding=encoding, extra_ignore_dirs=extra_ignore_dirs, @@ -438,7 +448,9 @@ def init(args): if x.lower() not in [z['name'].lower() for z in local]] imports = local + get_imports_info(difference, proxy=proxy, - pypi_server=pypi_server) + pypi_server=pypi_server, + verify_ssl=verify_ssl) + # sort imports based on lowercase name of package, similar to `pip freeze`. imports = sorted(imports, key=lambda x: x['name'].lower())