Skip to content

Commit 7d02b7e

Browse files
committed
Make PIP comment parsing in JBangIntegration more robust
1 parent 2b2fbe0 commit 7d02b7e

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ repos:
33
rev: v5.0.0
44
hooks:
55
- id: trailing-whitespace
6+
exclude: ^integration-tests/jbang/EmptyPIPComments\.j$
67
- id: end-of-file-fixer
78
- id: check-yaml
89
- id: check-added-large-files

integration-tests/jbang/EmptyPIPComments.j

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
//DEPS org.graalvm.python:jbang:${env.GRAALPY_VERSION:26.0.0}
44
//PIP
55
// one blank after PIP
6-
//PIP
6+
//PIP
77
// three blanks after PIP
8-
//PIP
8+
//PIP
99

1010
public class EmptyPIPComments {
1111
public static void main(String[] args) {

org.graalvm.python.jbang/src/main/java/org/graalvm/python/jbang/JBangIntegration.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,13 @@ public static Map<String, Object> postBuild(Path temporaryJar, Path pomFile,
180180
resourcesDirectory = Path.of(path);
181181
}
182182
} else if (comment.startsWith(PIP)) {
183-
pkgs.addAll(Arrays.stream(comment.substring(PIP.length()).trim().split(" "))
184-
.filter(s -> !s.trim().isEmpty()).collect(Collectors.toList()));
183+
String content = comment.substring(PIP.length()).trim();
184+
if (!content.isEmpty()) {
185+
// Some versions of JBang seem to pass "[null]" in the comment string for some
186+
// reason, we filter that out
187+
pkgs.addAll(Arrays.stream(content.split("\\s+")).filter(s -> !s.equals("[null]"))
188+
.collect(Collectors.toList()));
189+
}
185190
}
186191
}
187192
if (!pkgs.isEmpty()) {

0 commit comments

Comments
 (0)