Skip to content

Commit

Permalink
Add Black Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Piphi5 authored and LeStarch committed Jun 23, 2021
1 parent 568562d commit 7b85edc
Show file tree
Hide file tree
Showing 23 changed files with 141 additions and 122 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/python-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Format Python

on: [push, pull_request]
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Check formatting
run: |
pip install black==21.6b0
black --check --diff ./
12 changes: 9 additions & 3 deletions Autocoders/Python/bin/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ def generate_topology(the_parsed_topology_xml, xml_filename, opt):
topology_dict.attrib["topology"] = the_parsed_topology_xml.get_name()
topology_dict.attrib["framework_version"] = get_fprime_version()

top_dict_gen = TopDictGenerator.TopDictGenerator(parsed_xml_dict, PRINT.debug)
top_dict_gen = TopDictGenerator.TopDictGenerator(
parsed_xml_dict, PRINT.debug
)
for comp in the_parsed_topology_xml.get_instances():
comp_type = comp.get_type()
comp_name = comp.get_name()
Expand Down Expand Up @@ -1267,7 +1269,9 @@ def main():
the_parsed_component_xml = XmlComponentParser.XmlComponentParser(
xml_filename
)
generate_component(the_parsed_component_xml, os.path.basename(xml_filename), opt)
generate_component(
the_parsed_component_xml, os.path.basename(xml_filename), opt
)
dependency_parser = the_parsed_component_xml
elif xml_type == "interface":
DEBUG.info("Detected Port type XML so Generating Port type C++ Files...")
Expand All @@ -1286,7 +1290,9 @@ def main():
the_parsed_topology_xml = XmlTopologyParser.XmlTopologyParser(xml_filename)
DEPLOYMENT = the_parsed_topology_xml.get_deployment()
print("Found assembly or deployment named: %s\n" % DEPLOYMENT)
generate_topology(the_parsed_topology_xml, os.path.basename(xml_filename), opt)
generate_topology(
the_parsed_topology_xml, os.path.basename(xml_filename), opt
)
dependency_parser = the_parsed_topology_xml
elif xml_type == "enum":
DEBUG.info("Detected Enum XML so Generating hpp, cpp, and py files...")
Expand Down
4 changes: 3 additions & 1 deletion Autocoders/Python/bin/gds_dictgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ def generate_xml_dict(the_parsed_topology_xml, xml_filename, opt):
topology_dict.attrib["topology"] = the_parsed_topology_xml.get_name()
topology_dict.attrib["framework_version"] = get_fprime_version()

top_dict_gen = TopDictGenerator.TopDictGenerator(parsed_xml_dict, print if VERBOSE else lambda _: None)
top_dict_gen = TopDictGenerator.TopDictGenerator(
parsed_xml_dict, print if VERBOSE else lambda _: None
)
for comp in the_parsed_topology_xml.get_instances():
comp_type = comp.get_type()
comp_name = comp.get_name()
Expand Down
32 changes: 17 additions & 15 deletions Autocoders/Python/schema/testSchemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def setup():
channel_test.add_test(
"Missing enum", "sample_XML_files/channel/missingEnum.xml", AssertionError
)

command_test.add_test(
"All working", "sample_XML_files/command/allWorking.xml", None
)
Expand All @@ -259,7 +259,7 @@ def setup():
"sample_XML_files/command/noStringSize.xml",
AssertionError,
)

component_test.add_test(
"Base all working", "sample_XML_files/component/baseAllWorking.xml", None
)
Expand All @@ -274,9 +274,9 @@ def setup():
"sample_XML_files/component/interfaceOnly.xml",
AssertionError,
)

event_test.add_test("All working", "sample_XML_files/event/allWorking.xml", None)

