Skip to content

Commit c02f804

Browse files
committed
Deprecate python-community artifact
1 parent 0e76143 commit c02f804

File tree

4 files changed

+69
-11
lines changed

4 files changed

+69
-11
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,15 @@ protected static String getGraalPyVersion(MavenProject project) throws IOExcepti
293293

294294
private static Artifact getGraalPyArtifact(MavenProject project) throws IOException {
295295
var projectArtifacts = resolveProjectDependencies(project);
296-
Artifact graalPyArtifact = projectArtifacts.stream().filter(a -> isPythonArtifact(a)).findFirst().orElse(null);
297-
return Optional.ofNullable(graalPyArtifact).orElseThrow(() -> new IOException(
298-
"Missing GraalPy dependency. Please add to your pom either %s:%s or %s:%s".formatted(POLYGLOT_GROUP_ID,
299-
PYTHON_COMMUNITY_ARTIFACT_ID, POLYGLOT_GROUP_ID, PYTHON_ARTIFACT_ID)));
296+
Artifact graalPyArtifact = projectArtifacts.stream()
297+
.filter(a -> (POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId())))
298+
.filter(a -> PYTHON_ARTIFACT_ID.equals(a.getArtifactId())).findFirst()
299+
.orElse(projectArtifacts.stream().filter(
300+
a -> (POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId())))
301+
.filter(a -> PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId())).findFirst().orElse(null));
302+
return Optional.ofNullable(graalPyArtifact)
303+
.orElseThrow(() -> new IOException("Missing GraalPy dependency. Please add to your pom %s:%s"
304+
.formatted(POLYGLOT_GROUP_ID, PYTHON_ARTIFACT_ID)));
300305
}
301306

302307
private static boolean isPythonArtifact(Artifact a) {
@@ -333,6 +338,11 @@ private Set<String> calculateLauncherClasspath(MavenProject project) throws IOEx
333338
// 2.) graalpy dependencies
334339
Artifact graalPyArtifact = getGraalPyArtifact(project);
335340
assert graalPyArtifact != null;
341+
if (PYTHON_COMMUNITY_ARTIFACT_ID.equals(graalPyArtifact.getArtifactId())) {
342+
getLog().warn("Deprecated artifact detected on classpath: " + graalPyArtifact.getGroupId() + ":"
343+
+ graalPyArtifact.getArtifactId() + ". Please use '" + POLYGLOT_GROUP_ID + ":"
344+
+ PYTHON_ARTIFACT_ID + "' instead.");
345+
}
336346
launcherClassPath.addAll(resolveDependencies(graalPyArtifact));
337347
}
338348
return launcherClassPath;

integration-tests/test_gradle_plugin.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
MISSING_FILE_WARNING = "The list of installed Python packages does not match the packages specified in the graalpy-maven-plugin configuration"
5050
PACKAGES_CHANGED_ERROR = "packages and their version constraints in graalpy-gradle-plugin configuration are different then previously used to generate the lock file"
5151
VENV_UPTODATE = "Virtual environment is up to date with lock file, skipping install"
52+
DEPRECATION_MSG = "python-community' is deprecated"
5253

5354
def append(file, txt):
5455
with open(file, "a") as f:
@@ -156,6 +157,7 @@ def check_gradle_generated_app(self):
156157
util.check_ouput("BUILD SUCCESS", out, logger=log)
157158
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, logger=log)
158159
util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem", out, logger=log)
160+
util.check_ouput(DEPRECATION_MSG, out, contains=False, logger=log)
159161
self.check_filelist(target_dir, log)
160162

161163
gradlew_cmd = util.get_gradle_wrapper(target_dir, self.env)
@@ -224,6 +226,7 @@ def check_lock_packages(self):
224226
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir, logger=log)
225227
util.check_ouput("pip install", out, logger=log)
226228
util.check_ouput("BUILD SUCCESS", out, logger=log)
229+
util.check_ouput(DEPRECATION_MSG, out, contains=False, logger=log)
227230
util.check_ouput(MISSING_FILE_WARNING, out, contains=True, logger=log)
228231
assert not os.path.exists(os.path.join(target_dir, "test-graalpy.lock")), log
229232

