Skip to content

Commit

Permalink
Fix typos in code comments, simplify them
Browse files Browse the repository at this point in the history
Signed-off-by: Bernhard Kaindl <[email protected]>
  • Loading branch information
bernhardkaindl committed Nov 16, 2024
1 parent 2802010 commit ed7bb9a
Show file tree
Hide file tree
Showing 17 changed files with 35 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ load-plugins=
# W0141 - Use of builtin functions

#
# For now, priorize Python3 mirgration as the use of pylint (e.g. enconding warnings).
# Disable warnings that are not severe, but warn e.g about missing encoding:
#
disable=W0142,W0703,C0111,R0201,W0603,W0613,W0212,W0141,
bad-option-value, # Skip complaining about suppressions for older option values
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ See <https://github.com/xenserver/python-libs/pull/23> for the context of this e

## Guidelines

Charset encoding/string handling:
Character set encoding/string handling:
See [README-Unicode.md](README-Unicode.md) for details on Unicode support.

## Users
Expand Down
17 changes: 5 additions & 12 deletions pylint_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
- Markdown Reports for showing them in the GitHub Actions Summary
- a pylint.txt for diff-quality to ensure no regressions in diffs.
Pylint for Python2 does not support JSONReporter, so this wrapper only supports
the native Python3 checks, not the 2to3 conversion checks selected by the --py3k
options provied only in the Pylint for Python2.
The older pylint-2.16 could be checked if it supports both.
The output for GitHub of this script is fitered for putting the
focus on severen warnings for the Python3 transition, expecially
the encoding warnings are important.
The output for GitHub of this script is filtered for focussing on severe warnings.
Especially, the encoding warnings are important.
On stdout, the format used by GitHub to generate error annotations us used.
These error annotations are shown on the top of the GitHub Action summary page
and are also shown in the diff view at the their code locations.
It also generates a markdown report including two Markdown
tables (one for summary, one with the individual erros)
tables (one for summary, one with the individual errors)
which can be viewed locally and is also shown in the GitHub
Action's Summary Report.
"""
Expand Down Expand Up @@ -99,7 +93,7 @@ def cleanup_results_dict(r, sym):
# This is illegal according to:
# https://docs.python.org/3/reference/datamodel.html#object.__hash__
#
# Reference: pylint3 removed the --py3k checker "because the transition is bedind us":
# Reference: pylint3 removed the --py3k checker "because the transition is behind us":
# https://github.com/pylint-dev/pylint/blob/main/pylint/extensions/eq_without_hash.py
#
# But some checks are still useful in python3 after all, and this is the remnant of it.
Expand Down Expand Up @@ -147,7 +141,6 @@ def pylint_project(check_dirs: List[str], errorlog: TextIO, branch_url: str):
lineno = r["line"]
# Write errors in the format for diff-quality to check against regressions:
errorlog.write(f"{path}:{lineno}: [{msg_id}({sym}), {r['obj']}] {msg}\n")
# For suggestions to fix existing warnings, be more focussed on serverity:
if not msg:
continue

Expand Down Expand Up @@ -214,7 +207,7 @@ def main(dirs: List[str], output_file: str, pylint_logfile: str, branch_url: str
with open(pylint_logfile, "w", encoding="utf-8") as txt_out:
panda_overview, panda_results = pylint_project(dirs, txt_out, branch_url)

# Write the panda dable to a markdown output file:
# Write the panda table to a markdown output file:
summary_file = output_file or os.environ.get("GITHUB_STEP_SUMMARY")
if not summary_file:
return
Expand Down
2 changes: 1 addition & 1 deletion pytype_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def setup_and_run_pytype_action(scriptname: str):
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
filelink_baseurl = f"{server_url}/{repository}/blob/{branch}"
retcode, results = run_pytype_and_parse_annotations(xfail_files, filelink_baseurl)
# Write the panda dable to a markdown output file:
# Write the panda table to a markdown output file:
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", None)
if summary_file:
with open(summary_file, "w", encoding="utf-8") as fp:
Expand Down
10 changes: 4 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ def set_warnings():
One purpose of this fixture that with it, we can globally enable
Development Mode (https://docs.python.org/3/library/devmode.html)
using setenv = PYTHONDEVMODE=yes in tox.int which enables further
using setenv:PYTHONDEVMODE=yes in tox.ini which enables further
run-time checking during tests.
By additionally using setenv = PYTHONWARNINGS=ignore in tox.ini,
we can disabling the Deprecation warnings wihch pytest plugins exhibit
(which we are not interested in, those are not our responsiblity).
and this fixture will still enable the default warning filter to
have e.g. ResourceWarning checks enabled.
Using setenv:PYTHONWARNINGS=ignore in tox.ini, we disable the Deprecation
warnings caused by pytest plugins. This fixture still enable the default
warning filter to have e.g. ResourceWarning checks enabled.
Another nice effect is that also during interactive pytest use, the
default warning filter also provides checking of ResourceWarning:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_grub2(self):

class TestLinuxBootloader(unittest.TestCase):
def setUp(self):
self.tmpdir = mkdtemp(prefix="testbl")
self.tmpdir = mkdtemp(prefix="test-bootloader")
bootdir = os.path.join(self.tmpdir, "boot")
grubdir = os.path.join(bootdir, "grub")
os.makedirs(grubdir)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ifrename_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_newhw_norules_1eth(self):
def test_newhw_norules_2eth(self):
"""
Two previously unrecognised nics, with no other rules. Expecting
them to be renamed to eth0 and 1 respectivly
them to be renamed to eth0 and 1 respectively
"""

eth0 = MACPCI("ab:cd:ef:12:34:56","0000:00:0f.0","side-12-eth1")
Expand All @@ -96,7 +96,7 @@ def test_newhw_norules_2eth(self):

def test_newhw_1srule_1eth(self):
"""
One previously unrecognised nic with a static rule refering to it.
One previously unrecognised nic with a static rule referring to it.
Expecting it to be named to eth0 as per the static rule.
"""

Expand Down Expand Up @@ -336,7 +336,7 @@ def test_usecase5(self):

def test_CA_94279(self):
"""
CA-94279 occured because the logic did no honour the order paramater
CA-94279 occurred because the logic did no honor the order parameter
from biosdevname if it was the only deciding factor. (It appears rare
for the embedded network cards to have a greater PCI sbdf than the non-
embedded cards)
Expand Down Expand Up @@ -528,11 +528,11 @@ def setUp(self):
Set up a lot of MACPCI objects.
This reflection magic creates many self.cXXX objects where XXX
represents the indicies of mac, pci and eth names.
represents the indices of mac, pci and eth names.
e.g. self.c123 means the 1st mac, 2nd pci and 3rd eth
self.c221 means the 2nd mac, 2nd pci and 1st eth
In addition, set up equivelent self.sXXX objects which have a kname
In addition, set up equivalent self.sXXX objects which have a kname
set to None and a tname set to the 'eth'
"""

Expand Down
4 changes: 2 additions & 2 deletions tests/test_mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def test_colon_too_many_octets(self):
MAC(val)
self.assertFalse(MAC.is_valid(val))

def test_dash_too_few_octetes(self):
def test_dash_too_few_octets(self):
val = "00-00-00-00-00"
with self.assertRaises(ValueError):
MAC(val)
Expand Down Expand Up @@ -190,7 +190,7 @@ def test_random(self):
self.assertEqual(mac.as_string("-", True), "15-52-4A-B4-0C-FF")
self.assertEqual(mac.as_string(".", True), "1552.4AB4.0CFF")

class TestCompaisons(unittest.TestCase):
class TestComparisons(unittest.TestCase):

def test_equal(self):

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sbdfi_to_nic.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def check_raises(exc_type, func, sbdfi, nic_list):


def test_sbdf_index():
"""Test all possible uses and xcp.pci.pci_sbdfi_to_nic() and raised Execptions"""
"""Test all possible uses and xcp.pci.pci_sbdfi_to_nic() and raised Exceptions"""
assert pci_sbdfi_to_nic("0000:01:00.0", nics) == nics[0]
assert pci_sbdfi_to_nic("0000:01:00.0[0]", nics) == nics[0]
assert pci_sbdfi_to_nic("0000:01:00.0[1]", nics) == nics[1]
Expand Down
4 changes: 2 additions & 2 deletions xcp/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ def __repr__(self):
return "<HTTPAccessor: %s>" % self.baseAddress


# Tuple passed in tests to isinstanc(val, ...Types) to check types:
# Tuple passed in tests to isinstance(val, ...Types) to check types:
MountingAccessorTypes = (DeviceAccessor, NFSAccessor)
"""Tuple for type checking in unit tests testing subclasses of MountingAccessor"""

# Tuple passed in tests to isinstanc(val, ...Types) to check types:
# Tuple passed in tests to isinstance(val, ...Types) to check types:
LocalTypes = (DeviceAccessor, NFSAccessor, FileAccessor)


Expand Down
2 changes: 1 addition & 1 deletion xcp/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def open_with_codec_handling(filename, mode="r", encoding="utf-8", **kwargs):

def open_with_codec_handling(filename, mode="r", encoding="", errors="", **kwargs):
# type:(str, str, str, str, str) -> IO[Any]
"""open() wrapper to pass mode and **kwargs to open(), ignores endcoding and errors args"""
"""open() wrapper to pass mode and **kwargs to open(), ignores encoding and errors args"""
_ = encoding
_ = errors
return open(filename, mode, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions xcp/net/biosdevname.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def all_devices_all_names():
Get all information, including all names, for all devices.
Returns a dictionary of devices, indexed by current kernel name. All
entries will be string to string mappings, with the exception of
'BIOS device' which will be a dictonary of policies to names.
'BIOS device' which will be a dictionary of policies to names.
"""

