From 18f8c0a403fcec0859c762708d711bd9759c67ff Mon Sep 17 00:00:00 2001 From: Dan Ryan Date: Wed, 21 Nov 2018 13:09:46 -0500 Subject: [PATCH] Write warnings to stderr during resolution - Fixes #3273 Signed-off-by: Dan Ryan --- news/3273.bugfix.rst | 1 + pipenv/utils.py | 13 ++++++++++++- tests/integration/test_lock.py | 10 ++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 news/3273.bugfix.rst diff --git a/news/3273.bugfix.rst b/news/3273.bugfix.rst new file mode 100644 index 0000000000..6e4abee41f --- /dev/null +++ b/news/3273.bugfix.rst @@ -0,0 +1 @@ +Pipenv will ensure that warnings do not interfere with the resolution process by suppressing warnings' usage of standard output and writing to standard error instead. diff --git a/pipenv/utils.py b/pipenv/utils.py index 84a4c105f0..e1ed77b377 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -448,6 +448,12 @@ def _should_include_hash(ireq): return self.hashes +def _show_warning(message, category, filename, lineno, line): + warnings.showwarning(message=message, category=category, filename=filename, + lineno=lineno, file=sys.stderr, line=line) + sys.stderr.flush() + + def actually_resolve_deps( deps, index_lookup, @@ -462,6 +468,9 @@ def actually_resolve_deps( if not req_dir: req_dir = create_tracked_tempdir(suffix="-requirements", prefix="pipenv-") + warning_list = [] + + with warnings.catch_warnings(record=True) as warning_list: constraints = get_resolver_metadata( deps, index_lookup, markers_lookup, project, sources, ) @@ -469,6 +478,9 @@ def actually_resolve_deps( resolved_tree = resolver.resolve() hashes = resolver.resolve_hashes() + for warning in warning_list: + _show_warning(warning.message, warning.category, warning.filename, warning.lineno, + warning.line) return (resolved_tree, hashes, markers_lookup, resolver) @@ -844,7 +856,6 @@ def mkdir_p(newdir): raise - def is_required_version(version, specified_version): """Check to see if there's a hard requirement for version number provided in the Pipfile. diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index f2f0ac76d2..3605e553ee 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -503,3 +503,13 @@ def test_lock_with_incomplete_source(PipenvInstance, pypi): c = p.pipenv('install') assert c.return_code == 0 assert p.lockfile['_meta']['sources'] + + +@pytest.mark.lock +@pytest.mark.install +def test_lock_no_warnings(PipenvInstance, pypi): + with PipenvInstance(pypi=pypi, chdir=True) as p: + os.environ["PYTHONWARNINGS"] = str("once") + c = p.pipenv("install six") + assert c.return_code == 0 + assert "Warning" in c.err