Skip to content

Commit 04f07fa

Browse files
committed
trying again
1 parent 9911c70 commit 04f07fa

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

open-codegen/opengen/config/build_config.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ def open_version(self):
105105
@property
106106
def local_path(self):
107107
"""Local path of OpEn (if any)"""
108-
return self.__local_path
108+
if self.__local_path is None:
109+
return None
110+
# Cargo.toml accepts forward slashes on Windows, while raw backslashes
111+
# inside TOML strings are treated as escape sequences.
112+
return self.__local_path.replace("\\", "/")
109113

110114
@property
111115
def build_c_bindings(self):
@@ -231,7 +235,7 @@ def with_open_version(self, open_version="*", local_path=None):
231235
:return: current instance of BuildConfiguration
232236
"""
233237
self.__open_version = open_version
234-
self.__local_path = local_path
238+
self.__local_path = None if local_path is None else str(local_path)
235239
return self
236240

237241
def with_build_c_bindings(self, build_c_bindings=True):

open-codegen/test/test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,26 @@
1010
import subprocess
1111
import logging
1212
import numpy as np
13+
from pathlib import PureWindowsPath
1314

1415

1516

1617

1718

19+
class BuildConfigurationTestCase(unittest.TestCase):
20+
21+
def test_local_path_is_toml_safe_on_windows(self):
22+
# some windows-type path...
23+
windows_style_path = PureWindowsPath("C:/temp/optimization-engine")
24+
build_config = og.config.BuildConfiguration() \
25+
.with_open_version(local_path=windows_style_path)
26+
27+
self.assertEqual(
28+
"C:/temp/optimization-engine",
29+
build_config.local_path
30+
)
31+
32+
1833
class RustBuildTestCase(unittest.TestCase):
1934

2035
TEST_DIR = ".python_test_build"

0 commit comments

Comments
 (0)