Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASP-4069] Naming convention for job files #401

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jobbergate-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file keeps track of all notable changes to jobbergate-cli

## Unreleased

- Added a new config to change the way job-script files are named to `<job-script-name>.job`, following behavior from jobbergate-legacy

## 4.1.0 -- 2023-11-07

- Added ability to open the login url on browser or copy it to clipboard
Expand Down
1 change: 1 addition & 0 deletions jobbergate-cli/jobbergate_cli/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Settings(BaseSettings):

# Compatibility mode: If True, add commands as they appear in the legacy app
JOBBERGATE_COMPATIBILITY_MODE: Optional[bool] = False
JOBBERGATE_LEGACY_NAME_CONVENTION: Optional[bool] = False

# Auth0 config for machine-to-machine security
OIDC_DOMAIN: str
Expand Down
17 changes: 13 additions & 4 deletions jobbergate-cli/jobbergate_cli/subapps/job_scripts/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from loguru import logger

from jobbergate_cli.config import settings
from jobbergate_cli.constants import FileType
from jobbergate_cli.exceptions import Abort, JobbergateCliError
from jobbergate_cli.requests import make_request
Expand Down Expand Up @@ -138,7 +139,7 @@ def remove_prefix_suffix(s: str) -> str:
return s


def get_template_output_name_mapping(config: JobbergateConfig) -> Dict[str, str]:
def get_template_output_name_mapping(config: JobbergateConfig, job_name: str) -> Dict[str, str]:
"""
Get the mapping of template names to output names.

Expand All @@ -153,7 +154,12 @@ def get_template_output_name_mapping(config: JobbergateConfig) -> Dict[str, str]
log_message="Entry point file not specified",
)

output_name_mapping = {config.default_template: output_dir / remove_prefix_suffix(config.default_template)}
if settings.JOBBERGATE_LEGACY_NAME_CONVENTION:
job_script_file_name = f"{job_name}.job"
else:
job_script_file_name = remove_prefix_suffix(config.default_template)

output_name_mapping = {config.default_template: output_dir / job_script_file_name}

if config.supporting_files:
for template in config.supporting_files:
Expand Down Expand Up @@ -227,13 +233,16 @@ def render_job_script(

param_dict_flat = flatten_param_dict(app_config.dict())

job_script_name = name if name else app_data.name
request_data = JobScriptRenderRequestData(
create_request=JobScriptCreateRequest(
name=name if name else app_data.name,
name=job_script_name,
description=description,
),
render_request=RenderFromTemplateRequest(
template_output_name_mapping=get_template_output_name_mapping(app_config.jobbergate_config),
template_output_name_mapping=get_template_output_name_mapping(
app_config.jobbergate_config, job_script_name
),
sbatch_params=sbatch_params,
param_dict={"data": param_dict_flat},
),
Expand Down
20 changes: 16 additions & 4 deletions jobbergate-cli/tests/subapps/job_scripts/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,19 @@ def test_default_template_valid_output_name(self):
)
expected_mapping = {"template.j2": "template"}

assert get_template_output_name_mapping(config) == expected_mapping
assert get_template_output_name_mapping(config, "dummy-name") == expected_mapping

def test_default_template_valid_output_name__legacy_mode(self, tweak_settings):
config = JobbergateConfig(
default_template="templates/template.j2",
output_directory=pathlib.Path("."),
supporting_files=None,
supporting_files_output_name=None,
)
expected_mapping = {"template.j2": "dummy-name.job"}

with tweak_settings(JOBBERGATE_LEGACY_NAME_CONVENTION=True):
assert get_template_output_name_mapping(config, "dummy-name") == expected_mapping

def test_supporting_files_with_valid_output_names(self):
config = JobbergateConfig(
Expand All @@ -376,7 +388,7 @@ def test_supporting_files_with_valid_output_names(self):

expected_mapping = {"template1.j2": "template1", "support1.j2": "output1.txt", "support2.j2": "output2.txt"}

assert get_template_output_name_mapping(config) == expected_mapping
assert get_template_output_name_mapping(config, "dummy-name") == expected_mapping

def test_default_template_not_specified(self):
config = JobbergateConfig(
Expand All @@ -386,7 +398,7 @@ def test_default_template_not_specified(self):
supporting_files=None,
)
with pytest.raises(Abort, match="Default template was not specified"):
get_template_output_name_mapping(config)
get_template_output_name_mapping(config, "dummy-name")

def test_supporting_files_output_names_multiple_values(self):
config = JobbergateConfig(
Expand All @@ -397,7 +409,7 @@ def test_supporting_files_output_names_multiple_values(self):
)

with pytest.raises(Abort, match="template='template2.j2' has 2 output names"):
get_template_output_name_mapping(config)
get_template_output_name_mapping(config, "dummy-name")


class TestUploadJobScriptFiles:
Expand Down
Loading