Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Windows #368

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
strategy:
matrix:
python3-version: ['11', '12', '13']
python3-platform: ['macos-latest']
python3-platform: ['windows-latest', 'macos-latest']
runs-on: ${{ matrix.python3-platform }}
needs: test
steps:
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"python.testing.cwd": "${workspaceFolder}",
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["-v"],
"python.testing.pytestArgs": ["-vv"],
"pylint.args": [
"--rcfile=${workspaceFolder}/tox.ini"
],
Expand Down
8 changes: 4 additions & 4 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _run_nnvg_main(
class GenTestPaths:
"""Helper to generate common paths used in our unit tests."""

def __init__(self, test_file: str, keep_temporaries: bool, node_name: str):
test_file_path = Path(test_file)
def __init__(self, test_file: Path, keep_temporaries: bool, node_name: str):
test_file_path = test_file.resolve()
self.test_name = f"{test_file_path.parent.stem}_{node_name}"
self.test_dir = test_file_path.parent
search_dir = self.test_dir.resolve()
Expand Down Expand Up @@ -237,7 +237,7 @@ def gen_paths(request: pytest.FixtureRequest) -> GenTestPaths:
Used by the "gentest" unit tests in Nunavut to standardize output paths for generated code created as part of
the tests. Use the --keep-generated argument to disable the auto-clean behaviour this fixture provides by default.
"""
g = GenTestPaths(str(request.fspath), request.config.option.keep_generated, request.node.name)
g = GenTestPaths(request.path, request.config.option.keep_generated, request.node.name)
request.addfinalizer(g.test_path_finalizer)
return g

Expand All @@ -251,7 +251,7 @@ def gen_paths_for_module(request: pytest.FixtureRequest) -> GenTestPaths: # pyl
Note: this fixture is different than gen_paths because it is scoped to the module level. This is useful for
Sybil tests that share temporary files across different test blocks within the same document.
"""
g = GenTestPaths(str(request.fspath), request.config.option.keep_generated, request.node.name)
g = GenTestPaths(request.path, request.config.option.keep_generated, request.node.name)
request.addfinalizer(g.test_path_finalizer)
return g

Expand Down
44 changes: 28 additions & 16 deletions src/nunavut/cli/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,33 @@ def _parse_target_paths(

from nunavut.cli.parsers import NunavutArgumentParser
from pytest import raises
from pathlib import Path

real_root = Path().cwd().as_posix()

parser = NunavutArgumentParser()
# Happy path
root_paths, target_files = parser._parse_target_paths(
[
"/one/to/root",
"/two/to/file.dsdl",
f"{real_root}one/to/root",
f"{real_root}two/to/file.dsdl",
"three/path/four:to/file.dsdl",
"/five/path/six:to/file.dsdl",
f"{real_root}five/path/six:to/file.dsdl",
"seven/path/eight\\\\:to/file.dsdl",
"/nine/path/ten/:to/file.dsdl",
f"{real_root}nine/path/ten/:to/file.dsdl",
],
False,
)
print(root_paths, target_files)
assert len(root_paths) == 4
assert len(target_files) == 5

assert Path("/one/to/root") in root_paths
assert Path(f"{real_root}one/to/root") in root_paths
assert Path("three/path/four") in root_paths
assert Path("/five/path/six") in root_paths
assert Path("/nine/path/ten") in root_paths
assert Path(f"{real_root}five/path/six") in root_paths
assert Path(f"{real_root}nine/path/ten") in root_paths

assert Path("/two/to/file.dsdl") in target_files
assert Path(f"{real_root}two/to/file.dsdl") in target_files
assert Path("four/to/file.dsdl") in target_files
assert Path("six/to/file.dsdl") in target_files
assert Path("seven/path/eight\\\\:to/file.dsdl") in target_files
Expand All @@ -250,33 +253,42 @@ def _parse_target_paths(

# Happy path: single target file
single_target_file_root_paths, single_target_file_target_files = parser._parse_target_paths(
["/one/to/file.dsdl"], True
[f"{real_root}one/to/file.dsdl"], True
)
assert len(single_target_file_root_paths) == 0
assert len(single_target_file_target_files) == 1
assert single_target_file_target_files.pop() == Path("/one/to/file.dsdl")
assert single_target_file_target_files.pop() == Path(f"{real_root}one/to/file.dsdl")

# errors: multiple colons
with raises(SystemExit):
parser._parse_target_paths(["one:two:three"], False)

# errors: leading slash
with raises(SystemExit):
parser._parse_target_paths(["path/to:/root/to/file.dsdl"], False)
parser._parse_target_paths([f"path/to:{Path.cwd().anchor}root/to/file.dsdl"], False)

"""

def _parse_lookup_dir(lookup_dir: str) -> Tuple[Optional[Path], Optional[Path]]:
split_path = re.split(r"(?<!\\):", lookup_dir)

lookup_path = Path(lookup_dir)
if lookup_path.is_absolute():
relative_lookup_dir = lookup_path.relative_to(lookup_path.anchor).as_posix()
else:
relative_lookup_dir = lookup_dir
split_path = re.split(r"(?<!\\):", relative_lookup_dir)
if len(split_path) > 2:
self.error(f"Invalid lookup path (too many colons) > {lookup_dir}")
if len(split_path) == 2:
if lookup_path.is_absolute():
root_path = Path(lookup_path.anchor, split_path[0])
else:
root_path = Path(split_path[0])
if len(split_path) == 2:
return root_path, Path(root_path.stem, split_path[1])
elif (first_path := Path(split_path[0])).suffix in self.DSDL_FILE_SUFFIXES:
return None, first_path
elif root_path.suffix in self.DSDL_FILE_SUFFIXES:
return None, root_path
else:
return first_path, None
return root_path, None

if target_files_or_root_namespace is None:
return set(), set()
Expand Down
12 changes: 6 additions & 6 deletions src/nunavut/lang/cpp/templates/_composite_type.j2
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct {% if composite_type.deprecated -%}
{%- endfor %}
{%- endif %}
{
(void)allocator; // avoid unused param warning
static_cast<void>(allocator); // avoid unused param warning
}

{%- if composite_type.inner_type is not UnionType %}
Expand All @@ -152,7 +152,7 @@ struct {% if composite_type.deprecated -%}
{{ field | id }}{{ field | value_initializer(SpecialMethod.INITIALIZING_CONSTRUCTOR_WITH_ALLOCATOR) }}
{%- endfor %}
{
(void)allocator; // avoid unused param warning
static_cast<void>(allocator); // avoid unused param warning
}
{%- endif %}
{%- endif %}
Expand All @@ -174,8 +174,8 @@ struct {% if composite_type.deprecated -%}
{%- endfor %}
{%- endif %}
{
(void)rhs; // avoid unused param warning
(void)allocator; // avoid unused param warning
static_cast<void>(rhs); // avoid unused param warning
static_cast<void>(allocator); // avoid unused param warning
}

// Move constructor
Expand All @@ -195,8 +195,8 @@ struct {% if composite_type.deprecated -%}
{%- endfor %}
{%- endif %}
{
(void)rhs; // avoid unused param warning
(void)allocator; // avoid unused param warning
static_cast<void>(rhs); // avoid unused param warning
static_cast<void>(allocator); // avoid unused param warning
}

{% if composite_type.inner_type is UnionType and not composite_type.bit_length_set.fixed_length %}
Expand Down
Loading