Skip to content

Commit b90ac4d

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

File tree

5 files changed

+79
-13
lines changed

5 files changed

+79
-13
lines changed

DEVELOPMENT.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ mvn -pl org.graalvm.python.gradle.plugin -am clean
6868
tl;dr:
6969

7070
```
71-
mvn install exec:java@integration-tests -Dintegration.test.args="test_maven_plugin.py" -Dgradle.java.home=...
71+
mvn install exec:java@integration-tests # to view the help
72+
mvn install exec:java@integration-tests -Dintegration.tests.args="test_maven_plugin.py" -Dgradle.java.home=...
7273
```
7374

7475
The integration tests are driven by Python and implemented using unittest framework, which is
@@ -78,7 +79,7 @@ published in Mavencentral or some snapshot repository configured in Maven settin
7879

7980
The whole execution of the tests is wrapped in Maven goal `exec:java@integration-tests`, which passes
8081
some necessary arguments to the test driver Python script. One can pass additional arguments for the
81-
unittest framework using system property `integration.test.args`, for example, tests to execute or
82+
unittest framework using system property `integration.tests.args`, for example, tests to execute or
8283
verbosity level.
8384

8485

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,16 +293,25 @@ 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);
296+
Artifact graalPyArtifact = projectArtifacts.stream().filter(AbstractGraalPyMojo::isPythonArtifact)
297+
.findFirst()
298+
.orElse(null);
297299
return Optional.ofNullable(graalPyArtifact).orElseThrow(() -> new IOException(
298300
"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)));
301+
PYTHON_ARTIFACT_ID, GRAALPY_GROUP_ID, PYTHON_ARTIFACT_ID)));
300302
}
301303

302304
private static boolean isPythonArtifact(Artifact a) {
303-
return (POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId()))
304-
&& (PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId())
305-
|| PYTHON_ARTIFACT_ID.equals(a.getArtifactId()));
305+
return isPythonOrPolyglotGroup(a) && (PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId())
306+
|| PYTHON_ARTIFACT_ID.equals(a.getArtifactId()));
307+
}
308+
309+
private static boolean isPythonCommunityArtifact(Artifact a) {
310+
return isPythonOrPolyglotGroup(a) && (PYTHON_COMMUNITY_ARTIFACT_ID.equals(a.getArtifactId()));
311+
}
312+
313+
private static boolean isPythonOrPolyglotGroup(Artifact a) {
314+
return POLYGLOT_GROUP_ID.equals(a.getGroupId()) || GRAALPY_GROUP_ID.equals(a.getGroupId());
306315
}
307316

308317
private static Collection<Artifact> resolveProjectDependencies(MavenProject project) {
@@ -330,6 +339,15 @@ private Set<String> calculateLauncherClasspath(MavenProject project) throws IOEx
330339
// and transitively all its dependencies
331340
launcherClassPath.addAll(resolveDependencies(graalPyLauncherArtifact));
332341

342+
// check for deprecated python-community
343+
var projectArtifacts = resolveProjectDependencies(project);
344+
Optional<Artifact> community = projectArtifacts.stream().filter(AbstractGraalPyMojo::isPythonCommunityArtifact).findFirst();
345+
if (community.isPresent()) {
346+
getLog().warn("Deprecated artifact detected on classpath: " + community.get().getGroupId() + ":"
347+
+ community.get().getArtifactId() + ". Please use '" + POLYGLOT_GROUP_ID + ":"
348+
+ PYTHON_ARTIFACT_ID + "' instead.");
349+
}
350+
333351
// 2.) graalpy dependencies
334352
Artifact graalPyArtifact = getGraalPyArtifact(project);
335353
assert graalPyArtifact != null;

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: 23 additions & 3 deletions
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
@@ -134,8 +135,9 @@ def setUpClass(cls):
134135
if util.extra_maven_repos and not found and not cls.extraRemoteRepo:
135136
print("WARNING: extra Maven repos passed, but could not find GraalPy Maven archetype "
136137
"in any of the local repos and there is no extra remote repo. This is OK only if "
137-
"GraalPy Maven archetype of the required version is available at Mavencentral, "
138-
"otherwise the tests will fail to generate the example application.")
138+
"GraalPy Maven archetype of the required version is available at Mavencentral or "
139+
"it is installed in local repo, otherwise the tests will fail to generate the "
140+
"example application.")
139141

