Skip to content

Commit

Permalink
Merge GH-365/emcee-submit into test/willard
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyWillard committed Nov 25, 2024
2 parents 63a8311 + 8d7b3d8 commit 38c7802
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
11 changes: 10 additions & 1 deletion flepimop/gempyor_pkg/src/gempyor/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 12 additions & 3 deletions flepimop/gempyor_pkg/src/gempyor/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 16 additions & 7 deletions flepimop/gempyor_pkg/tests/info/test__infer_cluster_from_fqdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 38c7802

Please sign in to comment.