Skip to content

Commit 6ddb0a8

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

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

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 either be a local or a remote one
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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,34 @@ 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 either samples_dir is correctly inferred
232+
using a remote path in HOME
233+
"""
234+
235+
# Save initial state
236+
# This runner has remote paths (for root_temp_dir for example)
237+
initial_runner = kh.get_runner()
238+
initial_home = os.environ.get("HOME")
239+
240+
# Set a remote path to HOME
241+
os.environ["HOME"] = initial_runner.root_temp_dir
242+
test_runner = KhiopsLocalRunner()
243+
kh.set_runner(test_runner)
244+
245+
# Test the home path is indeed remote
246+
self.assertFalse(fs.is_local_resource(os.environ["HOME"]))
247+
248+
# Test that samples_dir is built according to the expectations
249+
expected_samples_dir = fs.get_child_path(
250+
fs.get_child_path(os.environ["HOME"], "khiops_data"), "samples"
251+
)
252+
self.assertEqual(test_runner.samples_dir, expected_samples_dir)
253+
254+
# Restore initial state
255+
os.environ["HOME"] = initial_home
256+
kh.set_runner(initial_runner)
257+
230258

231259
class KhiopsS3RemoteFileTests(KhiopsRemoteAccessTestsContainer.KhiopsRemoteAccessTests):
232260
"""Integration tests with Amazon S3 filesystems"""

0 commit comments

Comments
 (0)