Skip to content

Commit

Permalink
add option to disable warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamed Koubaa committed May 14, 2024
1 parent f2058b4 commit a279362
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
7 changes: 6 additions & 1 deletion clr_loader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def get_mono(
debug: bool = False,
jit_options: Optional[Sequence[str]] = None,
assembly_dir: Optional[str] = None,
disable_warning: Optional[bool] = False,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False
) -> Runtime:
Expand All @@ -53,6 +54,9 @@ def get_mono(
"Command line options" passed to Mono's ``mono_jit_parse_options``
:param assembly_dir:
The base directory for assemblies, passed to ``mono_set_dirs``
:param disable_warning:
Whether to disable the warning message that is printed for Mono versions
older than 6.12
:param config_dir:
The base directory for configuration files, passed to ``mono_set_dirs``
:param set_signal_chaining:
Expand Down Expand Up @@ -80,8 +84,9 @@ def get_mono(
global_config_file=_maybe_path(global_config_file),
libmono=libmono,
assembly_dir=assembly_dir,
disable_warning=disable_warning,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
set_signal_chaining=set_signal_chaining
)
return impl

Expand Down
35 changes: 21 additions & 14 deletions clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(
config_file: Optional[Path] = None,
global_config_file: Optional[Path] = None,
assembly_dir: Optional[str] = None,
disable_warning: Optional[bool] = False,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
):
Expand All @@ -37,6 +38,7 @@ def __init__(
global_config_file=optional_path_as_string(global_config_file),
libmono=libmono,
assembly_dir=assembly_dir,
disable_warning=disable_warning,
config_dir=config_dir,
set_signal_chaining=set_signal_chaining,
)
Expand Down Expand Up @@ -121,13 +123,30 @@ def __call__(self, ptr, size):
return unboxed[0]


def _warn_mono_version(ver_str: str):
ver = re.match(r"^(?P<major>\d+)\.(?P<minor>\d+)\.[\d.]+", ver_str)
if ver is not None:
major = int(ver.group("major"))
minor = int(ver.group("minor"))

if major < 6 or (major == 6 and minor < 12):
import warnings

warnings.warn(
"Hosting Mono versions before v6.12 is known to be problematic. "
"If the process crashes shortly after you see this message, try "
"updating Mono to at least v6.12."
)


def initialize(
libmono: Optional[Path],
debug: bool = False,
jit_options: Optional[Sequence[str]] = None,
config_file: Optional[str] = None,
global_config_file: Optional[str] = None,
assembly_dir: Optional[str] = None,
disable_warning: Optional[bool] = False,
config_dir: Optional[str] = None,
set_signal_chaining: bool = False,
) -> str:
Expand Down Expand Up @@ -168,20 +187,8 @@ def initialize(
build = _MONO.mono_get_runtime_build_info()
_check_result(build, "Failed to get Mono version")
ver_str = ffi.string(build).decode("utf8") # e.g. '6.12.0.122 (tarball)'

ver = re.match(r"^(?P<major>\d+)\.(?P<minor>\d+)\.[\d.]+", ver_str)
if ver is not None:
major = int(ver.group("major"))
minor = int(ver.group("minor"))

if major < 6 or (major == 6 and minor < 12):
import warnings

warnings.warn(
"Hosting Mono versions before v6.12 is known to be problematic. "
"If the process crashes shortly after you see this message, try "
"updating Mono to at least v6.12."
)
if not disable_warning:
_warn_mono_version(ver_str)

atexit.register(_release)
return ver_str
Expand Down

0 comments on commit a279362

Please sign in to comment.