Skip to content

Commit 21915dc

Browse files
committed
fix: correct requirements.txt handling and lock-file behaviour
1 parent b58bb1f commit 21915dc

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

integration-tests/prepare_venv_requirements_pom.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
44
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
66
The Universal Permissive License (UPL), Version 1.0
@@ -44,11 +44,10 @@ SOFTWARE.
4444
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4545
<modelVersion>4.0.0</modelVersion>
4646

47-
<groupId>org.apache.maven.plugin.my.unit</groupId>
48-
<artifactId>project-prepare-venv</artifactId>
47+
<groupId>archetype.it</groupId>
48+
<artifactId>requirements_packages</artifactId>
4949
<version>1.0-SNAPSHOT</version>
5050
<packaging>jar</packaging>
51-
<name>Test MyMojo</name>
5251

5352
<dependencies>
5453
<dependency>
@@ -68,6 +67,11 @@ SOFTWARE.
6867
<artifactId>python-launcher</artifactId>
6968
<version>${env.GRAALPY_VERSION}</version>
7069
</dependency>
70+
<dependency>
71+
<groupId>org.graalvm.python</groupId>
72+
<artifactId>python-embedding</artifactId>
73+
<version>${env.GRAALPY_VERSION}</version>
74+
</dependency>
7175
</dependencies>
7276

7377
<build>
@@ -84,6 +88,9 @@ SOFTWARE.
8488
</execution>
8589
</executions>
8690
<configuration>
91+
<resourceDirectory>
92+
GRAALPY-VFS/${project.groupId}/${project.artifactId}
93+
</resourceDirectory>
8794
<requirementsFile>requirements.txt</requirementsFile>
8895
</configuration>
8996
</plugin>

integration-tests/test_maven_plugin.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ def test_requirements_txt_packages(self):
848848
requirements_txt = os.path.join(target_dir, "requirements.txt")
849849
if not os.path.exists(requirements_txt):
850850
with open(requirements_txt, "w", encoding="utf-8") as f:
851-
f.write("pyfiglet==1.0.2\n")
851+
f.write("termcolor==2.4.0\n")
852852

853853
mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
854854

@@ -858,7 +858,17 @@ def test_requirements_txt_packages(self):
858858
assert return_code == 0
859859

860860
lock_file = os.path.join(target_dir, "graalpy.lock")
861-
assert not os.path.exists(lock_file)
861+
assert not os.path.exists(lock_file), "lock-file must NOT exist for requirements.txt mode"
862+
cmd = mvnw_cmd + ["package", "-DmainClass=it.pkg.GraalPy"]
863+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
864+
util.check_ouput("BUILD SUCCESS", out)
865+
assert return_code == 0
866+
867+
cmd = mvnw_cmd + ["exec:java", "-Dexec.mainClass=it.pkg.GraalPy"]
868+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
869+
util.check_ouput("hello java", out)
870+
util.check_ouput("BUILD SUCCESS", out)
871+
assert return_code == 0
862872

863873

864874
if __name__ == "__main__":

org.graalvm.python.embedding.tools/src/main/java/org/graalvm/python/embedding/tools/vfs/VFSUtils.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ static boolean installPackagesFromReqFile(Path venvDirectory, Launcher launcher,
557557
if (reqFile != null) {
558558
log.info("Using <requirements.txt> dependency mode.");
559559
log.info("Installing Python dependencies from: " + reqFile);
560-
log.warning("Lock file is ignored in <requirements.txt> mode.");
561-
log.warning("The 'lock-packages' goal should not be used together with <requirementsFile>.");
560+
561+
warnIfLockFileExists(venvDirectory,log);
562562

563563
VenvContents vc = ensureVenv(venvDirectory, graalPyVersion, launcher, log);
564564

@@ -574,6 +574,14 @@ static boolean installPackagesFromReqFile(Path venvDirectory, Launcher launcher,
574574
return false;
575575
}
576576

577+
private static void warnIfLockFileExists(Path venvDirectory, BuildToolLog log) {
578+
Path lockFile = venvDirectory.resolve("graalpy.lock");
579+
if (Files.exists(lockFile)) {
580+
log.warning("Lock file is ignored in <requirements.txt> mode.");
581+
}
582+
}
583+
584+
577585
static void installPackages(Path venvDirectory, List<String> packages, Path lockFilePath,
578586
String missingLockFileWarning, Launcher launcher, String graalPyVersion,
579587
BuildToolLog log) throws IOException, PackagesChangedException {

0 commit comments

Comments
 (0)