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

Allow setting the workdir using environment variables #3792

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions sky/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,11 @@ def from_yaml_config(
config['service'] = _fill_in_env_vars(config['service'],
config.get('envs', {}))

# Fill in any Task.envs into workdir
if config.get('workdir') is not None:
config['workdir'] = _fill_in_env_vars(config['workdir'],
config.get('envs', {}))

task = Task(
config.pop('name', None),
run=config.pop('run', None),
Expand Down
11 changes: 11 additions & 0 deletions tests/test_yaml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,14 @@ def test_invalid_empty_envs(tmp_path):
with pytest.raises(ValueError) as e:
Task.from_yaml(config_path)
assert 'Environment variable \'env_key2\' is None.' in e.value.args[0]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to run ./format.sh (after running pip install -r requirements-dev.txt) to keep the linter happy.

Suggested change


def test_replace_envs_in_path(tmpdir, tmp_path):
BabyChouSr marked this conversation as resolved.
Show resolved Hide resolved
config_path = _create_config_file(
textwrap.dedent(f"""\
envs:
env_key1: {tmpdir}
workdir: $env_key1
"""), tmp_path)
task = Task.from_yaml(config_path)
assert task.workdir == tmpdir
Loading