@@ -641,6 +644,22 @@ def test_gradle_python_resources_dir_and_external_dir_error(self):
641644
def test_proxy_settings(self):
642645
self.check_proxy_settings()
643646

647+
def test_gradle_community_deprecation(self):
648+
with TemporaryTestDirectory() as tmpdir:
649+
target_dir = os.path.join(str(tmpdir), "community_deprecation_gradle" + self.target_dir_name_sufix())
650+
self.generate_app(target_dir)
651+
build_file = os.path.join(target_dir, self.build_file_name)
652+
append(build_file, textwrap.dedent("""
653+
graalPy {
654+
community = true
655+
packages = ["termcolor"]
656+
}
657+
"""))
658+
gradlew_cmd = util.get_gradle_wrapper(target_dir, self.env)
659+
cmd = gradlew_cmd + ["graalPyInstallPackages"]
660+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
661+
util.check_ouput(DEPRECATION_MSG, out, contains=True)
662+
644663
def target_dir_name_sufix(self):
645664
return "_groovy"
646665

integration-tests/test_maven_plugin.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
MISSING_FILE_WARNING = "The list of installed Python packages does not match the packages specified in the graalpy-maven-plugin configuration."
5252
PACKAGES_CHANGED_ERROR = "but packages and their version constraints in graalpy-maven-plugin configuration are different then previously used to generate the lock file"
5353
VENV_UPTODATE = "Virtual environment is up to date with lock file, skipping install"
54+
DEPRECATION_MSG = "Deprecated artifact detected on classpath"
5455

5556
class MavenPluginTest(util.BuildToolTestBase):
5657
@classmethod
@@ -204,6 +205,7 @@ def check_generated_app(self, use_default_vfs_path):
204205
util.check_ouput("BUILD SUCCESS", out, logger=log)
205206
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=use_default_vfs_path, logger=log)
206207
util.check_ouput("This can cause conflicts if used with other Java libraries that also deploy GraalPy virtual filesystem.", out, contains=use_default_vfs_path, logger=log)
208+
util.check_ouput(DEPRECATION_MSG, out, contains=False, logger=log)
207209

208210
# check fileslist.txt
209211
fl_path = os.path.join(target_dir, "target", "classes", vfs_prefix, "fileslist.txt")
@@ -310,6 +312,7 @@ def test_lock_file(self):
310312
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
311313
util.check_ouput("pip install", out)
312314
util.check_ouput("BUILD SUCCESS", out)
315+
util.check_ouput(DEPRECATION_MSG, out, contains=False)
313316
util.check_ouput(MISSING_FILE_WARNING, out, contains=True)
314317
assert not os.path.exists(os.path.join(target_dir, "test-graalpy.lock"))
315318

@@ -411,6 +414,7 @@ def test_generated_app_external_resources(self):
411414
cmd = mvnw_cmd + ["package"] + native_image_arg + ["-DmainClass=it.pkg.GraalPy"]
412415
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
413416
util.check_ouput("BUILD SUCCESS", out)
417+
util.check_ouput(DEPRECATION_MSG, out, contains=False)
414418

415419
# execute and check JVM mode
416420
cmd = mvnw_cmd + ["exec:java", "-Dexec.mainClass=it.pkg.GraalPy"]
@@ -448,7 +452,7 @@ def test_fail_without_graalpy_dep(self):
448452

449453
cmd = mvnw_cmd + ["process-resources"]
450454
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
451-
util.check_ouput("Missing GraalPy dependency. Please add to your pom either org.graalvm.polyglot:python-community or org.graalvm.polyglot:python", out)
455+
util.check_ouput("Missing GraalPy dependency. Please add to your pom org.graalvm.polyglot:python", out)
452456

453457

454458
def test_check_home_warning(self):
@@ -835,6 +839,21 @@ def test_multiple_namespaced_vfs(self):
835839
assert return_code == 0, log
836840

