GeezerVison is showing github.com — [GR-62398] Unify error handling in gradle. · elide-dev/graalpython@fab3eb0
File treeExpand file treeCollapse file tree Open diff view settings com.oracle.graal.python.test/src org/graalvm/python/embedding
graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin org.graalvm.python.embedding.tools/src/org/graalvm/python/embedding/tools/vfs org.graalvm.python.gradle.plugin/src/main/java/org/graalvm/python/tasks
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/cext/test/MultiContextCExtTest.java +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 58 | 58 | import org.graalvm.polyglot.PolyglotException; | 59 | 59 | import org.graalvm.polyglot.Source; | 60 | 60 | import org.graalvm.python.embedding.tools.exec.BuildToolLog; | | 61 | +import org.graalvm.python.embedding.tools.vfs.VFSUtils; | 61 | 62 | import org.junit.Test; | 62 | 63 |
| 63 | 64 | import static org.graalvm.python.embedding.test.EmbeddingTestUtils.deleteDirOnShutdown; | @@ -165,7 +166,7 @@ public void close() { | 165 | 166 | } | 166 | 167 |
| 167 | 168 | @Test | 168 | | - public void testCreatingVenvForMulticontext() throws IOException { | | 169 | + public void testCreatingVenvForMulticontext() throws IOException, VFSUtils.PackagesChangedException { | 169 | 170 | var log = new TestLog(); | 170 | 171 | Path tmpdir = Files.createTempDirectory("MultiContextCExtTest"); | 171 | 172 | Path venvDir = tmpdir.resolve("venv"); | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/test/EmbeddingTestUtils.java +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -58,18 +58,18 @@ public final class EmbeddingTestUtils { | 58 | 58 | private EmbeddingTestUtils() { | 59 | 59 | } | 60 | 60 |
| 61 | | - public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, String... packages) throws IOException { | 62 | | - createVenv(venvDir, graalPyVersion, log, null, null, null, packages); | | 61 | + public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, String... packages) throws IOException, VFSUtils.PackagesChangedException { | | 62 | + createVenv(venvDir, graalPyVersion, log, null, null, packages); | 63 | 63 | } | 64 | 64 |
| 65 | | - public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, Path lockFile, String missingLockFileWarning, String packageRemovedError, String... packages) | 66 | | - throws IOException { | | 65 | + public static void createVenv(Path venvDir, String graalPyVersion, BuildToolLog log, Path lockFile, String missingLockFileWarning, String... packages) | | 66 | + throws IOException, VFSUtils.PackagesChangedException { | 67 | 67 | try { | 68 | 68 | info(log, "<<<<<< create test venv %s <<<<<<", venvDir); | 69 | 69 |
| 70 | 70 | Launcher launcher = createLauncher(venvDir); | 71 | 71 | if (lockFile != null) { | 72 | | - VFSUtils.createVenv(venvDir, Arrays.asList(packages), lockFile, packageRemovedError, missingLockFileWarning, launcher, graalPyVersion, log); | | 72 | + VFSUtils.createVenv(venvDir, Arrays.asList(packages), lockFile, missingLockFileWarning, launcher, graalPyVersion, log); | 73 | 73 | } else { | 74 | 74 | VFSUtils.createVenv(venvDir, Arrays.asList(packages), launcher, graalPyVersion, log); | 75 | 75 | } | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test/src/org/graalvm/python/embedding/vfs/test/VFSUtilsTest.java +11-14Lines changed: 11 additions & 14 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 44 | 44 | import org.graalvm.python.embedding.test.EmbeddingTestUtils; | 45 | 45 | import org.graalvm.python.embedding.tools.exec.BuildToolLog; | 46 | 46 | import org.graalvm.python.embedding.tools.vfs.VFSUtils; | | 47 | +import org.graalvm.python.embedding.tools.vfs.VFSUtils.PackagesChangedException; | 47 | 48 | import org.junit.Test; | 48 | 49 |
| 49 | 50 | import java.io.IOException; | @@ -86,7 +87,6 @@ public class VFSUtilsTest { | 86 | 87 |
| 87 | 88 | private static final String PACKAGE_WAS_REMOVED = "A package with transitive dependencies was removed since last install, setting up a clean venv"; | 88 | 89 | private static final String LOCK_FILE_HEADER = "generated by graalpy tests\nwith a two line header"; | 89 | | - private static final String PACKAGES_CHANGED_ERROR = "packages changed in lock file %s, current packages %s, previous packages %s"; | 90 | 90 | private static final String MISSING_LOCK_FILE_WARNING = "missing lock file"; | 91 | 91 | private static final CharSequence STALE_VENV = "Stale GraalPy virtual environment, updating to"; | 92 | 92 |
| @@ -184,7 +184,7 @@ private static boolean isVerbose() { | 184 | 184 | * - packages declared only in plugin config - lock file path is provided, but does not exist | 185 | 185 | */ | 186 | 186 | @Test | 187 | | - public void withPackagesOnlyFromPluginConfig() throws IOException { | | 187 | + public void withPackagesOnlyFromPluginConfig() throws IOException, PackagesChangedException { | 188 | 188 | TestLog log = new TestLog(); | 189 | 189 | Path tmpDir = Files.createTempDirectory("withPackagesOnlyFromPluginConfig"); | 190 | 190 | Path venvDir = tmpDir.resolve("venv"); | @@ -262,7 +262,7 @@ public void withPackagesOnlyFromPluginConfig() throws IOException { | 262 | 262 | * - packages declared only in plugin config - and lock file path is not provided | 263 | 263 | */ | 264 | 264 | @Test | 265 | | - public void withoutLockFile() throws IOException { | | 265 | + public void withoutLockFile() throws IOException, PackagesChangedException { | 266 | 266 | TestLog log = new TestLog(); | 267 | 267 | Path tmpDir = Files.createTempDirectory("withoutLockFile"); | 268 | 268 | Path venvDir = tmpDir.resolve("venv"); | @@ -375,7 +375,7 @@ private static List<String> createLockFileHeader(String graalPyVersion, String.. | 375 | 375 | } | 376 | 376 |
| 377 | 377 | @Test | 378 | | - public void installAndLock() throws IOException { | | 378 | + public void installAndLock() throws IOException, PackagesChangedException { | 379 | 379 | TestLog log = new TestLog(); | 380 | 380 | Path tmpDir = Files.createTempDirectory("installAndLock"); | 381 | 381 | Path venvDir = tmpDir.resolve("venv"); | @@ -407,7 +407,7 @@ public void installAndLock() throws IOException { | 407 | 407 | log.clearOutput(); | 408 | 408 |
| 409 | 409 | // reinstall without exact version declared - fails | 410 | | - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests")); | | 410 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests")); | 411 | 411 | checkVenvCreate(log.getOutput(), false); | 412 | 412 | assertFalse(log.getOutput().contains("pip install")); | 413 | 413 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.2", "charset-normalizer", "idna", "urllib3", "certifi"); | @@ -446,10 +446,9 @@ public void installAndLock() throws IOException { | 446 | 446 |
| 447 | 447 | // add tiny-tiny - fails because inconsistent with lock file | 448 | 448 | assert Files.exists(lockFile); | 449 | | - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.1", "tiny-tiny==0.2")); | | 449 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.1", "tiny-tiny==0.2")); | 450 | 450 | checkVenvCreate(log.getOutput(), false); | 451 | 451 | assertFalse(log.getOutput().contains("pip install")); | 452 | | - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "requests==2.32.1, tiny-tiny==0.2", "requests==2.32.1"))); | 453 | 452 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.1", "charset-normalizer", "idna", "urllib3", "certifi"); | 454 | 453 | checkVenvContentsFile(contents, "0.1", "requests==2.32.1"); | 455 | 454 | assertFalse(log.getOutput().contains(MISSING_LOCK_FILE_WARNING)); | @@ -481,10 +480,9 @@ public void installAndLock() throws IOException { | 481 | 480 | log.clearOutput(); | 482 | 481 |
| 483 | 482 | // update in declared packages requests version back to 2.32.2 - fails | 484 | | - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.2", "tiny-tiny==0.2")); | | 483 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "requests==2.32.2", "tiny-tiny==0.2")); | 485 | 484 | checkVenvCreate(log.getOutput(), false); | 486 | 485 | assertFalse(log.getOutput().contains("pip install")); | 487 | | - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "requests==2.32.2, tiny-tiny==0.2", "requests==2.32.1, tiny-tiny==0.2"))); | 488 | 486 | checkInstalledPackages(venvDir.resolve("installed.txt"), "requests==2.32.1", "tiny-tiny==0.2", "charset-normalizer", "idna", "urllib3", "certifi"); | 489 | 487 | checkVenvContentsFile(contents, "0.1", "requests==2.32.1", "tiny-tiny==0.2"); | 490 | 488 | assertFalse(log.getOutput().contains(MISSING_LOCK_FILE_WARNING)); | @@ -520,10 +518,9 @@ public void installAndLock() throws IOException { | 520 | 518 | log.clearOutput(); | 521 | 519 |
| 522 | 520 | // remove requests from packages list - fails because it is still in lock | 523 | | - checkException(IOException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "tiny-tiny==0.2")); | | 521 | + checkException(PackagesChangedException.class, () -> createVenv(venvDir, "0.1", log, lockFile, "tiny-tiny==0.2")); | 524 | 522 | checkVenvCreate(log.getOutput(), false); | 525 | 523 | assertFalse(log.getOutput().contains("pip install")); | 526 | | - assertTrue(log.getOutput().contains(String.format(PACKAGES_CHANGED_ERROR, lockFile, "tiny-tiny==0.2", "requests==2.32.2, tiny-tiny==0.2"))); | 527 | 524 | log.clearOutput(); | 528 | 525 | // lock only with tiny-tiny | 529 | 526 | lock(venvDir, lockFile, log, "tiny-tiny==0.2"); | @@ -656,12 +653,12 @@ private static void checkPackages(Path file, List<String> linesArg, String... pa | 656 | 653 | } | 657 | 654 | } | 658 | 655 |
| 659 | | - private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, String... packages) throws IOException { | | 656 | + private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, String... packages) throws IOException, PackagesChangedException { | 660 | 657 | EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, packages); | 661 | 658 | } | 662 | 659 |
| 663 | | - private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path lockFile, String... packages) throws IOException { | 664 | | - EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, lockFile, MISSING_LOCK_FILE_WARNING, PACKAGES_CHANGED_ERROR, packages); | | 660 | + private static void createVenv(Path venvDir, String graalPyVersion, TestLog log, Path lockFile, String... packages) throws IOException, PackagesChangedException { | | 661 | + EmbeddingTestUtils.createVenv(venvDir, graalPyVersion, log, lockFile, MISSING_LOCK_FILE_WARNING, packages); | 665 | 662 | } | 666 | 663 |
| 667 | 664 | private static void checkVenvContentsFile(Path contents, String graalPyVersion, String... packages) throws IOException { | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test/src/tests/standalone/test_gradle_plugin.py +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -429,7 +429,7 @@ def check_gradle_empty_packages(self): | 429 | 429 | cmd = gradle_cmd + ["graalpyLockPackages"] | 430 | 430 | out, return_code = util.run_cmd(cmd, self.env, cwd=target_dir) | 431 | 431 | util.check_ouput("BUILD SUCCESS", out, contains=False) | 432 | | - util.check_ouput("In order to run the graalpyLockPackages task there have to be python packages declared in the graalpy-gradle-plugin configuration.", out) | | 432 | + util.check_ouput("In order to run the graalPyLockPackages task there have to be python packages declared in the graalpy-gradle-plugin configuration.", out) | 433 | 433 | assert not os.path.exists(os.path.join(target_dir, "graalpy.lock")) | 434 | 434 |
| 435 | 435 |
| |
Collapse file Copy file name to clipboardExpand all lines: graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/AbstractGraalPyMojo.java -35Lines changed: 0 additions & 35 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -72,41 +72,6 @@ public abstract class AbstractGraalPyMojo extends AbstractMojo { | 72 | 72 | private static final String PYTHON_ARTIFACT_ID = "python"; | 73 | 73 | private static final String GRAALPY_MAVEN_PLUGIN_ARTIFACT_ID = "graalpy-maven-plugin"; | 74 | 74 |
| 75 | | - protected static final String LOCK_FILE_HEADER = """ | 76 | | - This file was generated by maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | 77 | | -
| 78 | | - WARNING: Any manual changes are done at your own risk and will be overwritten when the goal is executed. | 79 | | -
| 80 | | - This file is meant to be tracked in a version control system. | 81 | | -
| 82 | | - This file contains a list of all required Python packages with their specific versions, | 83 | | - based on the packages defined in the plugin configuration and their dependencies. | 84 | | - """; | 85 | | - | 86 | | - protected static final String MISSING_LOCK_FILE_WARNING = """ | 87 | | - | 88 | | - The list of installed Python packages does not match the packages specified in the graalpy-maven-plugin configuration. | 89 | | - This could indicate that either extra dependencies were installed or some packages were installed with a more specific versions than declared. | 90 | | - | 91 | | - In such cases, it is strongly recommended to lock the Python dependencies by executing the Maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | 92 | | - | 93 | | - For more details on managing Python dependencies, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools#Python-Dependency-Management | 94 | | - | 95 | | - """; | 96 | | - | 97 | | - protected static final String PACKAGES_CHANGED_ERROR = """ | 98 | | - Install of python packages is based on lock file %s, | 99 | | - but packages and their version constraints in graalpy-maven-plugin configuration are different then previously used to generate the lock file. | 100 | | - | 101 | | - Packages currently declared in graalpy-maven-plugin configuration: %s | 102 | | - Packages which were used to generate the lock file: %s | 103 | | - | 104 | | - The lock file has to be refreshed by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | 105 | | - | 106 | | - For more information, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools#Python-Dependency-Management | 107 | | - | 108 | | - """; | 109 | | - | 110 | 75 | @Parameter(defaultValue = "${project}", required = true, readonly = true) | 111 | 76 | MavenProject project; | 112 | 77 |
| |
Collapse file Copy file name to clipboardExpand all lines: graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/InstallPackagesMojo.java +31-2Lines changed: 31 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 45 | 45 | import org.apache.maven.plugins.annotations.Mojo; | 46 | 46 | import org.apache.maven.plugins.annotations.ResolutionScope; | 47 | 47 | import org.graalvm.python.embedding.tools.vfs.VFSUtils; | | 48 | +import org.graalvm.python.embedding.tools.vfs.VFSUtils.PackagesChangedException; | 48 | 49 |
| 49 | 50 | import java.io.IOException; | 50 | 51 | import java.nio.file.Path; | | 54 | 55 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) | 55 | 56 | public class InstallPackagesMojo extends AbstractGraalPyMojo { | 56 | 57 |
| | 58 | + private static final String PACKAGES_CHANGED_ERROR = """ | | 59 | + | | 60 | + Install of python packages is based on lock file %s, | | 61 | + but packages and their version constraints in graalpy-maven-plugin configuration are different then previously used to generate the lock file. | | 62 | + | | 63 | + Packages currently declared in graalpy-maven-plugin configuration: %s | | 64 | + Packages which were used to generate the lock file: %s | | 65 | + | | 66 | + The lock file has to be refreshed by running the maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | | 67 | + | | 68 | + For more information, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools#Python-Dependency-Management | | 69 | + """; | | 70 | + | | 71 | + protected static final String MISSING_LOCK_FILE_WARNING = """ | | 72 | + | | 73 | + The list of installed Python packages does not match the packages specified in the graalpy-maven-plugin configuration. | | 74 | + This could indicate that either extra dependencies were installed or some packages were installed with a more specific versions than declared. | | 75 | + | | 76 | + In such cases, it is strongly recommended to lock the Python dependencies by executing the Maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | | 77 | + | | 78 | + For more details on managing Python dependencies, please refer to https://www.graalvm.org/latest/reference-manual/python/Embedding-Build-Tools#Python-Dependency-Management | | 79 | + | | 80 | + """; | | 81 | + | 57 | 82 | public void execute() throws MojoExecutionException { | 58 | 83 | preExec(true); | 59 | 84 |
| @@ -67,9 +92,13 @@ public void execute() throws MojoExecutionException { | 67 | 92 | private void manageVenv() throws MojoExecutionException { | 68 | 93 | Path venvDirectory = getVenvDirectory(); | 69 | 94 | MavenDelegateLog log = new MavenDelegateLog(getLog()); | 70 | | - Path requirements = getLockFile(); | | 95 | + Path lockFile = getLockFile(); | 71 | 96 | try { | 72 | | - VFSUtils.createVenv(venvDirectory, packages, requirements, PACKAGES_CHANGED_ERROR, MISSING_LOCK_FILE_WARNING, createLauncher(), getGraalPyVersion(project), log); | | 97 | + VFSUtils.createVenv(venvDirectory, packages, lockFile, MISSING_LOCK_FILE_WARNING, createLauncher(), getGraalPyVersion(project), log); | | 98 | + } catch(PackagesChangedException pce) { | | 99 | + String pluginPkgsString = pce.getPluginPackages().isEmpty() ? "None" : String.join(", ", pce.getPluginPackages()); | | 100 | + String lockFilePkgsString = pce.getLockFilePackages().isEmpty() ? "None" : String.join(", ", pce.getLockFilePackages()); | | 101 | + throw new MojoExecutionException(String.format(PACKAGES_CHANGED_ERROR, lockFile, pluginPkgsString, lockFilePkgsString)); | 73 | 102 | } catch (IOException e) { | 74 | 103 | throw new MojoExecutionException(String.format("failed to create venv %s", venvDirectory), e); | 75 | 104 | } | |
Collapse file Copy file name to clipboardExpand all lines: graalpython/graalpy-maven-plugin/src/main/java/org/graalvm/python/maven/plugin/LockPackagesMojo.java +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 55 | 55 | requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME) | 56 | 56 | public class LockPackagesMojo extends AbstractGraalPyMojo { | 57 | 57 |
| | 58 | + protected static final String LOCK_FILE_HEADER = """ | | 59 | + This file was generated by maven goal 'org.graalvm.python:graalpy-maven-plugin:lock-packages'. | | 60 | +
| | 61 | + WARNING: Any manual changes are done at your own risk and will be overwritten when the goal is executed. | | 62 | +
| | 63 | + This file is meant to be tracked in a version control system. | | 64 | +
| | 65 | + This file contains a list of all required Python packages with their specific versions, | | 66 | + based on the packages defined in the plugin configuration and their dependencies. | | 67 | + """; | | 68 | + | 58 | 69 | public void execute() throws MojoExecutionException { | 59 | 70 | preExec(false); | 60 | 71 | checkEmptyPackages(); | |
|