Skip to content

Commit 301a1cd

Browse files
committed
black -l 160 *.py via scripts/linter
1 parent 580326a commit 301a1cd

22 files changed

+385
-468
lines changed

conftest.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
23
try:
34
import json
45
except ImportError:
@@ -15,25 +16,24 @@ def pytest_collect_file(path, parent):
1516

1617

1718
def parse_test(raw):
18-
raw = re.compile('#.*$', re.M).sub('', raw).strip()
19+
raw = re.compile("#.*$", re.M).sub("", raw).strip()
1920
if raw.startswith('"""'):
2021
raw = raw[3:]
2122

2223
for fixture in raw.split('r"""'):
23-
name = ''
24+
name = ""
2425
doc, _, body = fixture.partition('"""')
2526
cases = []
26-
for case in body.split('$')[1:]:
27-
argv, _, expect = case.strip().partition('\n')
27+
for case in body.split("$")[1:]:
28+
argv, _, expect = case.strip().partition("\n")
2829
expect = json.loads(expect)
29-
prog, _, argv = argv.strip().partition(' ')
30+
prog, _, argv = argv.strip().partition(" ")
3031
cases.append((prog, argv, expect))
3132

3233
yield name, doc, cases
3334

3435

3536
class DocoptTestFile(pytest.File):
36-
3737
def collect(self):
3838
raw = self.fspath.open().read()
3939
index = 1
@@ -46,7 +46,6 @@ def collect(self):
4646

4747

4848
class DocoptTestItem(pytest.Item):
49-
5049
def __init__(self, name, parent, doc, case):
5150
super(DocoptTestItem, self).__init__(name, parent)
5251
self.doc = doc
@@ -56,21 +55,23 @@ def runtest(self):
5655
try:
5756
result = docopt.docopt(self.doc, argv=self.argv)
5857
except docopt.DocoptExit:
59-
result = 'user-error'
58+
result = "user-error"
6059

6160
if self.expect != result:
6261
raise DocoptTestException(self, result)
6362

6463
def repr_failure(self, excinfo):
6564
"""Called when self.runtest() raises an exception."""
6665
if isinstance(excinfo.value, DocoptTestException):
67-
return "\n".join((
68-
"usecase execution failed:",
69-
self.doc.rstrip(),
70-
"$ %s %s" % (self.prog, self.argv),
71-
"result> %s" % json.dumps(excinfo.value.args[1]),
72-
"expect> %s" % json.dumps(self.expect),
73-
))
66+
return "\n".join(
67+
(
68+
"usecase execution failed:",
69+
self.doc.rstrip(),
70+
"$ %s %s" % (self.prog, self.argv),
71+
"result> %s" % json.dumps(excinfo.value.args[1]),
72+
"expect> %s" % json.dumps(self.expect),
73+
)
74+
)
7475

7576
def reportinfo(self):
7677
return self.fspath, 0, "usecase: %s" % self.name

examples/arguments_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@
2020
from docopt import docopt
2121

2222

23-
if __name__ == '__main__':
23+
if __name__ == "__main__":
2424
arguments = docopt(__doc__)
2525
print(arguments)

examples/calculator_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
from docopt import docopt
1818

1919

20-
if __name__ == '__main__':
20+
if __name__ == "__main__":
2121
arguments = docopt(__doc__)
2222
print(arguments)

examples/config_file_example.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@
99

