diff --git a/README.md b/README.md index de6dee5..cfef473 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ communication protocol. This repo is located: -> https://github.com/laerdal/python-objdictgen +> https://github.com/Laerdal/python-objdictgen objdictgen includes tools to generate c code that works in tandem with a canfestival library. This tool has been built to work together with the Laerdal Medical fork for the canfestival library: -> https://github.com/laerdal/canfestival-laerdal +> https://github.com/Laerdal/canfestival-laerdal objdictgen is a tool to parse, view and manipulate files containing object dictionary (OD). An object dictionary is entries with data and configuration @@ -22,23 +22,6 @@ reading and writing OD files in `.json` format, in legacy XML `.od` and `.eds` files. It can generate c code for use with the canfestival library. -## Motivation - -The biggest improvement with the new tool over the original implementation is -the introduction of a new `.json` based format to store the object dictionary. -The JSON format is well-known and easy to read. The tool supports jsonc, -allowing comments in the json file. `odg` will process the file in a repeatable -manner, making it possible support diffing of the `.json` file output. `odg` -remains 100% compatible with the legacy `.od` format on both input and output. - -The original objdictedit and objdictgen tool were written in legacy python2 and -and this is a port to python3. - -This tool is a fork from upstream canfestival-3-asc repo: - -> https://github.com/laerdal/canfestival-3-asc - - ## Install To install into a virtual environment `venv`. Check out this repo and go to @@ -46,11 +29,14 @@ the top in a command-prompt (here assuming Windows and git bash): $ py -3 -mvenv venv $ venv/Scripts/python -mpip install --upgrade pip wheel setuptools - $ venv/Scripts/pip install . + $ venv/Scripts/pip install .[ui] # [ui] will install GUI tools After this `venv/Scripts/odg.exe` (on Windows) will exist and can be called from anywhere to run it. +The `[ui]` suffix to `pip install` will install the wx dependency needed +for the UI `odg edit`. If no UI is needed, this suffix can be omitted. + ## `odg` command-line tool `odg` is a command-line tool which is installed when the python package @@ -72,8 +58,8 @@ The most useful commands are: ### Legacy commands -The legacy commands `objdictgen` and `objdictedit` are still available. The -same commands are available under `odg gen` and `odg edit` respectively. +The legacy commands `objdictgen` and `objdictedit` are no longer available. The +commands are available under `odg gen` and `odg edit` respectively. ## JSON schema @@ -100,7 +86,6 @@ descriptions, help with values and validate the file. } ``` - ## Conversion The recommended way to convert existing/legacy `.od` files to the new JSON @@ -114,6 +99,23 @@ parameters. The `--drop-unused` will remove any unused *profile* and *DS-302* parameter that might be used in the file. +## Motivation + +The biggest improvement with the new tool over the original implementation is +the introduction of a new `.json` based format to store the object dictionary. +The JSON format is well-known and easy to read. The tool supports jsonc, +allowing comments in the json file. `odg` will process the file in a repeatable +manner, making it possible support diffing of the `.json` file output. `odg` +remains 100% compatible with the legacy `.od` format on both input and output. + +The original objdictedit and objdictgen tool were written in legacy python 2 and +and this is a port to python 3. + +This tool is a fork from upstream canfestival-3-asc repo: + +> https://github.com/Laerdal/canfestival-3-asc + + ## License Objdictgen has been based on the python tool included in CanFestival. This @@ -123,4 +125,4 @@ original work from CanFestival is: The Python 3 port and tool improvements have been implemented under - Copyright (C) 2022-2023 Svein Seldal, Laerdal Medical AS + Copyright (C) 2022-2024 Svein Seldal, Laerdal Medical AS diff --git a/setup.cfg b/setup.cfg index 2519372..c7e863e 100644 --- a/setup.cfg +++ b/setup.cfg @@ -32,7 +32,6 @@ install_requires = jsonschema colorama deepdiff - wxPython [options.packages.find] where = src @@ -44,6 +43,8 @@ objdictgen.img = * objdictgen.schema = *.json [options.extras_require] +ui = + wxPython dist = build dev = @@ -61,6 +62,3 @@ dev = [options.entry_points] console_scripts = odg = objdictgen.__main__:main - objdictgen = objdictgen.__main__:main_objdictgen - objdictedit = objdictgen.__main__:main_objdictedit - diff --git a/src/objdictgen/__main__.py b/src/objdictgen/__main__.py index 84a0997..0817875 100644 --- a/src/objdictgen/__main__.py +++ b/src/objdictgen/__main__.py @@ -424,51 +424,6 @@ def main(debugopts: DebugOpts, args: Sequence[str]|None = None): parser.error(f"Programming error: Uknown option '{opts.command}'") -def main_objdictgen(): - """ Legacy objdictgen command """ - - def usage(): - print("\nUsage of objdictgen :") - print(f"\n {sys.argv[0]} XMLFilePath CFilePath\n") - - try: - opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) - except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - - for opt, _ in opts: - if opt in ("-h", "--help"): - usage() - sys.exit() - - filein = "" - fileout = "" - if len(args) == 2: - filein = args[0] - fileout = args[1] - else: - usage() - sys.exit() - - if filein != "" and fileout != "": - print("Parsing input file", filein) - node = objdictgen.LoadFile(filein) - print("Writing output file", fileout) - node.DumpFile(fileout, filetype='c') - print("All done") - - -def main_objdictedit(): - """ Legacy objdictedit command """ - - # Import here to prevent including optional UI components for cmd-line use - from .ui.objdictedit import \ - main as _main # pylint: disable=import-outside-toplevel - _main() - - # To support -m objdictgen if __name__ == '__main__': # pylint: disable=no-value-for-parameter diff --git a/tests/test_imports.py b/tests/test_imports.py index d4a0623..52f4c72 100644 --- a/tests/test_imports.py +++ b/tests/test_imports.py @@ -26,20 +26,20 @@ def test_import_nosis(): def test_import_typing(): import objdictgen.typing -def test_import_ui_commondialogs(): - import objdictgen.ui.commondialogs +# def test_import_ui_commondialogs(): +# import objdictgen.ui.commondialogs -def test_import_ui_exception(): - import objdictgen.ui.exception +# def test_import_ui_exception(): +# import objdictgen.ui.exception -def test_import_ui_networkedit(): - import objdictgen.ui.networkedit +# def test_import_ui_networkedit(): +# import objdictgen.ui.networkedit -def test_import_ui_networkeditortemplate(): - import objdictgen.ui.networkeditortemplate +# def test_import_ui_networkeditortemplate(): +# import objdictgen.ui.networkeditortemplate -def test_import_ui_objdictedit(): - import objdictgen.ui.objdictedit +# def test_import_ui_objdictedit(): +# import objdictgen.ui.objdictedit -def test_import_ui_subindextable(): - import objdictgen.ui.subindextable +# def test_import_ui_subindextable(): +# import objdictgen.ui.subindextable diff --git a/tests/test_objdictgen.py b/tests/test_objdictgen.py deleted file mode 100644 index 4a09ec7..0000000 --- a/tests/test_objdictgen.py +++ /dev/null @@ -1,59 +0,0 @@ - -import pytest -import objdictgen.__main__ - - -def test_objdictgen_run(odjsoneds, mocker, wd): - """Test that we're able to run objdictgen on our od files""" - - od = odjsoneds - tmpod = od.stem - - if tmpod in ('legacy-strings', 'strings'): - pytest.xfail("UNICODE_STRINGS is not supported in C") - - mocker.patch("sys.argv", [ - "objdictgen", - str(od), - od.stem + '.c', - ]) - - objdictgen.__main__.main_objdictgen() - - -def test_objdictgen_py2_compare(py2_cfile, mocker, wd, fn): - """Test that comparing objectdictgen output from python2 and python3 is the same.""" - - # Extract the path to the OD and the path to the python2 c file - od, py2od = py2_cfile - tmpod = od.stem - - if tmpod in ('strings', 'legacy-strings', 'domain'): - pytest.xfail("UNICODE_STRINGS is not supported in C") - - mocker.patch("sys.argv", [ - "objdictgen", - str(od), - tmpod + '.c', - ]) - - objdictgen.__main__.main_objdictgen() - - def accept_known_py2_bugs(lines): - """ Python2 outputs floats differently than python3, but the - change is expected. This function attempts to find if the diff - output only contains these expected differences.""" - for line in lines: - if line in ("---", "+++"): - continue - if any(line.startswith(s) for s in ( - "@@ ", "-REAL32 ", "+REAL32 ", "-REAL64 ", "+REAL64 ", - )): - continue - # No match, so there is some other difference. Report as error - return lines - pytest.xfail("Py2 prints floats differently than py3 which is expected") - - assert fn.diff(tmpod + '.c', py2od + '.c', n=0, postprocess=accept_known_py2_bugs) - assert fn.diff(tmpod + '.h', py2od + '.h', n=0) - assert fn.diff(tmpod + '_objectdefines.h', py2od + '_objectdefines.h', n=0)