Skip to content

Commit 8e389c5

Browse files
authored
Fix python formatting everywhere (#1837)
1 parent 72a134c commit 8e389c5

39 files changed

+785
-454
lines changed

.flake8

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[flake8]
2+
extend-ignore = F704, F821, F401, F841
3+
exclude = .git,build,dist
4+
max-complexity = 20

.github/workflows/python-lint.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Lint Python Code Snippets
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
7+
jobs:
8+
python_lint:
9+
name: Check Python snippets in Markdown files
10+
continue-on-error: true
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Install Flake8 Markdown linter
16+
run: pip3 install flake8-markdown
17+
18+
- name: Markdown Lint
19+
run: flake8-markdown "docs/**/*.md"

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ python3 -m http.server 9000 --directory public
4343

4444
## Test the docs locally
4545

46+
To ensure all python snippets are properly formatted before creating a commit, install [flake8-markdown](https://github.com/johnfraney/flake8-markdown) and add the following like to `.git/hooks/pre-commit`:
47+
48+
```sh
49+
flake8-markdown $(git diff --diff-filter=d --name-only HEAD | grep '\.md$')
50+
```
51+
4652
To ensure your markdown is properly formatted, run `make markdowntest`.
4753

4854
To check for broken links run `make htmltest`.

docs/components/arm/_index.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,16 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
257257
```python {class="line-numbers linkable-line-numbers"}
258258
my_arm = Arm.from_robot(robot=robot, name="my_arm")
259259

260-
# Declare a list of values with your desired rotational value for each joint on the arm.
260+
# Declare a list of values with your desired rotational value for each joint on
261+
# the arm.
261262
degrees = [0.0, 45.0, 0.0, 0.0, 0.0]
262263

263264
# Declare a new JointPositions with these values.
264-
jointPos = arm.move_to_joint_positions(JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
265+
jointPos = arm.move_to_joint_positions(
266+
JointPositions(values=[0.0, 45.0, 0.0, 0.0, 0.0]))
265267

266268
# Move each joint of the arm to the position these values specify.
267-
await my_arm.move_to_joint_positions(positions= jointPos)
269+
await my_arm.move_to_joint_positions(positions=jointPos)
268270
```
269271

270272
{{% /tab %}}
@@ -425,14 +427,13 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
425427
my_arm = Arm.from_robot(robot=robot, name="my_arm")
426428

427429
# Get the kinematics information associated with the arm.
428-
kinematics := await my_arm.get_kinematics()
430+
kinematics = await my_arm.get_kinematics()
429431

430432
# Get the format of the kinematics file.
431433
k_file = kinematics[0]
432434

433435
# Get the byte contents of the file.
434436
k_bytes = kinematics[1]
435-
436437
```
437438

438439
{{% /tab %}}

docs/components/base/_index.md

+19-9
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,27 @@ my_base = Base.from_robot(robot=robot, name="my_base")
225225

226226
# Make your wheeled base move forward. Set linear power to 75%.
227227
print("move forward")
228-
await my_base.set_power(linear=Vector3(x=0,y=-.75,z=0), angular=Vector3(x=0,y=0,z=0))
228+
await my_base.set_power(
229+
linear=Vector3(x=0, y=-.75, z=0),
230+
angular=Vector3(x=0, y=0, z=0))
229231

230232
# Make your wheeled base move backward. Set linear power to -100%.
231233
print("move backward")
232-
await my_base.set_power(linear=Vector3(x=0,y=-1.0,z=0), angular=Vector3(x=0,y=0,z=0))
234+
await my_base.set_power(
235+
linear=Vector3(x=0, y=-1.0, z=0),
236+
angular=Vector3(x=0, y=0, z=0))
233237

234238
# Make your wheeled base spin left. Set angular power to 100%.
235239
print("spin left")
236-
await my_base.set_power(linear=Vector3(x=0,y=0,z=0), angular=Vector3(x=0,y=0,z=1))
240+
await my_base.set_power(
241+
linear=Vector3(x=0, y=0, z=0),
242+
angular=Vector3(x=0, y=0, z=1))
237243

238244
# Make your wheeled base spin right. Set angular power to -75%.
239245
print("spin right")
240-
await my_base.set_power(linear=Vector3(x=0,y=0,z=0), angular=Vector3(x=0,y=0,z=-.75))
246+
await my_base.set_power(
247+
linear=Vector3(x=0, y=0, z=0),
248+
angular=Vector3(x=0, y=0, z=-.75))
241249
```
242250

243251
{{% /tab %}}
@@ -309,8 +317,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
309317
```python {class="line-numbers linkable-line-numbers"}
310318
my_base = Base.from_robot(robot=robot, name="my_base")
311319

312-
# Set the linear velocity to 50 mm/sec and the angular velocity to 15 degree/sec.
313-
await my_base.set_velocity(linear=Vector3(x=0,y=50,z=0), angular=Vector3(x=0,y=0,z=15))
320+
# Set the linear velocity to 50 mm/sec and the angular velocity to
321+
# 15 degree/sec.
322+
await my_base.set_velocity(
323+
linear=Vector3(x=0, y=50, z=0), angular=Vector3(x=0, y=0, z=15))
314324
```
315325

316326
{{% /tab %}}
@@ -469,10 +479,10 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
469479
```python {class="line-numbers linkable-line-numbers"}
470480
my_base = Base.from_robot(robot=robot, name="my_base")
471481

472-
# Get the width and turning radius of the base
482+
# Get the width and turning radius of the base
473483
properties = await my_base.get_properties()
474484

475-
# Get the width
485+
# Get the width
476486
print(f"Width of base in meters: {properties.width}")
477487

478488
# Get the turning radius
@@ -497,7 +507,7 @@ For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/c
497507
```go {class="line-numbers linkable-line-numbers"}
498508
myBase, err := base.FromRobot(robot, "my_base")
499509

500-
// Get the width and turning radius of the base
510+
// Get the width and turning radius of the base
501511
properties, err := myBase.Properties(context.Background(), nil)
502512

503513
// Get the width

docs/components/board/_index.md

+25-13
Original file line numberDiff line numberDiff line change
@@ -448,10 +448,11 @@ Get an [`DigitalInterrupt`](#digital_interrupts) by `name.`
448448
For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/board/index.html#viam.components.board.Board.digital_interrupt_by_name).
449449

450450
```python
451-
my_board = Board.from_robot(robot=robot, name=)
451+
my_board = Board.from_robot(robot=robot, name="my_board")
452452

453453
# Get the DigitalInterrupt "my_example_digital_interrupt".
454-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
454+
interrupt = await my_board.digital_interrupt_by_name(
455+
name="my_example_digital_interrupt")
455456
```
456457

457458
{{% /tab %}}
@@ -1047,7 +1048,8 @@ my_board = Board.from_robot(robot=robot, name="my_board")
10471048
# Get the GPIOPin with pin number 15.
10481049
pin = await my_board.GPIO_pin_by_name(name="15")
10491050

1050-
# Set the duty cycle to .6, meaning that this pin will be in the high state for 60% of the duration of the PWM interval period.
1051+
# Set the duty cycle to .6, meaning that this pin will be in the high state for
1052+
# 60% of the duration of the PWM interval period.
10511053
await pin.set_pwm(cycle=.6)
10521054
```
10531055

@@ -1225,9 +1227,11 @@ pin = await my_board.GPIO_pin_by_name(name="15")
12251227
duty_cycle = await pin.get_pwm()
12261228

12271229
# Get the AnalogReader "my_example_analog_reader".
1228-
reader = await my_board.analog_reader_by_name(name="my_example_analog_reader")
1230+
reader = await my_board.analog_reader_by_name(
1231+
name="my_example_analog_reader")
12291232

1230-
# Get the value of the digital signal "my_example_analog_reader" has most recently measured.
1233+
# Get the value of the digital signal "my_example_analog_reader" has most
1234+
# recently measured.
12311235
reading = reader.read()
12321236
```
12331237

@@ -1288,9 +1292,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
12881292
my_board = Board.from_robot(robot=robot, name="my_board")
12891293

12901294
# Get the DigitalInterrupt "my_example_digital_interrupt".
1291-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1295+
interrupt = await my_board.digital_interrupt_by_name(
1296+
name="my_example_digital_interrupt")
12921297

1293-
# Get the amount of times this DigitalInterrupt has been interrupted with a tick.
1298+
# Get the amount of times this DigitalInterrupt has been interrupted with a
1299+
# tick.
12941300
count = await interrupt.value()
12951301
```
12961302

@@ -1341,9 +1347,11 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
13411347
my_board = Board.from_robot(robot=robot, name="my_board")
13421348

13431349
# Get the DigitalInterrupt "my_example_digital_interrupt".
1344-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1350+
interrupt = await my_board.digital_interrupt_by_name(
1351+
name="my_example_digital_interrupt")
13451352

1346-
# Get the rolling average of the pulse width across each time the DigitalInterrupt is interrupted with a tick.
1353+
# Get the rolling average of the pulse width across each time the
1354+
# DigitalInterrupt is interrupted with a tick.
13471355
rolling_avg = await interrupt.value()
13481356
```
13491357

@@ -1407,7 +1415,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
14071415
my_board = Board.from_robot(robot=robot, name="my_board")
14081416
14091417
# Get the DigitalInterrupt "my_example_digital_interrupt".
1410-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1418+
interrupt = await my_board.digital_interrupt_by_name(
1419+
name="my_example_digital_interrupt")
14111420
14121421
# Record an interrupt and notify any interested callbacks.
14131422
await interrupt.tick(high=true, nanos=12345)
@@ -1431,7 +1440,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
14311440
my_board = Board.from_robot(robot=robot, name="my_board")
14321441
14331442
# Get the DigitalInterrupt "my_example_digital_interrupt".
1434-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1443+
interrupt = await my_board.digital_interrupt_by_name(
1444+
name="my_example_digital_interrupt")
14351445
14361446
# Record an interrupt and notify any interested callbacks.
14371447
await interrupt.tick(high=true, nanos=12345)
@@ -1524,7 +1534,8 @@ pin = await my_board.GPIO_pin_by_name(name="15")
15241534
callback_queue = Queue(maxsize=10)
15251535
15261536
# Get the DigitalInterrupt "my_example_digital_interrupt".
1527-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1537+
interrupt = await my_board.digital_interrupt_by_name(
1538+
name="my_example_digital_interrupt")
15281539
15291540
# Add a queue to the interrupt.
15301541
interrupt.add_callback(callback_queue)
@@ -1618,7 +1629,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/
16181629
my_board = Board.from_robot(robot=robot, name="my_board")
16191630
16201631
# Get the DigitalInterrupt "my_example_digital_interrupt".
1621-
interrupt = await my_board.digital_interrupt_by_name(name="my_example_digital_interrupt")
1632+
interrupt = await my_board.digital_interrupt_by_name(
1633+
name="my_example_digital_interrupt")
16221634
```
16231635
``` -->
16241636

docs/components/camera/_index.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ frame = await my_cam.get_image()
133133

134134
# Convert "frame" to a standard 2D image representation.
135135
# Remove the 1st 3x8 bytes and reshape the raw bytes to List[List[Int]].
136-
standard_frame frame.bytes_to_depth_array()
136+
standard_frame = frame.bytes_to_depth_array()
137137
```
138138

139139
{{% alert title="Tip" color="tip" %}}
@@ -253,7 +253,7 @@ To deserialize the returned information into a numpy array, use the Open3D libra
253253
import numpy as np
254254
import open3d as o3d
255255

256-
my_camera= Camera.from_robot(robot=robot, name="my_camera")
256+
my_camera = Camera.from_robot(robot=robot, name="my_camera")
257257

258258
data, _ = await my_camera.get_point_cloud()
259259

@@ -306,7 +306,7 @@ Get the camera intrinsic parameters and camera distortion, as well as whether th
306306
- [(Properties)](https://python.viam.dev/autoapi/viam/components/camera/index.html#viam.components.camera.Camera.Properties): The properties of the camera.
307307

308308
```python {class="line-numbers linkable-line-numbers"}
309-
my_camera= Camera.from_robot(robot=robot, name="my_camera")
309+
my_camera = Camera.from_robot(robot=robot, name="my_camera")
310310

311311
properties = await my_camera.get_properties()
312312
```
@@ -356,7 +356,7 @@ If you are implementing your own camera and adding features that have no native
356356
- [(Dict[str, Any])](https://docs.python.org/3/library/stdtypes.html#typesmapping): Result of the executed command.
357357

358358
```python {class="line-numbers linkable-line-numbers"}
359-
my_camera= Camera.from_robot(robot, "my_camera")
359+
my_camera = Camera.from_robot(robot, "my_camera")
360360

361361
command = {"cmd": "test", "data1": 500}
362362
result = my_camera.do(command)

docs/components/gantry/_index.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
156156
```python
157157
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")
158158

159-
# Create a list of positions for the axes of the gantry to move to. Assume in this example that the gantry is multi-axis, with 3 axes.
159+
# Create a list of positions for the axes of the gantry to move to. Assume in
160+
# this example that the gantry is multi-axis, with 3 axes.
160161
examplePositions = [1, 2, 3]
161162

162163
exampleSpeeds = [3, 9, 12]
163164

164165
# Move the axes of the gantry to the positions specified.
165-
await my_gantry.move_to_position(positions=examplePositions, speeds=exampleSpeeds)
166+
await my_gantry.move_to_position(
167+
positions=examplePositions, speeds=exampleSpeeds)
166168
```
167169

168170
{{% /tab %}}
@@ -315,7 +317,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
315317
```python
316318
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")
317319

318-
# Stop all motion of the gantry. It is assumed that the gantry stops immediately.
320+
# Stop all motion of the gantry. It is assumed that the gantry stops
321+
# immediately.
319322
await my_gantry.stop()
320323
```
321324

@@ -363,7 +366,8 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/_modules
363366
```python
364367
my_gantry = Gantry.from_robot(robot=robot, name="my_gantry")
365368

366-
# Stop all motion of the gantry. It is assumed that the gantry stops immediately.
369+
# Stop all motion of the gantry. It is assumed that the
370+
# gantry stops immediately.
367371
await my_gantry.stop()
368372

369373
# Print if the gantry is currently moving.

0 commit comments

Comments
 (0)