Merge branch 'master' into vendoring/enable-c-libs

This commit is contained in:
Pradyun Gedam 2017-11-07 15:38:07 +05:30
commit 945196e5f0
No known key found for this signature in database
GPG Key ID: DA17C4B29CB32E4B
14 changed files with 106 additions and 23 deletions

View File

@ -22,7 +22,9 @@ Console logging
~~~~~~~~~~~~~~~
pip offers :ref:`-v, --verbose <--verbose>` and :ref:`-q, --quiet <--quiet>`
to control the console log level.
to control the console log level. By default, some messages (error and warnings)
are colored in the terminal. If you want to suppress the colored output use
:ref:`--no-color <--no-color>`.
.. _`FileLogging`:

View File

@ -728,7 +728,7 @@ change without notice. While we do try not to break things as much as possible,
the internal APIs can change at any time, for any reason. It also means that we
generally *won't* fix issues that are a result of using pip in an unsupported way.
It should also be noted that modifying the contents of ``sys.path`` in a running Python
It should also be noted that installing packages into ``sys.path`` in a running Python
process is something that should only be done with care. The import system caches
certain data, and installing new packages while a program is running may not always
behave as expected. In practice, there is rarely an issue, but it is something to be
@ -756,7 +756,5 @@ of ability. Some examples that you could consider include:
* ``setuptools`` (specifically ``pkg_resources``) - Functions for querying what
packages the user has installed on their system.
* ``wheel`` - Code for manipulating (creating, querying and installing) wheels.
* ``distlib`` - Packaging and distribution utilities (including functions for
interacting with PyPI).

2
news/2449.feature Normal file
View File

@ -0,0 +1,2 @@
Add `--no-color` to `pip`. All colored output is disabled
if this flag is detected.

1
news/3016.feature Normal file
View File

@ -0,0 +1 @@
pip uninstall now ignores the absence of a requirement and prints a warning.

1
news/4642.feature Normal file
View File

@ -0,0 +1 @@
pip uninstall now ignores the absence of a requirement and prints a warning.

View File

