Closed TomDeRybel closed 3 years ago
This is kind of a hilarious problem actually that I stumbled upon myself and it was also briefly mentioned in https://github.com/UAVCAN/pyuavcan/issues/127. Strictly speaking, it does behave exactly as documented; the docs say:
Existing packages will be overwritten entirely.
Meaning that the output directory is removed before the package is generated. The name of the output directory matches the input one (unless stropping is applied), so it follows that if the input is in the current working directory, the tool diligently deletes it and then complains that it can't find the source files.
I guess we just need to postpone deleting the directory and emit an adequate error message here.
Now I have the mental image of the snake that bites itself in the tail ;-)
Though, now I'm kinda stuck: the old GUI tool doesn't work for V1 and I clearly fail to compile the DSDL stuff for pyuavcan-cli. Testing my own implementation against my own implementation also has that circular thing going on... (Internally-consistent, but ultimately wrong.)
I was hoping to use the Python tool to help develop the PnP implementation in my code. Any thoughts?
Just move your DSDL definitions into a subdirectory, or override the default destination directory.
Getting closer, but now this: Seems there is something going on with the "8184.Record.1.1.uavcan" DSDL definition.
(base) tomr@Feynman:~$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ --lookup https://github.com/UAVCAN/public_regulated_data_types/archive/master.zip ~/dsdl/public_regulated_data_types/
2020-11-19 11:12:26 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Input DSDL root namespace directories: ['/home/tomr/dsdl/public_regulated_data_types']
2020-11-19 11:12:26 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Downloading the archive from 'https://github.com/UAVCAN/public_regulated_data_types/archive/master.zip' into '/tmp/pyuavcan-cli-dsdl9asbimd4/dsdl.zip'...
2020-11-19 11:12:27 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Extracting the archive into '/tmp/pyuavcan-cli-dsdl9asbimd4'...
2020-11-19 11:12:27 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Resource 'https://github.com/UAVCAN/public_regulated_data_types/archive/master.zip' contains the following root namespace directories: ['/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/uavcan', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/.vscode', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/reg']
2020-11-19 11:12:27 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Lookup DSDL root namespace directories: ['/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/uavcan', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/.vscode', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/reg']
2020-11-19 11:12:27 11961 INFO pyuavcan._cli.commands.dsdl_generate_packages: Generating DSDL package PosixPath('/home/tomr/dsdl/pyuavcan/public_regulated_data_types') from root namespace PosixPath('/home/tomr/dsdl/public_regulated_data_types') with lookup dirs: ['/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/.vscode', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/uavcan', '/tmp/pyuavcan-cli-dsdl9asbimd4/public_regulated_data_types-master/reg', '/home/tomr/dsdl/public_regulated_data_types']
2020-11-19 11:12:27 11961 INFO pydsdl._namespace: Reading 194 definitions from the root namespace 'public_regulated_data_types', with 388 lookup definitions located in root namespaces: reg, public_regulated_data_types, uavcan
2020-11-19 11:12:27 11961 INFO pydsdl._dsdl_definition: public_regulated_data_types.reg.drone.phy.acoustics.Note.0.1: Starting processing with 387 lookup definitions located in root namespaces: reg, public_regulated_data_types, uavcan
///--------------------------------------------------///
///----- CUT A LOT OF SUCCESSES ----///
///--------------------------------------------------///
2020-11-19 11:12:27 11961 INFO pydsdl._dsdl_definition: public_regulated_data_types.uavcan.diagnostic.Record.1.1: Starting processing with 387 lookup definitions located in root namespaces: reg, public_regulated_data_types, uavcan
2020-11-19 11:12:27 11961 INFO pydsdl._dsdl_definition: public_regulated_data_types.uavcan.diagnostic.Severity.1.0: Starting processing with 386 lookup definitions located in root namespaces: reg, public_regulated_data_types, uavcan
2020-11-19 11:12:27 11961 INFO pydsdl._dsdl_definition: public_regulated_data_types.uavcan.diagnostic.Severity.1.0: Processed in 9 ms; category: StructureType, fixed port ID: None
Error: UnregulatedFixedPortIDError: /home/tomr/dsdl/public_regulated_data_types/uavcan/diagnostic/8184.Record.1.1.uavcan: Regulated port ID 8184 for message type 'public_regulated_data_types.uavcan.diagnostic.Record' is not valid. Consider using allow_unregulated_fixed_port_id.
2020-11-19 11:12:27 11961 INFO pyuavcan._cli._main: Unhandled exception: /home/tomr/dsdl/public_regulated_data_types/uavcan/diagnostic/8184.Record.1.1.uavcan: Regulated port ID 8184 for message type 'public_regulated_data_types.uavcan.diagnostic.Record' is not valid. Consider using allow_unregulated_fixed_port_id.
Traceback (most recent call last):
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 25, in main
exit(_main_impl())
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 56, in _main_impl
result = args.func(args)
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 152, in execute
return cmd.execute(args, subsystems)
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/commands/dsdl_generate_packages.py", line 113, in execute
gpi_list = self._generate_dsdl_packages(source_root_namespace_dirs=inputs,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/commands/dsdl_generate_packages.py", line 184, in _generate_dsdl_packages
gpi = pyuavcan.dsdl.generate_package(root_namespace_directory=ns,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/dsdl/_compiler.py", line 188, in generate_package
composite_types = pydsdl.read_namespace(root_namespace_directory=str(root_namespace_directory),
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 185, in read_namespace
types = _read_namespace_definitions(target_dsdl_definitions,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 236, in _read_namespace_definitions
raise ex
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 231, in _read_namespace_definitions
dt = tdd.read(lookup_definitions,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_dsdl_definition.py", line 149, in read
raise ex
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_dsdl_definition.py", line 139, in read
self._cached_type = builder.finalize()
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_data_type_builder.py", line 108, in finalize
raise UnregulatedFixedPortIDError(
pydsdl._data_type_builder.UnregulatedFixedPortIDError: /home/tomr/dsdl/public_regulated_data_types/uavcan/diagnostic/8184.Record.1.1.uavcan: Regulated port ID 8184 for message type 'public_regulated_data_types.uavcan.diagnostic.Record' is not valid. Consider using allow_unregulated_fixed_port_id.
(base) tomr@Feynman:~$
$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ --lookup https://github.com/UAVCAN/public_regulated_data_types/archive/master.zip ~/dsdl/public_regulated_data_types/
Here's the culprit: ~/dsdl/public_regulated_data_types/
. You are saying that the root namespace is public_regulated_data_types
, but what you mean is ~/dsdl/public_regulated_data_types/uavcan/
.
Also, you don't need any lookup definitions when processing the standard namespace. Providing them will actually trigger an error because of the namespace name conflict --- you would have uavcan
both in your target namespace and in the look-up directory.
The correct commands are:
$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ ~/dsdl/public_regulated_data_types/uavcan
$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ ~/dsdl/public_regulated_data_types/reg
That is entirely not how I thought that worked...
Sorry I'm being so useless at this. I'm one of those people who needs a worked example to really grok things, and then builds on that.
(base) tomr@Feynman:~$ export PYTHONPATH="/home/tomr/dsdl/pyuavcan"
(base) tomr@Feynman:~$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ ~/dsdl/public_regulated_data_types/reg
2020-11-19 12:16:45 12708 INFO pyuavcan._cli.commands.dsdl_generate_packages: Input DSDL root namespace directories: ['/home/tomr/dsdl/public_regulated_data_types/reg']
2020-11-19 12:16:45 12708 INFO pyuavcan._cli.commands.dsdl_generate_packages: Lookup DSDL root namespace directories: []
2020-11-19 12:16:45 12708 INFO pyuavcan._cli.commands.dsdl_generate_packages: Generating DSDL package PosixPath('/home/tomr/dsdl/pyuavcan/reg') from root namespace PosixPath('/home/tomr/dsdl/public_regulated_data_types/reg') with lookup dirs: ['/home/tomr/dsdl/public_regulated_data_types/reg']
2020-11-19 12:16:45 12708 INFO pydsdl._namespace: Reading 40 definitions from the root namespace 'reg', with 40 lookup definitions located in root namespaces: reg
2020-11-19 12:16:45 12708 INFO pydsdl._dsdl_definition: reg.drone.phy.acoustics.Note.0.1: Starting processing with 39 lookup definitions located in root namespaces: reg
Error: UndefinedDataTypeError: /home/tomr/dsdl/public_regulated_data_types/reg/drone/phy/acoustics/Note.0.1.uavcan:6: Data type uavcan.si.unit.frequency.Scalar.1.0 could not be found in the following root namespaces: {'reg'}. Please make sure that you specified the directories correctly.
2020-11-19 12:16:45 12708 INFO pyuavcan._cli._main: Unhandled exception: /home/tomr/dsdl/public_regulated_data_types/reg/drone/phy/acoustics/Note.0.1.uavcan:6: Data type uavcan.si.unit.frequency.Scalar.1.0 could not be found in the following root namespaces: {'reg'}. Please make sure that you specified the directories correctly.
Traceback (most recent call last):
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 25, in main
exit(_main_impl())
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 56, in _main_impl
result = args.func(args)
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/_main.py", line 152, in execute
return cmd.execute(args, subsystems)
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/commands/dsdl_generate_packages.py", line 113, in execute
gpi_list = self._generate_dsdl_packages(source_root_namespace_dirs=inputs,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/_cli/commands/dsdl_generate_packages.py", line 184, in _generate_dsdl_packages
gpi = pyuavcan.dsdl.generate_package(root_namespace_directory=ns,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pyuavcan/dsdl/_compiler.py", line 188, in generate_package
composite_types = pydsdl.read_namespace(root_namespace_directory=str(root_namespace_directory),
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 185, in read_namespace
types = _read_namespace_definitions(target_dsdl_definitions,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 236, in _read_namespace_definitions
raise ex
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_namespace.py", line 231, in _read_namespace_definitions
dt = tdd.read(lookup_definitions,
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_dsdl_definition.py", line 149, in read
raise ex
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_dsdl_definition.py", line 137, in read
_parser.parse(f.read(), builder)
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_parser.py", line 36, in parse
raise ex
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/_parser.py", line 30, in parse
pr.parse(text) # type: ignore
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/third_party/parsimonious/nodes.py", line 254, in parse
return self._parse_or_match(text, pos, 'parse')
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/third_party/parsimonious/nodes.py", line 289, in _parse_or_match
return self.visit(getattr(self.grammar, method_name)(text, pos=pos))
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/third_party/parsimonious/nodes.py", line 217, in visit
return method(node, [self.visit(n) for n in node])
File "/home/tomr/anaconda3/lib/python3.8/site-packages/pydsdl/third_party/parsimonious/nodes.py", line 217, in
Ah, sorry, it's my fault -- forgot the --lookup
. The second command is:
$ pyuavcan -v dsdl-gen-pkg --output ~/dsdl/pyuavcan/ ~/dsdl/public_regulated_data_types/reg --lookup ~/dsdl/public_regulated_data_types/uavcan
Cool! That all worked now. And now the synthax makes much more sense to me. Especially the second command showcases them all: where to put the compiled results; from which dsdl definitions; using these public regulated types.
May I propose to add a version of both these lines as an example to the documentation? Right now, they show how to generate a custom type. It would have helped if they also showed how to set-up the basics. Perhaps here: https://pyuavcan.readthedocs.io/en/latest/pages/usage.html#basic-usage-demo or https://pyuavcan.readthedocs.io/en/latest/pages/usage.html#generating-data-type-packages-from-dsdl or https://pyuavcan.readthedocs.io/en/latest/pages/cli.html#subcommand-dsdl-generate-packages
Thanks again for your time!
There, I fixed it. Now you get helpful suggestions:
Nice! I like helpful suggestions :-)
Also, having finally understood enough of the syntax, I was able to use Nunavut to generate the DSDL serialization headers for C and C++. Though, I noticed these are a work in progress, so I'll stick to my home-grown all-manual serialization for now.
Please keep it open. Someone should address the confusing behavior where the DSDL namespace directory is unexpectedly deleted.
Ok
Using the latest pypi version of pyuavcan (1.1.0-dev3), I encountered the following problem trying to exactly reproduce the example described here: https://pyuavcan.readthedocs.io/en/latest/pages/cli.html
Issues:
Below are the exact commands I used, with the resulting output. To make sure I was running the newest code, I removed and then re-installed pyuavcan as well.