140142
def generate_app(self, tmpdir, target_dir, target_name, pom_template=None, group_id="archetype.it", package="it.pkg", log=Logger()):
141143
extra_repo = []
@@ -204,6 +206,7 @@ def check_generated_app(self, use_default_vfs_path):
204206
util.check_ouput("BUILD SUCCESS", out, logger=log)
205207
util.check_ouput("Virtual filesystem is deployed to default resources directory", out, contains=use_default_vfs_path, logger=log)
206208
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)
209+
util.check_ouput(DEPRECATION_MSG, out, contains=False, logger=log)
207210

208211
# check fileslist.txt
209212
fl_path = os.path.join(target_dir, "target", "classes", vfs_prefix, "fileslist.txt")
@@ -310,6 +313,7 @@ def test_lock_file(self):
310313
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
311314
util.check_ouput("pip install", out)
312315
util.check_ouput("BUILD SUCCESS", out)
316+
util.check_ouput(DEPRECATION_MSG, out, contains=False)
313317
util.check_ouput(MISSING_FILE_WARNING, out, contains=True)
314318
assert not os.path.exists(os.path.join(target_dir, "test-graalpy.lock"))
315319

@@ -411,6 +415,7 @@ def test_generated_app_external_resources(self):
411415
cmd = mvnw_cmd + ["package"] + native_image_arg + ["-DmainClass=it.pkg.GraalPy"]
412416
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
413417
util.check_ouput("BUILD SUCCESS", out)
418+
util.check_ouput(DEPRECATION_MSG, out, contains=False)
414419

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

449454
cmd = mvnw_cmd + ["process-resources"]
450455
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)
456+
util.check_ouput("Missing GraalPy dependency. Please add to your pom org.graalvm.polyglot:python", out)
452457

453458

454459
def test_check_home_warning(self):
@@ -835,6 +840,21 @@ def test_multiple_namespaced_vfs(self):
835840
assert return_code == 0, log
836841

837842

843+
def test_community_dep_deprecation_message(self):
844+
with util.TemporaryTestDirectory() as tmpdir:
845+
target_name = "community_dep_deprecation_test"
846+
target_dir = os.path.join(str(tmpdir), target_name)
847+
self.generate_app(tmpdir, target_dir, target_name)
848+
849+
mvnw_cmd = util.get_mvn_wrapper(target_dir, self.env)
850+
pom_path = os.path.join(target_dir, "pom.xml")
851+
852+
util.replace_in_file(pom_path, "<artifactId>python</artifactId>", "<artifactId>python-community</artifactId>")
853+
854+
cmd = mvnw_cmd + ["process-resources"]
855+
out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir)
856+
util.check_ouput(DEPRECATION_MSG, out, contains=True)
857+
838858
if __name__ == "__main__":
839859
run_path = os.path.join(os.path.abspath(__file__), 'run.py')
840860
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: 11 additions & 3 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. "
@@ -332,10 +337,13 @@ private static void makeSureBothEditionsAreNotOnClasspathSimultaneously(Configur
332337
}
333338
if (hasCommunityEdition && hasOracleEdition) {
334339
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 } "
340+
"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. "
341+
+ "The 'python-community' artifact is deprecated. Ensure only one edition is present. You may configure "
342+
+ "the GraalPy plugin to inject the deprecated 'python-community' artifact by using the graalPy { community = true } "
338343
+ "configuration block instead.");
344+
} else if (hasCommunityEdition && !hasOracleEdition) {
345+
org.gradle.api.logging.Logging.getLogger(GraalPyGradlePlugin.class).warn(
346+
"WARNING: 'python-community' is deprecated. Please depend on 'org.graalvm.python:python' or 'org.graalvm.polyglot:python' instead.");
339347
}
340348
});
341349
}

0 commit comments

Comments
 (0)