-
-
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.
Use pathlib.Path instead of plain string paths (#77)
* Drop Python 3.6 and update dependencies * Use pathlib.Path instead of raw str throughout; keep API compatible * Add missing future imports * Apply non-POSIX normalization * Fix #71 * Enhance diagnostics to help with macos debugging * CI: run macos build sooner * macos-specific fixes
- Loading branch information
1 parent
f055865
commit ced95ef
Showing
15 changed files
with
309 additions
and
308 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,7 @@ | |
# This software is distributed under the terms of the MIT License. | ||
# Author: Pavel Kirienko <[email protected]> | ||
|
||
import typing | ||
from __future__ import annotations | ||
from . import _error | ||
from . import _serializable | ||
from . import _bit_length_set | ||
|
@@ -34,26 +34,26 @@ def __str__(self) -> str: | |
|
||
class DataSchemaBuilder: | ||
def __init__(self) -> None: | ||
self._fields = [] # type: typing.List[_serializable.Field] | ||
self._constants = [] # type: typing.List[_serializable.Constant] | ||
self._serialization_mode = None # type: typing.Optional[SerializationMode] | ||
self._fields: list[_serializable.Field] = [] | ||
self._constants: list[_serializable.Constant] = [] | ||
self._serialization_mode: SerializationMode | None = None | ||
self._is_union = False | ||
self._bit_length_computed_at_least_once = False | ||
self._doc = "" | ||
|
||
@property | ||
def fields(self) -> typing.List[_serializable.Field]: | ||
def fields(self) -> list[_serializable.Field]: | ||
assert all(map(lambda x: isinstance(x, _serializable.Field), self._fields)) | ||
return self._fields | ||
|
||
@property | ||
def constants(self) -> typing.List[_serializable.Constant]: | ||
def constants(self) -> list[_serializable.Constant]: | ||
assert all(map(lambda x: isinstance(x, _serializable.Constant), self._constants)) | ||
return self._constants | ||
|
||
@property | ||
def attributes(self) -> typing.List[_serializable.Attribute]: # noinspection PyTypeChecker | ||
out = [] # type: typing.List[_serializable.Attribute] | ||
def attributes(self) -> list[_serializable.Attribute]: # noinspection PyTypeChecker | ||
out = [] # type: list[_serializable.Attribute] | ||
out += self.fields | ||
out += self.constants | ||
return out | ||
|
@@ -63,7 +63,7 @@ def doc(self) -> str: | |
return self._doc | ||
|
||
@property | ||
def serialization_mode(self) -> typing.Optional[SerializationMode]: | ||
def serialization_mode(self) -> SerializationMode | None: | ||
return self._serialization_mode | ||
|
||
@property | ||
|
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,9 +2,9 @@ | |
# This software is distributed under the terms of the MIT License. | ||
# Author: Pavel Kirienko <[email protected]> | ||
|
||
import os | ||
import typing | ||
from typing import Optional, Callable, Iterable | ||
import logging | ||
from pathlib import Path | ||
from . import _serializable | ||
from . import _expression | ||
from . import _error | ||
|
@@ -45,15 +45,15 @@ class DataTypeBuilder(_parser.StatementStreamProcessor): | |
def __init__( | ||
self, | ||
definition: _dsdl_definition.DSDLDefinition, | ||
lookup_definitions: typing.Iterable[_dsdl_definition.DSDLDefinition], | ||
print_output_handler: typing.Callable[[int, str], None], | ||
lookup_definitions: Iterable[_dsdl_definition.DSDLDefinition], | ||
print_output_handler: Callable[[int, str], None], | ||
allow_unregulated_fixed_port_id: bool, | ||
): | ||
self._definition = definition | ||
self._lookup_definitions = list(lookup_definitions) | ||
self._print_output_handler = print_output_handler | ||
self._allow_unregulated_fixed_port_id = allow_unregulated_fixed_port_id | ||
self._element_callback = None # type: typing.Optional[typing.Callable[[str], None]] | ||
self._element_callback = None # type: Optional[Callable[[str], None]] | ||
|
||
assert isinstance(self._definition, _dsdl_definition.DSDLDefinition) | ||
assert all(map(lambda x: isinstance(x, _dsdl_definition.DSDLDefinition), lookup_definitions)) | ||
|
@@ -148,7 +148,7 @@ def on_padding_field(self, padding_field_type: _serializable.VoidType) -> None: | |
) | ||
|
||
def on_directive( | ||
self, line_number: int, directive_name: str, associated_expression_value: typing.Optional[_expression.Any] | ||
self, line_number: int, directive_name: str, associated_expression_value: Optional[_expression.Any] | ||
) -> None: | ||
try: | ||
handler = { | ||
|
@@ -209,8 +209,8 @@ def resolve_versioned_data_type(self, name: str, version: _serializable.Version) | |
lookup_nss or "(empty set)", | ||
) | ||
if requested_ns not in lookup_nss and requested_ns == subroot_ns: | ||
error_description += " Did you mean to use the directory %r instead of %r?" % ( | ||
os.path.join(self._definition.root_namespace_path, subroot_ns), | ||
error_description += " Did you mean to use the directory %s instead of %s?" % ( | ||
self._definition.root_namespace_path / subroot_ns, | ||
self._definition.root_namespace_path, | ||
) | ||
else: | ||
|
@@ -231,7 +231,7 @@ def resolve_versioned_data_type(self, name: str, version: _serializable.Version) | |
allow_unregulated_fixed_port_id=self._allow_unregulated_fixed_port_id, | ||
) | ||
|
||
def _queue_attribute(self, element_callback: typing.Callable[[str], None]) -> None: | ||
def _queue_attribute(self, element_callback: Callable[[str], None]) -> None: | ||
self._flush_attribute("") | ||
self._element_callback = element_callback | ||
|
||
|
@@ -247,7 +247,7 @@ def _on_attribute(self) -> None: | |
"This is to prevent errors if the extent is dependent on the bit length set of the data schema." | ||
) | ||
|
||
def _on_print_directive(self, line_number: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_print_directive(self, line_number: int, value: Optional[_expression.Any]) -> None: | ||
_logger.info( | ||
"Print directive at %s:%d%s", | ||
self._definition.file_path, | ||
|
@@ -256,7 +256,7 @@ def _on_print_directive(self, line_number: int, value: typing.Optional[_expressi | |
) | ||
self._print_output_handler(line_number, str(value if value is not None else "")) | ||
|
||
def _on_assert_directive(self, line_number: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_assert_directive(self, line_number: int, value: Optional[_expression.Any]) -> None: | ||
if isinstance(value, _expression.Boolean): | ||
if not value.native_value: | ||
raise AssertionCheckFailureError( | ||
|
@@ -268,7 +268,7 @@ def _on_assert_directive(self, line_number: int, value: typing.Optional[_express | |
else: | ||
raise InvalidDirectiveError("The assertion check expression must yield a boolean, not %s" % value.TYPE_NAME) | ||
|
||
def _on_extent_directive(self, line_number: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_extent_directive(self, line_number: int, value: Optional[_expression.Any]) -> None: | ||
if self._structs[-1].serialization_mode is not None: | ||
raise InvalidDirectiveError( | ||
"Misplaced extent directive. The serialization mode is already set to %s" | ||
|
@@ -284,7 +284,7 @@ def _on_extent_directive(self, line_number: int, value: typing.Optional[_express | |
else: | ||
raise InvalidDirectiveError("The extent directive expects a rational, not %s" % value.TYPE_NAME) | ||
|
||
def _on_sealed_directive(self, _ln: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_sealed_directive(self, _ln: int, value: Optional[_expression.Any]) -> None: | ||
if self._structs[-1].serialization_mode is not None: | ||
raise InvalidDirectiveError( | ||
"Misplaced sealing directive. The serialization mode is already set to %s" | ||
|
@@ -294,7 +294,7 @@ def _on_sealed_directive(self, _ln: int, value: typing.Optional[_expression.Any] | |
raise InvalidDirectiveError("The sealed directive does not expect an expression") | ||
self._structs[-1].set_serialization_mode(_data_schema_builder.SealedSerializationMode()) | ||
|
||
def _on_union_directive(self, _ln: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_union_directive(self, _ln: int, value: Optional[_expression.Any]) -> None: | ||
if value is not None: | ||
raise InvalidDirectiveError("The union directive does not expect an expression") | ||
if self._structs[-1].union: | ||
|
@@ -303,7 +303,7 @@ def _on_union_directive(self, _ln: int, value: typing.Optional[_expression.Any]) | |
raise InvalidDirectiveError("The union directive must be placed before the first " "attribute definition") | ||
self._structs[-1].make_union() | ||
|
||
def _on_deprecated_directive(self, _ln: int, value: typing.Optional[_expression.Any]) -> None: | ||
def _on_deprecated_directive(self, _ln: int, value: Optional[_expression.Any]) -> None: | ||
if value is not None: | ||
raise InvalidDirectiveError("The deprecated directive does not expect an expression") | ||
if self._is_deprecated: | ||
|
@@ -322,8 +322,8 @@ def _make_composite( # pylint: disable=too-many-arguments | |
name: str, | ||
version: _serializable.Version, | ||
deprecated: bool, | ||
fixed_port_id: typing.Optional[int], | ||
source_file_path: str, | ||
fixed_port_id: Optional[int], | ||
source_file_path: Path, | ||
has_parent_service: bool, | ||
) -> _serializable.CompositeType: | ||
ty = _serializable.UnionType if builder.union else _serializable.StructureType | ||
|
Oops, something went wrong.