OpenCyphal / pydsdl

Cyphal DSDL processing front end implemented in Python
https://opencyphal.org
MIT License
10 stars 9 forks source link

Support symlinked namespaces #83

Closed thirtytwobits closed 2 years ago

thirtytwobits commented 2 years ago

Create bug.py:


import pydsdl
import pathlib
import sys

target_directory = pathlib.Path("reg")
lookup_directories = pathlib.Path("uavcan")

try:
    types = pydsdl.read_namespace(target_directory, lookup_directories)
except pydsdl.InvalidDefinitionError as ex:
    print(f'{ex.path}:{ex.line}: Invalid DSDL: {ex.text}', file=sys.stderr)
    exit(1)
else:
    for t in types:
        print(t)  # Process the type -- generate code, analyze, etc.

create a symlink to the top-level types:

mkdir reg
cd reg
mkdir udral
cd udral
ln -s ../../../public_regulated_data_types/reg/udral/physics physics
ln -s ../../../public_regulated_data_types/reg/udral/service service

do:

python bug.py

Expected to parse and print dsdl. Actual:

/workspace/github/thirtytwobits/public_regulated_data_types/reg/udral/physics/acoustics/Note.0.1.uavcan:None: Invalid DSDL: Invalid name for namespace component: '..'
thirtytwobits commented 2 years ago

Poking at this bug is showing a network of problems with the use of Python's file APIS. Specifically, the mixing of pathlib, os.path, and manual transformations is causing significant fragility in this code. I have a fix for the specific problem reported but it requires fixing all the unit tests to make more concise assertions so the patch might take a bit to post. After this we need to generally go through the entire codebase here and use pathlib consistently.

thirtytwobits commented 2 years ago

Added #84 to track follow-on tasks.