devices = {}
Expand Down Expand Up @@ -90,7 +90,7 @@ def all_devices_all_names():

def has_ppn_quirks(bdn_dicts):
# CA-75599 - Assert that no devices share the same SMBIOS Instance. Some
# BIOSes have multiple different nics with the same value set, which causes
# BIOSes have multiple different NICs with the same value set, which causes
# biosdevname to mis-name its physical policy names (emXX, pciXpX etc)

smbios_instances = set()
Expand Down
2 changes: 1 addition & 1 deletion xcp/net/ifrename/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
list of MACPCI objects in form ethXXX|side-XXX-ethXX->(mac, pci)
[in] last_state - Last boot state (post rename) of network cards on the machine
list of MACPCI objects in form (mac, pci)->ethXX
[in] old_state - Any older nics which have disappeared in the meantime
[in] old_state - Any older NICs which have disappeared in the meantime
list of MACPCI objects in form (mac, pci)->ethXX
[out] transactions
Expand Down
6 changes: 3 additions & 3 deletions xcp/net/ifrename/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def load_and_parse(self):
# If no validators, assume label
method = "label"

# If we have a validator, test the valididy
# If we have a validator, test the validity
else:
if method in StaticRules.validators:
if StaticRules.validators[method].match(value) is None:
Expand Down Expand Up @@ -215,7 +215,7 @@ def generate(self, state):
"""

# CA-75599 - check that state has no shared ppns.
# See net.biodevname.has_ppn_quirks() for full reason
# See net.biosdevname.has_ppn_quirks() for full reason
ppns = [ x.ppn for x in state if x.ppn is not None ]
ppn_quirks = ( len(ppns) != len(set(ppns)) )

Expand Down Expand Up @@ -311,7 +311,7 @@ def write(self, header = True):
LOG.warning("Method %s not recognised. Ignoring" % (method,))
continue

# If we have a validator, test the valididy
# If we have a validator, test the validity
if method in StaticRules.validators:
if StaticRules.validators[method].match(value) is None:
LOG.warning("Invalid %s value '%s'. Ignoring"
Expand Down
2 changes: 1 addition & 1 deletion xcp/net/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def ip_link_set_name(src_name, dst_name):
# if the device was up before, bring it back up
if isup:

# Performace note: if we are doing an intermediate rename to
# Performance note: if we are doing an intermediate rename to
# move a device sideways, we shouldn't bring it back until it has
# its final name. However, I can't think of a non-hacky way of doing
# this with the current implementation
Expand Down
6 changes: 3 additions & 3 deletions xcp/net/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MAC(object):
@classmethod
def is_valid(cls, addr):
"""
Static method to assertain whether addr is a recognised MAC address or
Static method to ascertain whether addr is a recognised MAC address or
not
"""
try:
Expand Down Expand Up @@ -134,7 +134,7 @@ def as_string(self, sep = ".", upper = False):

if sep == ".":
# this is a hack but I cant think of an easy way of
# manipulating self.octetes
# manipulating self.octets
res = "%0.4x.%0.4x.%0.4x" % ( (self.integer >> 32) & 0xffff,
(self.integer >> 16) & 0xffff,
(self.integer ) & 0xffff )
Expand All @@ -146,7 +146,7 @@ def as_string(self, sep = ".", upper = False):
res = ':'.join([ "%0.2x" % o for o in self.octets])

else:
raise ValueError("'%s' is not a valid seperator" % sep)
raise ValueError("'%s' is not a valid separator" % sep)

if upper:
return res.upper()
Expand Down
3 changes: 1 addition & 2 deletions xcp/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ class PCI(object):
@classmethod
def is_valid(cls, addr):
"""
Static method to assertain whether addr is a recognised PCI address
or not
Static method to ascertain whether addr is a recognised PCI address
"""
try:
PCI(addr)
Expand Down

0 comments on commit ed7bb9a

Please sign in to comment.