Skip to content

Commit d89ce9f

Browse files
thirtytwobitsScott Dixon
andauthored
Issue/388 (#389)
Co-authored-by: Scott Dixon <thirtytwobits@Scotts-MacBook-Pro.local>
1 parent a451f05 commit d89ce9f

27 files changed

Lines changed: 190 additions & 301 deletions

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
compat-test-python3-ubuntu:
123123
strategy:
124124
matrix:
125-
python3-version: ['8', '9', '10', '11', '12', '13']
125+
python3-version: ['10', '11', '12', '13']
126126
runs-on: ubuntu-latest
127127
container: ghcr.io/opencyphal/toxic:tx22.4.3
128128
needs: test

setup.cfg

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ classifiers =
1616
License :: OSI Approved :: MIT License
1717
Programming Language :: Python
1818
Programming Language :: Python :: 3
19-
Programming Language :: Python :: 3.8
20-
Programming Language :: Python :: 3.9
2119
Programming Language :: Python :: 3.10
2220
Programming Language :: Python :: 3.11
2321
Programming Language :: Python :: 3.12
@@ -46,7 +44,7 @@ config =
4644

4745
zip_safe = False
4846

49-
python_requires >= 3.8
47+
python_requires >= 3.10
5048

5149
[options.entry_points]
5250
console_scripts =

setup.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,8 @@
3333
pydsdl_version_specifier = f"pydsdl {match.group(1)} {match.group(2)}"
3434
package_data = {"": ["*.j2", "**/*.css", "**/*.js", "*.ini", "*.json", "*.hpp", "*.h"]}
3535

36-
if sys.version_info < (3, 9):
37-
# For version 3.8 we need to add importlib_resources as a dependency. This seems to blow away the values
38-
# in setup.cfg so we need to specify them here.
39-
setuptools.setup(
40-
version=version["__version__"],
41-
package_data=package_data,
42-
install_requires=["importlib_resources", pydsdl_version_specifier],
43-
)
44-
else:
45-
# For version 3.9 and later we don't need to add importlib_resources as a dependency.
46-
setuptools.setup(
47-
version=version["__version__"],
48-
package_data=package_data,
49-
install_requires=[pydsdl_version_specifier],
50-
)
36+
setuptools.setup(
37+
version=version["__version__"],
38+
package_data=package_data,
39+
install_requires=[pydsdl_version_specifier],
40+
)

src/nunavut/__init__.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,26 @@
1515
invoking the ``nunavut.generate_all`` method.
1616
1717
"""
18+
1819
import sys as _sys
1920

20-
from ._generators import AbstractGenerator
21-
from ._generators import generate_all
22-
from ._generators import generate_all_for_language
23-
from ._generators import generate_all_from_namespace
24-
from ._generators import generate_all_from_namespace_with_generators
25-
from ._generators import basic_language_context_builder_from_args
21+
from ._generators import (
22+
AbstractGenerator,
23+
basic_language_context_builder_from_args,
24+
generate_all,
25+
generate_all_for_language,
26+
generate_all_from_namespace,
27+
generate_all_from_namespace_with_generators,
28+
)
2629
from ._namespace import Namespace
27-
from ._utilities import TEMPLATE_SUFFIX
28-
from ._utilities import DefaultValue
29-
from ._utilities import ResourceType
30-
from ._utilities import ResourceSearchPolicy
31-
from ._utilities import YesNoDefault
32-
from ._version import __author__
33-
from ._version import __copyright__
34-
from ._version import __email__
35-
from ._version import __license__
36-
from ._version import __version__
37-
from .jinja import CodeGenerator
38-
from .jinja import DSDLCodeGenerator
39-
from .jinja import SupportGenerator
40-
from .lang import Language
41-
from .lang import LanguageContext
42-
from .lang import LanguageContextBuilder
43-
from .lang import UnsupportedLanguageError
30+
from ._utilities import TEMPLATE_SUFFIX, DefaultValue, ResourceSearchPolicy, ResourceType, YesNoDefault
31+
from ._version import __author__, __copyright__, __email__, __license__, __version__
32+
from .jinja import CodeGenerator, DSDLCodeGenerator, SupportGenerator
33+
from .lang import Language, LanguageContext, LanguageContextBuilder, UnsupportedLanguageError
4434
from .lang._config import LanguageConfig
4535

46-
if _sys.version_info[:2] < (3, 8): # pragma: no cover
47-
print("A newer version of Python is required", file=_sys.stderr)
36+
if _sys.version_info[:2] < (3, 10): # pragma: no cover
37+
print("Python 3.10 or newer is required", file=_sys.stderr)
4838
_sys.exit(1)
4939

5040
__version_info__ = tuple(map(int, __version__.split(".")[:3]))

src/nunavut/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,4 @@
1111

1212
from .cli.runners import main as cli_main
1313

14-
1514
sys.exit(cli_main())

src/nunavut/_namespace.py

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,9 @@
6666
Iterator,
6767
KeysView,
6868
List,
69-
Optional,
7069
Protocol,
7170
Tuple,
7271
TypeVar,
73-
Union,
7472
cast,
7573
)
7674

@@ -79,15 +77,6 @@
7977
from .lang import Language, LanguageContext
8078
from .lang._common import IncludeGenerator
8179

82-
if sys.version_info < (3, 9):
83-
# Python 3.8 has a bug. This is a workaround per https://stackoverflow.com/a/66518591/310659
84-
def _register(self, cls, method=None): # type: ignore
85-
if hasattr(cls, "__func__"):
86-
setattr(cls, "__annotations__", cls.__func__.__annotations__)
87-
return self.dispatcher.register(cls, func=method)
88-
89-
singledispatchmethod.register = _register # type: ignore
90-
9180
# +--------------------------------------------------------------------------------------------------------------------+
9281

9382

@@ -96,7 +85,7 @@ class AsyncResultProtocol(Protocol):
9685
Defines the protocol for a duck-type compatible with multiprocessing.pool.AsyncResult.
9786
"""
9887

99-
def get(self, timeout: Optional[Any] = None) -> Any:
88+
def get(self, timeout: Any | None = None) -> Any:
10089
"""
10190
See multiprocessing.pool.AsyncResult.get
10291
"""
@@ -113,7 +102,7 @@ def __init__(self, read_method: Callable[..., Any], args: Tuple[Any, ...]) -> No
113102
self.args = args
114103
self._logger = logging.getLogger(NotAsyncResult.__name__)
115104

116-
def get(self, timeout: Optional[Any] = None) -> Any:
105+
def get(self, timeout: Any | None = None) -> Any:
117106
"""
118107
Perform the work synchronously.
119108
"""
@@ -130,7 +119,7 @@ def get(self, timeout: Optional[Any] = None) -> Any:
130119
def _read_files_strategy(
131120
index: "Namespace",
132121
apply_method: ApplyMethodT,
133-
dsdl_files: Union[Path, str, Iterable[Union[Path, str]]],
122+
dsdl_files: Path | str | Iterable[Path | str],
134123
job_timeout_seconds: float,
135124
omit_dependencies: bool,
136125
args: Iterable[Any],
@@ -274,7 +263,7 @@ def wrap(
274263
"""
275264
return Generatable(definition, input_types, path)
276265

277-
def with_segments(self, *pathsegments: Union[str, PathLike]) -> Path:
266+
def with_segments(self, *pathsegments: str | PathLike) -> Path:
278267
"""
279268
Path override: Construct a new path object from any number of path-like objects.
280269
We discard the Generatable type here and continue on with a default Path object.
@@ -380,11 +369,11 @@ def strop_namespace(cls, full_namespace: str, language_context: LanguageContext)
380369
def add_types(
381370
cls,
382371
index: "Namespace",
383-
types: Union[
384-
Tuple[pydsdl.CompositeType, List[pydsdl.CompositeType]],
385-
List[Tuple[pydsdl.CompositeType, List[pydsdl.CompositeType]]],
386-
],
387-
extension: Optional[str] = None,
372+
types: (
373+
Tuple[pydsdl.CompositeType, List[pydsdl.CompositeType]]
374+
| List[Tuple[pydsdl.CompositeType, List[pydsdl.CompositeType]]]
375+
),
376+
extension: str | None = None,
388377
) -> None:
389378
"""
390379
Add a set of types to a namespace tree building new nodes as needed.
@@ -441,9 +430,9 @@ def Identity(cls, output_path: Path, lctx: LanguageContext) -> "Namespace":
441430
def read_namespace(
442431
cls,
443432
index: "Namespace",
444-
root_namespace_directory: Union[Path, str],
445-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
446-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
433+
root_namespace_directory: Path | str,
434+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
435+
print_output_handler: Callable[[Path, int, str], None] | None = None,
447436
allow_unregulated_fixed_port_id: bool = False,
448437
allow_root_namespace_name_collision: bool = True,
449438
) -> "Namespace":
@@ -477,9 +466,9 @@ def _(
477466
cls,
478467
output_path: str,
479468
lctx: LanguageContext,
480-
root_namespace_directory: Union[Path, str],
481-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
482-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
469+
root_namespace_directory: Path | str,
470+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
471+
print_output_handler: Callable[[Path, int, str], None] | None = None,
483472
allow_unregulated_fixed_port_id: bool = False,
484473
allow_root_namespace_name_collision: bool = True,
485474
) -> pydsdl.Any:
@@ -510,9 +499,9 @@ def _(
510499
cls,
511500
output_path: Path,
512501
lctx: LanguageContext,
513-
root_namespace_directory: Union[Path, str],
514-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
515-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
502+
root_namespace_directory: Path | str,
503+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
504+
print_output_handler: Callable[[Path, int, str], None] | None = None,
516505
allow_unregulated_fixed_port_id: bool = False,
517506
allow_root_namespace_name_collision: bool = True,
518507
) -> pydsdl.Any:
@@ -542,12 +531,12 @@ def _(
542531
def read_files(
543532
cls,
544533
index: "Namespace",
545-
dsdl_files: Union[Path, str, Iterable[Union[Path, str]]],
546-
root_namespace_directories_or_names: Optional[Union[Path, str, Iterable[Union[Path, str]]]],
534+
dsdl_files: Path | str | Iterable[Path | str],
535+
root_namespace_directories_or_names: Path | str | Iterable[Path | str] | None,
547536
jobs: int = 0,
548537
job_timeout_seconds: float = 0,
549-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
550-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
538+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
539+
print_output_handler: Callable[[Path, int, str], None] | None = None,
551540
allow_unregulated_fixed_port_id: bool = False,
552541
omit_dependencies: bool = False,
553542
) -> "Namespace":
@@ -590,12 +579,12 @@ def _(
590579
cls,
591580
output_path: Path,
592581
lctx: LanguageContext,
593-
dsdl_files: Optional[Union[Path, str, Iterable[Union[Path, str]]]],
594-
root_namespace_directories_or_names: Optional[Union[Path, str, Iterable[Union[Path, str]]]],
582+
dsdl_files: Path | str | Iterable[Path | str] | None,
583+
root_namespace_directories_or_names: Path | str | Iterable[Path | str] | None,
595584
jobs: int = 0,
596585
job_timeout_seconds: float = 0,
597-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
598-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
586+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
587+
print_output_handler: Callable[[Path, int, str], None] | None = None,
599588
allow_unregulated_fixed_port_id: bool = False,
600589
omit_dependencies: bool = False,
601590
) -> pydsdl.Any:
@@ -633,12 +622,12 @@ def _(
633622
cls,
634623
output_path: str,
635624
lctx: LanguageContext,
636-
dsdl_files: Optional[Union[Path, str, Iterable[Union[Path, str]]]],
637-
root_namespace_directories_or_names: Optional[Union[Path, str, Iterable[Union[Path, str]]]],
625+
dsdl_files: Path | str | Iterable[Path | str] | None,
626+
root_namespace_directories_or_names: Path | str | Iterable[Path | str] | None,
638627
jobs: int = 0,
639628
job_timeout_seconds: float = 0,
640-
lookup_directories: Optional[Union[Path, str, Iterable[Union[Path, str]]]] = None,
641-
print_output_handler: Optional[Callable[[Path, int, str], None]] = None,
629+
lookup_directories: Path | str | Iterable[Path | str] | None = None,
630+
print_output_handler: Callable[[Path, int, str], None] | None = None,
642631
allow_unregulated_fixed_port_id: bool = False,
643632
omit_dependencies: bool = False,
644633
) -> pydsdl.Any:
@@ -677,7 +666,7 @@ def __init__(
677666
full_namespace: str,
678667
namespace_dir: Path,
679668
language_context: LanguageContext,
680-
parent: Optional["Namespace"] = None,
669+
parent: "Namespace | None" = None,
681670
):
682671
if full_namespace.startswith("."):
683672
full_namespace = full_namespace[1:]
@@ -741,7 +730,7 @@ def output_path(self) -> Path:
741730
return self._output_path
742731

743732
@property
744-
def parent(self) -> Optional["Namespace"]:
733+
def parent(self) -> "Namespace | None":
745734
"""
746735
The parent namespace of this namespace or None if this is a root namespace.
747736
"""
@@ -934,14 +923,14 @@ def get_all_namespaces(self) -> Generator[Tuple["Namespace", Path], None, None]:
934923
"""
935924
yield from self._recursive_namespace_generator(self)
936925

937-
def get_all_types(self) -> Generator[Tuple[pydsdl.Any, Union[Generatable, Path]], None, None]:
926+
def get_all_types(self) -> Generator[Tuple[pydsdl.Any, Generatable | Path], None, None]:
938927
"""
939928
Generates tuples relating datatypes and nested namespaces at and below this
940929
namespace to the path for each type's generated output.
941930
"""
942931
yield from self._recursive_data_type_and_namespace_generator(self)
943932

944-
def find_output_path_for_type(self, compound_type: Union["Namespace", pydsdl.CompositeType]) -> Path:
933+
def find_output_path_for_type(self, compound_type: "Namespace | pydsdl.CompositeType") -> Path:
945934
"""
946935
Searches the entire namespace tree to find a mapping of the type to an
947936
output file path.
@@ -958,7 +947,7 @@ def find_output_path_for_type(self, compound_type: Union["Namespace", pydsdl.Com
958947
return root_namespace._bfs_search_for_output_path(compound_type) # pylint: disable=protected-access
959948

960949
def add_data_type(
961-
self, dsdl_type: pydsdl.CompositeType, input_types: List[pydsdl.CompositeType], extension: Optional[str]
950+
self, dsdl_type: pydsdl.CompositeType, input_types: List[pydsdl.CompositeType], extension: str | None
962951
) -> Generatable:
963952
"""
964953
Add a datatype to this namespace.
@@ -1098,7 +1087,7 @@ def _recursive_namespace_generator(cls, namespace: "Namespace") -> Generator[Tup
10981087
@classmethod
10991088
def _recursive_data_type_and_namespace_generator(
11001089
cls, namespace: "Namespace"
1101-
) -> Generator[Tuple[pydsdl.Any, Union[Path, Generatable]], None, None]:
1090+
) -> Generator[Tuple[pydsdl.Any, Path | Generatable], None, None]:
11021091
yield (namespace, namespace.output_path)
11031092

11041093
for data_type, output_path in namespace.get_nested_types():
@@ -1113,8 +1102,8 @@ def _recursive_data_type_and_namespace_generator(
11131102

11141103
def build_namespace_tree(
11151104
types: List[pydsdl.CompositeType],
1116-
root_namespace_dir: Union[str, Path],
1117-
output_dir: Union[str, Path],
1105+
root_namespace_dir: str | Path,
1106+
output_dir: str | Path,
11181107
language_context: LanguageContext,
11191108
) -> Namespace:
11201109
"""

src/nunavut/_postprocessors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
"""
77
Module containing post processing logic to run on generated files.
88
"""
9+
910
import abc
1011
import pathlib
11-
import typing
1212
import re
1313
import sys
14+
import typing
1415
from subprocess import run as subprocess_run # nosec
1516

1617
# +---------------------------------------------------------------------------+

src/nunavut/_templates.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Abstractions around template engine internals.
88
"""
9+
910
import functools
1011
import inspect
1112
import types

0 commit comments

Comments
 (0)