-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for file-based reads and externalized type dependencies (
#102) This is non-breaking change that adds a new public method: read_files - a file-oriented entry point to the front end. This takes a list of target DSDL files allowing the user to maintain an explicit list instead of depending on globular filesystem discovery. Furthermore this method returns a set which is the transitive closure of types depended on by the target list of types. This allows consumers to track dependencies and compiler back ends to generate .d files and otherwise support incremental builds. The new method may increase performance for systems with large pools of messages when generating code for a small sub-set as it only considers the target and dependencies of the target when parsing dsdl files.
- Loading branch information
1 parent
6a6828b
commit 31df90d
Showing
20 changed files
with
1,546 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "Python dev environment", | ||
"image": "ghcr.io/opencyphal/toxic:tx22.4.2", | ||
"workspaceFolder": "/workspace", | ||
"workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=delegated", | ||
"mounts": [ | ||
"source=root-vscode-server,target=/root/.vscode-server/extensions,type=volume", | ||
"source=pydsdl-tox,target=/workspace/.nox,type=volume" | ||
], | ||
"customizations": { | ||
"vscode": { | ||
"extensions": [ | ||
"uavcan.dsdl", | ||
"wholroyd.jinja", | ||
"streetsidesoftware.code-spell-checker", | ||
"ms-python.python", | ||
"ms-python.mypy-type-checker", | ||
"ms-python.black-formatter", | ||
"ms-python.pylint" | ||
] | ||
} | ||
}, | ||
"postCreateCommand": "git submodule update --init --recursive && tox -e local" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# | ||
# Copyright (C) OpenCyphal Development Team <opencyphal.org> | ||
# Copyright Amazon.com Inc. or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
""" | ||
Configuration for pytest tests including fixtures and hooks. | ||
""" | ||
|
||
import tempfile | ||
from pathlib import Path | ||
from typing import Any, Optional | ||
|
||
import pytest | ||
|
||
|
||
# +-------------------------------------------------------------------------------------------------------------------+ | ||
# | TEST FIXTURES | ||
# +-------------------------------------------------------------------------------------------------------------------+ | ||
class TemporaryDsdlContext: | ||
""" | ||
Powers the temp_dsdl_factory test fixture. | ||
""" | ||
def __init__(self) -> None: | ||
self._base_dir: Optional[Any] = None | ||
|
||
def new_file(self, file_path: Path, text: Optional[str] = None) -> Path: | ||
if file_path.is_absolute(): | ||
raise ValueError(f"{file_path} is an absolute path. The test fixture requires relative paths to work.") | ||
file = self.base_dir / file_path | ||
file.parent.mkdir(parents=True, exist_ok=True) | ||
if text is not None: | ||
file.write_text(text) | ||
return file | ||
|
||
@property | ||
def base_dir(self) -> Path: | ||
if self._base_dir is None: | ||
self._base_dir = tempfile.TemporaryDirectory() | ||
return Path(self._base_dir.name).resolve() | ||
|
||
def _test_path_finalizer(self) -> None: | ||
""" | ||
Finalizer to clean up any temporary directories created during the test. | ||
""" | ||
if self._base_dir is not None: | ||
self._base_dir.cleanup() | ||
del self._base_dir | ||
self._base_dir = None | ||
|
||
@pytest.fixture(scope="function") | ||
def temp_dsdl_factory(request: pytest.FixtureRequest) -> Any: # pylint: disable=unused-argument | ||
""" | ||
Fixture for pydsdl tests that have to create files as part of the test. This object stays in-scope for a given | ||
test method and does not requires a context manager in the test itself. | ||
Call `new_file(path)` to create a new file path in the fixture's temporary directory. This will create all | ||
uncreated parent directories but will _not_ create the file unless text is provided: `new_file(path, "hello")` | ||
""" | ||
f = TemporaryDsdlContext() | ||
request.addfinalizer(f._test_path_finalizer) # pylint: disable=protected-access | ||
return f | ||
|
||
|
||
|
||
@pytest.fixture | ||
def public_types() -> Path: | ||
""" | ||
Path to the public regulated data types directory used for tests. | ||
""" | ||
return Path(".dsdl-test") / "uavcan" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
sphinx == 4.4.0 | ||
sphinx_rtd_theme == 1.0.0 | ||
sphinx >= 5.0 | ||
sphinx_rtd_theme >= 1.0.0 | ||
sphinx-computron >= 0.2, < 2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.