Skip to content

Commit

Permalink
remove the ProgCodeSyntax enum class (#199)
Browse files Browse the repository at this point in the history
* remove the `ProgCodeSyntax` enum class

instead, make this a string because the SYNTAX subtag of
SINGLE-ECU-JOB is specified to be a plain string in the ODX
specification. It seems like we wanted to be more strict on our own
files and tried to constrain the possible values for this. This was
implemented using a string literal (which is like a type-checking only
enum, i.e., it does not check if the value specified is valid if can
only be determined at runtime). After changing this to an `Enum` class
in #172, it got some (incorrect) teeth which bit users that used
non-Java single ECU jobs.

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>

* re-add type annotation in `TextTableCompuMethod.convert_physical_to_internal()`

this is for the benefit of IDEs. Note that mypy now produces a
(non-fatal) warning about this.

this was requested by [at]kayoub5. Thanks for the nudge.

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>

---------

Signed-off-by: Andreas Lauser <[email protected]>
Signed-off-by: Katja Köhler <[email protected]>
  • Loading branch information
andlaus authored Sep 5, 2023
1 parent ca4a522 commit 96a12b5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/somersaultecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from odxtools.parentref import ParentRef
from odxtools.physicaldimension import PhysicalDimension
from odxtools.physicaltype import PhysicalType
from odxtools.progcode import ProgCode, ProgCodeSyntax
from odxtools.progcode import ProgCode
from odxtools.relateddoc import RelatedDoc
from odxtools.request import Request
from odxtools.response import Response
Expand Down Expand Up @@ -1787,7 +1787,7 @@ class SomersaultSID(IntEnum):
ProgCode(
code_file="jobs.jar",
encryption=None,
syntax=ProgCodeSyntax.JAR,
syntax="JAR",
entrypoint="com.supervisor.jobs.CompulsoryProgram",
revision="1.23.4",
library_refs=[],
Expand Down
17 changes: 2 additions & 15 deletions odxtools/progcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@
from .diaglayer import DiagLayer


class ProgCodeSyntax(Enum):
JAVA = "JAVA"
CLASS = "CLASS"
JAR = "JAR"


@dataclass
class ProgCode:
"""A reference to code that is executed by a single ECU job"""
code_file: str
syntax: ProgCodeSyntax
syntax: str
revision: str
encryption: Optional[str]
entrypoint: Optional[str]
Expand All @@ -32,14 +26,7 @@ def from_et(et_element: ElementTree.Element, doc_frags: List[OdxDocFragment]) ->
code_file = odxrequire(et_element.findtext("CODE-FILE"))

encryption = et_element.findtext("ENCRYPTION")

syntax_str = odxrequire(et_element.findtext("SYNTAX"))
try:
syntax = ProgCodeSyntax(syntax_str)
except ValueError:
syntax = cast(ProgCodeSyntax, None)
odxraise(f"Encountered unknown program code syntax '{syntax_str}'")

syntax = odxrequire(et_element.findtext("SYNTAX"))
revision = odxrequire(et_element.findtext("REVISION"))
entrypoint = et_element.findtext("ENTRYPOINT")

Expand Down
2 changes: 1 addition & 1 deletion odxtools/templates/macros/printSingleEcuJob.xml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
{%- if prog.encryption %}
<ENCRYPTION>{{prog.encryption}}</ENCRYPTION>
{%- endif %}
<SYNTAX>{{prog.syntax.value}}</SYNTAX>
<SYNTAX>{{prog.syntax}}</SYNTAX>
<REVISION>{{prog.revision}}</REVISION>
{%- if prog.entrypoint %}
<ENTRYPOINT>{{prog.entrypoint}}</ENTRYPOINT>
Expand Down
6 changes: 3 additions & 3 deletions tests/test_singleecujob.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from odxtools.odxtypes import DataType
from odxtools.outputparam import OutputParam
from odxtools.physicaltype import PhysicalType
from odxtools.progcode import ProgCode, ProgCodeSyntax
from odxtools.progcode import ProgCode
from odxtools.singleecujob import SingleEcuJob
from odxtools.standardlengthtype import StandardLengthType
from odxtools.write_pdx_file import jinja2_odxraise_helper, make_bool_xml_attrib, make_xml_attrib
Expand Down Expand Up @@ -221,7 +221,7 @@ class Context(NamedTuple):
ProgCode(
code_file="abc.jar",
encryption="RSA512",
syntax=ProgCodeSyntax.JAR,
syntax="JAR",
revision="0.12.34",
entrypoint="CalledClass",
library_refs=[OdxLinkRef("my.favourite.lib", doc_frags)],
Expand Down Expand Up @@ -251,7 +251,7 @@ class Context(NamedTuple):
<PROG-CODE>
<CODE-FILE>{self.singleecujob_object.prog_codes[0].code_file}</CODE-FILE>
<ENCRYPTION>{self.singleecujob_object.prog_codes[0].encryption}</ENCRYPTION>
<SYNTAX>{self.singleecujob_object.prog_codes[0].syntax.value}</SYNTAX>
<SYNTAX>{self.singleecujob_object.prog_codes[0].syntax}</SYNTAX>
<REVISION>{self.singleecujob_object.prog_codes[0].revision}</REVISION>
<ENTRYPOINT>{self.singleecujob_object.prog_codes[0].entrypoint}</ENTRYPOINT>
<LIBRARY-REFS>
Expand Down

0 comments on commit 96a12b5

Please sign in to comment.