Repository: aws/aws-cli

Issue:
pip raises a pkg_resources.VersionConflict exception because colorama is 0.3.7 instead of 0.3.3
When I try to install awscli under Ubuntu 16.04 and python 3.5.1 (pip3) or python 2.7.11 (pip)  I get the VersionConflict  exception raised:

```
root@jeff-desktop:~# pip install awscli
Collecting awscli
  Downloading awscli-1.10.43-py2.py3-none-any.whl (969kB)
    100% |████████████████████████████████| 972kB 1.9MB/s 
Exception:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1006, in check_if_exists
    self.satisfied_by = pkg_resources.get_distribution(str(no_marker))
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 535, in get_distribution
    dist = get_provider(dist)
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 415, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/share/python-wheels/pkg_resources-0.0.0-py2.py3-none-any.whl/pkg_resources/__init__.py", line 695, in find
    raise VersionConflict(dist, req)
pkg_resources.VersionConflict: (colorama 0.3.7 (/usr/lib/python3/dist-packages), Requirement.parse('colorama<=0.3.3,>=0.2.5'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python3/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python3/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 448, in _prepare_file
    req_to_install, finder)
  File "/usr/lib/python3/dist-packages/pip/req/req_set.py", line 387, in _check_skip_installed
    req_to_install.check_if_exists()
  File "/usr/lib/python3/dist-packages/pip/req/req_install.py", line 1011, in check_if_exists
    self.req.project_name
AttributeError: 'Requirement' object has no attribute 'project_name'
You are using pip version 8.1.1, however version 8.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
root@jeff-desktop:~# 
```

I looked at colorama, it's up to 0.3.7  and it's kinda frustrating that this should crash over such a minor feature.  I got version 0.3.3 from https://pypi.python.org/pypi/colorama/0.3.3, untar'd it, ran 
`python setup.py install`.  Then I ran `pip install awscli`   and that worked properly.

Update colorama version
It seems like the current aws-cli requires colorama >=0.2.5 and <=0.3.3, but the current colorama stable version in 0.3.6.
From tickets #1698 and #1700 I guess some fix will have to be executed before it's possible to update

PS: From colorama [changelog](https://github.com/tartley/colorama/blob/master/CHANGELOG.rst), it seems like from v0.3.3 they just fixed bugs, so it should not create any problem for the update (unless awscli was using a colorama bug as if it was a feature)



Discussion:
Does downgrading via pip not work? You could also try installing via the bundled installer.

Either way, I think this means we need to either accept the breaking change from .3.3+ or find a way to fix the issue.

Jordon,

I didn't think of downgrading via pip, so I don't know the answer.  Is that
an important enough question that I should try the experiment?

My thinking at the moment is that however I downgraded colorama, that was
the work around to the problem.  Yes, in retrospect I probably did do it
the hard way, but it's done now.

I don't have a lot of expertise in some of the finer things you can do with
pip.  If you want me to, I can restore colorama to its original state,
verify that the problem returns, then use pip to downgrade, and verify that
that solves the issue.  That does seem like a lot of work.  But I defer to
your expertise - if you want me to do it, then I will do it.

Jeff

On Wed, Jun 29, 2016 at 10:00 AM, Jordon Phillips notifications@github.com
wrote:

> Does downgrading via pip not work? You could also try installing via the
> bundled installer.
> 
> Either way, I think this means we need to either accept the breaking
> change from .3.3+ or find a way to fix the issue.
> 
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> https://github.com/aws/aws-cli/issues/2043#issuecomment-229420657, or mute
> the thread
> https://github.com/notifications/unsubscribe/AAhhh2JLJU0DAfYlOp9pbeVMwk_7ORDkks5qQqS2gaJpZM4JAxNv
> .

## 

Jeff Silverman, linux sysadmin
nine two four   twentieth avenue east
Seattle, WA, nine eight one one two -3507
(253) 459-2318
jeffsilverm@gmail.c0m (note the zero!)
http://www.commercialventvac.com
See my portfolio of writings and talks
http://www.commercialventvac.com/portfolio.html

Any update on this? In the mean time, colorama 0.3.7 has been released and many distributions are starting to ship colorama 0.3.4 or higher (from Fedora 24, Ubuntu xenial, Debian stretch v0.3.7 is used).


Resolving patch:
diff --git a/awscli/table.py b/awscli/table.py
--- a/awscli/table.py
+++ b/awscli/table.py
@@ -161,9 +161,9 @@ def style_indentation_char(self, text):
 
 class ColorizedStyler(Styler):
     def __init__(self):
-        # autoreset allows us to not have to sent
-        # reset sequences for every string.
-        colorama.init(autoreset=True)
+        # `autoreset` allows us to not have to sent reset sequences for every
+        # string. `strip` lets us preserve color when redirecting.
+        colorama.init(autoreset=True, strip=False)
 
     def style_title(self, text):
         # Originally bold + underline
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@
 
 
 requires = ['botocore==1.4.36',
-            'colorama>=0.2.5,<=0.3.3',
+            'colorama>=0.2.5,<=0.3.7',
             'docutils>=0.10',
             'rsa>=3.1.2,<=3.5.0',
             's3transfer==0.0.1']


Test patch:
diff --git a/tests/functional/test_table.py b/tests/functional/test_table.py
new file mode 100644
--- /dev/null
+++ b/tests/functional/test_table.py
@@ -0,0 +1,35 @@
+# Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"). You
+# may not use this file except in compliance with the License. A copy of
+# the License is located at
+#
+#     http://aws.amazon.com/apache2.0/
+#
+# or in the "license" file accompanying this file. This file is
+# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
+# ANY KIND, either express or implied. See the License for the specific
+# language governing permissions and limitations under the License.
+from awscli.testutils import BaseAWSCommandParamsTest
+
+
+class TestColor(BaseAWSCommandParamsTest):
+
+    def test_pipe_color(self):
+        command = "s3api list-buckets --output table --color on"
+        self.parsed_response = {
+            "Owner": {
+                "DisplayName": "foo",
+                "ID": "bar"
+            },
+            "Buckets": [
+                {
+                    "CreationDate": "2016-06-15T16:49:44.000Z",
+                    "Name": "foo-bucket"
+                }
+            ]
+        }
+        stdout, stderr, rc = self.run_cmd(command, 0)
+        # `\x1b` is the ANSI color prefix character.
+        self.assertIn('\x1b', stdout)
+