Skip to content

Commit

Permalink
Write warnings to stderr during resolution
Browse files Browse the repository at this point in the history
- Fixes #3273

Signed-off-by: Dan Ryan <[email protected]>
  • Loading branch information
techalchemy committed Nov 21, 2018
1 parent 02dee12 commit 18f8c0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/3273.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 12 additions & 1 deletion pipenv/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -462,13 +468,19 @@ 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,
)
resolver = Resolver(constraints, req_dir, project, sources, clear=clear, pre=pre)
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)


Expand Down Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 18f8c0a

Please sign in to comment.