Skip to content

Commit

Permalink
Apply suggestions from code review.
Browse files Browse the repository at this point in the history
Add basic config doc string;
Clarify a comment;
Tweak installed check.

Co-authored-by: Tim Pillinger <[email protected]>
  • Loading branch information
hjoliver and wxtim committed Jun 26, 2023
1 parent c99c09d commit 2bf8bd3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
24 changes: 18 additions & 6 deletions cylc/flow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@
from cylc.flow.parsec.exceptions import ItemNotFoundError
from cylc.flow.parsec.OrderedDict import OrderedDictWithDefaults
from cylc.flow.parsec.util import replicate
from cylc.flow.pathutil import get_workflow_name_from_id
from cylc.flow.pathutil import (
get_workflow_name_from_id,
get_cylc_run_dir,
is_relative_to,
)
from cylc.flow.platforms import FORBIDDEN_WITH_PLATFORM
from cylc.flow.print_tree import print_tree
from cylc.flow.subprocctx import SubFuncContext
Expand All @@ -100,7 +104,6 @@
NO_TITLE,
WorkflowFiles,
check_deprecation,
is_installed,
)
from cylc.flow.xtrigger_mgr import XtriggerManager

Expand Down Expand Up @@ -235,14 +238,22 @@ def __init__(
work_dir: Optional[str] = None,
share_dir: Optional[str] = None
) -> None:
"""
Initialize the workflow config object.
Positional args:
workflow: workflow ID
fpath: workflow config file path
options: CLI options
"""
check_deprecation(Path(fpath))
self.mem_log = mem_log_func
if self.mem_log is None:
self.mem_log = lambda x: None
self.mem_log("config.py:config.py: start init config")
self.workflow = workflow # workflow id
self.workflow = workflow
self.workflow_name = get_workflow_name_from_id(self.workflow)
self.fpath: Path = Path(fpath) # workflow definition
self.fpath: Path = Path(fpath)
self.fdir = str(self.fpath.parent)
self.run_dir = run_dir
self.log_dir = log_dir
Expand Down Expand Up @@ -1500,7 +1511,7 @@ def process_workflow_env(self):
}.items():
os.environ[key] = value

if is_installed(self.fdir):
if is_relative_to(self.fdir, get_cylc_run_dir()):
# This is an installed workflow.
# - self.run_dir is only defined by the scheduler
# - but the run dir exists, created at installation
Expand All @@ -1513,7 +1524,8 @@ def process_workflow_env(self):
os.environ[key] = value

if self.run_dir is not None:
# This is the scheduler; run sub-dirs must exist.
# Run directory is only defined if the scheduler is running; in
# which case the following run sub-directories must exist.
for key, value in {
'CYLC_WORKFLOW_LOG_DIR': str(self.log_dir),
'CYLC_WORKFLOW_WORK_DIR': str(self.work_dir),
Expand Down
9 changes: 6 additions & 3 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,8 @@ def test__warn_if_queues_have_implicit_tasks(caplog):
'CYLC_WORKFLOW_WORK_DIR': False,
'CYLC_WORKFLOW_SHARE_DIR': False,
'CYLC_WORKFLOW_LOG_DIR': False,
}
},
id="source-dir"
),
pytest.param(
True,
Expand All @@ -1592,7 +1593,8 @@ def test__warn_if_queues_have_implicit_tasks(caplog):
'CYLC_WORKFLOW_WORK_DIR': False,
'CYLC_WORKFLOW_SHARE_DIR': False,
'CYLC_WORKFLOW_LOG_DIR': False,
}
},
id="run-dir"
),
pytest.param(
True,
Expand All @@ -1604,7 +1606,8 @@ def test__warn_if_queues_have_implicit_tasks(caplog):
'CYLC_WORKFLOW_WORK_DIR': True,
'CYLC_WORKFLOW_SHARE_DIR': True,
'CYLC_WORKFLOW_LOG_DIR': True,
}
},
id="run-dir-from-scheduler"
),
]
)
Expand Down

0 comments on commit 2bf8bd3

Please sign in to comment.