diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2023-04-04 14:45:01 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2023-04-04 16:01:56 +1000 |
commit | 05eaa8c81352dffd7b7dba7d73cad23a72db03ee (patch) | |
tree | 4dfe746b4f690cc40b759684f5b8e32ed75db44c | |
parent | b064bcc063f5645f9240f16673cca5208f405e59 (diff) | |
download | libwacom-05eaa8c81352dffd7b7dba7d73cad23a72db03ee.tar.gz |
Format python files with Python black
-rwxr-xr-x | test/test_data_files.py | 45 | ||||
-rwxr-xr-x | tools/clean_svg.py | 6 | ||||
-rwxr-xr-x | tools/libwacom-update-db.py | 17 |
3 files changed, 43 insertions, 25 deletions
diff --git a/test/test_data_files.py b/test/test_data_files.py index d732bd1..c2db899 100755 --- a/test/test_data_files.py +++ b/test/test_data_files.py @@ -9,23 +9,23 @@ from pathlib import Path WACOM_RECEIVER_USBIDS = [ - (0x56a, 0x84), + (0x56A, 0x84), ] def datadir(): - return Path(os.getenv('MESON_SOURCE_ROOT') or '.') / 'data' + return Path(os.getenv("MESON_SOURCE_ROOT") or ".") / "data" def layoutsdir(): - return datadir() / 'layouts' + return datadir() / "layouts" def pytest_generate_tests(metafunc): # for any function that takes a "tabletfile" argument return the path to # a tablet file - if 'tabletfile' in metafunc.fixturenames: - metafunc.parametrize('tabletfile', [f for f in datadir().glob('*.tablet')]) + if "tabletfile" in metafunc.fixturenames: + metafunc.parametrize("tabletfile", [f for f in datadir().glob("*.tablet")]) def test_device_match(tabletfile): @@ -36,14 +36,23 @@ def test_device_match(tabletfile): # where bus is 'usb' or 'bluetooth' # where vid/pid is a lowercase hex # where name is optional - for match in config['Device']['DeviceMatch'].split(';'): - if not match or match == 'generic': + for match in config["Device"]["DeviceMatch"].split(";"): + if not match or match == "generic": continue - bus, vid, pid = match.split(':')[:3] # skip the name part of the match - assert bus in ['usb', 'bluetooth', 'i2c', 'serial'], f'{tabletfile}: unknown bus type' - assert re.match('[0-9a-f]{4}', vid), f'{tabletfile}: {vid} must be lowercase hex' - assert re.match('[0-9a-f]{4}', pid), f'{tabletfile}: {pid} must be lowercase hex' + bus, vid, pid = match.split(":")[:3] # skip the name part of the match + assert bus in [ + "usb", + "bluetooth", + "i2c", + "serial", + ], f"{tabletfile}: unknown bus type" + assert re.match( + "[0-9a-f]{4}", vid + ), f"{tabletfile}: {vid} must be lowercase hex" + assert re.match( + "[0-9a-f]{4}", pid + ), f"{tabletfile}: {pid} must be lowercase hex" def test_no_receiver_id(tabletfile): @@ -52,8 +61,8 @@ def test_no_receiver_id(tabletfile): config.optionxform = lambda option: option config.read(tabletfile) - receivers = ['usb:{:04x}:{:04x}'.format(*r) for r in WACOM_RECEIVER_USBIDS] - for match in config['Device']['DeviceMatch'].split(';'): + receivers = ["usb:{:04x}:{:04x}".format(*r) for r in WACOM_RECEIVER_USBIDS] + for match in config["Device"]["DeviceMatch"].split(";"): assert match not in receivers @@ -64,7 +73,7 @@ def test_svg_exists(tabletfile): config.read(tabletfile) try: - svg = config['Device']['Layout'] + svg = config["Device"]["Layout"] assert (layoutsdir() / svg).exists() except KeyError: @@ -78,9 +87,11 @@ def test_button_evcodes(tabletfile): config.read(tabletfile) try: - nbuttons = int(config['Features']['Buttons']) - str = config['Buttons']['EvdevCodes'] - codes = [c for c in str.split(";") if c] # drop empty strings from trailing semicolons + nbuttons = int(config["Features"]["Buttons"]) + str = config["Buttons"]["EvdevCodes"] + codes = [ + c for c in str.split(";") if c + ] # drop empty strings from trailing semicolons assert len(codes) == nbuttons, "Number of buttons mismatches the EvdevCodes" except KeyError: pass diff --git a/tools/clean_svg.py b/tools/clean_svg.py index f3566a9..92a6a6b 100755 --- a/tools/clean_svg.py +++ b/tools/clean_svg.py @@ -81,7 +81,7 @@ def round_if_number(value): def remove_non_svg_nodes_and_strip_namespace(root): if root.tag.startswith(BRACKETS_NAMESPACE): - root.tag = root.tag[len(BRACKETS_NAMESPACE):] + root.tag = root.tag[len(BRACKETS_NAMESPACE) :] for elem in root: if ( not elem.tag.startswith(BRACKETS_NAMESPACE) @@ -102,7 +102,7 @@ def remove_transform_if_exists(node): transform = transform.strip() if transform.startswith(TRANSLATE): - values = transform[len(TRANSLATE) + 1:-1].split(",") + values = transform[len(TRANSLATE) + 1 : -1].split(",") try: x, y = float(values[0]), float(values[1]) except Exception: @@ -110,7 +110,7 @@ def remove_transform_if_exists(node): apply_translation(node, 1, 0, 0, 1, x, y) elif transform.startswith(MATRIX): - values = transform[len(MATRIX) + 1:-1].split(",") + values = transform[len(MATRIX) + 1 : -1].split(",") try: a, b, c, d, e, f = [float(value.strip()) for value in values] except Exception: diff --git a/tools/libwacom-update-db.py b/tools/libwacom-update-db.py index 54298cf..63c4093 100755 --- a/tools/libwacom-update-db.py +++ b/tools/libwacom-update-db.py @@ -84,7 +84,7 @@ class HWDBFile: # to accept those. # Let's add a generic exclusion rule for anything we know of with a # Keyboard device name. - if int(vid, 16) != 0x56a: + if int(vid, 16) != 0x56A: entries["* Keyboard"] = ["ID_INPUT_TABLET=0"] lines = [f"# {tablet.name}"] @@ -189,8 +189,11 @@ if __name__ == "__main__": description="Update the system according to the current set of tablet data files" ) parser.add_argument( - "path", nargs="?", type=Path, default='/etc/libwacom', - help="Directory to load .tablet files from" + "path", + nargs="?", + type=Path, + default="/etc/libwacom", + help="Directory to load .tablet files from", ) # buildsystem-mode is what we use from meson, it changes the # the behavior to just generate the file and print it @@ -241,8 +244,12 @@ if __name__ == "__main__": print(f"New hwdb file: {hwdbfile}") if not ns.skip_systemd_hwdb_update: - subprocess.run(["systemd-hwdb", "update"], - capture_output=True, check=True, text=True) + subprocess.run( + ["systemd-hwdb", "update"], + capture_output=True, + check=True, + text=True, + ) print("Finished, please unplug and replug your device") except PermissionError as e: print(f"{e}, please run me as root") |