summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-07-25 14:16:00 (GMT)
committerThomas Haller <thaller@redhat.com>2023-07-25 14:16:00 (GMT)
commitc7d473fd7ba21bd17433136c331c7821bc694cfd (patch)
treed0d59983e5e2064e0168cdc2ba60ec203d4360fc
parenteb9b9c077a99350addf1b092ec7d45bacfddad14 (diff)
parent35a68109ac9217e6d378d0cdc7d8bd9760203635 (diff)
downloadlibnl-c7d473fd7ba21bd17433136c331c7821bc694cfd.zip
libnl-c7d473fd7ba21bd17433136c331c7821bc694cfd.tar.gz
libnl-c7d473fd7ba21bd17433136c331c7821bc694cfd.tar.bz2
python: merge branch 'th/flake8'
-rw-r--r--.flake87
-rw-r--r--.github/workflows/ci.yml2
-rwxr-xr-xdoc/doxygen-link.py1
-rwxr-xr-xdoc/resolve-asciidoc-refs.py3
-rw-r--r--python/doc/conf.py2
-rw-r--r--python/examples/iface.py4
-rw-r--r--python/examples/wiphy.py4
-rw-r--r--python/netlink/core.py10
-rw-r--r--python/netlink/route/link.py4
-rw-r--r--python/netlink/route/links/bridge.py2
-rw-r--r--python/netlink/route/tc.py12
-rw-r--r--python/netlink/util.py3
12 files changed, 28 insertions, 26 deletions
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..afddf49
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,7 @@
+[flake8]
+extend-ignore =
+ E203
+ E501
+filename =
+ *.py
+ *.py.in
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index fb71c30..6dae08e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -57,7 +57,7 @@ jobs:
if: ${{ matrix.cc == 'gcc' }}
run: |
python3 -m pip install flake8
- flake8 . --count --select=E703,E9,F63,F7,F82,Y --show-source --statistics
+ flake8 . --count --show-source --statistics
- name: Code formatting with Python black
if: ${{ matrix.cc == 'gcc' }}
diff --git a/doc/doxygen-link.py b/doc/doxygen-link.py
index 8f3cbcc..2dcd5f0 100755
--- a/doc/doxygen-link.py
+++ b/doc/doxygen-link.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
from __future__ import print_function
-import fileinput
import re
import sys
diff --git a/doc/resolve-asciidoc-refs.py b/doc/resolve-asciidoc-refs.py
index e7d79fe..d661c56 100755
--- a/doc/resolve-asciidoc-refs.py
+++ b/doc/resolve-asciidoc-refs.py
@@ -2,7 +2,6 @@
from __future__ import print_function
-import fileinput
import re
import sys
@@ -12,7 +11,7 @@ complete_file = ""
for line in open(sys.argv[1], "r"):
complete_file += line
-for m in re.findall("\[\[(.+)\]\]\n=+ ([^\n]+)", complete_file):
+for m in re.findall("\\[\\[(.+)\\]\\]\n=+ ([^\n]+)", complete_file):
ref, title = m
refs["<<" + ref + ">>"] = "<<" + ref + ", " + title + ">>"
diff --git a/python/doc/conf.py b/python/doc/conf.py
index 97f931a..dfa53ab 100644
--- a/python/doc/conf.py
+++ b/python/doc/conf.py
@@ -11,8 +11,6 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
-
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
diff --git a/python/examples/iface.py b/python/examples/iface.py
index 8cc8df5..afeafff 100644
--- a/python/examples/iface.py
+++ b/python/examples/iface.py
@@ -63,7 +63,7 @@ def msg_handler(m, a):
sys.stdout.write("\n")
return nl.NL_SKIP
- except Exception as e:
+ except Exception:
(t, v, tb) = sys.exc_info()
print(v.message)
traceback.print_tb(tb)
@@ -106,7 +106,7 @@ try:
while cbd.done > 0 and not err < 0:
err = nl.nl_recvmsgs(s, rx_cb)
-except Exception as e:
+except Exception:
(t, v, tb) = sys.exc_info()
print(v.message)
traceback.print_tb(tb)
diff --git a/python/examples/wiphy.py b/python/examples/wiphy.py
index 777ac69..572e95a 100644
--- a/python/examples/wiphy.py
+++ b/python/examples/wiphy.py
@@ -113,7 +113,7 @@ def msg_handler(m, a):
for nl_mode in ifattr:
print("\t\t* %s" % nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
return nl.NL_SKIP
- except Exception as e:
+ except Exception:
(t, v, tb) = sys.exc_info()
print(v.message)
traceback.print_tb(tb)
@@ -155,7 +155,7 @@ try:
while cbd.done > 0 and not err < 0:
err = nl.nl_recvmsgs(s, rx_cb)
-except Exception as e:
+except Exception:
(t, v, tb) = sys.exc_info()
print(v.message)
traceback.print_tb(tb)
diff --git a/python/netlink/core.py b/python/netlink/core.py
index 1fd42dc..b994a73 100644
--- a/python/netlink/core.py
+++ b/python/netlink/core.py
@@ -191,7 +191,7 @@ class Socket(object):
def __init__(self, cb=None):
if isinstance(cb, Callback):
self._sock = capi.nl_socket_alloc_cb(cb._cb)
- elif cb == None:
+ elif cb is None:
self._sock = capi.nl_socket_alloc()
else:
raise Exception("'cb' parameter has wrong type")
@@ -421,10 +421,10 @@ class Object(object):
# accessing properties of subclass/subtypes (e.g. link.vlan.id)
def _resolve(self, attr):
obj = self
- l = attr.split(".")
- while len(l) > 1:
- obj = getattr(obj, l.pop(0))
- return (obj, l.pop(0))
+ lst = attr.split(".")
+ while len(lst) > 1:
+ obj = getattr(obj, lst.pop(0))
+ return (obj, lst.pop(0))
def _setattr(self, attr, val):
obj, attr = self._resolve(attr)
diff --git a/python/netlink/route/link.py b/python/netlink/route/link.py
index c57b96c..e6089e2 100644
--- a/python/netlink/route/link.py
+++ b/python/netlink/route/link.py
@@ -473,7 +473,7 @@ class Link(netlink.Object):
buf += self._foreach_af("details", fmt)
if stats:
- l = [
+ lst = [
["Packets", RX_PACKETS, TX_PACKETS],
["Bytes", RX_BYTES, TX_BYTES],
["Errors", RX_ERRORS, TX_ERRORS],
@@ -528,7 +528,7 @@ class Link(netlink.Object):
util.title("TX"),
)
- for row in l:
+ for row in lst:
row[0] = util.kw(row[0])
row[1] = self.get_stat(row[1]) if row[1] else ""
row[2] = self.get_stat(row[2]) if row[2] else ""
diff --git a/python/netlink/route/links/bridge.py b/python/netlink/route/links/bridge.py
index 7710584..d3e72e5 100644
--- a/python/netlink/route/links/bridge.py
+++ b/python/netlink/route/links/bridge.py
@@ -26,7 +26,7 @@ class BRIDGELink(object):
]
def bridge_assert_ext_info(self):
- if self._has_ext_info == False:
+ if not self._has_ext_info:
print(
"""
Please update your kernel to be able to call this method.
diff --git a/python/netlink/route/tc.py b/python/netlink/route/tc.py
index 4908c0b..daad697 100644
--- a/python/netlink/route/tc.py
+++ b/python/netlink/route/tc.py
@@ -551,7 +551,7 @@ _qdisc_cache = QdiscCache()
def get_qdisc(ifindex, handle=None, parent=None):
- l = []
+ lst = []
_qdisc_cache.refill()
@@ -562,16 +562,16 @@ def get_qdisc(ifindex, handle=None, parent=None):
continue
if (parent is not None) and (qdisc.parent != parent):
continue
- l.append(qdisc)
+ lst.append(qdisc)
- return l
+ return lst
_class_cache = {}
def get_class(ifindex, parent, handle=None):
- l = []
+ lst = []
try:
cache = _class_cache[ifindex]
@@ -586,9 +586,9 @@ def get_class(ifindex, parent, handle=None):
continue
if (handle is not None) and (cl.handle != handle):
continue
- l.append(cl)
+ lst.append(cl)
- return l
+ return lst
_cls_cache = {}
diff --git a/python/netlink/util.py b/python/netlink/util.py
index 8f1513e..afe7ef0 100644
--- a/python/netlink/util.py
+++ b/python/netlink/util.py
@@ -10,13 +10,12 @@
from __future__ import absolute_import
-from . import core as netlink
from . import capi as capi
from string import Formatter
-import types
__version__ = "1.0"
+
# rename into colored_output
def _color(t, c):
return "{esc}[{color}m{text}{esc}[0m".format(esc=b"\x1b".decode(), color=c, text=t)