Pylint throws lots of errors and warnings

Bug #914739 reported by Juerg Haefliger
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init
Fix Released
Undecided
Unassigned

Bug Description

When running pylint against the cloud-init source, lots of errors and warnings are reported. Part of the full output is shown below. Some of them are bogus but some are serious and need to be addressed. I'll post a series of patches shortly that will take care of these errors/warnings.

No config file found, using default configuration
************* Module cloud-init-cfg
C0103: 1: Invalid name "cloud-init-cfg" (should match (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$)
C0111: 1: Missing docstring
C0103: 28:Usage: Invalid name "Usage" (should match [a-z_][a-z0-9_]{2,30}$)
C0111: 28:Usage: Missing docstring
C0111: 31:main: Missing docstring
C0322: 53:main: Operator not preceded by a space
        name=sys.argv[1]
            ^
C0322: 59:main: Operator not preceded by a space
            run_args=sys.argv[3:]
                    ^
C0103: 69:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0324: 73:main: Comma not followed by a space
    cc = CC.CloudConfig(cfg_path,cloud)
                                ^^
C0103: 73:main: Invalid name "cc" (should match [a-z_][a-z0-9_]{2,30}$)
W0703: 78:main: Catch "Exception"
C0324: 76:main: Comma not followed by a space
        (outfmt, errfmt) = CC.get_output_cfg(cc.cfg,modename)
                                                   ^^
C0103: 78:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0324: 88:main: Comma not followed by a space
        module_list = CC.read_cc_modules(cc.cfg,modlist_cfg_name)
                                               ^^
C0324: 90:main: Comma not followed by a space
            err("no modules to run in cloud_config [%s]" % modename,log)
                                                                   ^^
C0324: 95:main: Comma not followed by a space
    failures = CC.run_cc_modules(cc,module_list,log)
                                   ^^
C0324: 97:main: Comma not followed by a space
        err("errors running cloud_config [%s]: %s" % (modename,failures), log)
                                                              ^^
R0912: 31:main: Too many branches (14/12)
R0915: 31:main: Too many statements (51/50)
C0324:100:err: Comma not followed by a space
def err(msg,log=None):
           ^^
C0111:100:err: Missing docstring
C0324:105:fail: Comma not followed by a space
def fail(msg,log=None):
            ^^
C0111:105:fail: Missing docstring
C0324:106:fail: Comma not followed by a space
    err(msg,log)
           ^^
W0611: 26: Unused import traceback
************* Module cloud-init
W0311: 59: Bad indentation. Found 7 spaces, expected 8
W0311: 60: Bad indentation. Found 7 spaces, expected 8
W0311: 61: Bad indentation. Found 7 spaces, expected 8
W0311: 63: Bad indentation. Found 7 spaces, expected 8
W0311: 64: Bad indentation. Found 7 spaces, expected 8
C0103: 1: Invalid name "cloud-init" (should match (([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$)
C0111: 1: Missing docstring

C0111: 33:warn: Missing docstring
C0111: 36:main: Missing docstring
R0914: 36:main: Too many local variables (27/15)
C0324: 57:main: Comma not followed by a space
    now = time.strftime("%a, %d %b %Y %H:%M:%S %z",time.gmtime())
                                                  ^^
C0322: 59:main: Operator not preceded by a space
       uptimef=open("/proc/uptime")
              ^
C0322: 60:main: Operator not preceded by a space
       uptime=uptimef.read().split(" ")[0]
             ^
C0103: 62:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
W0703: 68:main: Catch "Exception"
C0103: 68:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0103: 72:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
W0703: 79:main: Catch "Exception"
C0103: 79:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
W0703: 87:main: Catch "Exception"
C0103: 87:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0103: 99:main: Invalid name "f" (should match [a-z_][a-z0-9_]{2,30}$)
W0702:104:main: No exception type(s) specified
C0103:101:main: Invalid name "fp" (should match [a-z_][a-z0-9_]{2,30}$)

C0324:112:main: Comma not followed by a space
        manclean = util.get_cfg_option_bool(cfg, 'manual_cache_clean',False)
                                                                     ^^
C0103:119:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0321:120:main: More than one statement on a single line
C0103:132:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)

C0103:157:main: Invalid name "cc" (should match [a-z_][a-z0-9_]{2,30}$)
W0703:167:main: Catch "Exception"
C0324:165:main: Comma not followed by a space
            warn("stdout, stderr changing to (%s,%s)" % (outfmt,errfmt))
                                                               ^^
C0103:167:main: Invalid name "e" (should match [a-z_][a-z0-9_]{2,30}$)
C0324:176:main: Comma not followed by a space
        if isinstance(cc_ready,str):
                              ^^
C0324:184:main: Comma not followed by a space
        failures = CC.run_cc_modules(cc,module_list,log)
                                       ^^

R0912: 36:main: Too many branches (24/12)
R0915: 36:main: Too many statements (111/50)

Related branches

Revision history for this message
Juerg Haefliger (juergh) wrote :

The attached tarball contains a patch series that takes care of the pylint errors.

Revision history for this message
Juerg Haefliger (juergh) wrote :

Above patchset fixes the following errors:

************* Module cloud-init-query
E1101: 36:main: Module 'cloudinit' has no 'cloud_config' member
************* Module cloudinit
E0211:583:InternalPartHandler.__repr__: Method has no argument
E0602:584:InternalPartHandler.__repr__: Undefined variable 'self'
************* Module cloudinit.util
E0702:233:read_seeded: Raising NoneType while only classes, instances or string are allowed
************* Module cloudinit.DataSourceEc2
E0102:235:wait_for_metadata_service.status_cb: function already defined line 205
************* Module cloudinit.UserDataHandler
E1101: 70:do_include: Module 'hashlib' has no 'md5' member
************* Module cloudinit.DataSource
E1103:122:DataSource.get_hostname: Instance of 'bool' has no 'split' member (but some types could not be inferred)
************* Module cloudinit.netinfo
E1103: 7:netdev_info: Instance of 'list' has no 'splitlines' member (but some types could not be inferred)
E1103: 45:route_info: Instance of 'list' has no 'splitlines' member (but some types could not be inferred)
************* Module cloudinit.SshUtil
E0101: 20:AuthKeyEntry.__init__: Explicit return in __init__
************* Module cloudinit.CloudConfig.cc_phone_home
E1101: 36:handle: Module 'cloudinit.util' has no 'readconf' member
E0702: 98:handle: Raising NoneType while only classes, instances or string are allowed
************* Module cloudinit.CloudConfig.cc_bootcmd
E0602: 38:handle: Undefined variable 'os'
************* Module cloudinit.CloudConfig.cc_resizefs
E1103: 65:handle: Instance of 'list' has no 'rstrip' member (but some types could not be inferred)
E1103: 67:handle: Instance of 'list' has no 'startswith' member (but some types could not be inferred)
************* Module cloudinit.CloudConfig.cc_apt_update_upgrade
E1103:125:get_release: Instance of 'list' has no 'strip' member (but some types could not be inferred)

Revision history for this message
Juerg Haefliger (juergh) wrote :
Download full text (3.4 KiB)

Attached patchset fixes the following pylint warnings. The patches get rid of a total of 281 warnings.

Juerg Haefliger (13):
  Fix pylint warnings W0311 (bad indentation)
  Fix pylint warnings W0312 (found indentation with tabs instead of spaces)
  Fix pylint warnings W0301 (unnecessary semicolon)
  Fix pylint warnings W0611 (unused import)
  Fix pylint warnings W0613 (unused argument)
  Fix pylint warnings W0612 (unused variable)
  Fix pylint warnings W0622 (redefining built-in 'xyz')
  Fix pylint warnings W0104 (statement seems to have no effect)
  Fix pylint warnings W0107 (unnecessary pass statement)
  Fix pylint warnings W0102 (dangerous default value as argument)
  Fix pylint warnings W0141 (used builtin function xyz)
  Fix pylint warnings W0201 (attribute xyz defined outside __init__)
  Disable bogus pylint warnings

 cloud-init-cfg.py | 1 -
 cloud-init-query.py | 4 -
 cloud-init.py | 10 +-
 cloudinit/CloudConfig/__init__.py | 6 +-
 cloudinit/CloudConfig/cc_apt_update_upgrade.py | 26 +++--
 cloudinit/CloudConfig/cc_bootcmd.py | 2 +-
 cloudinit/CloudConfig/cc_byobu.py | 2 +-
 cloudinit/CloudConfig/cc_chef.py | 12 +--
 cloudinit/CloudConfig/cc_disable_ec2_metadata.py | 2 +-
 cloudinit/CloudConfig/cc_final_message.py | 2 +-
 cloudinit/CloudConfig/cc_foo.py | 10 +-
 cloudinit/CloudConfig/cc_grub_dpkg.py | 4 +-
 cloudinit/CloudConfig/cc_keys_to_console.py | 2 +-
 cloudinit/CloudConfig/cc_landscape.py | 2 +-
 cloudinit/CloudConfig/cc_locale.py | 2 +-
 cloudinit/CloudConfig/cc_mcollective.py | 6 +-
 cloudinit/CloudConfig/cc_mounts.py | 4 +-
 cloudinit/CloudConfig/cc_phone_home.py | 3 +-
 cloudinit/CloudConfig/cc_puppet.py | 2 +-
 cloudinit/CloudConfig/cc_resizefs.py | 14 +-
 cloudinit/CloudConfig/cc_rightscale_userdata.py | 8 +-
 cloudinit/CloudConfig/cc_rsyslog.py | 8 +-
 cloudinit/CloudConfig/cc_runcmd.py | 4 +-
 cloudinit/CloudConfig/cc_scripts_per_boot.py | 7 +-
 cloudinit/CloudConfig/cc_scripts_per_instance.py | 7 +-
 cloudinit/CloudConfig/cc_scripts_per_once.py | 7 +-
 cloudinit/CloudConfig/cc_scripts_user.py | 7 +-
 cloudinit/CloudConfig/cc_set_hostname.py | 8 +-
 cloudinit/CloudConfig/cc_set_passwords.py | 6 +-
 cloudinit/CloudConfig/cc_ssh.py | 2 +-
 cloudinit/CloudConfig/cc_ssh_import_id.py | 2 +-
 cloudinit/CloudConfig/cc_timezone.py | 4 +-
 cloudinit/CloudConfig/cc_update_etc_hosts.py | 64 +++++-----
 cloudinit/CloudConfig/cc_update_hostname.py | 6 +-
 cloudinit/DataSource.py | 12 +-
 cloudinit/DataSourceEc2.py | 10 +-
 cloudinit/DataSourceNoCloud.py | 8 +-
 cloudinit/DataSourceOVF.py | 10 +-
 cloudinit/SshUtil.py | 8 +-
 cloudinit/U...

Read more...

Scott Moser (smoser)
Changed in cloud-init:
status: New → Fix Committed
Revision history for this message
Juerg Haefliger (juergh) wrote :

Attached patchset fixed the following pylint convention violations. The patches fix a total of 450 violations.

Juerg Haefliger (4):
  Fix pylint conventions C0321 (more than one statement on a single line)
  Fix pylint conventions C0322 (operator not preceded by a space)
  Fix pylint conventions C0324 (comma not followed by a space)
  Fix pylint conventions C0301 (line too long)

 cloud-init-cfg.py | 22 ++--
 cloud-init-query.py | 2 +-
 cloud-init.py | 27 ++--
 cloudinit/CloudConfig/__init__.py | 89 +++++++-----
 cloudinit/CloudConfig/cc_apt_update_upgrade.py | 55 ++++----
 cloudinit/CloudConfig/cc_bootcmd.py | 6 +-
 cloudinit/CloudConfig/cc_byobu.py | 9 +-
 cloudinit/CloudConfig/cc_chef.py | 39 +++---
 cloudinit/CloudConfig/cc_disable_ec2_metadata.py | 4 +-
 cloudinit/CloudConfig/cc_final_message.py | 10 +-
 cloudinit/CloudConfig/cc_foo.py | 2 +-
 cloudinit/CloudConfig/cc_grub_dpkg.py | 25 ++--
 cloudinit/CloudConfig/cc_keys_to_console.py | 10 +-
 cloudinit/CloudConfig/cc_landscape.py | 2 +-
 cloudinit/CloudConfig/cc_locale.py | 7 +-
 cloudinit/CloudConfig/cc_mcollective.py | 32 +++--
 cloudinit/CloudConfig/cc_mounts.py | 52 +++++---
 cloudinit/CloudConfig/cc_phone_home.py | 12 +-
 cloudinit/CloudConfig/cc_puppet.py | 18 ++-
 cloudinit/CloudConfig/cc_resizefs.py | 16 ++-
 cloudinit/CloudConfig/cc_rightscale_userdata.py | 10 +-
 cloudinit/CloudConfig/cc_rsyslog.py | 9 +-
 cloudinit/CloudConfig/cc_runcmd.py | 6 +-
 cloudinit/CloudConfig/cc_scripts_per_boot.py | 2 +-
 cloudinit/CloudConfig/cc_scripts_per_instance.py | 2 +-
 cloudinit/CloudConfig/cc_scripts_per_once.py | 2 +-
 cloudinit/CloudConfig/cc_scripts_user.py | 2 +-
 cloudinit/CloudConfig/cc_set_hostname.py | 6 +-
 cloudinit/CloudConfig/cc_set_passwords.py | 34 +++---
 cloudinit/CloudConfig/cc_ssh.py | 30 +++--
 cloudinit/CloudConfig/cc_ssh_import_id.py | 9 +-
 cloudinit/CloudConfig/cc_timezone.py | 9 +-
 cloudinit/CloudConfig/cc_update_etc_hosts.py | 6 +-
 cloudinit/CloudConfig/cc_update_hostname.py | 17 ++-
 cloudinit/DataSource.py | 16 ++-
 cloudinit/DataSourceEc2.py | 34 +++--
 cloudinit/DataSourceNoCloud.py | 40 +++---
 cloudinit/DataSourceOVF.py | 68 +++++----
 cloudinit/SshUtil.py | 23 ++--
 cloudinit/UserDataHandler.py | 23 ++--
 cloudinit/__init__.py | 161 ++++++++++++----------
 cloudinit/netinfo.py | 6 +-
 cloudinit/util.py | 151 +++++++++++---------
 43 files changed, 619 insertions(+), 486 deletions(-)

Revision history for this message
Juerg Haefliger (juergh) wrote :

Attached patch fixes the remaining PEP8 violations (http://www.python.org/dev/peps/pep-0008/').

Juerg Haefliger (1):
  PEP8 coding style fixes.

 cloud-init-cfg.py | 18 ++-
 cloud-init-query.py | 12 +-
 cloud-init.py | 16 ++-
 cloudinit/CloudConfig/__init__.py | 34 ++++--
 cloudinit/CloudConfig/cc_apt_update_upgrade.py | 38 ++++---
 cloudinit/CloudConfig/cc_bootcmd.py | 5 +-
 cloudinit/CloudConfig/cc_byobu.py | 11 +-
 cloudinit/CloudConfig/cc_chef.py | 18 ++-
 cloudinit/CloudConfig/cc_disable_ec2_metadata.py | 1 +
 cloudinit/CloudConfig/cc_final_message.py | 4 +-
 cloudinit/CloudConfig/cc_foo.py | 1 +
 cloudinit/CloudConfig/cc_grub_dpkg.py | 10 +-
 cloudinit/CloudConfig/cc_keys_to_console.py | 3 +-
 cloudinit/CloudConfig/cc_landscape.py | 6 +-
 cloudinit/CloudConfig/cc_locale.py | 4 +-
 cloudinit/CloudConfig/cc_mcollective.py | 8 +-
 cloudinit/CloudConfig/cc_mounts.py | 28 +++---
 cloudinit/CloudConfig/cc_phone_home.py | 15 ++-
 cloudinit/CloudConfig/cc_puppet.py | 6 +-
 cloudinit/CloudConfig/cc_resizefs.py | 13 +-
 cloudinit/CloudConfig/cc_rightscale_userdata.py | 9 +-
 cloudinit/CloudConfig/cc_rsyslog.py | 9 +-
 cloudinit/CloudConfig/cc_runcmd.py | 3 +-
 cloudinit/CloudConfig/cc_scripts_per_boot.py | 1 +
 cloudinit/CloudConfig/cc_scripts_per_instance.py | 1 +
 cloudinit/CloudConfig/cc_scripts_per_once.py | 1 +
 cloudinit/CloudConfig/cc_scripts_user.py | 1 +
 cloudinit/CloudConfig/cc_set_hostname.py | 4 +-
 cloudinit/CloudConfig/cc_set_passwords.py | 25 +++--
 cloudinit/CloudConfig/cc_ssh.py | 30 +++---
 cloudinit/CloudConfig/cc_ssh_import_id.py | 9 +-
 cloudinit/CloudConfig/cc_timezone.py | 5 +-
 cloudinit/CloudConfig/cc_update_etc_hosts.py | 8 +-
 cloudinit/CloudConfig/cc_update_hostname.py | 12 +-
 cloudinit/DataSource.py | 31 +++---
 cloudinit/DataSourceEc2.py | 39 ++++---
 cloudinit/DataSourceNoCloud.py | 31 +++--
 cloudinit/DataSourceOVF.py | 66 ++++++-----
 cloudinit/SshUtil.py | 30 +++--
 cloudinit/UserDataHandler.py | 44 +++++---
 cloudinit/__init__.py | 131 ++++++++++++---------
 cloudinit/netinfo.py | 23 +++--
 cloudinit/util.py | 96 +++++++++++-----
 43 files changed, 501 insertions(+), 359 deletions(-)

Revision history for this message
Juerg Haefliger (juergh) wrote :

Sorry, link to PEP8 in the previous comment is broken. Correct link is: http://www.python.org/dev/peps/pep-0008/

Revision history for this message
Juerg Haefliger (juergh) wrote :

With the attached patches, the code is now clean when checked as follows:

#!/bin/bash

files='cloud*.py cloudinit/*.py cloudinit/CloudConfig/*.py'

cmd=(
    pylint
    --reports=n
    --include-ids=y
    --max-line-length=79

    --disable=R
    --disable=I

    --disable=W0142 # Used * or ** magic
    --disable=W0402 # Uses of a deprecated module
    --disable=W0404 # Reimport xyz
    --disable=W0511 # TODO/FIXME note
    --disable=W0603 # Using the global statement
    --disable=W0621 # Redefining name xyz from outer scope
    --disable=W0702 # No exception type(s) specified
    --disable=W0703 # Catch "Exception"

    --disable=C0103 # Invalid name
    --disable=C0111 # Missing docstring

    $files
)

echo -e "\nRunning pylint:"
echo ${cmd[*]}
eval ${cmd[*]}

cmd=(
    pep8

    --ignore=E501 # Line too long (these are caught by pylint above)

    $files
)

echo -e "\nRunning pep8:"
echo ${cmd[*]}
eval ${cmd[*]}

Revision history for this message
Juerg Haefliger (juergh) wrote :

Final patch that adds HP to the copyright notice to please the legal department.

Juerg Haefliger (1):
  Fix license to please HP legal

 cloud-init-cfg.py | 2 ++
 cloud-init-query.py | 2 ++
 cloud-init.py | 2 ++
 cloudinit/CloudConfig/__init__.py | 3 +++
 cloudinit/CloudConfig/cc_apt_update_upgrade.py | 3 +++
 cloudinit/CloudConfig/cc_bootcmd.py | 2 ++
 cloudinit/CloudConfig/cc_byobu.py | 3 +++
 cloudinit/CloudConfig/cc_chef.py | 3 +++
 cloudinit/CloudConfig/cc_disable_ec2_metadata.py | 2 ++
 cloudinit/CloudConfig/cc_final_message.py | 3 +++
 cloudinit/CloudConfig/cc_foo.py | 2 ++
 cloudinit/CloudConfig/cc_grub_dpkg.py | 2 ++
 cloudinit/CloudConfig/cc_keys_to_console.py | 3 +++
 cloudinit/CloudConfig/cc_landscape.py | 3 +++
 cloudinit/CloudConfig/cc_locale.py | 3 +++
 cloudinit/CloudConfig/cc_mcollective.py | 2 ++
 cloudinit/CloudConfig/cc_mounts.py | 3 +++
 cloudinit/CloudConfig/cc_phone_home.py | 2 ++
 cloudinit/CloudConfig/cc_puppet.py | 3 +++
 cloudinit/CloudConfig/cc_resizefs.py | 2 ++
 cloudinit/CloudConfig/cc_rightscale_userdata.py | 2 ++
 cloudinit/CloudConfig/cc_rsyslog.py | 2 ++
 cloudinit/CloudConfig/cc_runcmd.py | 2 ++
 cloudinit/CloudConfig/cc_scripts_per_boot.py | 2 ++
 cloudinit/CloudConfig/cc_scripts_per_instance.py | 2 ++
 cloudinit/CloudConfig/cc_scripts_per_once.py | 2 ++
 cloudinit/CloudConfig/cc_scripts_user.py | 2 ++
 cloudinit/CloudConfig/cc_set_hostname.py | 2 ++
 cloudinit/CloudConfig/cc_set_passwords.py | 2 ++
 cloudinit/CloudConfig/cc_ssh.py | 3 +++
 cloudinit/CloudConfig/cc_ssh_import_id.py | 3 +++
 cloudinit/CloudConfig/cc_timezone.py | 2 ++
 cloudinit/CloudConfig/cc_update_etc_hosts.py | 3 +++
 cloudinit/CloudConfig/cc_update_hostname.py | 3 +++
 cloudinit/DataSource.py | 2 ++
 cloudinit/DataSourceEc2.py | 2 ++
 cloudinit/DataSourceNoCloud.py | 2 ++
 cloudinit/DataSourceOVF.py | 2 ++
 cloudinit/SshUtil.py | 19 +++++++++++++++++++
 cloudinit/UserDataHandler.py | 3 +++
 cloudinit/__init__.py | 2 ++
 cloudinit/netinfo.py | 21 +++++++++++++++++++++
 cloudinit/util.py | 3 +++
 43 files changed, 138 insertions(+), 0 deletions(-)

Scott Moser (smoser)
Changed in cloud-init:
status: Fix Committed → Fix Released
Revision history for this message
James Falcon (falcojr) wrote :
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.