← Back to team overview

curtin-dev team mailing list archive

[Merge] ~dbungert/curtin:pylint-vs-namedtuple into curtin:master

 

Dan Bungert has proposed merging ~dbungert/curtin:pylint-vs-namedtuple into curtin:master.

Commit message:
Ignore no-member false positive from pylint

pylint is, about 15% of the time, reporting a no-member error on users
of DISTROS.  So we can disable that error in that case and get more
predictable behavior, but why is the error on 15% of the time?


Requested reviews:
  Michael Hudson-Doyle (mwhudson)

For more details, see:
https://code.launchpad.net/~dbungert/curtin/+git/curtin/+merge/402610

Reproduction steps for pylint
Run `tox -e py3-pylint` 100 times, and expect to see the no-member errors ~15 of those times.
-- 
Your team curtin developers is subscribed to branch curtin:master.
diff --git a/curtin/commands/install_grub.py b/curtin/commands/install_grub.py
index ba46bd2..54d078f 100644
--- a/curtin/commands/install_grub.py
+++ b/curtin/commands/install_grub.py
@@ -90,7 +90,7 @@ def get_grub_config_file(target=None, osfamily=None):
     if not osfamily:
         osfamily = distro.get_osfamily(target=target)
 
-    if osfamily == distro.DISTROS.debian:
+    if osfamily == distro.DISTROS.debian:  # pylint: disable=E1101
         # to avoid tripping prompts on upgrade LP: #564853
         return '/etc/default/grub.d/50-curtin-settings.cfg'
 
@@ -152,7 +152,7 @@ def get_carryover_params(distroinfo):
             carry_lead.append(tok)
 
     # always append rd.auto=1 for redhat family
-    if distroinfo.family == distro.DISTROS.redhat:
+    if distroinfo.family == distro.DISTROS.redhat:  # pylint: disable=E1101
         carry_extra.append('rd.auto=1')
 
     return carry_lead + carry_extra
@@ -243,11 +243,11 @@ def get_efi_disk_part(devices):
 
 def get_grub_install_command(uefi, distroinfo, target):
     grub_install_cmd = 'grub-install'
-    if distroinfo.family == distro.DISTROS.debian:
+    if distroinfo.family == distro.DISTROS.debian:  # pylint: disable=E1101
         # prefer grub-multi-install if present
         if uefi and os.path.exists(target_path(target, GRUB_MULTI_INSTALL)):
             grub_install_cmd = GRUB_MULTI_INSTALL
-    elif distroinfo.family == distro.DISTROS.redhat:
+    elif distroinfo.family == distro.DISTROS.redhat:  # pylint: disable=E1101
         grub_install_cmd = 'grub2-install'
 
     LOG.debug('Using grub install command: %s', grub_install_cmd)
@@ -260,10 +260,10 @@ def gen_uefi_install_commands(grub_name, grub_target, grub_cmd, update_nvram,
     post_cmds = []
     bootid = distroinfo.variant
     efidir = '/boot/efi'
-    if distroinfo.family == distro.DISTROS.debian:
+    if distroinfo.family == distro.DISTROS.debian:  # pylint: disable=E1101
         install_cmds.append(['dpkg-reconfigure', grub_name])
         install_cmds.append(['update-grub'])
-    elif distroinfo.family == distro.DISTROS.redhat:
+    elif distroinfo.family == distro.DISTROS.redhat:  # pylint: disable=E1101
         # RHEL distros uses 'redhat' for bootid
         if bootid == 'rhel':
             bootid = 'redhat'
@@ -309,10 +309,10 @@ def gen_install_commands(grub_name, grub_cmd, distroinfo, devices,
                          rhel_ver=None):
     install_cmds = []
     post_cmds = []
-    if distroinfo.family == distro.DISTROS.debian:
+    if distroinfo.family == distro.DISTROS.debian:  # pylint: disable=E1101
         install_cmds.append(['dpkg-reconfigure', grub_name])
         install_cmds.append(['update-grub'])
-    elif distroinfo.family == distro.DISTROS.redhat:
+    elif distroinfo.family == distro.DISTROS.redhat:  # pylint: disable=E1101
         if rhel_ver in ["7", "8"]:
             post_cmds.append(
                 ['grub2-mkconfig', '-o', '/boot/grub2/grub.cfg'])
@@ -372,7 +372,8 @@ def install_grub(devices, target, uefi=None, grubcfg=None):
     distroinfo = distro.get_distroinfo(target=target)
     target_arch = distro.get_architecture(target=target)
     rhel_ver = (distro.rpm_get_dist_id(target)
-                if distroinfo.family == distro.DISTROS.redhat else None)
+                if distroinfo.family == distro.DISTROS.redhat  # pylint: disable=E1101
+                else None)
 
     check_target_arch_machine(target, arch=target_arch, uefi=uefi)
     grub_name, grub_target = get_grub_package_name(target_arch, uefi, rhel_ver)
diff --git a/curtin/distro.py b/curtin/distro.py
index 82a4dd5..2143c2f 100644
--- a/curtin/distro.py
+++ b/curtin/distro.py
@@ -32,6 +32,11 @@ def distro_enum(*distros):
     return namedtuple('Distros', distros)(*distros)
 
 
+# Users of DISTROS may encounter a no-member error from pylint, but that
+# appears to be a pylint bug.
+# https://github.com/PyCQA/pylint/issues/1628
+# https://github.com/PyCQA/pylint/issues/3876
+# affected code has been marked with pylint: disable=E1101
 DISTROS = distro_enum(*DISTRO_NAMES)
 
 OS_FAMILIES = {

Follow ups