diff --git a/flepimop/gempyor_pkg/src/gempyor/batch.py b/flepimop/gempyor_pkg/src/gempyor/batch.py index 5a9ba1f5d..d12f60c63 100644 --- a/flepimop/gempyor_pkg/src/gempyor/batch.py +++ b/flepimop/gempyor_pkg/src/gempyor/batch.py @@ -27,7 +27,7 @@ from ._jinja import _render_template_to_file, _render_template_to_temp_file from .file_paths import run_id -from .info import Cluster, get_cluster_info +from .info import Cluster, _infer_cluster_from_fqdn, get_cluster_info from .logging import get_script_logger from .utils import _format_cli_options, _git_checkout, _git_head, _shutil_which, config from .shared_cli import ( @@ -1107,6 +1107,15 @@ def _click_submit(ctx: click.Context = mock_context, **kwargs: Any) -> None: kwargs["email"], batch_system, ) + if ( + batch_system == BatchSystem.LOCAL + and (cluster_name := _infer_cluster_from_fqdn(raise_error=False)) is not None + ): + logger.critical( + "The batch system is local but detected a cluster, '%s'. " + "This will likely result in a vague error.", + cluster_name, + ) # Job size job_size = JobSize.from_jobs_simulations_blocks( diff --git a/flepimop/gempyor_pkg/src/gempyor/info.py b/flepimop/gempyor_pkg/src/gempyor/info.py index bdcdc7b36..958b29168 100644 --- a/flepimop/gempyor_pkg/src/gempyor/info.py +++ b/flepimop/gempyor_pkg/src/gempyor/info.py @@ -152,18 +152,27 @@ def get_cluster_info(name: str | None, flepi_path: os.PathLike | None = None) -> return _get_info("cluster", name, Cluster, flepi_path) -def _infer_cluster_from_fqdn() -> str: +def _infer_cluster_from_fqdn(raise_error: bool = True) -> str | None: """ Infer the cluster name from the FQDN. + Args: + raise_error: A flag indicating whether to raise an error if the FQDN does not + match any of the expected regexes. + Returns: The name of the cluster inferred from the FQDN. Raises: - ValueError: If the value of `socket.getfqdn()` does not match an expected regex. + ValueError: If the value of `socket.getfqdn()` does not match an expected regex + and `raise_error` is `True`. """ fqdn = getfqdn() for cluster, regex in _CLUSTER_FQDN_REGEXES: if regex.match(fqdn): return cluster - raise ValueError(f"The fqdn, '{fqdn}', does not match any of the expected clusters.") + if raise_error: + raise ValueError( + f"The fqdn, '{fqdn}', does not match any of the expected clusters." + ) + return None diff --git a/flepimop/gempyor_pkg/tests/info/test__infer_cluster_from_fqdn.py b/flepimop/gempyor_pkg/tests/info/test__infer_cluster_from_fqdn.py index a26705503..0502cdf9f 100644 --- a/flepimop/gempyor_pkg/tests/info/test__infer_cluster_from_fqdn.py +++ b/flepimop/gempyor_pkg/tests/info/test__infer_cluster_from_fqdn.py @@ -20,18 +20,27 @@ def socket_fqdn_wraps() -> str: @pytest.mark.parametrize( - ("fqdn", "expected"), + ("fqdn", "raise_error", "expected"), ( - ("login01.cm.cluster", "rockfish"), - ("login3.cm.cluster", "rockfish"), - ("longleaf-login1.its.unc.edu", "longleaf"), - ("longleaf-login07.its.unc.edu", "longleaf"), + ("login01.cm.cluster", True, "rockfish"), + ("login01.cm.cluster", False, "rockfish"), + ("login3.cm.cluster", True, "rockfish"), + ("login3.cm.cluster", False, "rockfish"), + ("longleaf-login1.its.unc.edu", True, "longleaf"), + ("longleaf-login1.its.unc.edu", False, "longleaf"), + ("longleaf-login07.its.unc.edu", True, "longleaf"), + ("longleaf-login07.its.unc.edu", False, "longleaf"), + ("longleaf-login07.its.unc.edu", True, "longleaf"), + ("longleaf-login07.its.unc.edu", False, "longleaf"), + ("epid-iss-MacBook-Pro.local", False, None), ), ) -def test_exact_results_for_select_values(fqdn: str, expected: str) -> None: +def test_exact_results_for_select_values( + fqdn: str, raise_error: bool, expected: str +) -> None: def socket_fqdn_wraps() -> str: return fqdn with patch("gempyor.info.getfqdn", wraps=socket_fqdn_wraps) as socket_fqdn_patch: - assert _infer_cluster_from_fqdn() == expected + assert _infer_cluster_from_fqdn(raise_error=raise_error) == expected socket_fqdn_patch.assert_called_once()