Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Update linting policy to enforce 120 char lines. (#1)
Browse files Browse the repository at this point in the history
Also apply this requirement to all files.
  • Loading branch information
corthon authored and spbrogan committed Dec 14, 2018
1 parent 1a9b656 commit 659538b
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
#E501 line too long
#E266 too many leading '#' for block comment
#E722 do not use bare 'except'
ignore = E501,E266,E722
ignore = E266,E722
max_line_length = 120
3 changes: 2 additions & 1 deletion ConfirmVersionAndTag.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'''
Quick script to check that the wheel/package created is aligned on a git tag. Official releases should not be made from non-tagged code.
Quick script to check that the wheel/package created is aligned on a git tag.
Official releases should not be made from non-tagged code.
'''

import glob
Expand Down
19 changes: 12 additions & 7 deletions MuPythonLibrary/ACPI/DMARParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ def __str__(self):
Creator ID : %s
Creator Revision : 0x%08X
Host Address Width : 0x%02X
Flags : 0x%02X
""" % (self.Signature, self.Length, self.Revision, self.Checksum, self.OEMID, self.OEMTableID, self.OEMRevision, self.CreatorID, self.CreatorRevision, self.HostAddressWidth, self.Flags)
Flags : 0x%02X\n""" % (self.Signature, self.Length, self.Revision, self.Checksum,
self.OEMID, self.OEMTableID, self.OEMRevision, self.CreatorID,
self.CreatorRevision, self.HostAddressWidth, self.Flags)

def toXml(self):
xml_repr = ET.Element('AcpiTableHeader')
Expand Down Expand Up @@ -245,7 +246,8 @@ def __init__(self, header_byte_array, length):
self.Reserved,
self.SegmentNumber,
self.ReservedMemoryBaseAddress,
self.ReservedMemoryRegionLimitAddress) = struct.unpack_from(DMAR_TABLE.RMRR_STRUCT.struct_format, header_byte_array)
self.ReservedMemoryRegionLimitAddress) = struct.unpack_from(DMAR_TABLE.RMRR_STRUCT.struct_format,
header_byte_array)

# Get Sub Structs
self.DeviceScope = list()
Expand Down Expand Up @@ -293,8 +295,9 @@ def __str__(self):
Reserved : 0x%04X
Segment Number : 0x%04x
Reserved Memory Base Address : 0x%016x
Reserved Memory Region Limit Address : 0x%016x
""" % (self.Type, self.Length, self.Reserved, self.SegmentNumber, self.ReservedMemoryBaseAddress, self.ReservedMemoryRegionLimitAddress)
Reserved Memory Region Limit Address : 0x%016x\n""" % (self.Type, self.Length, self.Reserved,
self.SegmentNumber, self.ReservedMemoryBaseAddress,
self.ReservedMemoryRegionLimitAddress)

for item in self.DeviceScope:
retstring += str(item)
Expand Down Expand Up @@ -455,7 +458,8 @@ def __init__(self, header_byte_array):
offset = 6
self.Path = list()
while number_path_entries > 0:
self.Path.append((struct.unpack("<B", header_byte_array[offset:offset + 1]), struct.unpack("<B", header_byte_array[offset + 1:offset + 2])))
self.Path.append((struct.unpack("<B", header_byte_array[offset:offset + 1]),
struct.unpack("<B", header_byte_array[offset + 1:offset + 2])))
offset += 2
number_path_entries -= 1

Expand All @@ -477,7 +481,8 @@ def __str__(self):
\t\t Reserved : 0x%04X
\t\t Enumeration ID : 0x%02x
\t\t Start Bus Number : 0x%02x
\t\t Path : """ % (self.TypeString, self.Type, self.Length, self.Reserved, self.EnumerationID, self.StartBusNumber)
\t\t Path : """ % (self.TypeString, self.Type, self.Length, self.Reserved,
self.EnumerationID, self.StartBusNumber)

