Skip to content

Commit d06b0e5

Browse files
authored
Merge pull request #115 from robotpy/black
Format code with black
2 parents e1b4aab + 7f0cce5 commit d06b0e5

Some content is hidden

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

45 files changed

+1235
-1076
lines changed

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ install:
2121
script:
2222
- tests/run_tests.sh
2323

24+
jobs:
25+
include:
26+
- stage: format-check
27+
python:
28+
- "3.6"
29+
install:
30+
- pip install black
31+
script:
32+
- black --check --diff .
33+
2434
deploy:
2535
- provider: pypi
2636
user: $PYPI_USERNAME

commandbased/cancelcommand.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,28 @@ def checkIfCanceled(self):
1010

1111

1212
class CancelCommand(Command):
13-
'''
13+
"""
1414
When this command is run, it cancels the command it was passed, even if that
1515
command is part of a :class:`wpilib.CommandGroup`.
16-
'''
17-
16+
"""
1817

1918
def __init__(self, command):
20-
'''
19+
"""
2120
:param command: The :class:`wpilib.Command` to cancel.
22-
'''
23-
super().__init__('Cancel %s' % command)
21+
"""
22+
super().__init__("Cancel %s" % command)
2423

2524
self.command = command
26-
if hasattr(self.command, '_isFinished'):
25+
if hasattr(self.command, "_isFinished"):
2726
return
2827

2928
self.command._isFinished = self.command.isFinished
3029
self.command.isFinished = checkIfCanceled.__get__(self.command)
3130
self.command.forceCancel = False
3231

33-
3432
def initialize(self):
3533
if self.command.isRunning():
3634
self.command.forceCancel = True
3735

38-
3936
def isFinished(self):
4037
return not self.command.isRunning()

commandbased/commandbasedrobot.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44

55
class CommandBasedRobot(TimedRobot):
6-
'''
6+
"""
77
The base class for a Command-Based Robot. To use, instantiate commands and
88
trigger them.
9-
'''
9+
"""
1010

1111
def startCompetition(self):
1212
"""Initalizes the scheduler before starting robotInit()"""
@@ -15,18 +15,18 @@ def startCompetition(self):
1515
super().startCompetition()
1616

