From cecbbfb65196e9e96765d2cf8fa9cd57a85d2988 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Fri, 26 Jul 2024 10:33:25 +0200 Subject: [PATCH 1/2] pkg: enable E501 for pkg/ directory This requires us to fix two easy violations. --- pkg/ruff.toml | 2 -- pkg/storaged/crypto/luksmeta-monitor-hack.py | 3 ++- pkg/storaged/mount-users.py | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/ruff.toml b/pkg/ruff.toml index 90be695d8c4..7272ad1fcf5 100644 --- a/pkg/ruff.toml +++ b/pkg/ruff.toml @@ -2,8 +2,6 @@ extend = "../pyproject.toml" [lint] ignore = [ - "E501", # https://github.com/charliermarsh/ruff/issues/3206#issuecomment-1562681390 - "EXE001", # Shebang is present but file is not executable "F821", # Undefined name ] diff --git a/pkg/storaged/crypto/luksmeta-monitor-hack.py b/pkg/storaged/crypto/luksmeta-monitor-hack.py index 770f64d984a..a55c4e9ce40 100755 --- a/pkg/storaged/crypto/luksmeta-monitor-hack.py +++ b/pkg/storaged/crypto/luksmeta-monitor-hack.py @@ -96,7 +96,8 @@ def info(dev): match = re.match(b" ([0-9]+): clevis$", line) if match: try: - token = subprocess.check_output(["cryptsetup", "token", "export", dev, "--token-id", match.group(1)], + token = subprocess.check_output(["cryptsetup", "token", "export", + dev, "--token-id", match.group(1)], stderr=subprocess.PIPE) token_object = json.loads(token.decode()) if token_object.get("type") == "clevis": diff --git a/pkg/storaged/mount-users.py b/pkg/storaged/mount-users.py index 88460f63537..f4e337f2da2 100644 --- a/pkg/storaged/mount-users.py +++ b/pkg/storaged/mount-users.py @@ -30,7 +30,8 @@ def get_stat(pid): # Field two is everything between the first "(" and the last ")", the rest is space separated. comm_start = stat.index("(") + 1 comm_end = stat.rindex(")") - return ([stat[0:comm_start - 1].strip(), stat[comm_start:comm_end], *list(filter(lambda f: f != '', stat[comm_end + 1:-1].split(' ')))]) + return ([stat[0:comm_start - 1].strip(), stat[comm_start:comm_end], + *list(filter(lambda f: f != '', stat[comm_end + 1:-1].split(' ')))]) def get_loginuser(pid): uid = os.stat("/proc/%s" % pid).st_uid From bed3d49ab4e4fffc383c0508b51410b920280249 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Fri, 26 Jul 2024 10:36:24 +0200 Subject: [PATCH 2/2] pkg: fix shebang present by file is not executable This leaves one exclude which is hard to fix (undefined name F821) due to the nature how we run python scripts with inotify. We can't import inotify as we use our own inotify Python library which we concatenate before the executed script (for example mount-users.py). --- pkg/ruff.toml | 1 - pkg/storaged/legacy-vdo/vdo-monitor.py | 0 pkg/storaged/mount-users.py | 0 3 files changed, 1 deletion(-) mode change 100644 => 100755 pkg/storaged/legacy-vdo/vdo-monitor.py mode change 100644 => 100755 pkg/storaged/mount-users.py diff --git a/pkg/ruff.toml b/pkg/ruff.toml index 7272ad1fcf5..56f360b8831 100644 --- a/pkg/ruff.toml +++ b/pkg/ruff.toml @@ -2,6 +2,5 @@ extend = "../pyproject.toml" [lint] ignore = [ - "EXE001", # Shebang is present but file is not executable "F821", # Undefined name ] diff --git a/pkg/storaged/legacy-vdo/vdo-monitor.py b/pkg/storaged/legacy-vdo/vdo-monitor.py old mode 100644 new mode 100755 diff --git a/pkg/storaged/mount-users.py b/pkg/storaged/mount-users.py old mode 100644 new mode 100755