retstring += "%02d" % self.StartBusNumber + ":"
for (index, item) in enumerate(self.Path):
Expand Down
11 changes: 7 additions & 4 deletions MuPythonLibrary/MuJunitReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,13 @@ def Output(self, outstream):
if self.Status == MuTestCase.SKIPPED:
outstream.write('<skipped />')
elif self.Status == MuTestCase.FAILED:
outstream.write('<failure message="{0}" type="{1}" />'.format(self.FailureMsg.Message, self.FailureMsg.Type))
outstream.write('<failure message="{0}" type="{1}" />'.format(self.FailureMsg.Message,
self.FailureMsg.Type))
elif self.Status == MuTestCase.ERROR:
outstream.write('<error message="{0}" type="{1}" />'.format(self.ErrorMsg.Message, self.ErrorMsg.Type))
elif self.Status != MuTestCase.SUCCESS:
raise Exception("Can't output a testcase {0}.{1} in invalid state {2}".format(self.ClassName, self.Name, self.Status))
raise Exception("Can't output a testcase {0}.{1} in invalid state {2}".format(self.ClassName,
self.Name, self.Status))

outstream.write('<system-out>' + self.StdOut + '</system-out>')
outstream.write('<system-err>' + self.StdErr + '</system-err>')
Expand Down Expand Up @@ -146,8 +148,9 @@ def Output(self, outstream):
elif(a.Status == MuTestCase.SKIPPED):
Skipped += 1

outstream.write('<testsuite id="{0}" name="{1}" package="{2}" errors="{3}" tests="{4}" failures="{5}" skipped="{6}">'.format
(self.TestId, self.Name, self.Package, Errors, Tests, Failures, Skipped))
outstream.write('<testsuite id="{0}" name="{1}" package="{2}" errors="{3}" tests="{4}" '
'failures="{5}" skipped="{6}">'.format(self.TestId, self.Name, self.Package,
Errors, Tests, Failures, Skipped))

for a in self.TestCases:
a.Output(outstream)
Expand Down
6 changes: 4 additions & 2 deletions MuPythonLibrary/TPM/Tpm2PolicyCalc_Test.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def test_create_with_valid_codes(self):
self.assertEqual(policy.get_code(), 'TPM_CC_Quote')

def test_get_buffer(self):
self.assertEqual(t2pc.PolicyCommandCode('TPM_CC_Clear').get_buffer_for_digest(), bytearray.fromhex("0000016C" + "00000126"))
self.assertEqual(t2pc.PolicyCommandCode('TPM_CC_ClearControl').get_buffer_for_digest(), bytearray.fromhex("0000016C" + "00000127"))
self.assertEqual(t2pc.PolicyCommandCode('TPM_CC_Clear').get_buffer_for_digest(),
bytearray.fromhex("0000016C" + "00000126"))
self.assertEqual(t2pc.PolicyCommandCode('TPM_CC_ClearControl').get_buffer_for_digest(),
bytearray.fromhex("0000016C" + "00000127"))


class TestPolicyTreeSolo(unittest.TestCase):
Expand Down
6 changes: 4 additions & 2 deletions MuPythonLibrary/Uefi/Capsule/CatGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ def OperatingSystem(self, value):
def MakeCat(self, OutputCatFile, PathToInf2CatTool=None):
# Find Inf2Cat tool
if(PathToInf2CatTool is None):
PathToInf2CatTool = os.path.join(os.getenv("ProgramFiles(x86)"), "Windows Kits", "10", "bin", "x86", "Inf2Cat.exe")
PathToInf2CatTool = os.path.join(os.getenv("ProgramFiles(x86)"), "Windows Kits", "10",
"bin", "x86", "Inf2Cat.exe")
if not os.path.exists(PathToInf2CatTool):
logging.debug("Windows Kit 10 not Found....trying 8.1")
# Try 8.1 kit
PathToInf2CatTool.replace("10", "8.1")

# check if exists
if not os.path.exists(PathToInf2CatTool):
raise Exception("Can't find Inf2Cat on this machine. Please install the Windows 10 WDK - https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit")
raise Exception("Can't find Inf2Cat on this machine. Please install the Windows 10 WDK - "
"https://developer.microsoft.com/en-us/windows/hardware/windows-driver-kit")

# Adjust for spaces in the path (when calling the command).
if " " in PathToInf2CatTool:
Expand Down
24 changes: 16 additions & 8 deletions MuPythonLibrary/Uefi/Capsule/InfGenerator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
from MuPythonLibrary.Uefi.Capsule.InfGenerator import InfGenerator

# must run from build env or set PYTHONPATH env variable to point to the MuPythonLibrary folder
# To run unit test open cmd prompt in the MuPythonLibrary folder and then run 'python -m unittest discover -p "*_test.py"'
# To run unit test open cmd prompt in the MuPythonLibrary folder
# and then run 'python -m unittest discover -p "*_test.py"'


