Skip to content

Commit d30f522

Browse files
authored
Merge pull request #67 from jelmer/ruff-format
Format with ruff
2 parents 0d676ed + 1f2ca88 commit d30f522

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+2668
-1897
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ jobs:
3737
python3 -m pip install -U wheel setuptools
3838
python3 -m pip install sphinx
3939
python3 -m pip install ".[test]"
40+
python3 -m pip install ruff
4041
4142
- name: Tests
4243
run: |
4344
python -W once -m testtools.run testrepository.tests.test_suite
4445
46+
- name: Check formatting
47+
run: |
48+
ruff format --check .
49+
4550
success:
4651
needs: build
4752
runs-on: ubuntu-latest

.testr.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[DEFAULT]
2-
test_command=${PYTHON:-python} -m subunit.run $LISTOPT $IDOPTION testrepository.tests.test_suite
2+
test_command=${PYTHON:-python3} -m subunit.run $LISTOPT $IDOPTION testrepository.tests.test_suite
33
test_id_option=--load-list $IDFILE
44
test_list_option=--list
55
;filter_tags=worker-0

testr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
#
33
# Copyright (c) 2009 Testrepository Contributors
44
#

testrepository/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2009 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the

testrepository/arguments/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2010 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -61,19 +61,18 @@ def __init__(self, name, min=1, max=1):
6161
def summary(self):
6262
"""Get a regex-like summary of this argument."""
6363
result = self.name
64-
if (self.minimum_count == self.maximum_count and
65-
self.minimum_count == 1):
66-
return result
64+
if self.minimum_count == self.maximum_count and self.minimum_count == 1:
65+
return result
6766
minmax = (self.minimum_count, self.maximum_count)
6867
if minmax == (0, 1):
69-
return result + '?'
68+
return result + "?"
7069
if minmax == (1, None):
71-
return result + '+'
70+
return result + "+"
7271
if minmax == (0, None):
73-
return result + '*'
72+
return result + "*"
7473
if minmax[1] == None:
75-
minmax = (minmax[0], '')
76-
return result + '{%s,%s}' % minmax
74+
minmax = (minmax[0], "")
75+
return result + "{%s,%s}" % minmax
7776

7877
def parse(self, argv):
7978
"""Evaluate arguments in argv.
@@ -87,7 +86,8 @@ def parse(self, argv):
8786
result = []
8887
error = None
8988
while len(argv) > count and (
90-
self.maximum_count is None or count < self.maximum_count):
89+
self.maximum_count is None or count < self.maximum_count
90+
):
9191
arg = argv[count]
9292
count += 1
9393
try:
@@ -100,13 +100,13 @@ def parse(self, argv):
100100
if count < self.minimum_count:
101101
if error is not None:
102102
raise error[1].with_traceback(error[2])
103-
raise ValueError('not enough arguments present/matched in %s' % argv)
103+
raise ValueError("not enough arguments present/matched in %s" % argv)
104104
del argv[:count]
105105
return result
106106

107107
def _parse_one(self, arg):
108108
"""Parse a single argument.
109-
109+
110110
:param arg: An arg from an argv.
111111
:result: The parsed argument.
112112
:raises ValueError: If the arg cannot be parsed/validated.

testrepository/arguments/command.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2010 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -19,10 +19,10 @@
1919

2020

2121
class CustomError(ValueError):
22-
2322
def __str__(self):
2423
return self.args[0]
2524

25+
2626
class CommandArgument(AbstractArgument):
2727
"""An argument that looks up a command."""
2828

testrepository/arguments/doubledash.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2012 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -21,9 +21,9 @@ class DoubledashArgument(AbstractArgument):
2121
"""An argument that captures '--'."""
2222

2323
def __init__(self):
24-
super(DoubledashArgument, self).__init__('doubledash', min=0)
24+
super(DoubledashArgument, self).__init__("doubledash", min=0)
2525

2626
def _parse_one(self, arg):
27-
if arg != '--':
28-
raise ValueError('not a doubledash %r' % (arg,))
27+
if arg != "--":
28+
raise ValueError("not a doubledash %r" % (arg,))
2929
return arg

testrepository/arguments/path.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2012 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -23,8 +23,8 @@ class ExistingPathArgument(AbstractArgument):
2323
"""An argument that stores a string verbatim."""
2424

2525
def _parse_one(self, arg):
26-
if arg == '--':
27-
raise ValueError('-- is not a valid argument')
26+
if arg == "--":
27+
raise ValueError("-- is not a valid argument")
2828
if not os.path.exists(arg):
29-
raise ValueError('No such path %r' % (arg,))
29+
raise ValueError("No such path %r" % (arg,))
3030
return arg

testrepository/arguments/string.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2010 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -21,6 +21,6 @@ class StringArgument(AbstractArgument):
2121
"""An argument that stores a string verbatim."""
2222

2323
def _parse_one(self, arg):
24-
if arg == '--':
25-
raise ValueError('-- is not a valid argument')
24+
if arg == "--":
25+
raise ValueError("-- is not a valid argument")
2626
return arg

