Skip to content

Commit

Permalink
Use pathlib.Path instead of plain string paths (#77)
Browse files Browse the repository at this point in the history
* 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
pavel-kirienko authored Mar 28, 2022
1 parent f055865 commit ced95ef
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 308 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/pavel.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ environment:
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
PYTHON: "C:\\Python310-x64"

- job_group: tests
APPVEYOR_BUILD_WORKER_IMAGE: macos
PYTHON: "3.9"

- job_group: tests
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
PYTHON: "3.10"
Expand All @@ -23,14 +27,6 @@ environment:
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
PYTHON: "3.7"

- job_group: tests
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
PYTHON: "3.6"

- job_group: tests
APPVEYOR_BUILD_WORKER_IMAGE: macos
PYTHON: "3.9"

- job_name: deploy
job_depends_on: tests
APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu2004
Expand Down
12 changes: 6 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import nox


PYTHONS = ["3.6", "3.7", "3.8", "3.9", "3.10"]
PYTHONS = ["3.7", "3.8", "3.9", "3.10"]
"""The newest supported Python shall be listed LAST."""

nox.options.error_on_external_run = True
Expand Down Expand Up @@ -48,9 +48,9 @@ def test(session):
session.log("Using the newest supported Python: %s", is_latest_python(session))
session.install("-e", ".")
session.install(
"pytest ~= 6.2",
"pytest-randomly ~= 3.5",
"coverage ~= 5.5",
"pytest ~= 7.0",
"pytest-randomly ~= 3.11",
"coverage ~= 6.3",
)
session.run("coverage", "run", "-m", "pytest")
session.run("coverage", "report", "--fail-under=95")
Expand All @@ -65,7 +65,7 @@ def lint(session):
session.log("Using the newest supported Python: %s", is_latest_python(session))
session.install(
"mypy == 0.931",
"pylint == 2.7.2",
"pylint == 2.12.*",
)
session.run(
"mypy",
Expand All @@ -84,7 +84,7 @@ def lint(session):
},
)
if is_latest_python(session):
session.install("black == 21.12b0")
session.install("black == 22.*")
session.run("black", "--check", ".")


Expand Down
2 changes: 1 addition & 1 deletion pydsdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os as _os
import sys as _sys

__version__ = "1.13.0"
__version__ = "1.14.0"
__version_info__ = tuple(map(int, __version__.split(".")[:3]))
__license__ = "MIT"
__author__ = "UAVCAN Consortium"
Expand Down
18 changes: 9 additions & 9 deletions pydsdl/_data_schema_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
34 changes: 17 additions & 17 deletions pydsdl/_data_type_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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
Expand Down
Loading

0 comments on commit ced95ef

Please sign in to comment.