event_test.add_test(
"Event throttle negative",
"sample_XML_files/event/negativeThrottle.xml",
Expand Down Expand Up @@ -392,17 +392,19 @@ def setup():
topology_test.parse_and_add_directory(["deployment", "assembly"], "../test")

# Add schemas to test_list

test_list.extend((
topology_test,
component_test,
command_test,
parameter_test,
channel_test,
interface_test,
serializable_test,
event_test
))

test_list.extend(
(
topology_test,
component_test,
command_test,
parameter_test,
channel_test,
interface_test,
serializable_test,
event_test,
)
)

return test_list

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def argsString(self, args):
"""
Make a list of args into a string
"""
return ', '.join(args)
return ", ".join(args)

def buildFileName(self, obj):
"""
Expand Down Expand Up @@ -436,10 +436,11 @@ def initPortFlags(self, obj, c):
c.has_output_ports = len(c.output_ports) > 0
c.has_typed_output_ports = len(c.typed_output_ports) > 0
c.has_serial_output_ports = len(c.serial_output_ports) > 0
roles = [role for name, ptype, sync, priority, role, max_number in c.output_ports]
roles = [
role for name, ptype, sync, priority, role, max_number in c.output_ports
]
c.has_time_get = "TimeGet" in roles


def initPortIncludes(self, obj, c):
c.port_includes = list()
for include in self.__model_parser.uniqueList(obj.get_xml_port_files()):
Expand Down Expand Up @@ -780,10 +781,7 @@ def initSerialIncludes(self, obj, c):
Include any headers for channel/parameter serializable includes
"""
ser_includes = self.__model_parser.uniqueList(obj.get_xml_serializable_files())
s_includes = [
sinc.replace("Ai.xml", "Ac.hpp")
for sinc in ser_includes
]
s_includes = [sinc.replace("Ai.xml", "Ac.hpp") for sinc in ser_includes]
c.ser_includes = s_includes

def initTelemetry(self, obj, c):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def argsString(self, args):
"""
Make a list of args into a string
"""
return ', '.join(args)
return ", ".join(args)

def eventArgsStr(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,9 @@ def initPortFlags(self, obj, c):
c.has_output_ports = len(c.output_ports) > 0
c.has_typed_output_ports = len(c.typed_output_ports) > 0
c.has_serial_output_ports = len(c.serial_output_ports) > 0
roles = [role for name, ptype, sync, priority, role, max_number in c.output_ports]
roles = [
role for name, ptype, sync, priority, role, max_number in c.output_ports
]
c.has_time_get = "TimeGet" in roles

def initPortIncludes(self, obj, c):
Expand Down
2 changes: 1 addition & 1 deletion Autocoders/Python/src/fprime_ac/models/Arg.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_comment(self):
return self.__comment

def __eq__(self, other):
""" Equality checker """
"""Equality checker"""
if type(other) != type(self):
return False
return (
Expand Down
2 changes: 1 addition & 1 deletion Autocoders/Python/src/fprime_ac/parsers/XmlArrayParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self, xml_file=None):

xml_parser = etree.XMLParser(remove_comments=True)
element_tree = etree.parse(fd, parser=xml_parser)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate against current schema. if more are imported later in the process, they will be reevaluated
relax_file_handler = open(ROOTDIR + self.Config.get("schema", "array"), "r")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(self, xml_file=None):

xml_parser = etree.XMLParser(remove_comments=True)
element_tree = etree.parse(fd, parser=xml_parser)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate against current schema. if more are imported later in the process, they will be reevaluated
relax_file_handler = open(ROOTDIR + self.Config.get("schema", "component"))
Expand Down
2 changes: 1 addition & 1 deletion Autocoders/Python/src/fprime_ac/parsers/XmlEnumParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, xml_file=None):

xml_parser = etree.XMLParser(remove_comments=True)
element_tree = etree.parse(fd, parser=xml_parser)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate against current schema. if more are imported later in the process, they will be reevaluated
relax_file_handler = open(ROOTDIR + self.Config.get("schema", "enum"))
Expand Down
2 changes: 1 addition & 1 deletion Autocoders/Python/src/fprime_ac/parsers/XmlPortsParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, xml_file=None):

xml_parser = etree.XMLParser(remove_comments=True)
element_tree = etree.parse(fd, parser=xml_parser)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate against schema
relax_file_handler = open(ROOTDIR + self.__config.get("schema", "interface"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, xml_file=None):

xml_parser = etree.XMLParser(remove_comments=True)
element_tree = etree.parse(fd, parser=xml_parser)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate new imports using their root tag as a key to find what schema to use
rng_file = self.__config.get(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, xml_file=None):

self.__prepend_instance_name = False # Used to turn off prepending instance name in the situation where instance dicts are being generated and only one instance of an object is created
element_tree = etree.parse(fd)
fd.close() #Close the file, which is only used for the parsing above
fd.close() # Close the file, which is only used for the parsing above

# Validate against schema
relax_file_handler = open(ROOTDIR + self.__config.get("schema", "assembly"))
Expand Down
58 changes: 23 additions & 35 deletions Autocoders/Python/src/fprime_ac/utils/TopDictGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from fprime_ac.utils.buildroot import search_for_file


class TopDictGenerator:
def __init__(self, parsed_xml_dict, log):
self.__log = log
Expand All @@ -37,12 +38,12 @@ def check_for_enum_xml(self):
self.__check_enum_files(enum_file_list)

def check_for_serial_xml(self):
serializable_file_list = self.__parsed_xml_dict[self.__comp_type].get_serializable_type_files()
serializable_file_list = self.__parsed_xml_dict[
self.__comp_type
].get_serializable_type_files()
if serializable_file_list is not None:
for serializable_file in serializable_file_list:
serializable_file = search_for_file(
"Serializable", serializable_file
)
serializable_file = search_for_file("Serializable", serializable_file)
serializable_model = XmlSerializeParser.XmlSerializeParser(
serializable_file
)
Expand Down Expand Up @@ -74,9 +75,7 @@ def check_for_serial_xml(self):
) in serializable_model.get_members():
member_elem = etree.Element("member")
member_elem.attrib["name"] = member_name
member_elem.attrib[
"format_specifier"
] = member_format_specifier
member_elem.attrib["format_specifier"] = member_format_specifier
if member_comment is not None:
member_elem.attrib["description"] = member_comment
if isinstance(member_type, tuple):
Expand Down Expand Up @@ -107,11 +106,7 @@ def __check_enum_files(self, enum_file_list):
enum_file = search_for_file("Enum", enum_file)
enum_model = XmlEnumParser.XmlEnumParser(enum_file)
enum_elem = etree.Element("enum")
enum_type = (
enum_model.get_namespace()
+ "::"
+ enum_model.get_name()
)
enum_type = enum_model.get_namespace() + "::" + enum_model.get_name()
enum_elem.attrib["type"] = enum_type
enum_value = 0
for (
Expand Down Expand Up @@ -144,9 +139,7 @@ def check_for_commands(self):
hex(int(command.get_opcodes()[0], base=0) + self.__comp_id)
)
if "comment" in list(command_elem.attrib.keys()):
command_elem.attrib["description"] = command_elem.attrib[
"comment"
]
command_elem.attrib["description"] = command_elem.attrib["comment"]
args_elem = etree.Element("args")
for arg in command.get_args():
arg_elem = etree.Element("arg")
Expand Down Expand Up @@ -181,19 +174,15 @@ def check_for_channels(self):
hex(int(chan.get_ids()[0], base=0) + self.__comp_id)
)
if chan.get_format_string() is not None:
channel_elem.attrib[
"format_string"
] = chan.get_format_string()
channel_elem.attrib["format_string"] = chan.get_format_string()
if chan.get_comment() is not None:
channel_elem.attrib["description"] = chan.get_comment()