testrepository/commands/__init__.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#
22
# Copyright (c) 2009, 2010 Testrepository Contributors
3-
#
3+
#
44
# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause
55
# license at the users choice. A copy of both licenses are available in the
66
# project source as Apache-2.0 and BSD. You may not use this file except in
77
# compliance with one of these two licences.
8-
#
8+
#
99
# Unless required by applicable law or agreed to in writing, software
1010
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -19,7 +19,7 @@
1919
2020
Actual commands can be found in testrepository.commands.$commandname.
2121
22-
For example, testrepository.commands.init is the init command name, and
22+
For example, testrepository.commands.init is the init command name, and
2323
testrepository.command.show_stats would be the show-stats command (if one
2424
existed). The Command discovery logic looks for a class in the module with
2525
the same name - e.g. tesrepository.commands.init.init would be the class.
@@ -41,9 +41,10 @@
4141

4242
from testrepository.repository import file
4343

44+
4445
def _find_command(cmd_name):
4546
orig_cmd_name = cmd_name
46-
cmd_name = cmd_name.replace('-', '_')
47+
cmd_name = cmd_name.replace("-", "_")
4748
classname = "%s" % cmd_name
4849
modname = "testrepository.commands.%s" % cmd_name
4950
try:
@@ -54,8 +55,9 @@ def _find_command(cmd_name):
5455
if result is None:
5556
raise KeyError(
5657
"Malformed command module - no command class %s found in module %s."
57-
% (classname, modname))
58-
if getattr(result, 'name', None) is None:
58+
% (classname, modname)
59+
)
60+
if getattr(result, "name", None) is None:
5961
# Store the name for the common case of name == lookup path.
6062
result.name = orig_cmd_name
6163
return result
@@ -69,13 +71,13 @@ def iter_commands():
6971
# For now, only support regular installs. TODO: support zip, eggs.
7072
for filename in os.listdir(path):
7173
base = os.path.basename(filename)
72-
if base.startswith('.'):
74+
if base.startswith("."):
7375
continue
74-
name = base.split('.', 1)[0]
75-
name = name.replace('_', '-')
76+
name = base.split(".", 1)[0]
77+
name = name.replace("_", "-")
7678
names.add(name)
77-
names.discard('--init--')
78-
names.discard('--pycache--')
79+
names.discard("--init--")
80+
names.discard("--pycache--")
7981
names = sorted(names)
8082
for name in names:
8183
yield _find_command(name)
@@ -91,7 +93,7 @@ class Command(object):
9193
:ivar ui: a UI object which is responsible for brokering the command
9294
arguments, input and output. There is no default ui, it must be
9395
passed to the constructor.
94-
96+
9597
:ivar repository_factory: a repository factory which is used to create or
9698
open repositories. The default repository factory is suitable for
9799
use in the command line tool.
@@ -129,7 +131,7 @@ def execute(self):
129131
This interrogates the UI to ensure that arguments and options are
130132
supplied, performs any validation for the same that the command needs
131133
and finally calls run() to perform the command. Most commands should
132-
not need to override this method, and any user wanting to run a
134+
not need to override this method, and any user wanting to run a
133135
command should call this method.
134136
135137
This is a synchronous method, and basically just a helper. GUI's or
@@ -150,7 +152,7 @@ def execute(self):
150152

151153
@classmethod
152154
def get_summary(klass):
153-
docs = klass.__doc__.split('\n')
155+
docs = klass.__doc__.split("\n")
154156
return docs[0]
155157

156158
def _init(self):
@@ -173,15 +175,16 @@ def run_argv(argv, stdin, stdout, stderr):
173175
cmd_name = None
174176
cmd_args = argv[1:]
175177
for arg in argv[1:]:
176-
if not arg.startswith('-'):
178+
if not arg.startswith("-"):
177179
cmd_name = arg
178180
break
179181
if cmd_name is None:
180-
cmd_name = 'help'
181-
cmd_args = ['help']
182+
cmd_name = "help"
183+
cmd_args = ["help"]
182184
cmd_args.remove(cmd_name)
183185
cmdclass = _find_command(cmd_name)
184186
from testrepository.ui import cli
187+
185188
ui = cli.UI(cmd_args, stdin, stdout, stderr)
186189
cmd = cmdclass(ui)
187190
result = cmd.execute()
@@ -203,11 +206,11 @@ def get_command_parser(cmd):
203206
parser = OptionParser()
204207
for option in cmd.options:
205208
parser.add_option(option)
206-
usage = '%%prog %(cmd)s [options] %(args)s\n\n%(help)s' % {
207-
'args': ' '.join(map(lambda x:x.summary(), cmd.args)),
208-
'cmd': getattr(cmd, 'name', cmd),
209-
'help': getdoc(cmd),
210-
}
209+
usage = "%%prog %(cmd)s [options] %(args)s\n\n%(help)s" % {
210+
"args": " ".join(map(lambda x: x.summary(), cmd.args)),
211+
"cmd": getattr(cmd, "name", cmd),
212+
"help": getdoc(cmd),
213+
}
211214
parser.set_usage(usage)
212215
return parser
213216

0 commit comments

Comments
 (0)