From edb634b943578351b095491779ebf70961517f26 Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Thu, 30 Jan 2025 17:28:26 +0900 Subject: [PATCH 1/2] Remove DOTNET_ROOT explicit setting --- stock_indicators/_cslib/__init__.py | 52 +++-------------------------- 1 file changed, 5 insertions(+), 47 deletions(-) diff --git a/stock_indicators/_cslib/__init__.py b/stock_indicators/_cslib/__init__.py index 57aac6b8..932bf370 100644 --- a/stock_indicators/_cslib/__init__.py +++ b/stock_indicators/_cslib/__init__.py @@ -8,11 +8,8 @@ The target framework of dll is `.NET 6.0`. """ -import json import logging -import os import platform -import sys from pathlib import Path from pythonnet import load @@ -24,52 +21,16 @@ logger = logging.getLogger(__name__) - -def verify_dotnet_environment(): - """Verify .NET environment setup""" - dotnet_root = os.environ.get("DOTNET_ROOT") - logger.debug("DOTNET_ROOT: %s", dotnet_root) - - if platform.system() == "Darwin": - if not dotnet_root: - os.environ["DOTNET_ROOT"] = "/usr/local/share/dotnet" - logger.debug("Setting DOTNET_ROOT for macOS") - - try: - verify_dotnet_environment() + # Load CLR + load(runtime="coreclr") + import clr + logger.debug("CLR loaded successfully on %s", platform.system()) # Get absolute paths base_path = Path(__file__).parent.resolve() - runtime_config_path = base_path / "runtimeconfig.json" dll_path = base_path / "lib" / "Skender.Stock.Indicators.dll" - - logger.debug("Base path: %s", base_path) - logger.debug("Runtime config path: %s", runtime_config_path) - logger.debug("DLL path: %s", dll_path) - - if not runtime_config_path.exists(): - raise FileNotFoundError( - f"runtimeconfig.json not found at: {runtime_config_path}" - ) - - if not dll_path.exists(): - raise FileNotFoundError(f"DLL not found at: {dll_path}") - - # Initialize runtime based on platform using runtimeconfig.json - if platform.system() == "Darwin": - load( - "coreclr", - dotnet_root=os.environ["DOTNET_ROOT"], - runtime_config=str(runtime_config_path), - ) - else: - load("coreclr", runtime_config=str(runtime_config_path)) - - import clr - - logger.debug("CLR loaded successfully on %s", platform.system()) - + # Set assembly resolve path from System import IO, AppDomain @@ -132,6 +93,3 @@ def verify_dotnet_environment(): from System.Collections.Generic import IEnumerable as CsIEnumerable from System.Collections.Generic import List as CsList from System.Globalization import CultureInfo as CsCultureInfo - -# Export initialized modules -__all__ = ["clr"] From ed6c47ab2b12f3cd85a077333dfe15276b96dbf5 Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Thu, 30 Jan 2025 17:28:52 +0900 Subject: [PATCH 2/2] Remove runtimeconfig.json --- stock_indicators/_cslib/runtimeconfig.json | 17 ----------------- 1 file changed, 17 deletions(-) delete mode 100644 stock_indicators/_cslib/runtimeconfig.json diff --git a/stock_indicators/_cslib/runtimeconfig.json b/stock_indicators/_cslib/runtimeconfig.json deleted file mode 100644 index d3dda563..00000000 --- a/stock_indicators/_cslib/runtimeconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "runtimeOptions": { - "tfm": "net6.0", - "framework": { - "name": "Microsoft.NETCore.App", - "version": "6.0.0" - }, - "configProperties": { - "System.Runtime.TieredCompilation": true, - "System.GC.Server": true, - "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, - "System.Runtime.Loader.EnableDependencyContext": true, - "System.Runtime.Loader.UseRuntimeAssemblies": true - }, - "rollForward": "latestMajor" - } -}