1010
def load_json_config():
1111
import json
12+
1213
# Pretend that we load the following JSON file:
13-
source = '''
14+
source = """
1415
{"--force": true,
1516
"--timeout": "10",
1617
"--baud": "9600"}
17-
'''
18+
"""
1819
return json.loads(source)
1920

2021

@@ -31,23 +32,22 @@ def load_ini_config():
3132
config = ConfigParser(allow_no_value=True)
3233

3334
# Pretend that we load the following INI file:
34-
source = '''
35+
source = """
3536
[default-arguments]
3637
--force
3738
--baud=19200
3839
<host>=localhost
39-
'''
40+
"""
4041

4142
# ConfigParser requires a file-like object and
4243
# no leading whitespace.
43-
config_file = StringIO('\n'.join(source.split()))
44+
config_file = StringIO("\n".join(source.split()))
4445
config.readfp(config_file)
4546

4647
# ConfigParsers sets keys which have no value
4748
# (like `--force` above) to `None`. Thus we
4849
# need to substitute all `None` with `True`.
49-
return dict((key, True if value is None else value)
50-
for key, value in config.items('default-arguments'))
50+
return dict((key, True if value is None else value) for key, value in config.items("default-arguments"))
5151

5252

5353
def merge(dict_1, dict_2):
@@ -57,22 +57,22 @@ def merge(dict_1, dict_2):
5757
`dict_1` takes priority over `dict_2`.
5858
5959
"""
60-
return dict((str(key), dict_1.get(key) or dict_2.get(key))
61-
for key in set(dict_2) | set(dict_1))
60+
return dict((str(key), dict_1.get(key) or dict_2.get(key)) for key in set(dict_2) | set(dict_1))
6261

6362

64-
if __name__ == '__main__':
63+
if __name__ == "__main__":
6564
json_config = load_json_config()
6665
ini_config = load_ini_config()
67-
arguments = docopt(__doc__, version='0.1.1rc')
66+
arguments = docopt(__doc__, version="0.1.1rc")
6867

6968
# Arguments take priority over INI, INI takes priority over JSON:
7069
result = merge(arguments, merge(ini_config, json_config))
7170

7271
from pprint import pprint
73-
print('\nJSON config:')
72+
73+
print("\nJSON config:")
7474
pprint(json_config)
75-
print('\nINI config:')
75+
print("\nINI config:")
7676
pprint(ini_config)
77-
print('\nResult:')
77+
print("\nResult:")
7878
pprint(result)

examples/git/git.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,26 @@
2828
from docopt import docopt
2929

3030

31-
if __name__ == '__main__':
31+
if __name__ == "__main__":
3232

33-
args = docopt(__doc__,
34-
version='git version 1.7.4.4',
35-
options_first=True)
36-
print('global arguments:')
33+
args = docopt(__doc__, version="git version 1.7.4.4", options_first=True)
34+
print("global arguments:")
3735
print(args)
38-
print('command arguments:')
36+
print("command arguments:")
3937

40-
argv = [args['<command>']] + args['<args>']
41-
if args['<command>'] == 'add':
38+
argv = [args["<command>"]] + args["<args>"]
39+
if args["<command>"] == "add":
4240
# In case subcommand is implemented as python module:
4341
import git_add
42+
4443
print(docopt(git_add.__doc__, argv=argv))
45-
elif args['<command>'] == 'branch':
44+
elif args["<command>"] == "branch":
4645
# In case subcommand is a script in some other programming language:
47-
exit(call(['python', 'git_branch.py'] + argv))
48-
elif args['<command>'] in 'checkout clone commit push remote'.split():
46+
exit(call(["python", "git_branch.py"] + argv))
47+
elif args["<command>"] in "checkout clone commit push remote".split():
4948
# For the rest we'll just keep DRY:
50-
exit(call(['python', 'git_%s.py' % args['<command>']] + argv))
51-
elif args['<command>'] in ['help', None]:
52-
exit(call(['python', 'git.py', '--help']))
49+
exit(call(["python", "git_%s.py" % args["<command>"]] + argv))
50+
elif args["<command>"] in ["help", None]:
51+
exit(call(["python", "git.py", "--help"]))
5352
else:
54-
exit("%r is not a git.py command. See 'git help'." % args['<command>'])
53+
exit("%r is not a git.py command. See 'git help'." % args["<command>"])

examples/git/git_add.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
from docopt import docopt
2020

2121

22-
if __name__ == '__main__':
22+
if __name__ == "__main__":
2323
print(docopt(__doc__))

examples/git/git_branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
from docopt import docopt
3030

3131

32-
if __name__ == '__main__':
32+
if __name__ == "__main__":
3333
print(docopt(__doc__))

examples/git/git_checkout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@
1919
from docopt import docopt
2020

2121

22-
if __name__ == '__main__':
22+
if __name__ == "__main__":
2323
print(docopt(__doc__))

examples/git/git_clone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
from docopt import docopt
2727

2828

29-
if __name__ == '__main__':
29+
if __name__ == "__main__":
3030
print(docopt(__doc__))

examples/git/git_commit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@
4646
from docopt import docopt
4747

4848

49-
if __name__ == '__main__':
49+
if __name__ == "__main__":
5050
print(docopt(__doc__))

examples/git/git_push.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
from docopt import docopt
2424

2525

26-
if __name__ == '__main__':
26+
if __name__ == "__main__":
2727
print(docopt(__doc__))

examples/git/git_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
from docopt import docopt
1919

2020

21-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2222
arguments = docopt(__doc__)
2323
print(arguments)

examples/interactive_example.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def docopt_cmd(func):
2525
This decorator is used to simplify the try/except block and pass the result
2626
of the docopt parsing to the called action.
2727
"""
28+
2829
def fn(self, arg):
2930
try:
3031
opt = docopt(fn.__doc__, arg)
@@ -33,7 +34,7 @@ def fn(self, arg):
3334
# The DocoptExit is thrown when the args do not match.
3435
# We print a message to the user and the usage block.
3536

36-
print('Invalid Command!')
37+
print("Invalid Command!")
3738
print(e)
3839
return
3940

@@ -51,10 +52,9 @@ def fn(self, arg):
5152
return fn
5253

5354

54-
class MyInteractive (cmd.Cmd):
55-
intro = 'Welcome to my interactive program!' \
56-
+ ' (type help for a list of commands.)'
57-
prompt = '(my_program) '
55+
class MyInteractive(cmd.Cmd):
56+
intro = "Welcome to my interactive program!" + " (type help for a list of commands.)"
57+
prompt = "(my_program) "
5858
file = None
5959

6060
@docopt_cmd
@@ -76,12 +76,13 @@ def do_serial(self, arg):
7676
def do_quit(self, arg):
7777
"""Quits out of Interactive Mode."""
7878

79-
print('Good Bye!')
79+
print("Good Bye!")
8080
exit()
8181

82+
8283
opt = docopt(__doc__, sys.argv[1:])
8384

84-
if opt['--interactive']:
85+
if opt["--interactive"]:
8586
MyInteractive().cmdloop()
8687

8788
print(opt)

examples/naval_fate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
from docopt import docopt
2020

2121

22-
if __name__ == '__main__':
23-
arguments = docopt(__doc__, version='Naval Fate 2.0')
22+
if __name__ == "__main__":
23+
arguments = docopt(__doc__, version="Naval Fate 2.0")
2424
print(arguments)

examples/odd_even_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
from docopt import docopt
1111

1212

13-
if __name__ == '__main__':
13+
if __name__ == "__main__":
1414
arguments = docopt(__doc__)
1515
print(arguments)

examples/options_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
from docopt import docopt
3535

3636

37-
if __name__ == '__main__':
38-
arguments = docopt(__doc__, version='1.0.0rc2')
37+
if __name__ == "__main__":
38+
arguments = docopt(__doc__, version="1.0.0rc2")
3939
print(arguments)

examples/options_shortcut_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
from docopt import docopt
1616

1717

18-
if __name__ == '__main__':
19-
arguments = docopt(__doc__, version='1.0.0rc2')
18+
if __name__ == "__main__":
19+
arguments = docopt(__doc__, version="1.0.0rc2")
2020
print(arguments)

examples/quick_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
from docopt import docopt
88

99

10-
if __name__ == '__main__':
11-
arguments = docopt(__doc__, version='0.1.1rc')
10+
if __name__ == "__main__":
11+
arguments = docopt(__doc__, version="0.1.1rc")
1212
print(arguments)

examples/validation_example.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
import os
1212

1313
from docopt import docopt
14+
1415
try:
1516
from schema import Schema, And, Or, Use, SchemaError
1617
except ImportError:
17-
exit('This example requires that `schema` data-validation library'
18-
' is installed: \n pip install schema\n'
19-
'https://github.com/halst/schema')
18+
exit("This example requires that `schema` data-validation library" " is installed: \n pip install schema\n" "https://github.com/halst/schema")
2019

2120

22-
if __name__ == '__main__':
21+
if __name__ == "__main__":
2322
args = docopt(__doc__)
2423

25-
schema = Schema({
26-
'FILE': [Use(open, error='FILE should be readable')],
27-
'PATH': And(os.path.exists, error='PATH should exist'),
28-
'--count': Or(None, And(Use(int), lambda n: 0 < n < 5),
29-
error='--count=N should be integer 0 < N < 5')})
24+
schema = Schema(
25+
{
26+
"FILE": [Use(open, error="FILE should be readable")],
27+
"PATH": And(os.path.exists, error="PATH should exist"),
28+
"--count": Or(None, And(Use(int), lambda n: 0 < n < 5), error="--count=N should be integer 0 < N < 5"),
29+
}
30+
)
3031
try:
3132
args = schema.validate(args)
3233
except SchemaError as e:

scripts/linter

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
set -exu
3+
4+
find . -name '*.py' -exec dos2unix {} \;
5+
6+
find . -name '*.py' -exec black -l 160 {} \;

0 commit comments

Comments
 (0)