@ -132,6 +132,11 @@ class Command(object):
if options.log:
root_level = "DEBUG"
if options.no_color:
logger_class = "logging.StreamHandler"
else:
logger_class = "pip._internal.utils.logging.ColorizedStreamHandler"
logging.config.dictConfig({
"version": 1,
"disable_existing_loggers": False,
@ -150,16 +155,14 @@ class Command(object):
"handlers": {
"console": {
"level": level,
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"class": logger_class,
"stream": self.log_streams[0],
"filters": ["exclude_warnings"],
"formatter": "indent",
},
"console_errors": {
"level": "WARNING",
"class":
"pip._internal.utils.logging.ColorizedStreamHandler",
"class": logger_class,
"stream": self.log_streams[1],
"formatter": "indent",
},

View File

@ -102,6 +102,15 @@ verbose = partial(
help='Give more output. Option is additive, and can be used up to 3 times.'
)
no_color = partial(
Option,
'--no-color',
dest='no_color',
action='store_true',
default=False,
help="Suppress colored output",
)
version = partial(
Option,
'-V', '--version',
@ -566,6 +575,7 @@ general_group = {
cache_dir,
no_cache,
disable_pip_version_check,
no_color,
]
}

View File

@ -64,7 +64,8 @@ class UninstallCommand(Command):
'"pip help %(name)s")' % dict(name=self.name)
)
for req in reqs_to_uninstall.values():
req.uninstall(
uninstall_pathset = req.uninstall(
auto_confirm=options.yes, verbose=options.verbose != 0
)
req.uninstalled_pathset.commit()
if uninstall_pathset:
uninstall_pathset.commit()

View File

@ -648,13 +648,13 @@ class InstallRequirement(object):
"""
if not self.check_if_exists():
raise UninstallationError(
"Cannot uninstall requirement %s, not installed" % (self.name,)
)
logger.warning("Skipping %s as it is not installed.", self.name)
return
dist = self.satisfied_by or self.conflicts_with
self.uninstalled_pathset = UninstallPathSet.from_dist(dist)
self.uninstalled_pathset.remove(auto_confirm, verbose)
uninstalled_pathset = UninstallPathSet.from_dist(dist)
uninstalled_pathset.remove(auto_confirm, verbose)
return uninstalled_pathset
def archive(self, build_dir):
assert self.source_dir

View File

@ -216,7 +216,9 @@ class RequirementSet(object):
requirement.conflicts_with,
)
with indent_log():
requirement.uninstall(auto_confirm=True)
uninstalled_pathset = requirement.uninstall(
auto_confirm=True
)
try:
requirement.install(
install_options,
@ -231,7 +233,7 @@ class RequirementSet(object):
)
# if install did not succeed, rollback previous uninstall
if should_rollback:
requirement.uninstalled_pathset.rollback()
uninstalled_pathset.rollback()
raise
else:
should_commit = (
@ -239,7 +241,7 @@ class RequirementSet(object):
requirement.install_succeeded
)
if should_commit:
requirement.uninstalled_pathset.commit()
uninstalled_pathset.commit()
requirement.remove_temporary_source()
return to_install

View File

@ -184,7 +184,7 @@ def test_git_with_tag_name_and_update(script, tmpdir):
result = script.pip(
'install', '-e', '%s#egg=pip-test-package' %
local_checkout(
'git+http://github.com/pypa/pip-test-package.git',
'git+https://github.com/pypa/pip-test-package.git',
tmpdir.join("cache"),
),
expect_error=True,
@ -194,7 +194,7 @@ def test_git_with_tag_name_and_update(script, tmpdir):
'install', '--global-option=--version', '-e',
'%s@0.1.2#egg=pip-test-package' %
local_checkout(
'git+http://github.com/pypa/pip-test-package.git',
'git+https://github.com/pypa/pip-test-package.git',
tmpdir.join("cache"),
),
expect_error=True,
@ -211,7 +211,7 @@ def test_git_branch_should_not_be_changed(script, tmpdir):
script.pip(
'install', '-e', '%s#egg=pip-test-package' %
local_checkout(
'git+http://github.com/pypa/pip-test-package.git',
'git+https://github.com/pypa/pip-test-package.git',
tmpdir.join("cache"),
),
expect_error=True,
@ -229,7 +229,7 @@ def test_git_with_non_editable_unpacking(script, tmpdir):
result = script.pip(
'install', '--global-option=--version',
local_checkout(
'git+http://github.com/pypa/pip-test-package.git@0.1.2'
'git+https://github.com/pypa/pip-test-package.git@0.1.2'
'#egg=pip-test-package',
tmpdir.join("cache")
),

View File

@ -0,0 +1,41 @@
"""
Test specific for the --no-color option
"""
import os
import platform
import subprocess as sp
import sys
import pytest
@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows")
def test_no_color(script):
"""
Test uninstalling an existing package - should out put red error
We must use subprocess with the script command, since redirection
in unix platform causes text coloring to disapper. Thus, we can't
use the testing infrastructure that other options has.
"""
sp.Popen("script --flush --quiet --return /tmp/colored-output.txt"
" --command \"pip uninstall noSuchPackage\"", shell=True,
stdout=sp.PIPE, stderr=sp.PIPE).communicate()
with open("/tmp/colored-output.txt", "r") as result:
assert "\x1b" in result.read()
os.unlink("/tmp/colored-output.txt")
sp.Popen("script --flush --quiet --return /tmp/no-color-output.txt"
" --command \"pip --no-color uninstall noSuchPackage\"",
shell=True,
stdout=sp.PIPE, stderr=sp.PIPE).communicate()
with open("/tmp/no-color-output.txt", "r") as result:
assert "\x1b" not in result.read()
os.unlink("/tmp/no-color-output.txt")

View File

@ -468,3 +468,25 @@ def test_uninstall_editable_and_pip_install(script, data):
) in uninstall2.files_deleted, list(uninstall2.files_deleted.keys())
list_result2 = script.pip('list', '--format=json')
assert "FSPkg" not in {p["name"] for p in json.loads(list_result2.stdout)}
def test_uninstall_ignores_missing_packages(script, data):
"""Uninstall of a non existent package prints a warning and exits cleanly
"""
result = script.pip(
'uninstall', '-y', 'non-existent-pkg', expect_stderr=True,
)
assert "Skipping non-existent-pkg as it is not installed." in result.stderr
assert result.returncode == 0, "Expected clean exit"
def test_uninstall_ignores_missing_packages_and_uninstalls_rest(script, data):
script.pip_install_local('simple')
result = script.pip(
'uninstall', '-y', 'non-existent-pkg', 'simple', expect_stderr=True,
)
assert "Skipping non-existent-pkg as it is not installed." in result.stderr
assert "Successfully uninstalled simple" in result.stdout
assert result.returncode == 0, "Expected clean exit"

View File

@ -4,7 +4,7 @@ envlist =
py27, py33, py34, py35, py36, py37, pypy
[testenv]
passenv = GIT_SSL_CAINFO
passenv = CI GIT_SSL_CAINFO
setenv =
# This is required in order to get UTF-8 output inside of the subprocesses
# that our tests use.