837841

842+
def test_community_dep_deprecation_message(self):
843+
with util.TemporaryTestDirectory() as tmpdir:
844+
target_name = "community_dep_deprecation_test"
845+
target_dir = os.path.join(str(tmpdir), target_name)
846+
self.generate_app(tmpdir, target_dir, target_name)
847+
848+
mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
849+
pom_path = os.path.join(target_dir, "pom.xml")
850+
851+
util.replace_in_file(pom_path, "<artifactId>python</artifactId>", "<artifactId>python-community</artifactId>")
852+
853+
cmd = mvnw_cmd + ["process-resources"]
854+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
855+
util.check_ouput(DEPRECATION_MSG, out, contains=True)
856+
838857
if __name__ == "__main__":
839858
run_path = os.path.join(os.path.abspath(__file__), 'run.py')
840859
print(f"Run this file using the run.py driver ({run_path})")

org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/GraalPyGradlePlugin.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ public void apply(Project project) {
133133
"WARNING: Property 'polyglotVersion' is experimental and should be used only for testing pre-release versions.");
134134
}
135135

136+
if (extension.getCommunity().convention(false).get()) {
137+
proj.getLogger().warn(
138+
"WARNING: 'python-community' is deprecated. The plugin defaults to 'python'. Support for 'python-community' may be removed in a future release.");
139+
}
140+
136141
if (extension.getPythonResourcesDirectory().isPresent() && extension.getExternalDirectory().isPresent()) {
137142
throw new GradleException(
138143
"Cannot set both 'externalDirectory' and 'resourceDirectory' at the same time. "
@@ -324,18 +329,23 @@ private static void makeSureBothEditionsAreNotOnClasspathSimultaneously(Configur
324329
boolean hasOracleEdition = false;
325330
for (Dependency dep : deps) {
326331
if (dep instanceof ExternalModuleDependency emd) {
327-
if (GRAALPY_GROUP_ID.equals(emd.getModule().getGroup())) {
328-
hasCommunityEdition |= PYTHON_COMMUNITY_ARTIFACT_ID.equals(emd.getModule().getName());
329-
hasOracleEdition |= PYTHON_ARTIFACT_ID.equals(emd.getModule().getName());
332+
String group = emd.getModule().getGroup();
333+
String name = emd.getModule().getName();
334+
if (GRAALPY_GROUP_ID.equals(group) || POLYGLOT_GROUP_ID.equals(group)) {
335+
hasCommunityEdition |= PYTHON_COMMUNITY_ARTIFACT_ID.equals(name);
336+
hasOracleEdition |= PYTHON_ARTIFACT_ID.equals(name);
330337
}
331338
}
332339
}
333340
if (hasCommunityEdition && hasOracleEdition) {
334341
throw new GradleException(
335-
"You have both 'org.graalvm.python:python' and 'org.graalvm.python:python-community' on the classpath. "
336-
+ "This is likely due to an explicit dependency added, or duplicate dependencies. You may configure "
337-
+ "the GraalPy plugin to inject the 'python-community' artifact by using the graalPy { community = true } "
342+
"You have both 'org.graalvm.python:python' (or 'org.graalvm.polyglot:python') and 'org.graalvm.python:python-community' (or 'org.graalvm.polyglot:python-community') on the classpath. "
343+
+ "The 'python-community' artifact is deprecated. Ensure only one edition is present. You may configure "
344+
+ "the GraalPy plugin to inject the deprecated 'python-community' artifact by using the graalPy { community = true } "
338345
+ "configuration block instead.");
346+
} else if (hasCommunityEdition && !hasOracleEdition) {
347+
org.gradle.api.logging.Logging.getLogger(GraalPyGradlePlugin.class).warn(
348+
"WARNING: 'python-community' is deprecated. Please depend on 'org.graalvm.python:python' or 'org.graalvm.polyglot:python' instead.");
339349
}
340350
});
341351
}

0 commit comments

Comments
 (0)