Skip to content

Commit 1590a04

Browse files
author
Thierry RAMORASOAVINA
committed
Fix a buggy samples_dir path construction when HOME contains a remote path
1 parent 9d19781 commit 1590a04

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

khiops/core/internals/runner.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import io
1616
import os
17-
import pathlib
1817
import platform
1918
import shlex
2019
import shutil
@@ -65,7 +64,11 @@ def get_default_samples_dir():
6564
elif platform.system() == "Windows" and "PUBLIC" in os.environ:
6665
samples_dir = os.path.join(os.environ["PUBLIC"], "khiops_data", "samples")
6766
else:
68-
samples_dir = str(pathlib.Path.home() / "khiops_data" / "samples")
67+
# The filesystem abstract layer is used here
68+
# as the path can be either local or remote
69+
samples_dir = fs.get_child_path(
70+
fs.get_child_path(os.environ["HOME"], "khiops_data"), "samples"
71+
)
6972
return samples_dir
7073

7174

tests/test_remote_access.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,33 @@ def test_train_predictor_fail_and_log_with_remote_access(self):
227227
self.assertTrue(fs.exists(log_file_path), f"Path: {log_file_path}")
228228
fs.remove(log_file_path)
229229

230+
def test_samples_dir_inferred_from_remote_home(self):
231+
"""Test samples_dir is correctly inferred using a remote path in HOME"""
232+
233+
# Save initial state
234+
# This runner has remote paths (for root_temp_dir for example)
235+
initial_runner = kh.get_runner()
236+
initial_home = os.environ.get("HOME")
237+
238+
# Set a remote path to HOME
239+
os.environ["HOME"] = initial_runner.root_temp_dir
240+
test_runner = KhiopsLocalRunner()
241+
kh.set_runner(test_runner)
242+
243+
# Test the home path is indeed remote
244+
self.assertFalse(fs.is_local_resource(os.environ["HOME"]))
245+
246+
# Test that samples_dir is built according to the expectations
247+
expected_samples_dir = fs.get_child_path(
248+
fs.get_child_path(os.environ["HOME"], "khiops_data"), "samples"
249+
)
250+
self.assertEqual(test_runner.samples_dir, expected_samples_dir)
251+
252+
# Restore initial state
253+
if initial_home is not None:
254+
os.environ["HOME"] = initial_home
255+
kh.set_runner(initial_runner)
256+
230257

231258
class KhiopsS3RemoteFileTests(KhiopsRemoteAccessTestsContainer.KhiopsRemoteAccessTests):
232259
"""Integration tests with Amazon S3 filesystems"""

0 commit comments

Comments
 (0)