class InfGeneratorTest(unittest.TestCase):
VALID_GUID_STRING = "3cad7a0c-d35b-4b75-96b1-03a9fb07b7fc"

def test_valid(self):
o = InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "aa.bb.cc.dd", "0xaabbccdd")
o = InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "aa.bb.cc.dd", "0xaabbccdd")
self.assertIsInstance(o, InfGenerator)
self.assertEqual(o.Name, "test_name")
self.assertEqual(o.Provider, "provider")
Expand Down Expand Up @@ -37,28 +39,34 @@ def test_invalid_name_symbol(self):
with self.subTest(name="test{}name".format(a)):
name = "test{}name".format(a)
with self.assertRaises(ValueError):
InfGenerator(name, "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "aa.bb", "0xaabbccdd")
InfGenerator(name, "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "aa.bb", "0xaabbccdd")

def test_version_string_format(self):
with self.subTest(version_string="zero ."):
with self.assertRaises(ValueError):
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "1234", "0x100000000")
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "1234", "0x100000000")

with self.subTest(version_string="> 3 ."):
with self.assertRaises(ValueError):
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "1.2.3.4.5", "0x100000000")
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "1.2.3.4.5", "0x100000000")

def test_version_hex_too_big(self):
with self.subTest("hex string too big"):
with self.assertRaises(ValueError):
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "aa.bb", "0x100000000")
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "aa.bb", "0x100000000")

with self.subTest("decimal too big"):
with self.assertRaises(ValueError):
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "aa.bb", "4294967296")
InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "aa.bb", "4294967296")

def test_version_hex_can_support_decimal(self):
o = InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64", "description", "aa.bb.cc.dd", "12356")
o = InfGenerator("test_name", "provider", InfGeneratorTest.VALID_GUID_STRING, "x64",
"description", "aa.bb.cc.dd", "12356")
self.assertEqual(int(o.VersionHex, 0), 12356)

def test_invalid_guid_format(self):
Expand Down
8 changes: 4 additions & 4 deletions MuPythonLibrary/Uefi/EdkII/Parsers/BuildReportParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def Parse(self):
line = self._RawContent[i].strip()

# parse start and end
if(line == ">----------------------------------------------------------------------------------------------------------------------<"):
if line == ">----------------------------------------------------------------------------------------------------------------------<": # noqa: E501
nextLineSection = True

elif(line == "<---------------------------------------------------------------------------------------------------------------------->"):
elif line == "<---------------------------------------------------------------------------------------------------------------------->": # noqa: E501
inPcdSection = False
inLibSection = False
inDepSection = False
Expand Down Expand Up @@ -324,7 +324,7 @@ def _ParseFdRegionForModules(self, rawcontents):
def _GetNextRegionStart(self, number):
lineNumber = number
while(lineNumber < len(self._ReportContents)):
if(self._ReportContents[lineNumber] == ">======================================================================================================================<"):
if self._ReportContents[lineNumber] == ">======================================================================================================================<": # noqa: E501
return lineNumber + 1
lineNumber += 1
logging.debug("Failed to find a Start Next Region after lineNumber: %d" % number)
Expand All @@ -337,7 +337,7 @@ def _GetNextRegionStart(self, number):
def _GetEndOfRegion(self, number):
lineNumber = number
while(lineNumber < len(self._ReportContents)):
if(self._ReportContents[lineNumber] == "<======================================================================================================================>"):
if self._ReportContents[lineNumber] == "<======================================================================================================================>": # noqa: E501
return lineNumber - 1
lineNumber += 1

