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

[opengl] Unify windows path to posix format in python. #3470

Merged
merged 1 commit into from Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/taichi/aot/module.py
@@ -1,6 +1,7 @@
import shutil
import warnings
from contextlib import contextmanager
from pathlib import Path, PurePosixPath

from taichi.core import ti_core as _ti_core
from taichi.lang import impl, kernel_impl
Expand Down Expand Up @@ -193,4 +194,5 @@ def save(self, filepath, filename):
filepath (str): path to a folder to store aot files.
filename (str): filename prefix for stored aot files.
"""
filepath = str(PurePosixPath(Path(filepath).resolve()))
self._aot_builder.dump(filepath, filename)
11 changes: 2 additions & 9 deletions taichi/backends/opengl/aot_module_builder_impl.cpp
Expand Up @@ -21,15 +21,8 @@ namespace {
void write_glsl_file(const std::string &output_dir,
const std::string &filename,
CompiledKernel &k) {
// Hack to assemble readable windows/unix path.
// Ideally we could use std::filesystem but it's not available on MacOS 10.14.
#if defined(TI_PLATFORM_WINDOWS)
const std::string path_delim = "\\";
#else
const std::string path_delim = "/";
#endif
const std::string glsl_path = fmt::format(
"{}{}{}_{}.glsl", output_dir, path_delim, filename, k.kernel_name);
const std::string glsl_path =
fmt::format("{}/{}_{}.glsl", output_dir, filename, k.kernel_name);
std::ofstream fs{glsl_path};
fs << k.kernel_src;
k.kernel_src = glsl_path;
Expand Down
13 changes: 2 additions & 11 deletions tests/python/test_aot.py
Expand Up @@ -8,11 +8,6 @@
import taichi as ti


def _escape_path_for_win(json_str):
return json_str.replace(os.sep,
r'\\') if ti.get_os_name() == 'win' else json_str


@ti.test(arch=ti.cc)
def test_record():
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down Expand Up @@ -62,9 +57,7 @@ def foo(n: ti.template()):
m.save(tmpdir, filename)
with open(os.path.join(tmpdir,
f'{filename}_metadata.json')) as json_file:
json_str = ''.join(json_file.readlines())
json_str = _escape_path_for_win(json_str)
json.loads(json_str)
json.load(json_file)


@ti.test(arch=ti.opengl)
Expand Down Expand Up @@ -175,6 +168,4 @@ def init():
m.save(tmpdir, filename)
with open(os.path.join(tmpdir,
f'{filename}_metadata.json')) as json_file:
json_str = ''.join(json_file.readlines())
json_str = _escape_path_for_win(json_str)
json.loads(json_str)
json.load(json_file)