1717
def commandPeriodic(self):
18-
'''
18+
"""
1919
Run the scheduler regularly. If an error occurs during a competition,
2020
prevent it from crashing the program.
21-
'''
21+
"""
2222

2323
try:
2424
self.scheduler.run()
2525
except Exception as error:
2626
if not self.ds.isFMSAttached():
2727
raise
2828

29-
'''Just to be safe, stop all running commands.'''
29+
"""Just to be safe, stop all running commands."""
3030
self.scheduler.removeAll()
3131

3232
self.handleCrash(error)
@@ -37,10 +37,10 @@ def commandPeriodic(self):
3737
# testPeriodic deliberately omitted
3838

3939
def handleCrash(self, error):
40-
'''
40+
"""
4141
Called if an exception is raised in the Scheduler during a competition.
4242
Writes an error message to the driver station by default. If you want
4343
more complex behavior, override this method in your robot class.
44-
'''
44+
"""
4545

4646
self.ds.reportError(str(error), printTrace=True)

commandbased/conditionalcommand.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
11
from wpilib.command.commandgroup import CommandGroup
22

3-
class ConditionalCommand(CommandGroup):
43

4+
class ConditionalCommand(CommandGroup):
55
def __init__(self, name, onTrue=None, onFalse=None):
66
super().__init__(name)
77

88
self.onTrue = self._processCommand(onTrue)
99
self.onFalse = self._processCommand(onFalse)
1010

11-
1211
def _processCommand(self, cmd):
1312
if cmd is None:
1413
return []
1514

1615
with self.mutex:
1716
if self.locked:
18-
raise ValueError('Cannot add conditions to ConditionalCommand')
17+
raise ValueError("Cannot add conditions to ConditionalCommand")
1918

2019
for reqt in cmd.getRequirements():
2120
self.requires(reqt)
2221

2322
cmd.setParent(self)
24-
cmd = CommandGroup.Entry(
25-
cmd,
26-
CommandGroup.Entry.IN_SEQUENCE,
27-
None
28-
)
23+
cmd = CommandGroup.Entry(cmd, CommandGroup.Entry.IN_SEQUENCE, None)
2924
return [cmd]
3025

31-
3226
def _initialize(self):
3327
super()._initialize()
3428

commandbased/flowcontrol.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import inspect
1111

12-
__all__ = ['IF', 'ELIF', 'ELSE', 'WHILE', 'RETURN', 'BREAK']
12+
__all__ = ["IF", "ELIF", "ELSE", "WHILE", "RETURN", "BREAK"]
1313

1414

1515
def _getCommandGroup():
@@ -20,19 +20,15 @@ def _getCommandGroup():
2020
# https://stackoverflow.com/a/14694234
2121
stack = inspect.stack()
2222
frame = stack[2].frame
23-
while 'self' not in frame.f_locals:
23+
while "self" not in frame.f_locals:
2424
frame = frame.f_back
2525
if frame is None:
26-
raise ValueError(
27-
'Could not find calling class for %s' %
28-
stack[1].function
29-
)
26+
raise ValueError("Could not find calling class for %s" % stack[1].function)
3027

31-
cg = frame.f_locals['self']
28+
cg = frame.f_locals["self"]
3229
if not isinstance(cg, CommandGroup):
3330
raise ValueError(
34-
'%s may not be used outside of a CommandGroup' %
35-
stack[1].function
31+
"%s may not be used outside of a CommandGroup" % stack[1].function
3632
)
3733

3834
return cg
@@ -88,13 +84,13 @@ def _popIfStack(cg):
8884
cmd = None
8985
for x in reversed(cg._ifStack):
9086
if x[0]:
91-
cmd = ConditionalCommand('flowcontrolELIF', x[1], cmd)
87+
cmd = ConditionalCommand("flowcontrolELIF", x[1], cmd)
9288
cmd.condition = x[0]
9389

9490
else:
9591
cmd = x[1]
9692

97-
cmd = ConditionalCommand('flowcontrolIF', top[1], cmd)
93+
cmd = ConditionalCommand("flowcontrolIF", top[1], cmd)
9894
cmd.condition = top[0]
9995

10096
cg._addSequential(cmd)
@@ -182,7 +178,7 @@ def flowcontrolELIF(func):
182178
try:
183179
parent._ifStack.append((condition, cg))
184180
except AttributeError:
185-
raise ValueError('Cannot use ELIF without IF')
181+
raise ValueError("Cannot use ELIF without IF")
186182

187183
return flowcontrolELIF
188184

@@ -200,7 +196,7 @@ def ELSE(func):
200196
try:
201197
parent._ifStack.append((None, cg))
202198
except AttributeError:
203-
raise ValueError('Cannot use ELSE without IF')
199+
raise ValueError("Cannot use ELSE without IF")
204200

205201
_popIfStack(parent)
206202

@@ -232,10 +228,10 @@ def flowcontrolWHILE(func):
232228
def cancelLoop(self):
233229
self.getGroup().forceCancel = True
234230

235-
end = Command('END WHILE')
231+
end = Command("END WHILE")
236232
end.initialize = cancelLoop.__get__(end)
237233

238-
cond = ConditionalCommand('flowcontrolWHILE', cg, end)
234+
cond = ConditionalCommand("flowcontrolWHILE", cg, end)
239235
cond.condition = condition
240236
cond.forceCancel = False
241237
cond.isFinished = _restartWhile.__get__(cond)
@@ -266,18 +262,18 @@ def BREAK(steps=1):
266262
"""
267263

268264
if steps < 1:
269-
raise ValueError('Steps to BREAK cannot be < 1')
265+
raise ValueError("Steps to BREAK cannot be < 1")
270266

271267
parent = _getCommandGroup()
272268
source = _getSource(parent)
273269

274270
try:
275271
loop = source._currentLoop
276272
except AttributeError:
277-
raise ValueError('Cannot BREAK outside of a loop')
273+
raise ValueError("Cannot BREAK outside of a loop")
278274

279275
if loop is None:
280-
raise ValueError('Cannot BREAK outside of a loop')
276+
raise ValueError("Cannot BREAK outside of a loop")
281277

282278
# We can't use CancelCommand here, because the conditionalCommand attribute
283279
# isn't yet bound to the CommandGroup, so we find it at initialization time
@@ -290,14 +286,13 @@ def cancelLoop():
290286

291287
if loop is None:
292288
raise ValueError(
293-
'BREAK %i not possible with loop depth %i' %
294-
(steps, step)
289+
"BREAK %i not possible with loop depth %i" % (steps, step)
295290
)
296291

297292
step += 1
298293

299294
loop.conditionalCommand.forceCancel = True
300295

301-
breakLoop = Command('flowcontrolBREAK')
296+
breakLoop = Command("flowcontrolBREAK")
302297
breakLoop.initialize = cancelLoop
303298
parent.addSequential(breakLoop)

0 commit comments

Comments
 (0)