-
-
Notifications
You must be signed in to change notification settings - Fork 9
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 (
#103) 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. --------- Co-authored-by: Pavel Kirienko <[email protected]>
- Loading branch information
1 parent
98453a4
commit c7d8ef9
Showing
19 changed files
with
1,581 additions
and
320 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 clone --depth 1 [email protected]:OpenCyphal/public_regulated_data_types.git .dsdl-test && nox -e test-3.12" | ||
} |
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,63 @@ | ||
# | ||
# 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 | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ Contents | |
-------- | ||
|
||
.. toctree:: | ||
:maxdepth: 2 | ||
|
||
pages/installation | ||
pages/pydsdl | ||
|
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 == 7.1.2 # this is the last version that supports Python 3.8 | ||
sphinx_rtd_theme == 2.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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
# This software is distributed under the terms of the MIT License. | ||
# Author: Pavel Kirienko <[email protected]> | ||
|
||
import typing | ||
import random | ||
import itertools | ||
from ._symbolic import NullaryOperator, validate_numerically | ||
|
@@ -140,7 +139,7 @@ def _unittest_repetition() -> None: | |
) | ||
assert op.min == 7 * 3 | ||
assert op.max == 17 * 3 | ||
assert set(op.expand()) == set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 3))) # type: ignore | ||
assert set(op.expand()) == set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 3))) | ||
assert set(op.expand()) == {21, 25, 29, 31, 33, 35, 39, 41, 45, 51} | ||
assert set(op.modulo(7)) == {0, 1, 2, 3, 4, 5, 6} | ||
assert set(op.modulo(8)) == {1, 3, 5, 7} | ||
|
@@ -149,15 +148,15 @@ def _unittest_repetition() -> None: | |
for _ in range(1): | ||
child = NullaryOperator(random.randint(0, 100) for _ in range(random.randint(1, 10))) | ||
k = random.randint(0, 10) | ||
ref = set(map(sum, itertools.combinations_with_replacement(child.expand(), k))) # type: ignore | ||
ref = set(map(sum, itertools.combinations_with_replacement(child.expand(), k))) | ||
op = RepetitionOperator(child, k) | ||
assert set(op.expand()) == ref | ||
|
||
assert op.min == min(child.expand()) * k | ||
assert op.max == max(child.expand()) * k | ||
|
||
div = random.randint(1, 64) | ||
assert set(op.modulo(div)) == {typing.cast(int, x) % div for x in ref} | ||
assert set(op.modulo(div)) == {x % div for x in ref} | ||
|
||
validate_numerically(op) | ||
|
||
|
@@ -173,9 +172,9 @@ def _unittest_range_repetition() -> None: | |
assert op.max == 17 * 3 | ||
assert set(op.expand()) == ( | ||
{0} | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 1))) # type: ignore | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 2))) # type: ignore | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 3))) # type: ignore | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 1))) | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 2))) | ||
| set(map(sum, itertools.combinations_with_replacement([7, 11, 17], 3))) | ||
) | ||
assert set(op.expand()) == {0, 7, 11, 14, 17, 18, 21, 22, 24, 25, 28, 29, 31, 33, 34, 35, 39, 41, 45, 51} | ||
assert set(op.modulo(7)) == {0, 1, 2, 3, 4, 5, 6} | ||
|
@@ -197,10 +196,7 @@ def _unittest_range_repetition() -> None: | |
k_max = random.randint(0, 10) | ||
ref = set( | ||
itertools.chain( | ||
*( | ||
map(sum, itertools.combinations_with_replacement(child.expand(), k)) # type: ignore | ||
for k in range(k_max + 1) | ||
) | ||
*(map(sum, itertools.combinations_with_replacement(child.expand(), k)) for k in range(k_max + 1)) | ||
) | ||
) | ||
op = RangeRepetitionOperator(child, k_max) | ||
|
@@ -210,7 +206,7 @@ def _unittest_range_repetition() -> None: | |
assert op.max == max(child.expand()) * k_max | ||
|
||
div = random.randint(1, 64) | ||
assert set(op.modulo(div)) == {typing.cast(int, x) % div for x in ref} | ||
assert set(op.modulo(div)) == {x % div for x in ref} | ||
|
||
validate_numerically(op) | ||
|
||
|
Oops, something went wrong.