channel_elem.attrib["id"] = "%s" % (
hex(int(chan.get_ids()[0], base=0) + self.__comp_id)
)
if "comment" in list(channel_elem.attrib.keys()):
channel_elem.attrib["description"] = channel_elem.attrib[
"comment"
]
channel_elem.attrib["description"] = channel_elem.attrib["comment"]
channel_type = chan.get_type()
if isinstance(channel_type, tuple):
type_name = "{}::{}::{}".format(
Expand Down Expand Up @@ -238,9 +227,7 @@ def check_for_events(self):
event_elem.attrib["severity"] = event.get_severity()
format_string = event.get_format_string()
if "comment" in list(event_elem.attrib.keys()):
event_elem.attrib["description"] = event_elem.attrib[
"comment"
]
event_elem.attrib["description"] = event_elem.attrib["comment"]
args_elem = etree.Element("args")
arg_num = 0
for arg in event.get_args():
Expand All @@ -256,8 +243,10 @@ def check_for_events(self):
enum_elem = self.__extract_enum_elem(type_name, arg_type[1])
self.__enum_list.append(enum_elem)
# replace enum format string %d with %s for ground system
format_string = DictTypeConverter.DictTypeConverter().format_replace(
format_string, arg_num, "d", "s"
format_string = (
DictTypeConverter.DictTypeConverter().format_replace(
format_string, arg_num, "d", "s"
)
)
else:
type_name = arg_type
Expand Down Expand Up @@ -298,9 +287,7 @@ def check_for_parameters(self):
param_default = None
command_elem_set = etree.Element("command")
command_elem_set.attrib["component"] = self.__comp_name
command_elem_set.attrib["mnemonic"] = (
parameter.get_name() + "_PRM_SET"
)
command_elem_set.attrib["mnemonic"] = parameter.get_name() + "_PRM_SET"
command_elem_set.attrib["opcode"] = "%s" % (
hex(int(parameter.get_set_opcodes()[0], base=0) + self.__comp_id)
)
Expand Down Expand Up @@ -387,16 +374,16 @@ def check_for_parameters(self):
self.__parameter_list.append(param_elem)

def check_for_arrays(self):
array_file_list = self.__parsed_xml_dict[self.__comp_type].get_array_type_files()
array_file_list = self.__parsed_xml_dict[
self.__comp_type
].get_array_type_files()
if array_file_list is not None:
for array_file in array_file_list:
array_file = search_for_file("Array", array_file)
array_model = XmlArrayParser.XmlArrayParser(array_file)
array_elem = etree.Element("array")

array_name = (
array_model.get_namespace() + "::" + array_model.get_name()
)
array_name = array_model.get_namespace() + "::" + array_model.get_name()
array_elem.attrib["name"] = array_name

array_type = array_model.get_type()
Expand Down Expand Up @@ -451,7 +438,8 @@ def remove_duplicate_enums(self):
i = 0
while i < len(children1) and i < len(children2):
if (
not children1[i].attrib["name"] == children2[i].attrib["name"]
not children1[i].attrib["name"]
== children2[i].attrib["name"]
and should_remove
):
should_remove = False
Expand All @@ -463,7 +451,7 @@ def remove_duplicate_enums(self):

def get_enum_list(self):
return self.__enum_list

def get_serializable_list(self):
return self.__serializable_list

Expand Down
Loading

0 comments on commit 7b85edc

Please sign in to comment.