Skip to content

Commit 3972e65

Browse files
committed
Reformat by ruff to pass tests
1 parent 4d9a4ad commit 3972e65

File tree

10 files changed

+160
-206
lines changed

10 files changed

+160
-206
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ mypy pypsn/*py --pretty --no-strict-optional
6666
```
6767
### Format
6868

69-
- to format, use [black](https://pypi.org/project/black/)
69+
- To format, use [ruff](https://docs.astral.sh/ruff/)
7070

7171
### Testing
7272

conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/bin/env python3
22
"""
3-
This file sets up a pytest fixtures for the tests.
4-
It is important that this file stays in this location
5-
as this makes pytest to load pypsn from the pypsn directory.
3+
This file sets up a pytest fixtures for the tests.
4+
It is important that this file stays in this location
5+
as this makes pytest to load pypsn from the pypsn directory.
66
"""
77

88
import pytest

examples/psn_to_sacn.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#! /bin/env python
22
"""
3-
Simple forwarder of PSN to DMX. Turns all coordinates to positive ints.
4-
Requires sacn module: pip install sacn
3+
Simple forwarder of PSN to DMX. Turns all coordinates to positive ints.
4+
Requires sacn module: pip install sacn
55
"""
6+
67
import sacn
78
import pypsn
89

@@ -12,7 +13,7 @@
1213

1314
def start_dmx():
1415
"""
15-
Start DMX sender thread.
16+
Start DMX sender thread.
1617
"""
1718
sender.start() # start the sending thread
1819
sender.activate_output(1) # start sending out data in the 1st universe
@@ -21,14 +22,14 @@ def start_dmx():
2122

2223
def stop_dmx():
2324
"""
24-
Stop DMX sender thread.
25+
Stop DMX sender thread.
2526
"""
2627
sender.stop() # do not forget to stop the sender
2728

2829

2930
def start_psn():
3031
"""
31-
Start PSN receiver thread.
32+
Start PSN receiver thread.
3233
"""
3334
pypsn.Receiver(fill_dmx, "192.168.20.177").start()
3435

examples/simple_send_and_receive/receive_psn.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /bin/env python3
22
"""
3-
Usage: python receive_psn.py 192.168.1.11 <--- change IP address
3+
Usage: python receive_psn.py 192.168.1.11 <--- change IP address
44
"""
55

66
import sys
@@ -43,13 +43,20 @@ def callback(psn_data):
4343
+ str(tracker.tracker_id)
4444
+ " tracker info: "
4545
+ str(tracker.info)
46-
+ " / " + str(tracker.pos)
47-
+ " / " + str(tracker.speed)
48-
+ " / " + str(tracker.ori)
49-
+ " / " + str(tracker.accel)
50-
+ " / " + str(tracker.trgtpos)
51-
+ " / " + str(tracker.status)
52-
+ " / " + str(tracker.timestamp)
46+
+ " / "
47+
+ str(tracker.pos)
48+
+ " / "
49+
+ str(tracker.speed)
50+
+ " / "
51+
+ str(tracker.ori)
52+
+ " / "
53+
+ str(tracker.accel)
54+
+ " / "
55+
+ str(tracker.trgtpos)
56+
+ " / "
57+
+ str(tracker.status)
58+
+ " / "
59+
+ str(tracker.timestamp)
5360
)
5461

5562

examples/simple_send_and_receive/send_psn.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#! /bin/env python3
22
"""
3-
Usage: python send_psn.py 192.168.1.4 <--- change IP address
3+
Usage: python send_psn.py 192.168.1.4 <--- change IP address
44
55
"""
6+
67
import sys
78
import pypsn
89

@@ -15,15 +16,16 @@
1516
frame_id=56,
1617
packet_count=1,
1718
),
18-
name='system_name_001',
19+
name="system_name_001",
1920
trackers=(
2021
[
2122
pypsn.PsnTrackerInfo(
2223
tracker_id=i,
2324
tracker_name="tracker_" + str(i),
24-
) for i in range(0, 7)
25+
)
26+
for i in range(0, 7)
2527
]
26-
)
28+
),
2729
)
2830

2931
psn_data = pypsn.PsnDataPacket(
@@ -60,9 +62,10 @@
6062
),
6163
status=0,
6264
timestamp=psn_info.info.timestamp,
63-
) for tracker in psn_info.trackers
65+
)
66+
for tracker in psn_info.trackers
6467
]
65-
)
68+
),
6669
)
6770

6871
print("\n--- PSN infos to be sent ---")
@@ -89,29 +92,35 @@
8992
+ str(tracker.tracker_id)
9093
+ " tracker info: "
9194
+ str(tracker.info)
92-
+ " / " + str(tracker.pos)
93-
+ " / " + str(tracker.speed)
94-
+ " / " + str(tracker.ori)
95-
+ " / " + str(tracker.accel)
96-
+ " / " + str(tracker.trgtpos)
97-
+ " / " + str(tracker.status)
98-
+ " / " + str(tracker.timestamp)
95+
+ " / "
96+
+ str(tracker.pos)
97+
+ " / "
98+
+ str(tracker.speed)
99+
+ " / "
100+
+ str(tracker.ori)
101+
+ " / "
102+
+ str(tracker.accel)
103+
+ " / "
104+
+ str(tracker.trgtpos)
105+
+ " / "
106+
+ str(tracker.status)
107+
+ " / "
108+
+ str(tracker.timestamp)
99109
)
100110

101111
psn_info_packet_bytes = pypsn.prepare_psn_info_packet_bytes(psn_info)
102112
psn_data_packet_bytes = pypsn.prepare_psn_data_packet_bytes(psn_data)
103113

104114
pypsn.send_psn_packet(
105115
psn_packet=psn_info_packet_bytes,
106-
mcast_ip='236.10.10.10',
116+
mcast_ip="236.10.10.10",
107117
ip_addr=sys.argv[1],
108118
mcast_port=56565,
109119
)
110120

111121
pypsn.send_psn_packet(
112122
psn_packet=psn_data_packet_bytes,
113-
mcast_ip='236.10.10.10',
123+
mcast_ip="236.10.10.10",
114124
ip_addr=sys.argv[1],
115125
mcast_port=56565,
116126
)
117-

examples/trigger/save_zones.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#! /bin/env python
22
"""
3-
Complete x,y sACN trigger.
4-
Callibration script.
3+
Complete x,y sACN trigger.
4+
Callibration script.
55
"""
6+
67
import pypsn
78

89
X = 0
@@ -12,7 +13,7 @@
1213

1314
def set_settings_from_file(old_settings):
1415
"""
15-
Update global settings from file.
16+
Update global settings from file.
1617
1718
"""
1819
try:
@@ -23,19 +24,13 @@ def set_settings_from_file(old_settings):
2324
if len(uni_line) < 1 or uni_line[1] == "#":
2425
continue
2526
if "universe" in uni_line:
26-
new_settings["universe"] = int(
27-
uni_line.split(":")[1].strip()
28-
)
27+
new_settings["universe"] = int(uni_line.split(":")[1].strip())
2928
elif "ip_addr" in uni_line:
3029
new_settings["ip_addr"] = uni_line.split(":")[1].strip()
3130
elif "min_distance" in uni_line:
32-
new_settings["min_distance"] = float(
33-
uni_line.split(":")[1].strip()
34-
)
31+
new_settings["min_distance"] = float(uni_line.split(":")[1].strip())
3532
elif "radius" in uni_line:
36-
new_settings["radius"] = float(
37-
uni_line.split(":")[1].strip()
38-
)
33+
new_settings["radius"] = float(uni_line.split(":")[1].strip())
3934
print("got these settings", new_settings)
4035
return new_settings
4136
except Exception as e:
@@ -88,8 +83,7 @@ def set_zones_from_file(old_zones):
8883
return new_zones
8984
except Exception as e:
9085
print(
91-
"Zones not imported from zones.txt, "
92-
+ "using default ones. Error was:", e
86+
"Zones not imported from zones.txt, " + "using default ones. Error was:", e
9387
)
9488
return old_zones
9589

@@ -123,9 +117,7 @@ def set_zones_to_file(zones):
123117
glob_receiver = start_psn(glob_settings.get("ip_addr"))
124118

125119
while True:
126-
val = input(
127-
"Press enter to store current position as a zone, press q to Quit"
128-
)
120+
val = input("Press enter to store current position as a zone, press q to Quit")
129121
if val.lower() == "q":
130122
glob_receiver.stop()
131123
break

examples/trigger/trigger_on_zones.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#! /bin/env python
22
"""
3-
Complete x,y sACN trigger.
4-
Trigger script.
3+
Complete x,y sACN trigger.
4+
Trigger script.
55
"""
66

77
import math
@@ -19,7 +19,7 @@
1919

2020
def start_dmx():
2121
"""
22-
Start DMX sender thread.
22+
Start DMX sender thread.
2323
"""
2424
universe = settings["universe"]
2525
sender.start() # start the sending thread
@@ -29,14 +29,14 @@ def start_dmx():
2929

3030
def stop_dmx():
3131
"""
32-
Stop DMX sender thread.
32+
Stop DMX sender thread.
3333
"""
3434
sender.stop() # do not forget to stop the sender
3535

3636

3737
def set_settings_from_file(settings):
3838
"""
39-
Update global settings from file.
39+
Update global settings from file.
4040
4141
"""
4242
try:
@@ -50,9 +50,7 @@ def set_settings_from_file(settings):
5050
elif "ip_addr" in uni_line:
5151
settings["ip_addr"] = uni_line.split(":")[1].strip()
5252
elif "min_distance" in uni_line:
53-
settings["min_distance"] = float(
54-
uni_line.split(":")[1].strip()
55-
)
53+
settings["min_distance"] = float(uni_line.split(":")[1].strip())
5654
elif "radius" in uni_line:
5755
settings["radius"] = float(uni_line.split(":")[1].strip())
5856
print("got these settings", settings)

0 commit comments

Comments
 (0)