diff --git a/clr_loader/__init__.py b/clr_loader/__init__.py index 2744cf0..ce239a1 100644 --- a/clr_loader/__init__.py +++ b/clr_loader/__init__.py @@ -157,7 +157,7 @@ def get_coreclr_command_line( *, entry_dll: StrOrPath, dotnet_root: Optional[StrOrPath] = None, - properties: Optional[Dict[str, str]] = None + properties: Optional[Dict[str, str]] = None, ) -> Runtime: """Get a CoreCLR (.NET Core) runtime instance The returned ``DotnetCoreRuntimeCommandLine`` also acts as a mapping of the config @@ -178,7 +178,9 @@ def get_coreclr_command_line( if dotnet_root is None: dotnet_root = find_dotnet_root() - impl = DotnetCoreCommandRuntime(entry_dll=_maybe_path(entry_dll), dotnet_root=dotnet_root) + impl = DotnetCoreCommandRuntime( + entry_dll=_maybe_path(entry_dll), dotnet_root=dotnet_root + ) if properties: for key, value in properties.items(): impl[key] = value diff --git a/clr_loader/ffi/__init__.py b/clr_loader/ffi/__init__.py index 7917af9..eb2b5ae 100644 --- a/clr_loader/ffi/__init__.py +++ b/clr_loader/ffi/__init__.py @@ -18,10 +18,9 @@ def load_hostfxr(dotnet_root: Path): hostfxr_name = _get_dll_name("hostfxr") dotnet_root = dotnet_root.absolute() - # This will fail as soon as .NET hits version 10, but hopefully by then - # we'll have a more robust way of finding the libhostfxr + # Find all hostfxr versions by looking for the library file in version subdirectories hostfxr_path = dotnet_root / "host" / "fxr" - hostfxr_paths = hostfxr_path.glob(f"?.*/{hostfxr_name}") + hostfxr_paths = hostfxr_path.glob(f"*/{hostfxr_name}") error_report = list() @@ -69,7 +68,9 @@ def load_netfx(): def _path_to_version(path: Path) -> Tuple[int, int, int]: name = path.parent.name try: - res = list(map(int, name.split("."))) + # Handle pre-release versions like "10.0.0-rc.1" by taking only the version part + version_part = name.split("-")[0] + res = list(map(int, version_part.split("."))) return tuple(res + [0, 0, 0])[:3] except Exception: return (0, 0, 0) diff --git a/clr_loader/hostfxr.py b/clr_loader/hostfxr.py index 7a159f3..60ad6b6 100644 --- a/clr_loader/hostfxr.py +++ b/clr_loader/hostfxr.py @@ -120,7 +120,9 @@ def info(self): class DotnetCoreRuntime(DotnetCoreRuntimeBase): def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str): super().__init__(dotnet_root) - self._handle = _get_handle_for_runtime_config(self._dll, self._dotnet_root, runtime_config) + self._handle = _get_handle_for_runtime_config( + self._dll, self._dotnet_root, runtime_config + ) for key, value in params.items(): self[key] = value @@ -132,7 +134,9 @@ def __init__(self, runtime_config: Path, dotnet_root: Path, **params: str): class DotnetCoreCommandRuntime(DotnetCoreRuntimeBase): def __init__(self, entry_dll: Path, dotnet_root: Path, **params: str): super().__init__(dotnet_root) - self._handle = _get_handle_for_dotnet_command_line(self._dll, self._dotnet_root, entry_dll) + self._handle = _get_handle_for_dotnet_command_line( + self._dll, self._dotnet_root, entry_dll + ) for key, value in params.items(): self[key] = value @@ -141,7 +145,9 @@ def __init__(self, entry_dll: Path, dotnet_root: Path, **params: str): self._version = "" -def _get_handle_for_runtime_config(dll, dotnet_root: StrOrPath, runtime_config: StrOrPath): +def _get_handle_for_runtime_config( + dll, dotnet_root: StrOrPath, runtime_config: StrOrPath +): params = ffi.new("hostfxr_initialize_parameters*") params.size = ffi.sizeof("hostfxr_initialize_parameters") # params.host_path = ffi.new("char_t[]", encode(sys.executable)) @@ -159,7 +165,9 @@ def _get_handle_for_runtime_config(dll, dotnet_root: StrOrPath, runtime_config: return handle_ptr[0] -def _get_handle_for_dotnet_command_line(dll, dotnet_root: StrOrPath, entry_dll: StrOrPath): +def _get_handle_for_dotnet_command_line( + dll, dotnet_root: StrOrPath, entry_dll: StrOrPath +): params = ffi.new("hostfxr_initialize_parameters*") params.size = ffi.sizeof("hostfxr_initialize_parameters") params.host_path = ffi.NULL @@ -172,9 +180,7 @@ def _get_handle_for_dotnet_command_line(dll, dotnet_root: StrOrPath, entry_dll: arg_ptr = ffi.new("char_t[]", encode(str(Path(entry_dll)))) args_ptr[0] = arg_ptr res = dll.hostfxr_initialize_for_dotnet_command_line( - 1, - args_ptr, - params, handle_ptr + 1, args_ptr, params, handle_ptr ) check_result(res)