From 9609593b8c26925f6c85219c980e3037c2c09d68 Mon Sep 17 00:00:00 2001 From: akutz Date: Mon, 9 Aug 2021 11:22:43 -0500 Subject: [PATCH] Update inconsistent indentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch updates some indentation in a comment that prevented an attempt to run the Black formatter (https://github.com/psf/black) against the cloud-init codebase: $ find cloudinit -name '*.py' -type f | xargs black -l 79 --check ... Oh no! 💥 💔 💥 262 files would be reformatted, 19 files would be left unchanged, 1 file would fail to reformat. The one file that fails to format is cloudinit/net/__init__.py, and running the black command directly against that fail reveals more about the failure: $ black -l 79 --check cloudinit/net/__init__.py error: cannot format cloudinit/net/__init__.py: INTERNAL ERROR: Black produced code that is not equivalent to the source. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: /var/folders/0c/ffr4wl4d37924s44ctztx_ym00bgms/T/blk_y_s4uilq.log Oh no! 💥 💔 💥 1 file would fail to reformat. The highlighted log file contains the abstract syntax tree (AST) that caused the black command to fail: --- src +++ dst @@ -4558,11 +4558,11 @@ value= Constant( kind= None, # NoneType value= - '/* interface name assignment types (sysfs name_assign_type attribute) */\n#define NET_NAME_UNKNOWN\t0\t/* unknown origin (not exposed to user) */\n#define NET_NAME_ENUM\t\t1\t/* enumerated by kernel */\n#define NET_NAME_PREDICTABLE\t2\t/* predictably named by the kernel */\n#define NET_NAME_USER\t\t3\t/* provided by user-space */\n#define NET_NAME_RENAMED\t4\t/* renamed by user-space */', # str + '/* interface name assignment types (sysfs name_assign_type attribute) */\n#define NET_NAME_UNKNOWN 0 /* unknown origin (not exposed to user) */\n#define NET_NAME_ENUM 1 /* enumerated by kernel */\n#define NET_NAME_PREDICTABLE 2 /* predictably named by the kernel */\n#define NET_NAME_USER 3 /* provided by user-space */\n#define NET_NAME_RENAMED 4 /* renamed by user-space */', # str ) # /Constant ) # /Expr Assign( targets= Name( With this fix in place, the black command can successfully parse the file into AST and back again: $ black -l 79 --check cloudinit/net/__init__.py would reformat cloudinit/net/__init__.py Oh no! 💥 💔 💥 1 file would be reformatted. Normally this patch would be part of such an overall effort, but since this is the only location that interrupted running the black command, this author felt it was worth addressing this discrepancy sooner than later in the case there is subsequent desire to use a standard format tool such as black. --- cloudinit/net/__init__.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py index b827d41a7ec..655558a1ef6 100644 --- a/cloudinit/net/__init__.py +++ b/cloudinit/net/__init__.py @@ -313,11 +313,11 @@ def is_netfail_standby(devname, driver=None): def is_renamed(devname): """ /* interface name assignment types (sysfs name_assign_type attribute) */ - #define NET_NAME_UNKNOWN 0 /* unknown origin (not exposed to user) */ - #define NET_NAME_ENUM 1 /* enumerated by kernel */ - #define NET_NAME_PREDICTABLE 2 /* predictably named by the kernel */ - #define NET_NAME_USER 3 /* provided by user-space */ - #define NET_NAME_RENAMED 4 /* renamed by user-space */ + #define NET_NAME_UNKNOWN 0 /* unknown origin (not exposed to user) */ + #define NET_NAME_ENUM 1 /* enumerated by kernel */ + #define NET_NAME_PREDICTABLE 2 /* predictably named by the kernel */ + #define NET_NAME_USER 3 /* provided by user-space */ + #define NET_NAME_RENAMED 4 /* renamed by user-space */ """ name_assign_type = read_sys_net_safe(devname, 'name_assign_type') if name_assign_type and name_assign_type in ['3', '4']: