Skip to content

Commit

Permalink
Fix path separator for generated YAML on Windows (fixes #68)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juha Kiili committed Oct 8, 2021
1 parent 71c1e64 commit 1d0ae06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tests/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from tests.utils import read_yaml_test_data
from valohai.internals.merge import python_to_yaml_merge_strategy
from valohai.internals.yaml import parse_config_from_source
from valohai.internals.yaml import parse_config_from_source, generate_step
from valohai.yaml import config_to_yaml


Expand Down Expand Up @@ -41,3 +41,24 @@ def test_yaml_update_from_source(tmpdir, original_yaml, source_python, expected_
with open(expected_yaml) as expected_yaml:
new_yaml = config_to_yaml(new_config)
assert new_yaml == expected_yaml.read()


def test_posix_path_separator():
# Let's be sneaky and force the path separator to simulate Windows
original_separator = os.sep
os.sep = "\\"

try:
step = generate_step(
relative_source_path="subfolder\\foo\\bar\\train.py",
step="train",
image="python:3.8",
parameters={},
inputs={},
)

# We expect the path separator be POSIX now
assert any("subfolder/foo/bar/train.py" in command for command in step.command)
finally:
# Try/finally just to be safe about resetting the separator back
os.sep = original_separator
4 changes: 4 additions & 0 deletions valohai/internals/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def get_parameter_type_name(name: str, value: Any) -> str:


def get_command(relative_source_path: str) -> List[str]:
# We need to generate a POSIX-compliant command, even if we are running this method in Windows
# The path separator must be forced to POSIX
relative_source_path = relative_source_path.replace(os.sep, "/")

if is_notebook_path(relative_source_path):
return get_notebook_command(relative_source_path)

Expand Down

0 comments on commit 1d0ae06

Please sign in to comment.