cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #01784
[Merge] ~powersj/cloud-init:enable-pylint into cloud-init:master
Joshua Powers has proposed merging ~powersj/cloud-init:enable-pylint into cloud-init:master.
Commit message:
test: enable pylint support in tox
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~powersj/cloud-init/+git/cloud-init/+merge/320560
Why enable pylint?
pylint has the ability to catch errors that pyflakes/flake8 simply wont. pylint sets the bar higher for what can get accepted in terms of quality.
This set of commits enables pylint to run without errors. This does not add it to the list of tests when running tox as I think that is something up for discussion. Please review the configuration and the changes to the code.
There are a number of legit errors that I have updated the code to avoid those errors. However, there are two places where a variable was changes from being instantiated as None to {}. This is due to pylint stating how a None object cannot be check for in (e.g. 'my_key' in variable, if variable is None). I really, really do not want to be breaking some existing infrastructure.
pylint output:
https://paste.ubuntu.com/24224371/
tox clean:
https://paste.ubuntu.com/24224366/
Integration test using Xenial:
https://paste.ubuntu.com/24224456/
--
Your team cloud init development team is requested to review the proposed merge of ~powersj/cloud-init:enable-pylint into cloud-init:master.
diff --git a/.pylintrc b/.pylintrc
new file mode 100644
index 0000000..d73d133
--- /dev/null
+++ b/.pylintrc
@@ -0,0 +1,34 @@
+[MASTER]
+
+# --go-faster, use multiple processes to speed up Pylint
+jobs=4
+
+
+[MESSAGES CONTROL]
+
+# Errors only
+disable=C, F, I, R, W
+
+
+[REPORTS]
+
+# Set the output format. Available formats are text, parseable, colorized, msvs
+output-format=colorized
+
+# Just the errors please, no full report
+reports=no
+
+
+[TYPECHECK]
+
+# List of module names for which member attributes should not be checked
+# (useful for modules/projects where namespaces are manipulated during runtime
+# and thus existing member attributes cannot be deduced by static analysis. It
+# supports qualified module names, as well as Unix pattern matching.
+ignored-modules=six.moves,pkg_resources
+
+# List of members which are set dynamically and missed by pylint inference
+# system, and so shouldn't trigger E1101 when accessed. Python regular
+# expressions are accepted.
+generated-members=types,http.client,command_handlers
+
diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
index 701aaa4..692b600 100644
--- a/cloudinit/net/network_state.py
+++ b/cloudinit/net/network_state.py
@@ -214,7 +214,7 @@ class NetworkStateInterpreter(object):
return util.yaml_dumps(self._network_state)
def as_dict(self):
- return {'version': self.version, 'config': self.config}
+ return {'version': self._version, 'config': self._config}
def get_network_state(self):
ns = self.network_state
@@ -611,7 +611,8 @@ class NetworkStateInterpreter(object):
self.handle_vlan(vlan_cmd)
def handle_wifis(self, command):
- raise NotImplemented('NetworkState V2: Skipping wifi configuration')
+ raise NotImplementedError("NetworkState V2: "
+ "Skipping wifi configuration")
def _v2_common(self, cfg):
LOG.debug('v2_common: handling config:\n%s', cfg)
diff --git a/cloudinit/sources/DataSourceAltCloud.py b/cloudinit/sources/DataSourceAltCloud.py
index c2b0eac..8528fa1 100644
--- a/cloudinit/sources/DataSourceAltCloud.py
+++ b/cloudinit/sources/DataSourceAltCloud.py
@@ -201,8 +201,7 @@ class DataSourceAltCloud(sources.DataSource):
util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
return False
except OSError as _err:
- util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd),
- _err.message)
+ util.logexc(LOG, 'Failed command: %s\n%s', ' '.join(cmd), _err)
return False
try:
diff --git a/cloudinit/sources/DataSourceOpenNebula.py b/cloudinit/sources/DataSourceOpenNebula.py
index 1f1baf4..10c6d3d 100644
--- a/cloudinit/sources/DataSourceOpenNebula.py
+++ b/cloudinit/sources/DataSourceOpenNebula.py
@@ -282,7 +282,7 @@ def parse_shell_config(content, keylist=None, bash=None, asuser=None,
excluded = ("RANDOM", "LINENO", "SECONDS", "_", "__v")
preset = {}
ret = {}
- target = None
+ target = {}
output = output[0:-1] # remove trailing null
# go through output. First _start_ is for 'preset', second for 'target'.
@@ -298,7 +298,7 @@ def parse_shell_config(content, keylist=None, bash=None, asuser=None,
except ValueError:
if line != "_start_":
raise
- if target is None:
+ if target == {}:
target = preset
elif target is preset:
target = ret
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 1829450..5c99437 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -50,7 +50,7 @@ class DataSource(object):
self.distro = distro
self.paths = paths
self.userdata = None
- self.metadata = None
+ self.metadata = {}
self.userdata_raw = None
self.vendordata = None
self.vendordata_raw = None
diff --git a/cloudinit/url_helper.py b/cloudinit/url_helper.py
index 312b046..2f6a158 100644
--- a/cloudinit/url_helper.py
+++ b/cloudinit/url_helper.py
@@ -45,7 +45,7 @@ try:
from distutils.version import LooseVersion
import pkg_resources
_REQ = pkg_resources.get_distribution('requests')
- _REQ_VER = LooseVersion(_REQ.version)
+ _REQ_VER = LooseVersion(_REQ.version) # pylint: disable=no-member
if _REQ_VER >= LooseVersion('0.8.8'):
SSL_ENABLED = True
if _REQ_VER >= LooseVersion('0.7.0') and _REQ_VER < LooseVersion('1.0.0'):
diff --git a/tox.ini b/tox.ini
index f016f20..d65ec48 100644
--- a/tox.ini
+++ b/tox.ini
@@ -17,6 +17,10 @@ commands = {envpython} -m flake8 {posargs:cloudinit/ tests/ tools/}
setenv =
LC_ALL = en_US.utf-8
+[testenv:pylint]
+deps = pylint
+commands = {envpython} -m pylint {posargs:cloudinit}
+
[testenv:py3]
basepython = python3
commands = {envpython} -m nose {posargs:--with-coverage \
Follow ups