diff --git a/README.md b/README.md index 1da438e0..5ee28d72 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ environment variables: DUCT_REPORT_INTERVAL=120.0 # Set default output location - DUCT_OUTPUT_PREFIX=~/duct-logs/{datetime_filesafe}-{pid}_ + DUCT_OUTPUT_PREFIX=~/duct-logs/{datetime}-{pid}_ # Add execution notes (multiline) DUCT_MESSAGE="Experiment run for paper revision @@ -173,11 +173,10 @@ options: File string format to be used as a prefix for the files -- the captured stdout and stderr and the resource usage logs. The understood variables are - {datetime}, {datetime_filesafe}, and {pid}. Leading - directories will be created if they do not exist. You - can also provide value via DUCT_OUTPUT_PREFIX env - variable. (default: - .duct/logs/{datetime_filesafe}-{pid}_) + {datetime} and {pid}. Leading directories will be + created if they do not exist. You can also provide + value via DUCT_OUTPUT_PREFIX env variable. (default: + .duct/logs/{datetime}-{pid}_) --summary-format SUMMARY_FORMAT Output template to use when printing the summary following execution. Accepts custom conversion flags: diff --git a/src/con_duct/_duct_main.py b/src/con_duct/_duct_main.py index 8c2623ee..f83f7db1 100644 --- a/src/con_duct/_duct_main.py +++ b/src/con_duct/_duct_main.py @@ -16,9 +16,7 @@ lgr = logging.getLogger("con-duct") -DUCT_OUTPUT_PREFIX = os.getenv( - "DUCT_OUTPUT_PREFIX", ".duct/logs/{datetime_filesafe}-{pid}_" -) +DUCT_OUTPUT_PREFIX = os.getenv("DUCT_OUTPUT_PREFIX", ".duct/logs/{datetime}-{pid}_") EXECUTION_SUMMARY_FORMAT = ( "Summary:\n" "Exit Code: {exit_code!E}\n" diff --git a/src/con_duct/_models.py b/src/con_duct/_models.py index 89c45bef..d3400893 100644 --- a/src/con_duct/_models.py +++ b/src/con_duct/_models.py @@ -131,7 +131,12 @@ def __iter__(self) -> Iterator[tuple[str, str]]: def create(cls, output_prefix: str, pid: None | int = None) -> LogPaths: datetime_filesafe = datetime.now().strftime("%Y.%m.%dT%H.%M.%S") formatted_prefix = output_prefix.format( - pid=pid, datetime_filesafe=datetime_filesafe + pid=pid, + datetime=datetime_filesafe, + # Use of the `datetime_filesafe` format field is deprecated. + # The setting of it here is to provide for backwards compatibility + # It should be removed eventually + datetime_filesafe=datetime_filesafe, ) return cls( stdout=f"{formatted_prefix}{SUFFIXES['stdout']}", diff --git a/src/con_duct/cli.py b/src/con_duct/cli.py index 2de8b42d..258d00aa 100644 --- a/src/con_duct/cli.py +++ b/src/con_duct/cli.py @@ -163,7 +163,7 @@ def _replay_early_logs(log_buffer: List[tuple[str, str]]) -> None: DUCT_REPORT_INTERVAL=120.0 # Set default output location - DUCT_OUTPUT_PREFIX=~/duct-logs/{{datetime_filesafe}}-{{pid}}_ + DUCT_OUTPUT_PREFIX=~/duct-logs/{{datetime}}-{{pid}}_ # Add execution notes (multiline) DUCT_MESSAGE="Experiment run for paper revision @@ -267,7 +267,7 @@ def _create_run_parser() -> argparse.ArgumentParser: default=DUCT_OUTPUT_PREFIX, help="File string format to be used as a prefix for the files -- the captured " "stdout and stderr and the resource usage logs. The understood variables are " - "{datetime}, {datetime_filesafe}, and {pid}. " + "{datetime} and {pid}. " "Leading directories will be created if they do not exist. " "You can also provide value via DUCT_OUTPUT_PREFIX env variable. ", ) diff --git a/test/duct_main/test_log_paths.py b/test/duct_main/test_log_paths.py index 86113756..389904fe 100644 --- a/test/duct_main/test_log_paths.py +++ b/test/duct_main/test_log_paths.py @@ -7,7 +7,15 @@ from con_duct._models import LogPaths, Outputs -def test_log_paths_filesafe_datetime_prefix() -> None: +def test_log_paths_datetime_prefix() -> None: + log_paths = LogPaths.create("start_{datetime}") + pattern = r"^start_\d{4}\.\d{2}\.\d{2}T\d{2}\.\d{2}\.\d{2}.*" + for path in asdict(log_paths).values(): + assert re.match(pattern, path) is not None + + +def test_log_paths_deprecated_datetime_filesafe_prefix() -> None: + """Ensure deprecated {datetime_filesafe} format field still works.""" log_paths = LogPaths.create("start_{datetime_filesafe}") pattern = r"^start_\d{4}\.\d{2}\.\d{2}T\d{2}\.\d{2}\.\d{2}.*" for path in asdict(log_paths).values():