Skip to content

Commit 850a56e

Browse files
committed
fix: avoid NPE when requirements.txt is not used
1 parent 09cc1ae commit 850a56e

File tree

2 files changed

+20
-14
lines changed
  • graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin
  • org.graalvm.python.embedding.tools/src/main/java/org/graalvm/python/embedding/tools/vfs

2 files changed

+20
-14
lines changed

graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/InstallPackagesMojo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ private void manageVenv() throws MojoExecutionException {
100100
MavenDelegateLog log = new MavenDelegateLog(getLog());
101101
Path lockFile = getLockFile();
102102
Path reqFile = resolveReqFile();
103+
if ((packages == null || packages.isEmpty()) && reqFile == null) {
104+
return;
105+
}
103106
try {
104107
VFSUtils.createVenv(venvDirectory, packages, lockFile, MISSING_LOCK_FILE_WARNING, createLauncher(),
105108
getGraalPyVersion(project), log, reqFile);

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -552,24 +552,27 @@ public static void createVenv(Path venvDirectory, List<String> packages, Path lo
552552

553553
static boolean installPackagesFromReqFile(Path venvDirectory, Launcher launcher, String graalPyVersion,
554554
BuildToolLog log, Path lockFilePath, Path reqFile) throws IOException {
555-
if (reqFile != null && Files.exists(reqFile)) {
556-
log.info("Using <requirements.txt> dependency mode.");
557-
log.info("Installing Python dependencies from: " + reqFile);
555+
if (reqFile == null) {
556+
return false;
557+
}
558+
if (!Files.exists(reqFile)) {
559+
return false;
560+
}
561+
log.info("Using <requirements.txt> dependency mode.");
562+
log.info("Installing Python dependencies from: " + reqFile);
558563

559-
warnIfLockFileExists(lockFilePath, log);
564+
warnIfLockFileExists(lockFilePath, log);
560565

561-
VenvContents vc = ensureVenv(venvDirectory, graalPyVersion, launcher, log);
566+
VenvContents vc = ensureVenv(venvDirectory, graalPyVersion, launcher, log);
562567

563-
runPip(venvDirectory, "install", log, "--compile", "-r", reqFile.toString());
564-
List<String> reqPackages = requirementsPackages(reqFile);
565-
vc.write(reqPackages);
568+
runPip(venvDirectory, "install", log, "--compile", "-r", reqFile.toString());
569+
List<String> reqPackages = requirementsPackages(reqFile);
570+
vc.write(reqPackages);
566571

567-
InstalledPackages installed = InstalledPackages.fromVenv(venvDirectory);
568-
installed.freeze(log);
572+
InstalledPackages installed = InstalledPackages.fromVenv(venvDirectory);
573+
installed.freeze(log);
569574

570-
return true;
571-
}
572-
return false;
575+
return true;
573576
}
574577

575578
private static void warnIfLockFileExists(Path lockFilePath, BuildToolLog log) {
@@ -591,7 +594,7 @@ static void installPackages(Path venvDirectory, List<String> packages, Path lock
591594

592595
List<String> pluginPackages = trim(packages);
593596

594-
LockFile lockFile = null;
597+
VFSUtils.LockFile lockFile = null;
595598
if (lockFilePath != null && Files.exists(lockFilePath)) {
596599
log.info("Lock-file detected: " + lockFilePath);
597600
lockFile = LockFile.fromFile(lockFilePath, log);

0 commit comments

Comments
 (0)