Skip to content

Commit 480c7f8

Browse files
committed
Finished removing all dependencies on the six module
1 parent 6b23d7e commit 480c7f8

8 files changed

Lines changed: 24 additions & 41 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
## 0.9.0 (TBD, 2018)
2+
* Enhancements
3+
* ``cmd2`` no longer depends on the ``six`` module
24
* Deletions (potentially breaking changes)
35
* Deleted all ``optparse`` code which had previously been deprecated in release 0.8.0
46
* The ``options`` decorator no longer exists

CONTRIBUTING.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ The tables below list all prerequisites along with the minimum required version
4545
| Prerequisite | Minimum Version |
4646
| --------------------------------------------------- | --------------- |
4747
| [Python](https://www.python.org/downloads/) | `3.4` |
48-
| [six](https://pypi.python.org/pypi/six) | `1.8` |
4948
| [pyparsing](http://pyparsing.wikispaces.com) | `2.1` |
5049
| [pyperclip](https://github.com/asweigart/pyperclip) | `1.6` |
5150

@@ -72,7 +71,6 @@ If Python is already installed in your machine, run the following commands to va
7271

7372
```shell
7473
python -V
75-
pip freeze | grep six
7674
pip freeze | grep pyparsing
7775
```
7876

@@ -192,7 +190,7 @@ Once you have cmd2 cloned, before you start any cmd2 application, you first need
192190

193191
```bash
194192
# Install cmd2 prerequisites
195-
pip install -U six pyparsing pyperclip
193+
pip install -U pyparsing pyperclip
196194

197195
# Install prerequisites for running cmd2 unit tests
198196
pip install -U pytest

cmd2.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import pyparsing
5454
import pyperclip
5555
from pyperclip import PyperclipException
56-
import six.moves as sm # Used for sm.input
5756

5857
# Collection is a container that is sizable and iterable
5958
# It was introduced in Python 3.6. We will try to import it, otherwise use our implementation
@@ -2402,9 +2401,9 @@ def pseudo_raw_input(self, prompt):
24022401
if self.use_rawinput:
24032402
try:
24042403
if sys.stdin.isatty():
2405-
line = sm.input(safe_prompt)
2404+
line = input(safe_prompt)
24062405
else:
2407-
line = sm.input()
2406+
line = input()
24082407
if self.echo:
24092408
sys.stdout.write('{}{}\n'.format(safe_prompt, line))
24102409
except EOFError:
@@ -2798,7 +2797,7 @@ def select(self, opts, prompt='Your choice? '):
27982797
for (idx, (value, text)) in enumerate(fulloptions):
27992798
self.poutput(' %2d. %s\n' % (idx + 1, text))
28002799
while True:
2801-
response = sm.input(prompt)
2800+
response = input(prompt)
28022801
hlen = readline.get_current_history_length()
28032802
if hlen >= 1 and response != '':
28042803
readline.remove_history_item(hlen - 1)

docs/install.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ either composition or inheritance to achieve the same goal.
9898
This approach will obviously NOT automatically install the required 3rd-party dependencies, so you need to make sure
9999
the following Python packages are installed:
100100

101-
* six
102101
* pyparsing
103102
* pyperclip
104103

docs/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pyparsing
2-
six
32
pyperclip
43
contextlib2
54
enum34

tests/test_cmd2.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
Released under MIT license, see LICENSE file
77
"""
88
import argparse
9+
import builtins
910
from code import InteractiveConsole
1011
import os
1112
import sys
1213
import io
1314
import tempfile
1415

1516
import pytest
16-
import six
17-
import six.moves as sm
1817

1918
# Python 3.5 had some regressions in the unitest.mock module, so use 3rd party mock if available
2019
try:
@@ -839,7 +838,7 @@ def test_base_cmdloop_without_queue():
839838

840839
# Mock out the input call so we don't actually wait for a user's response on stdin
841840
m = mock.MagicMock(name='input', return_value='quit')
842-
sm.input = m
841+
builtins.input = m
843842

844843
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
845844
testargs = ["prog"]
@@ -861,7 +860,7 @@ def test_cmdloop_without_rawinput():
861860

862861
# Mock out the input call so we don't actually wait for a user's response on stdin
863862
m = mock.MagicMock(name='input', return_value='quit')
864-
sm.input = m
863+
builtins.input = m
865864

866865
# Need to patch sys.argv so cmd2 doesn't think it was called with arguments equal to the py.test args
867866
testargs = ["prog"]
@@ -916,7 +915,7 @@ def test_interrupt_quit(say_app):
916915
# Mock out the input call so we don't actually wait for a user's response on stdin
917916
m = mock.MagicMock(name='input')
918917
m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof']
919-
sm.input = m
918+
builtins.input = m
920919

921920
say_app.cmdloop()
922921

@@ -930,7 +929,7 @@ def test_interrupt_noquit(say_app):
930929
# Mock out the input call so we don't actually wait for a user's response on stdin
931930
m = mock.MagicMock(name='input')
932931
m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof']
933-
sm.input = m
932+
builtins.input = m
934933

935934
say_app.cmdloop()
936935

@@ -1189,7 +1188,7 @@ def select_app():
11891188
def test_select_options(select_app):
11901189
# Mock out the input call so we don't actually wait for a user's response on stdin
11911190
m = mock.MagicMock(name='input', return_value='2')
1192-
sm.input = m
1191+
builtins.input = m
11931192

11941193
food = 'bacon'
11951194
out = run_cmd(select_app, "eat {}".format(food))
@@ -1210,7 +1209,7 @@ def test_select_invalid_option(select_app):
12101209
m = mock.MagicMock(name='input')
12111210
# If side_effect is an iterable then each call to the mock will return the next value from the iterable.
12121211
m.side_effect = ['3', '1'] # First pass and invalid selection, then pass a valid one
1213-
sm.input = m
1212+
builtins.input = m
12141213

12151214
food = 'fish'
12161215
out = run_cmd(select_app, "eat {}".format(food))
@@ -1232,7 +1231,7 @@ def test_select_invalid_option(select_app):
12321231
def test_select_list_of_strings(select_app):
12331232
# Mock out the input call so we don't actually wait for a user's response on stdin
12341233
m = mock.MagicMock(name='input', return_value='2')
1235-
sm.input = m
1234+
builtins.input = m
12361235

12371236
out = run_cmd(select_app, "study")
12381237
expected = normalize("""
@@ -1250,7 +1249,7 @@ def test_select_list_of_strings(select_app):
12501249
def test_select_list_of_tuples(select_app):
12511250
# Mock out the input call so we don't actually wait for a user's response on stdin
12521251
m = mock.MagicMock(name='input', return_value='2')
1253-
sm.input = m
1252+
builtins.input = m
12541253

12551254
out = run_cmd(select_app, "procrastinate")
12561255
expected = normalize("""
@@ -1269,7 +1268,7 @@ def test_select_list_of_tuples(select_app):
12691268
def test_select_uneven_list_of_tuples(select_app):
12701269
# Mock out the input call so we don't actually wait for a user's response on stdin
12711270
m = mock.MagicMock(name='input', return_value='2')
1272-
sm.input = m
1271+
builtins.input = m
12731272

12741273
out = run_cmd(select_app, "play")
12751274
expected = normalize("""
@@ -1352,7 +1351,7 @@ def test_multiline_complete_empty_statement_raises_exception(multiline_app):
13521351
def test_multiline_complete_statement_without_terminator(multiline_app):
13531352
# Mock out the input call so we don't actually wait for a user's response on stdin when it looks for more input
13541353
m = mock.MagicMock(name='input', return_value='\n')
1355-
sm.input = m
1354+
builtins.input = m
13561355

13571356
command = 'orate'
13581357
args = 'hello world'
@@ -1452,10 +1451,8 @@ def test_echo(capsys):
14521451
def test_pseudo_raw_input_tty_rawinput_true():
14531452
# use context managers so original functions get put back when we are done
14541453
# we dont use decorators because we need m_input for the assertion
1455-
with mock.patch('sys.stdin.isatty',
1456-
mock.MagicMock(name='isatty', return_value=True)):
1457-
with mock.patch('six.moves.input',
1458-
mock.MagicMock(name='input', side_effect=['set', EOFError])) as m_input:
1454+
with mock.patch('sys.stdin.isatty', mock.MagicMock(name='isatty', return_value=True)):
1455+
with mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError])) as m_input:
14591456
# run the cmdloop, which should pull input from our mocks
14601457
app = cmd2.Cmd()
14611458
app.use_rawinput = True
@@ -1498,21 +1495,17 @@ def piped_rawinput_true(capsys, echo, command):
14981495
out, err = capsys.readouterr()
14991496
return (app, out)
15001497

1501-
# using the decorator puts the original function at six.moves.input
1502-
# back when this method returns
1503-
@mock.patch('six.moves.input',
1504-
mock.MagicMock(name='input', side_effect=['set', EOFError]))
1498+
# using the decorator puts the original input function back when this unit test returns
1499+
@mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError]))
15051500
def test_pseudo_raw_input_piped_rawinput_true_echo_true(capsys):
15061501
command = 'set'
15071502
app, out = piped_rawinput_true(capsys, True, command)
15081503
out = out.splitlines()
15091504
assert out[0] == '{}{}'.format(app.prompt, command)
15101505
assert out[1].startswith('colors:')
15111506

1512-
# using the decorator puts the original function at six.moves.input
1513-
# back when this method returns
1514-
@mock.patch('six.moves.input',
1515-
mock.MagicMock(name='input', side_effect=['set', EOFError]))
1507+
# using the decorator puts the original input function back when this unit test returns
1508+
@mock.patch('builtins.input', mock.MagicMock(name='input', side_effect=['set', EOFError]))
15161509
def test_pseudo_raw_input_piped_rawinput_true_echo_false(capsys):
15171510
command = 'set'
15181511
app, out = piped_rawinput_true(capsys, False, command)
@@ -1554,7 +1547,7 @@ def test_raw_input(base_app):
15541547

15551548
# Mock out the input call so we don't actually wait for a user's response on stdin
15561549
m = mock.Mock(name='input', return_value=fake_input)
1557-
sm.input = m
1550+
builtins.input = m
15581551

15591552
line = base_app.pseudo_raw_input('(cmd2)')
15601553
assert line == fake_input

tests/test_transcript.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from unittest import mock
1515
import pytest
16-
import six
1716

1817
import cmd2
1918
from cmd2 import Cmd, Cmd2TestCase, set_posix_shlex, set_strip_quotes

tox.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ deps =
1818
pytest-cov
1919
pytest-forked
2020
pytest-xdist
21-
six
2221
wcwidth
2322
commands =
2423
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
@@ -32,7 +31,6 @@ deps =
3231
pytest
3332
pytest-forked
3433
pytest-xdist
35-
six
3634
wcwidth
3735
commands = py.test -v -n2 --forked
3836

@@ -44,7 +42,6 @@ deps =
4442
pyreadline
4543
pytest
4644
pytest-xdist
47-
six
4845
commands = py.test -v -n2
4946

5047
[testenv:py36]
@@ -56,7 +53,6 @@ deps =
5653
pytest-cov
5754
pytest-forked
5855
pytest-xdist
59-
six
6056
wcwidth
6157
commands =
6258
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing --forked
@@ -71,7 +67,6 @@ deps =
7167
pytest
7268
pytest-cov
7369
pytest-xdist
74-
six
7570
commands =
7671
py.test {posargs: -n 2} --cov=cmd2 --cov-report=term-missing
7772
codecov
@@ -83,7 +78,6 @@ deps =
8378
pytest
8479
pytest-forked
8580
pytest-xdist
86-
six
8781
wcwidth
8882
commands = py.test -v -n2 --forked
8983

0 commit comments

Comments
 (0)