1+ from collections .abc import Sequence
12from pathlib import Path
23from tempfile import TemporaryDirectory
3- from typing import Dict , Optional , Sequence
44
5- from .types import Assembly , Runtime , RuntimeInfo
6- from .util import StrOrPath
5+ from .types import Assembly , Runtime , RuntimeInfo , StrOrPath
76from .util .find import find_dotnet_root , find_libmono , find_runtimes
87from .util .runtime_spec import DotnetCoreRuntimeSpec
98
2423def get_mono (
2524 * ,
2625 # domain: Optional[str] = None,
27- config_file : Optional [ StrOrPath ] = None ,
28- global_config_file : Optional [ StrOrPath ] = None ,
29- libmono : Optional [ StrOrPath ] = None ,
26+ config_file : StrOrPath | None = None ,
27+ global_config_file : StrOrPath | None = None ,
28+ libmono : StrOrPath | None = None ,
3029 sgen : bool = True ,
3130 debug : bool = False ,
32- jit_options : Optional [ Sequence [str ]] = None ,
33- assembly_dir : Optional [ str ] = None ,
34- config_dir : Optional [ str ] = None ,
31+ jit_options : Sequence [str ] | None = None ,
32+ assembly_dir : StrOrPath | None = None ,
33+ config_dir : StrOrPath | None = None ,
3534 set_signal_chaining : bool = False ,
36- trace_mask : Optional [ str ] = None ,
37- trace_level : Optional [ str ] = None ,
35+ trace_mask : str | None = None ,
36+ trace_level : str | None = None ,
3837) -> Runtime :
3938 """Get a Mono runtime instance
4039
@@ -92,11 +91,12 @@ def get_mono(
9291
9392def get_coreclr (
9493 * ,
95- runtime_config : Optional [StrOrPath ] = None ,
96- entry_dll : Optional [StrOrPath ] = None ,
97- dotnet_root : Optional [StrOrPath ] = None ,
98- properties : Optional [Dict [str , str ]] = None ,
99- runtime_spec : Optional [DotnetCoreRuntimeSpec ] = None ,
94+ runtime_config : StrOrPath | None = None ,
95+ entry_dll : StrOrPath | None = None ,
96+ dotnet_root : StrOrPath | None = None ,
97+ properties : dict [str , str ] | None = None ,
98+ runtime_spec : DotnetCoreRuntimeSpec | None = None ,
99+ runtime_version : str | None = None ,
100100) -> Runtime :
101101 """Get a CoreCLR (.NET Core) runtime instance
102102
@@ -122,7 +122,11 @@ def get_coreclr(
122122 :param runtime_spec:
123123 If the ``runtime_config`` is not specified, the concrete runtime to use
124124 can be controlled by passing this parameter. Possible values can be
125- retrieved using :py:func:`find_runtimes`."""
125+ retrieved using :py:func:`find_runtimes`.
126+ :param runtime_version:
127+ If neither the ``runtime_config`` nor the ``runtime_spec`` are specified,
128+ the concrete runtime version to use can be controlled by passing the
129+ major.minor version to this parameter."""
126130
127131 from .hostfxr import DotnetCoreRuntime
128132
@@ -139,6 +143,12 @@ def get_coreclr(
139143 candidates = [
140144 rt for rt in find_runtimes () if rt .name == "Microsoft.NETCore.App"
141145 ]
146+ if runtime_version is not None :
147+ candidates = [
148+ rt
149+ for rt in candidates
150+ if f"{ rt .version_info [0 ]} .{ rt .version_info [1 ]} " == runtime_version
151+ ]
142152 candidates .sort (key = lambda spec : spec .version_info , reverse = True )
143153 if not candidates :
144154 raise RuntimeError ("Failed to find a suitable runtime" )
@@ -168,7 +178,7 @@ def get_coreclr(
168178
169179
170180def get_netfx (
171- * , domain : Optional [ str ] = None , config_file : Optional [ StrOrPath ] = None
181+ * , domain : str | None = None , config_file : StrOrPath | None = None
172182) -> Runtime :
173183 """Get a .NET Framework runtime instance
174184
@@ -186,7 +196,7 @@ def get_netfx(
186196 return impl
187197
188198
189- def _maybe_path (p : Optional [ StrOrPath ] ) -> Optional [ Path ] :
199+ def _maybe_path (p : StrOrPath | None ) -> Path | None :
190200 if p is None :
191201 return None
192202 else :
0 commit comments