From 0025a9a0ce865008b5cbb5f365a630dc5cd11c43 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 11 Oct 2024 16:59:11 +0200 Subject: [PATCH 1/5] pyproject.toml: drop ruff excludes redundant to gitignore, rather extend excludes ruff's "exclude" documentation [1] reads: "Note that you'll typically want to use extend-exclude to modify the excluded paths." Do that. The default for the "respect-gitignore" setting [2] is "true", so we can safely drop entries that are already specified there. [1] https://docs.astral.sh/ruff/settings/#exclude [2] https://docs.astral.sh/ruff/settings/#respect-gitignore Signed-off-by: Bastian Krause --- pyproject.toml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f19952943..64686167c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -206,16 +206,11 @@ commands = pylint -f colorized labgrid [tool.ruff] line-length = 119 -exclude = [ - "__pycache__", - "labgrid.egg-info", +extend-exclude = [ ".pybuild", - "build", "debian", "env", - "venv", "envs", - "dist", "labgrid/remote/generated", ] From 8576744611124f3251f70c2c60409f3d13fffff9 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 11 Oct 2024 17:00:43 +0200 Subject: [PATCH 2/5] pyproject.toml: maintain ruff include centrally The default value of the "include" setting is ["*.py", "*.pyi", "*.ipynb", "**/pyproject.toml"] [1]. We're only interested in pyproject.toml and *.py files, so add pyproject.toml and the pre-formatted labgrid.remote module (previously specified in the CI configuration only). [1] https://docs.astral.sh/ruff/settings/#include Signed-off-by: Bastian Krause --- .github/workflows/reusable-unit-tests.yml | 2 +- pyproject.toml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-unit-tests.yml b/.github/workflows/reusable-unit-tests.yml index 064b7f1b1..a415034a3 100644 --- a/.github/workflows/reusable-unit-tests.yml +++ b/.github/workflows/reusable-unit-tests.yml @@ -55,7 +55,7 @@ jobs: pylint labgrid - name: Format with ruff run: | - ruff format --check --diff labgrid/remote/ + ruff format --check --diff - name: Test with pytest run: | pytest -r a --cov-config .coveragerc --cov=labgrid --local-sshmanager --ssh-username runner -k "not test_docker_with_daemon" diff --git a/pyproject.toml b/pyproject.toml index 64686167c..546d33595 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -213,6 +213,10 @@ extend-exclude = [ "envs", "labgrid/remote/generated", ] +include = [ + "**/pyproject.toml", + "labgrid/remote/**/*.py", +] [tool.ruff.lint] select = ["B", "E", "F", "I", "SIM", "UP"] From 55c2c3a6904ccf83c4f1f517d461cc06aac950f7 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 11 Oct 2024 17:03:35 +0200 Subject: [PATCH 3/5] labgrid/protocol: run ruff format Signed-off-by: Bastian Krause --- labgrid/protocol/infoprotocol.py | 2 +- labgrid/protocol/resetprotocol.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/labgrid/protocol/infoprotocol.py b/labgrid/protocol/infoprotocol.py index c95e1411c..e266c3121 100644 --- a/labgrid/protocol/infoprotocol.py +++ b/labgrid/protocol/infoprotocol.py @@ -5,7 +5,7 @@ class InfoProtocol(abc.ABC): """Abstract class providing the InfoProtocol interface""" @abc.abstractmethod - def get_ip(self, interface: str = 'eth0'): + def get_ip(self, interface: str = "eth0"): """Implementations should return the IP address for the supplied interface.""" raise NotImplementedError diff --git a/labgrid/protocol/resetprotocol.py b/labgrid/protocol/resetprotocol.py index f7a6fe388..6dc838706 100644 --- a/labgrid/protocol/resetprotocol.py +++ b/labgrid/protocol/resetprotocol.py @@ -1,5 +1,6 @@ import abc + class ResetProtocol(abc.ABC): @abc.abstractmethod def reset(self): From fb2cfba44dc2f9b97e737e3072ee85b2cafcc590 Mon Sep 17 00:00:00 2001 From: Bastian Krause Date: Fri, 11 Oct 2024 17:32:07 +0200 Subject: [PATCH 4/5] examples: run ruff format Signed-off-by: Bastian Krause --- examples/barebox/conftest.py | 4 +- examples/barebox/test_barebox.py | 6 +- examples/barebox/test_bootchooser.py | 6 +- examples/barebox/test_sleep.py | 4 +- examples/barebox/test_state.py | 4 +- examples/barebox/test_watchdog.py | 6 +- examples/deditec-relais8/deditec.py | 2 +- examples/deditec-relais8/deditec_remote.py | 2 +- examples/docker/conftest.py | 8 +- examples/docker/test_shell.py | 6 +- examples/library/test.py | 12 +-- examples/modbusrtu/conftest.py | 4 +- examples/network-test/pkg-replay-record.py | 1 + examples/networkmanager/nm.py | 77 +++++++++---------- examples/power/power_example.py | 2 +- examples/pyvisa/pyvisa_example.py | 8 +- .../qemu-networking/test_qemu_networking.py | 1 + examples/remote/test_barebox.py | 8 +- examples/shell/conftest.py | 4 +- examples/shell/test_hwclock.py | 8 +- examples/shell/test_memory.py | 10 +-- examples/shell/test_rt.py | 10 +-- examples/shell/test_shell.py | 6 +- examples/sigrok/main.py | 2 +- examples/strategy/bareboxrebootstrategy.py | 6 +- examples/strategy/quartusstrategy.py | 7 +- examples/strategy/test_barebox_strategy.py | 22 +++--- examples/strategy/test_uboot_strategy.py | 22 +++--- examples/sysfsgpio/sysfsgpio.py | 2 +- examples/sysfsgpio/sysfsgpio_remote.py | 2 +- examples/usb/test_usb_mxs.py | 5 +- examples/usb/test_usb_storage.py | 5 +- examples/usbpower/cycle.py | 5 +- examples/usbpower/examplestrategy.py | 9 +-- examples/usbpower/test_example.py | 14 ++-- examples/usbsdmux/test_sdmux.py | 6 +- 36 files changed, 153 insertions(+), 153 deletions(-) diff --git a/examples/barebox/conftest.py b/examples/barebox/conftest.py index 151cacb1b..f0f6af199 100644 --- a/examples/barebox/conftest.py +++ b/examples/barebox/conftest.py @@ -1,8 +1,8 @@ import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def command(target): - barebox = target.get_driver('CommandProtocol') + barebox = target.get_driver("CommandProtocol") target.activate(barebox) return barebox diff --git a/examples/barebox/test_barebox.py b/examples/barebox/test_barebox.py index 271ac17ff..b9ebf9c4b 100644 --- a/examples/barebox/test_barebox.py +++ b/examples/barebox/test_barebox.py @@ -1,11 +1,11 @@ def test_barebox(command): - stdout, stderr, returncode = command.run('version') + stdout, stderr, returncode = command.run("version") assert returncode == 0 assert stdout assert not stderr - assert 'barebox' in '\n'.join(stdout) + assert "barebox" in "\n".join(stdout) - stdout, stderr, returncode = command.run('false') + stdout, stderr, returncode = command.run("false") assert returncode == 1 assert not stdout assert not stderr diff --git a/examples/barebox/test_bootchooser.py b/examples/barebox/test_bootchooser.py index 57e68e2e6..76498b3b4 100644 --- a/examples/barebox/test_bootchooser.py +++ b/examples/barebox/test_bootchooser.py @@ -2,10 +2,10 @@ def test_bootchooser(command): - stdout, stderr, returncode = command.run('bootchooser -i') + stdout, stderr, returncode = command.run("bootchooser -i") if returncode == 127: pytest.skip("bootchooser command not available") assert returncode == 0 assert not stderr - assert stdout[0].startswith('Good targets') - assert stdout[1] != 'none' + assert stdout[0].startswith("Good targets") + assert stdout[1] != "none" diff --git a/examples/barebox/test_sleep.py b/examples/barebox/test_sleep.py index 1df4ce66e..b7f654243 100644 --- a/examples/barebox/test_sleep.py +++ b/examples/barebox/test_sleep.py @@ -6,14 +6,14 @@ def test_sleep(command): # measure the round-trip-time timestamp = monotonic() - stdout, stderr, returncode = command.run('true') + stdout, stderr, returncode = command.run("true") elapsed_true = monotonic() - timestamp assert returncode == 0 assert not stdout assert not stderr timestamp = monotonic() - stdout, stderr, returncode = command.run('sleep 1') + stdout, stderr, returncode = command.run("sleep 1") elapsed_sleep = monotonic() - timestamp assert returncode == 0 assert not stdout diff --git a/examples/barebox/test_state.py b/examples/barebox/test_state.py index 13e397dcf..49415cdcf 100644 --- a/examples/barebox/test_state.py +++ b/examples/barebox/test_state.py @@ -2,10 +2,10 @@ def test_state(command): - stdout, stderr, returncode = command.run('state') + stdout, stderr, returncode = command.run("state") if returncode == 127: pytest.skip("state command not available") assert returncode == 0 assert not stderr - assert stdout[0] == 'registered state instances:' + assert stdout[0] == "registered state instances:" assert len(stdout) > 1 diff --git a/examples/barebox/test_watchdog.py b/examples/barebox/test_watchdog.py index 43b75183b..2d0b58a86 100644 --- a/examples/barebox/test_watchdog.py +++ b/examples/barebox/test_watchdog.py @@ -2,7 +2,7 @@ def test_watchdog(command): - stdout, stderr, returncode = command.run('wd 1') + stdout, stderr, returncode = command.run("wd 1") if returncode == 127: pytest.skip("wd command not available") assert returncode == 0 @@ -11,6 +11,6 @@ def test_watchdog(command): command._await_prompt() - stdout = command.run_check('echo ${global.system.reset}') + stdout = command.run_check("echo ${global.system.reset}") assert len(stdout) == 1 - assert stdout[0] == 'WDG' + assert stdout[0] == "WDG" diff --git a/examples/deditec-relais8/deditec.py b/examples/deditec-relais8/deditec.py index 0a47982ca..b007994de 100644 --- a/examples/deditec-relais8/deditec.py +++ b/examples/deditec-relais8/deditec.py @@ -12,7 +12,7 @@ # log labgrid steps StepLogger.start() -t = Target('main') +t = Target("main") r = DeditecRelais8(t, name=None, index=1) d = DeditecRelaisDriver(t, name=None) diff --git a/examples/deditec-relais8/deditec_remote.py b/examples/deditec-relais8/deditec_remote.py index 53a860ed3..c0e45e385 100644 --- a/examples/deditec-relais8/deditec_remote.py +++ b/examples/deditec-relais8/deditec_remote.py @@ -10,7 +10,7 @@ # show labgrid steps on the console StepLogger.start() -e = Environment('import-dedicontrol.yaml') +e = Environment("import-dedicontrol.yaml") t = e.get_target() p = t.get_driver("DigitalOutputProtocol") diff --git a/examples/docker/conftest.py b/examples/docker/conftest.py index 6c407bf4e..46bacd6de 100644 --- a/examples/docker/conftest.py +++ b/examples/docker/conftest.py @@ -1,9 +1,9 @@ import pytest -@pytest.fixture(scope='session') + +@pytest.fixture(scope="session") def command(target): - strategy = target.get_driver('DockerStrategy') + strategy = target.get_driver("DockerStrategy") strategy.transition("accessible") - shell = target.get_driver('CommandProtocol') + shell = target.get_driver("CommandProtocol") return shell - diff --git a/examples/docker/test_shell.py b/examples/docker/test_shell.py index 50b9b7d5d..450af06bb 100644 --- a/examples/docker/test_shell.py +++ b/examples/docker/test_shell.py @@ -1,11 +1,11 @@ def test_shell(command): - stdout, stderr, returncode = command.run('cat /proc/version') + stdout, stderr, returncode = command.run("cat /proc/version") assert returncode == 0 assert len(stdout) > 0 assert len(stderr) == 0 - assert 'Linux' in stdout[0] + assert "Linux" in stdout[0] - stdout, stderr, returncode = command.run('false') + stdout, stderr, returncode = command.run("false") assert returncode != 0 assert len(stdout) == 0 assert len(stderr) == 0 diff --git a/examples/library/test.py b/examples/library/test.py index 9870e1670..e2851eaed 100755 --- a/examples/library/test.py +++ b/examples/library/test.py @@ -15,15 +15,17 @@ # log labgrid steps StepLogger.start() + def run_once(target): - s = target.get_driver('BareboxStrategy') + s = target.get_driver("BareboxStrategy") s.status = Status.unknown # force a power-cycle - s.transition('barebox') - cmd = target['CommandProtocol'] - cmd.run_check('test -e /dev/nand0') + s.transition("barebox") + cmd = target["CommandProtocol"] + cmd.run_check("test -e /dev/nand0") target.deactivate(cmd) + env = Environment(sys.argv[1]) -target = env.get_target('main') +target = env.get_target("main") while True: run_once(target) diff --git a/examples/modbusrtu/conftest.py b/examples/modbusrtu/conftest.py index 4d28384ff..cf9696a98 100644 --- a/examples/modbusrtu/conftest.py +++ b/examples/modbusrtu/conftest.py @@ -1,7 +1,7 @@ import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def instrument(target): - _modbus = target.get_driver('ModbusRTUDriver') + _modbus = target.get_driver("ModbusRTUDriver") return _modbus diff --git a/examples/network-test/pkg-replay-record.py b/examples/network-test/pkg-replay-record.py index 124991ca0..6cbcf3d3f 100755 --- a/examples/network-test/pkg-replay-record.py +++ b/examples/network-test/pkg-replay-record.py @@ -11,6 +11,7 @@ from labgrid import Environment from labgrid.logging import basicConfig, StepLogger + def generate_frame(): frame = Ether(dst="11:22:33:44:55:66", src="66:55:44:33:22:11", type=0x9000) padding = "\x00" * (conf.min_pkt_size - len(frame)) diff --git a/examples/networkmanager/nm.py b/examples/networkmanager/nm.py index e2e9f8876..505364d50 100644 --- a/examples/networkmanager/nm.py +++ b/examples/networkmanager/nm.py @@ -12,72 +12,71 @@ StepLogger.start() -e = Environment('nm.env') +e = Environment("nm.env") t = e.get_target() -d = t.get_driver('NetworkInterfaceDriver') +d = t.get_driver("NetworkInterfaceDriver") # based on https://developer.gnome.org/NetworkManager/stable/ch01.html, but adapted to python dicts s_client = { - 'connection': { - 'type': "802-11-wireless", + "connection": { + "type": "802-11-wireless", }, - '802-11-wireless': { - 'mode': "infrastructure", - 'ssid': "local-rpi", + "802-11-wireless": { + "mode": "infrastructure", + "ssid": "local-rpi", }, - '802-11-wireless-security': { - 'key-mgmt': "wpa-psk", - 'psk': "obMinwyurArc5", + "802-11-wireless-security": { + "key-mgmt": "wpa-psk", + "psk": "obMinwyurArc5", }, - 'ipv4': { - 'method': "auto", - 'ignore-auto-dns': True, - 'ignore-auto-routes': True, - 'never-default': True, + "ipv4": { + "method": "auto", + "ignore-auto-dns": True, + "ignore-auto-routes": True, + "never-default": True, }, - 'ipv6': { - 'method': "link-local", + "ipv6": { + "method": "link-local", }, } s_ap = { - 'connection': { - 'type': "802-11-wireless", + "connection": { + "type": "802-11-wireless", }, - '802-11-wireless': { - 'mode': "ap", - 'ssid': "local-rpi", + "802-11-wireless": { + "mode": "ap", + "ssid": "local-rpi", }, - '802-11-wireless-security': { - 'key-mgmt': "wpa-psk", - 'psk': "obMinwyurArc5", + "802-11-wireless-security": { + "key-mgmt": "wpa-psk", + "psk": "obMinwyurArc5", }, - 'ipv4': { + "ipv4": { #'method': "auto", #'method': "link-local", - 'method': "shared", - 'addresses': ["172.16.0.2/29"], + "method": "shared", + "addresses": ["172.16.0.2/29"], }, - 'ipv6': { - 'method': "link-local", + "ipv6": { + "method": "link-local", }, } d.disable() -d.wait_state('disconnected') +d.wait_state("disconnected") print("access points after scan") pprint(d.get_access_points()) d.configure(s_ap) -d.wait_state('activated') +d.wait_state("activated") print("settings in AP mode") pprint(d.get_settings()) print("state in AP mode") pprint(d.get_state()) -#d.configure(s_client) -#d.wait_state('activated') -#print("settings in client mode") -#pprint(d.get_settings()) -#print("state in client mode") -#pprint(d.get_state()) - +# d.configure(s_client) +# d.wait_state('activated') +# print("settings in client mode") +# pprint(d.get_settings()) +# print("state in client mode") +# pprint(d.get_state()) diff --git a/examples/power/power_example.py b/examples/power/power_example.py index 82a8ac6f5..4fc5fed68 100644 --- a/examples/power/power_example.py +++ b/examples/power/power_example.py @@ -3,7 +3,7 @@ @pytest.fixture() def pdu(target): - return target.get_driver('NetworkPowerDriver') + return target.get_driver("NetworkPowerDriver") def test_something(pdu): diff --git a/examples/pyvisa/pyvisa_example.py b/examples/pyvisa/pyvisa_example.py index 16743ef40..da37ca052 100644 --- a/examples/pyvisa/pyvisa_example.py +++ b/examples/pyvisa/pyvisa_example.py @@ -3,13 +3,13 @@ @pytest.fixture() def signal_generator(target): - return target.get_driver('PyVISADriver').get_session() + return target.get_driver("PyVISADriver").get_session() def test_with_signal_generator_example(signal_generator): - signal_generator.write('*RST') + signal_generator.write("*RST") # Setup channel 1 - signal_generator.write('C1:BSWV WVTP,SQUARE,HLEV,5,LLEV,0,DUTY,50') + signal_generator.write("C1:BSWV WVTP,SQUARE,HLEV,5,LLEV,0,DUTY,50") # Switch on channel 1 - signal_generator.write('C1:OUTP ON,LOAD,HZ,PLRT,NOR') + signal_generator.write("C1:OUTP ON,LOAD,HZ,PLRT,NOR") diff --git a/examples/qemu-networking/test_qemu_networking.py b/examples/qemu-networking/test_qemu_networking.py index 8f256128b..c1cc971b3 100644 --- a/examples/qemu-networking/test_qemu_networking.py +++ b/examples/qemu-networking/test_qemu_networking.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. + def test_shell(shell_command): shell_command.run("true") diff --git a/examples/remote/test_barebox.py b/examples/remote/test_barebox.py index e8ae6319d..4564c7a94 100644 --- a/examples/remote/test_barebox.py +++ b/examples/remote/test_barebox.py @@ -1,14 +1,14 @@ def test_target(target): - barebox = target.get_driver('CommandProtocol') + barebox = target.get_driver("CommandProtocol") target.activate(barebox) - stdout, stderr, returncode = barebox.run('version') + stdout, stderr, returncode = barebox.run("version") assert returncode == 0 assert stdout assert not stderr - assert 'barebox' in '\n'.join(stdout) + assert "barebox" in "\n".join(stdout) - stdout, stderr, returncode = barebox.run('false') + stdout, stderr, returncode = barebox.run("false") assert returncode == 1 assert not stdout assert not stderr diff --git a/examples/shell/conftest.py b/examples/shell/conftest.py index 22aecbdcf..c4ab03d57 100644 --- a/examples/shell/conftest.py +++ b/examples/shell/conftest.py @@ -1,8 +1,8 @@ import pytest -@pytest.fixture(scope='session') +@pytest.fixture(scope="session") def command(target): - shell = target.get_driver('CommandProtocol') + shell = target.get_driver("CommandProtocol") target.activate(shell) return shell diff --git a/examples/shell/test_hwclock.py b/examples/shell/test_hwclock.py index c774d0ee2..843c6fc83 100644 --- a/examples/shell/test_hwclock.py +++ b/examples/shell/test_hwclock.py @@ -3,7 +3,7 @@ def test_hwclock_rate(command): """Test that the hardware clock rate is not too inaccurate.""" - result = command.run_check('hwclock -c | head -n 3') + result = command.run_check("hwclock -c | head -n 3") hw_time, sys_time, freq_offset_ppm, tick = result[-1].strip().split() assert abs(int(freq_offset_ppm)) < 1000 @@ -15,11 +15,11 @@ def test_hwclock_value(command): """ def get_time(): - result = command.run_check('hwclock --utc --show')[0].strip() - return datetime.strptime(result, '%Y-%m-%d %H:%M:%S.%f+0:00') + result = command.run_check("hwclock --utc --show")[0].strip() + return datetime.strptime(result, "%Y-%m-%d %H:%M:%S.%f+0:00") def set_time(time): - time = time.strftime('%Y-%m-%d %H:%M:%S.%f+0:00') + time = time.strftime("%Y-%m-%d %H:%M:%S.%f+0:00") command.run_check(f'hwclock --utc --set --date "{time}"') offset = abs((get_time() - datetime.utcnow()).total_seconds()) diff --git a/examples/shell/test_memory.py b/examples/shell/test_memory.py index c4c8841bc..7c6477b2c 100644 --- a/examples/shell/test_memory.py +++ b/examples/shell/test_memory.py @@ -8,26 +8,26 @@ def test_memory_mbw(command): """Test memcopy bandwidth""" try: - command.run_check('which mbw') + command.run_check("which mbw") except ExecutionError: pytest.skip("mbw missing") - result = command.run_check('mbw -qt0 8M') + result = command.run_check("mbw -qt0 8M") result = result[-1].strip() pattern = r"AVG\s+.*Copy:\s+(?P\S+)\s+MiB/s" - bw, = map(float, re.fullmatch(pattern, result).groups()) + (bw,) = map(float, re.fullmatch(pattern, result).groups()) assert bw > 40 # > 40 MiB/second def test_memory_memtester_short(command): """Test RAM for errors""" try: - command.run_check('which memtester') + command.run_check("which memtester") except ExecutionError: pytest.skip("memtester missing") - result = command.run_check('memtester 128k 1 | tail -n 1') + result = command.run_check("memtester 128k 1 | tail -n 1") result = result[-1].strip() assert result == "Done." diff --git a/examples/shell/test_rt.py b/examples/shell/test_rt.py index 85824ea62..b2fa1b96f 100644 --- a/examples/shell/test_rt.py +++ b/examples/shell/test_rt.py @@ -8,11 +8,11 @@ def test_rt_cyclictest_short(command): """Test a basic cyclictest run""" try: - command.run_check('which cyclictest') + command.run_check("which cyclictest") except ExecutionError: pytest.skip("cyclictest missing") - result = command.run_check('cyclictest -SN -D 5 -q') + result = command.run_check("cyclictest -SN -D 5 -q") result = result[-1].strip() pattern = r"Min:\s+(?P\w+)\s+Act:\s+\w+\s+Avg:\s+(?P\w+)\s+Max:\s+(?P\w+)" @@ -25,13 +25,13 @@ def test_rt_cyclictest_short(command): def test_rt_hackbench_short(command): """Test a basic hackbench run""" try: - command.run_check('which hackbench') + command.run_check("which hackbench") except ExecutionError: pytest.skip("hackbench missing") - result = command.run_check('hackbench -f 10') + result = command.run_check("hackbench -f 10") result = result[-1].strip() pattern = r"Time:\s+(?P