Skip to content

Commit 606fdf0

Browse files
committed
BatchFile rendering from templates
xtl.jobs.config2:BatchJobConfig - New configuration class for storing options and templates for programmatic BatchFile generation - Will replace xtl.jobs.config:BatchConfig in the future xtl.jobs.batchfiles:BatchFile - New .from_config() class method for creating pre-configured BatchFiles with pre-defined payload/content - Fixed a bug in .save() where extra new line characters would be generated if there was no preamble/content/postamble - Added more docstrings - Fixed some circular imports xtl.jobs.sites - Fixed a bug where ComputeSite was not hashable - Fixed some circular imports xtl.settings - Added options for jobs and batchfiles xtl.common.validators - Added new validation function for returning a temp dir if None is provided
1 parent 242bca9 commit 606fdf0

File tree

6 files changed

+420
-20
lines changed

6 files changed

+420
-20
lines changed

src/xtl/common/validators.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111
'PathIsAbsoluteValidator',
1212
'CastAsValidator',
1313
'CastAsNoneIfEmpty',
14-
'CastAsPathOrNone',
14+
'CastAsPathOrNone'
1515
]
1616

1717
from functools import partial
1818
from pathlib import Path
19+
import tempfile
1920
from typing import Any, Callable, Iterable, Optional
2021

2122
from pydantic import AfterValidator, BeforeValidator
@@ -140,6 +141,16 @@ def cast_as_path_or_none(value: Any) -> Optional[Path]:
140141
return None
141142

142143

144+
def cast_as_temp_dir_if_none(value: Any, prefix: str = 'xtl_') -> Path:
145+
"""
146+
Cast the value to a temporary directory if it is ``None``.
147+
"""
148+
if value is None:
149+
temp_dir = tempfile.TemporaryDirectory(prefix=prefix)
150+
return Path(temp_dir.name)
151+
return Path(value)
152+
153+
143154
# Custom validator classes
144155
def LengthValidator(length: int) -> AfterValidator:
145156
"""
@@ -203,3 +214,4 @@ def CastAsPathOrNone() -> BeforeValidator:
203214
value is empty.
204215
"""
205216
return BeforeValidator(cast_as_path_or_none)
217+

src/xtl/config/settings.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
models that are used to configure various aspects of XTL. The main class that holds all
44
settings is :class:`XTLSettings`.
55
"""
6-
6+
from __future__ import annotations
77
from pathlib import Path
8-
from typing import ClassVar, Optional, TYPE_CHECKING
8+
from typing import ClassVar, Optional
99

1010
from pydantic import PrivateAttr
1111

@@ -14,6 +14,7 @@
1414

1515
from xtl import version as current_version
1616
from xtl.automate import ComputeSite
17+
from xtl.jobs.sites import ComputeSite as ComputeSite2
1718
from xtl.config.version import version_from_str
1819
from xtl.common.os import FilePermissions
1920
from xtl.common.options import Option, Options
@@ -107,6 +108,40 @@ class AutomateSettings(Settings):
107108
)
108109

109110

111+
class BatchSettings(Settings):
112+
"""
113+
Settings for batch files in :mod:`xtl.jobs.batchfiles`
114+
"""
115+
116+
# Model attributes
117+
permissions: FilePermissions = \
118+
Option(
119+
default=FilePermissions(0o700),
120+
desc='Permissions for the batch file in octal format (e.g., 700)',
121+
cast_as=FilePermissions,
122+
formatter=PermissionOctal
123+
)
124+
125+
126+
class JobsSettings(Settings):
127+
"""
128+
Settings for jobs in :mod:`xtl.jobs`
129+
"""
130+
131+
# Model attributes
132+
batch: BatchSettings = \
133+
Option(
134+
default=BatchSettings(),
135+
desc='Settings for batch files'
136+
)
137+
138+
compute_site: ComputeSite2 = \
139+
Option(
140+
default=ComputeSite2.LOCAL,
141+
desc='Default compute site for job execution'
142+
)
143+
144+
110145
class DependencySettings(Settings):
111146
"""
112147
Generic external dependency settings
@@ -235,6 +270,9 @@ class XTLSettings(Settings):
235270
automate: AutomateSettings = Option(default=AutomateSettings())
236271
"""Settings for the :mod:`xtl.automate` module"""
237272

273+
jobs: JobsSettings = Option(default=JobsSettings())
274+
"""Settings for jobs in :mod:`xtl.jobs`"""
275+
238276
dependencies: DependenciesSettings = Option(default=DependenciesSettings())
239277
"""Settings for external tools and dependencies used by XTL"""
240278

0 commit comments

Comments
 (0)