Expand Down
12 changes: 8 additions & 4 deletions MuPythonLibrary/Uefi/EdkII/Parsers/DscParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def __ParseLine(self, Line):
p = self.ParseInfPathLib(line_resolved)
self.Libs.append(p)
self.Logger.debug("Found Library in a 64bit BuildOptions Section: %s" % p)
elif("tokenspaceguid" in line_resolved.lower() and (line_resolved.count('|') > 0) and (line_resolved.count('.') > 0)):
elif "tokenspaceguid" in line_resolved.lower() and \
line_resolved.count('|') > 0 and line_resolved.count('.') > 0:
# should be a pcd statement
p = line_resolved.partition('|')
self.Pcds.append(p[0].strip())
Expand All @@ -105,7 +106,8 @@ def __ParseLine(self, Line):
p = self.ParseInfPathLib(line_resolved)
self.Libs.append(p)
self.Logger.debug("Found Library in a 32bit BuildOptions Section: %s" % p)
elif("tokenspaceguid" in line_resolved.lower() and (line_resolved.count('|') > 0) and (line_resolved.count('.') > 0)):
elif "tokenspaceguid" in line_resolved.lower() and \
line_resolved.count('|') > 0 and line_resolved.count('.') > 0:
# should be a pcd statement
p = line_resolved.partition('|')
self.Pcds.append(p[0].strip())
Expand All @@ -128,7 +130,8 @@ def __ParseLine(self, Line):
p = self.ParseInfPathLib(line_resolved)
self.Libs.append(p)
self.Logger.debug("Found Library in a BuildOptions Section: %s" % p)
elif("tokenspaceguid" in line_resolved.lower() and (line_resolved.count('|') > 0) and (line_resolved.count('.') > 0)):
elif "tokenspaceguid" in line_resolved.lower() and \
line_resolved.count('|') > 0 and line_resolved.count('.') > 0:
# should be a pcd statement
p = line_resolved.partition('|')
self.Pcds.append(p[0].strip())
Expand All @@ -153,7 +156,8 @@ def __ParseLine(self, Line):
return (line_resolved, [])
# process line in PCD section
elif(self.CurrentSection.upper().startswith("PCDS")):
if("tokenspaceguid" in line_resolved.lower() and (line_resolved.count('|') > 0) and (line_resolved.count('.') > 0)):
if "tokenspaceguid" in line_resolved.lower() and \
line_resolved.count('|') > 0 and line_resolved.count('.') > 0:
# should be a pcd statement
p = line_resolved.partition('|')
self.Pcds.append(p[0].strip())
Expand Down
8 changes: 6 additions & 2 deletions MuPythonLibrary/Uefi/EdkII/Parsers/InfParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import os


AllPhases = ["SEC", "PEIM", "PEI_CORE", "DXE_DRIVER", "DXE_CORE", "DXE_RUNTIME_DRIVER", "UEFI_DRIVER", "SMM_CORE", "DXE_SMM_DRIVER", "UEFI_APPLICATION"]
AllPhases = ["SEC", "PEIM", "PEI_CORE", "DXE_DRIVER", "DXE_CORE", "DXE_RUNTIME_DRIVER", "UEFI_DRIVER",
"SMM_CORE", "DXE_SMM_DRIVER", "UEFI_APPLICATION"]


class InfParser(HashFileParser):
Expand Down Expand Up @@ -175,7 +176,10 @@ def ParseFile(self, filepath):
elif sline.strip().lower().startswith('[guids'):
InGuidsSection = True

elif sline.strip().lower().startswith('[pcd') or sline.strip().lower().startswith('[patchpcd') or sline.strip().lower().startswith('[fixedpcd') or sline.strip().lower().startswith('[featurepcd'):
elif sline.strip().lower().startswith('[pcd') or \
sline.strip().lower().startswith('[patchpcd') or \
sline.strip().lower().startswith('[fixedpcd') or \
sline.strip().lower().startswith('[featurepcd'):
InPcdSection = True

elif sline.strip().lower().startswith('[sources'):
Expand Down
6 changes: 4 additions & 2 deletions MuPythonLibrary/Uefi/EdkII/PiFirmwareFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def load_from_file(self, file):
file.seek(orig_seek)

# Load this object with the contents of the data.
(self.FileSystemGuid, self.Checksum, self.Type, self.Attributes, self.Size0, self.Size1, self.Size2, self.State) = struct.unpack(self.StructString, struct_bytes)
(self.FileSystemGuid, self.Checksum, self.Type, self.Attributes, self.Size0, self.Size1,
self.Size2, self.State) = struct.unpack(self.StructString, struct_bytes)

# Update the GUID to be a UUID object.
if sys.byteorder == 'big':
Expand All @@ -74,4 +75,5 @@ def load_from_file(self, file):

def serialize(self):
file_system_guid_bin = self.FileSystemGuid.bytes if sys.byteorder == 'big' else self.FileSystemGuid.bytes_le
return struct.pack(self.StructString, file_system_guid_bin, self.Checksum, self.Type, self.Attributes, self.Size0, self.Size1, self.Size2, self.State)
return struct.pack(self.StructString, file_system_guid_bin, self.Checksum,
self.Type, self.Attributes, self.Size0, self.Size1, self.Size2, self.State)
Loading

0 comments on commit 659538b

Please sign in to comment.