Skip to content

Commit

Permalink
fix for issue #83
Browse files Browse the repository at this point in the history
Fixing logic that causes various troubles when symlinks are used by a build-system. This is a patch ahead of a full cleanup prescribed by issue #84 .
  • Loading branch information
thirtytwobits authored Sep 6, 2022
1 parent f95fc78 commit 1dceca2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pydsdl/_dsdl_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class DSDLDefinition:

def __init__(self, file_path: Path, root_namespace_path: Path):
# Normalizing the path and reading the definition text
self._file_path = Path(file_path).resolve()
self._file_path = Path(file_path)
del file_path
self._root_namespace_path = Path(root_namespace_path).resolve()
self._root_namespace_path = Path(root_namespace_path)
del root_namespace_path
with open(self._file_path) as f:
self._text = str(f.read())
Expand All @@ -48,7 +48,7 @@ def __init__(self, file_path: Path, root_namespace_path: Path):
relative_path = str(
os.path.join(
os.path.split(self._root_namespace_path)[-1],
os.path.relpath(self._file_path, self._root_namespace_path),
self._file_path.relative_to(self._root_namespace_path),
)
)

Expand Down
2 changes: 1 addition & 1 deletion pydsdl/_namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def on_walk_error(os_ex: Exception) -> None:
for root, _dirnames, filenames in walker:
for glb in _DSDL_FILE_GLOBS:
for filename in fnmatch.filter(filenames, glb):
source_file_paths.add(Path(root, filename).resolve())
source_file_paths.add(Path(root, filename))

output = [] # type: List[_dsdl_definition.DSDLDefinition]
for fp in sorted(source_file_paths):
Expand Down
8 changes: 4 additions & 4 deletions pydsdl/_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def _unittest_define() -> None:
assert d.full_name == "uavcan.test.Message"
assert d.version == (1, 2)
assert d.fixed_port_id == 5000
assert d.file_path == Path(_DIRECTORY.name, "uavcan", "test", "5000.Message.1.2.dsdl").resolve()
assert d.root_namespace_path == Path(_DIRECTORY.name, "uavcan").resolve()
assert d.file_path.samefile(Path(_DIRECTORY.name, "uavcan", "test", "5000.Message.1.2.dsdl"))
assert d.root_namespace_path.samefile(Path(_DIRECTORY.name, "uavcan"))
assert open(d.file_path).read() == "# empty"

# BUT WHEN I DO, I WRITE UNIT TESTS FOR MY UNIT TESTS
d = _define("uavcan/Service.255.254.dsdl", "# empty 2")
assert d.full_name == "uavcan.Service"
assert d.version == (255, 254)
assert d.fixed_port_id is None
assert d.file_path == Path(_DIRECTORY.name, "uavcan", "Service.255.254.dsdl").resolve()
assert d.root_namespace_path == Path(_DIRECTORY.name, "uavcan").resolve()
assert d.file_path.samefile(Path(_DIRECTORY.name, "uavcan", "Service.255.254.dsdl"))
assert d.root_namespace_path.samefile(Path(_DIRECTORY.name, "uavcan"))
assert open(d.file_path).read() == "# empty 2"


Expand Down

0 comments on commit 1dceca2

Please sign in to comment.