Skip to content

Commit a587cc9

Browse files
committed
[WIP] [GR-52202] Hardcode the path to the vfs.
PullRequest: graalpython/3252
2 parents 991989e + 884cb06 commit a587cc9

File tree

22 files changed

+145
-153
lines changed

22 files changed

+145
-153
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/org.graalvm.python.vfs/
2+
/org.graalvm.python.vfs/dir1/
3+
/org.graalvm.python.vfs/dir1/dir2/
4+
/org.graalvm.python.vfs/dir1/file2
5+
/org.graalvm.python.vfs/emptydir/
6+
/org.graalvm.python.vfs/file1
7+
/org.graalvm.python.vfs/fileslist.txt
8+
/org.graalvm.python.vfs/SomeFile

graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/utils/test/VirtualFileSystemTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@
6161

6262
public class VirtualFileSystemTest {
6363

64-
private static final String VFS_PREFIX = "/org/graalvm/python/embedding/utils/test/vfs";
65-
6664
private static final String VFS_UNIX_MOUNT_POINT = "/test_mount_point";
6765
private static final String VFS_WIN_MOUNT_POINT = "X:\\test_win_mount_point";
6866
private static final String VFS_MOUNT_POINT = IS_WINDOWS ? VFS_WIN_MOUNT_POINT : VFS_UNIX_MOUNT_POINT;
@@ -81,7 +79,6 @@ public void defaultValues() throws Exception {
8179
@Test
8280
public void toRealPath() throws Exception {
8381
VirtualFileSystem vfs = VirtualFileSystem.newBuilder().//
84-
vfsPrefix(VFS_PREFIX).//
8582
unixMountPoint(VFS_MOUNT_POINT).//
8683
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
8784
extractFilter(p -> p.getFileName().toString().equals("file1")).//
@@ -97,7 +94,6 @@ public void toRealPath() throws Exception {
9794
@Test
9895
public void toAbsolutePath() throws Exception {
9996
VirtualFileSystem vfs = VirtualFileSystem.newBuilder().//
100-
vfsPrefix(VFS_PREFIX).//
10197
unixMountPoint(VFS_MOUNT_POINT).//
10298
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
10399
extractFilter(p -> p.getFileName().toString().equals("file1")).//
@@ -384,7 +380,7 @@ public Context getContext(Function<VirtualFileSystem.Builder, VirtualFileSystem.
384380
return cachedContext;
385381
}
386382
VirtualFileSystem.Builder builder = VirtualFileSystem.newBuilder().//
387-
vfsPrefix(VFS_PREFIX).//
383+
// vfsPrefix(VFS_PREFIX).//
388384
unixMountPoint(VFS_MOUNT_POINT).//
389385
windowsMountPoint(VFS_WIN_MOUNT_POINT).//
390386
resourceLoadingClass(VirtualFileSystemTest.class);

graalpython/com.oracle.graal.python.test.integration/src/org/graalvm/python/embedding/utils/test/vfs/fileslist.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_jbang_integration.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,20 +196,20 @@ def test_graal_version(self):
196196
script_path = os.path.normpath(os.path.join(os.path.dirname(self.catalog_file), script_ref))
197197
with open(script_path, 'r') as script_file:
198198
content = script_file.read()
199-
self.assertIn (f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION} was not foudn in {script_path}")
200-
self.assertIn (f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION} was not foudn in {script_path}")
201-
self.assertIn (f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION} was not foudn in {script_path}")
202-
self.assertIn (f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION} was not foudn in {script_path}")
199+
self.assertIn (f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION} was not found in {script_path}")
200+
self.assertIn (f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION} was not found in {script_path}")
201+
self.assertIn (f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION} was not found in {script_path}")
202+
self.assertIn (f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION} was not found in {script_path}")
203203

204204
for template in json_data.get("templates", {}).values():
205205
for file_ref in template.get("file-refs", {}).values():
206206
file_path = os.path.normpath(os.path.join(os.path.dirname(self.catalog_file), file_ref))
207207
with open(script_path, 'r') as script_file:
208208
content = script_file.read()
209-
self.assertIn (f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION} was not foudn in {script_path}")
210-
self.assertIn (f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION} was not foudn in {script_path}")
211-
self.assertIn (f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION} was not foudn in {script_path}")
212-
self.assertIn (f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION} was not foudn in {script_path}")
209+
self.assertIn (f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-language:{GRAAL_VERSION} was not found in {script_path}")
210+
self.assertIn (f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-resources:{GRAAL_VERSION} was not found in {script_path}")
211+
self.assertIn (f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-launcher:{GRAAL_VERSION} was not found in {script_path}")
212+
self.assertIn (f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION}", content, f"//DEPS org.graalvm.python:python-embedding:{GRAAL_VERSION} was not found in {script_path}")
213213

214214
@unittest.skipUnless(is_enabled, "ENABLE_JBANG_INTEGRATION_UNITTESTS is not true")
215215
def test_graalpy_template(self):

graalpython/com.oracle.graal.python.test/src/tests/standalone/test_standalone.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,17 @@
4949

5050
MVN_CMD = [shutil.which('mvn'), "--batch-mode"]
5151

52+
VFS_PREFIX = "org.graalvm.python.vfs"
53+
5254
def run_cmd(cmd, env, cwd=None):
5355
print(f"Executing:\n {cmd=}\n")
5456
process = subprocess.Popen(cmd, env=env, cwd=cwd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, text=True, errors='backslashreplace')
5557
out = []
58+
print("============== output =============")
5659
for line in iter(process.stdout.readline, ""):
5760
print(line, end="")
5861
out.append(line)
62+
print("\n========== end of output ==========")
5963
return "".join(out), process.wait()
6064

6165
def get_executable(file):
@@ -259,28 +263,28 @@ def test_generated_app(self):
259263
self.generate_app(tmpdir, target_dir, target_name)
260264

261265
# build
262-
cmd = MVN_CMD + ["package", "-Pnative", "-DmainClass=it.pkg.GraalPy"] #, f"-Dgraalpy.version={self.graalvmVersion}", "-Dgraalpy.edition=python-community"]
266+
cmd = MVN_CMD + ["package", "-Pnative", "-DmainClass=it.pkg.GraalPy"]
263267
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
264-
assert "BUILD SUCCESS" in out
268+
assert "BUILD SUCCESS" in out, "unexpected output from " + str(cmd)
265269

266270
# check fileslist.txt
267-
fl_path = os.path.join(target_dir, "target", "classes", "vfs", "fileslist.txt")
271+
fl_path = os.path.join(target_dir, "target", "classes", VFS_PREFIX, "fileslist.txt")
268272
with open(fl_path) as f:
269273
lines = f.readlines()
270-
assert "/vfs/\n" in lines
271-
assert "/vfs/home/\n" in lines
272-
assert "/vfs/home/lib-graalpython/\n" in lines
273-
assert "/vfs/home/lib-python/\n" in lines
274+
assert "/" + VFS_PREFIX + "/\n" in lines, "unexpected output from " + str(cmd)
275+
assert "/" + VFS_PREFIX + "/home/\n" in lines, "unexpected output from " + str(cmd)
276+
assert "/" + VFS_PREFIX + "/home/lib-graalpython/\n" in lines, "unexpected output from " + str(cmd)
277+
assert "/" + VFS_PREFIX + "/home/lib-python/\n" in lines, "unexpected output from " + str(cmd)
274278

275279
# execute and check native image
276280
cmd = [os.path.join(target_dir, "target", target_name)]
277281
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
278-
assert "hello java" in out
282+
assert "hello java" in out, "unexpected output from " + str(cmd)
279283

280284
# execute with java and check
281285
cmd = MVN_CMD + ["exec:java", "-Dexec.mainClass=it.pkg.GraalPy"]
282286
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
283-
assert "hello java" in out
287+
assert "hello java" in out, "unexpected output from " + str(cmd)
284288

285289
#GR-51132 - NoClassDefFoundError when running polyglot app in java mode
286290
assert "java.lang.NoClassDefFoundError" not in out
@@ -307,18 +311,18 @@ def test_gen_launcher_and_venv(self):
307311

308312
cmd = MVN_CMD + ["process-resources"]
309313
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
310-
assert "-m venv" in out
311-
assert "-m ensurepip" in out
312-
assert "ujson" in out
313-
assert "termcolor" in out
314+
assert "-m venv" in out, "unexpected output from " + str(cmd)
315+
assert "-m ensurepip" in out, "unexpected output from " + str(cmd)
316+
assert "ujson" in out, "unexpected output from " + str(cmd)
317+
assert "termcolor" in out, "unexpected output from " + str(cmd)
314318

315319
# run again and assert that we do not regenerate the venv
316320
cmd = MVN_CMD + ["process-resources"]
317321
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
318-
assert "-m venv" not in out
319-
assert "-m ensurepip" not in out
320-
assert "ujson" not in out
321-
assert "termcolor" not in out
322+
assert "-m venv" not in out, "unexpected output from " + str(cmd)
323+
assert "-m ensurepip" not in out, "unexpected output from " + str(cmd)
324+
assert "ujson" not in out, "unexpected output from " + str(cmd)
325+
assert "termcolor" not in out, "unexpected output from " + str(cmd)
322326

323327
# remove ujson pkg from plugin config and check if unistalled
324328
with open(os.path.join(target_dir, "pom.xml"), "r") as f:
@@ -329,10 +333,10 @@ def test_gen_launcher_and_venv(self):
329333

330334
cmd = MVN_CMD + ["process-resources"]
331335
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
332-
assert "-m venv" not in out
333-
assert "-m ensurepip" not in out
334-
assert "Uninstalling ujson" in out
335-
assert "termcolor" not in out
336+
assert "-m venv" not in out, "unexpected output from " + str(cmd)
337+
assert "-m ensurepip" not in out, "unexpected output from " + str(cmd)
338+
assert "Uninstalling ujson" in out, "unexpected output from " + str(cmd)
339+
assert "termcolor" not in out, "unexpected output from " + str(cmd)
336340

337341
@unittest.skipUnless(is_enabled, "ENABLE_STANDALONE_UNITTESTS is not true")
338342
def test_check_home(self):
@@ -346,13 +350,13 @@ def test_check_home(self):
346350
out, return_code = run_cmd(cmd, self.env, cwd=target_dir)
347351

348352
# check fileslist.txt
349-
fl_path = os.path.join(target_dir, "target", "classes", "vfs", "fileslist.txt")
353+
fl_path = os.path.join(target_dir, "target", "classes", VFS_PREFIX, "fileslist.txt")
350354
with open(fl_path) as f:
351355
for line in f:
352356
line = f.readline()
353357
# string \n
354358
line = line[:len(line)-1]
355-
if line.endswith("/") or line == "/vfs/home/tagfile" or line == "/vfs/proj/hello.py":
359+
if line.endswith("/") or line == "/" + VFS_PREFIX + "/home/tagfile" or line == "/" + VFS_PREFIX + "/proj/hello.py":
356360
continue
357361
assert line.endswith("/__init__.py")
358362
assert not line.endswith("html/__init__.py")
@@ -376,11 +380,11 @@ def test_native_executable_one_file():
376380
cmd = [graalpy, "-m", "standalone", "--verbose", "native", "-ce", "-m", source_file, "-o", target_file]
377381

378382
out, return_code = run_cmd(cmd, env)
379-
assert "Bundling Python resources into" in out
383+
assert "Bundling Python resources into" in out, "unexpected output from " + str(cmd)
380384

381385
cmd = [target_file, "arg1", "arg2"]
382386
out, return_code = run_cmd(cmd, env)
383-
assert "hello world, argv[1:]: " + str(cmd[1:]) in out
387+
assert "hello world, argv[1:]: " + str(cmd[1:]) in out, "unexpected output from " + str(cmd)
384388

385389
@unittest.skipUnless(is_enabled, "ENABLE_STANDALONE_UNITTESTS is not true")
386390
def test_native_executable_venv_and_one_file():
@@ -411,13 +415,12 @@ def test_native_executable_venv_and_one_file():
411415
target_file = os.path.join(target_dir, "hello")
412416
cmd = [graalpy, "-m", "standalone", "--verbose", "native", "-ce", "-Os", "-m", source_file, "--venv", venv_dir, "-o", target_file]
413417
out, return_code = run_cmd(cmd, env)
414-
assert "Bundling Python resources into" in out
418+
assert "Bundling Python resources into" in out, "unexpected output from " + str(cmd)
415419

416420
cmd = [target_file]
417421
out, return_code = run_cmd(cmd, env)
418-
419-
assert "hello standalone world" in out
420-
assert "key=value" in out
422+
assert "hello standalone world" in out, "unexpected output from " + str(cmd)
423+
assert "key=value" in out, "unexpected output from " + str(cmd)
421424

422425
@unittest.skipUnless(is_enabled, "ENABLE_STANDALONE_UNITTESTS is not true")
423426
def test_native_executable_module():
@@ -444,13 +447,12 @@ def test_native_executable_module():
444447

445448
target_file = os.path.join(tmp_dir, "hello")
446449
cmd = [graalpy, "-m", "standalone", "--verbose", "native", "-ce", "-Os", "-m", module_dir, "-o", target_file]
447-
448450
out, return_code = run_cmd(cmd, env)
449-
assert "Bundling Python resources into" in out
451+
assert "Bundling Python resources into" in out, "unexpected output from " + str(cmd)
450452

451453
cmd = [target_file]
452454
out, return_code = run_cmd(cmd, env)
453-
assert "hello standalone world" in out
455+
assert "hello standalone world" in out, "unexpected output from " + str(cmd)
454456

455457

456458
unittest.skip_deselected_test_functions(globals())

graalpython/graalpy-archetype-polyglot-app/src/main/resources/archetype-resources/src/main/java/GraalPy.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@
5454
import org.graalvm.python.embedding.vfs.VirtualFileSystem;
5555

5656
public class GraalPy {
57-
private static final String VENV_PREFIX = "/vfs/venv";
58-
private static final String HOME_PREFIX = "/vfs/home";
59-
private static final String PROJ_PREFIX = "/vfs/proj";
60-
6157
private static final String PYTHON = "python";
6258

6359
public static Context getContext() {
@@ -102,14 +98,14 @@ public static Context getContext() {
10298
// Force to automatically import site.py module, to make Python packages available
10399
.option("python.ForceImportSite", "true")
104100
// The sys.executable path, a virtual path that is used by the interpreter to discover packages
105-
.option("python.Executable", vfs.resourcePathToPlatformPath(VENV_PREFIX) + (VirtualFileSystem.isWindows() ? "${symbol_escape}${symbol_escape}Scripts${symbol_escape}${symbol_escape}python.exe" : "/bin/python"))
101+
.option("python.Executable", vfs.vfsVenvPath() + (VirtualFileSystem.isWindows() ? "${symbol_escape}${symbol_escape}Scripts${symbol_escape}${symbol_escape}python.exe" : "/bin/python"))
106102
// Set the python home to be read from the embedded resources
107-
.option("python.PythonHome", vfs.resourcePathToPlatformPath(HOME_PREFIX))
103+
.option("python.PythonHome", vfs.vfsHomePath())
108104
// Do not warn if running without JIT. This can be desirable for short running scripts
109105
// to reduce memory footprint.
110106
.option("engine.WarnInterpreterOnly", "false")
111-
// Set python path to point to sources stored in src/main/resources/vfs/proj
112-
.option("python.PythonPath", vfs.resourcePathToPlatformPath(PROJ_PREFIX))
107+
// Set python path to point to sources stored in src/main/resources/org.graalvm.python.vfs/proj
108+
.option("python.PythonPath", vfs.vfsProjPath())
113109
.build();
114110
return context;
115111
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"resources": {
33
"includes": [
4-
{"pattern": "vfs/.*"}
4+
{"pattern": "org.graalvm.python.vfs/.*"}
55
]
66
}
77
}

0 commit comments

Comments
 (0)