-
Notifications
You must be signed in to change notification settings - Fork 5
feat: requirements.txt support for maven plugin #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
2e03393
9d151f5
9df0778
7f123dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,8 +64,50 @@ public class LockPackagesMojo extends AbstractGraalPyMojo { | |
| This file contains a list of all required Python packages with their specific versions, | ||
| based on the packages defined in the plugin configuration and their dependencies. | ||
| """; | ||
|
|
||
| @Inject | ||
| public static final String MISSING_DEPENDENCY_CONFIGURATION_ERROR = """ | ||
| In order to run the lock-packages goal you must declare Python dependencies in the graalpy-maven-plugin configuration. | ||
|
|
||
| You must configure Python dependencies in one of the following ways: | ||
|
|
||
| Option 1: Use <packages> with inline versioned package entries: | ||
|
|
||
| <plugin> | ||
| <groupId>org.graalvm.python</groupId> | ||
| <artifactId>graalpy-maven-plugin</artifactId> | ||
| <configuration> | ||
| <packages> | ||
| <package>{package_name}=={package_version}</package> | ||
| </packages> | ||
| ... | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| Option 2: Use a pip-compatible requirements.txt file: | ||
|
|
||
| <plugin> | ||
| <groupId>org.graalvm.python</groupId> | ||
| <artifactId>graalpy-maven-plugin</artifactId> | ||
| <configuration> | ||
| <requirementsFile>requirements.txt</requirementsFile> | ||
| ... | ||
| </configuration> | ||
| </plugin> | ||
|
|
||
| IMPORTANT: | ||
| • The requirementsFile workflow follows pip's native behavior. | ||
| • GraalPy lock files are NOT used or generated when requirementsFile is specified. | ||
| • The 'lock-packages' goal is NOT supported with <requirementsFile>. | ||
| • Users are expected to manage locking / freezing themselves using pip conventions (e.g., pip freeze). | ||
| • Do not define both <packages> and <requirementsFile> at the same time. | ||
| • The <configuration> section must be declared on the graalpy-maven-plugin itself, | ||
| not inside a specific execution. | ||
|
|
||
| For more details, see: | ||
| https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md | ||
| """; | ||
ih0r-d marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @Inject | ||
| public LockPackagesMojo(ProjectBuilder projectBuilder) { | ||
| super(projectBuilder); | ||
| } | ||
|
|
@@ -93,33 +135,15 @@ protected void manageVenv() throws MojoExecutionException { | |
| } | ||
| } | ||
|
|
||
| private void checkEmptyPackages() throws MojoExecutionException { | ||
| if ((packages == null || packages.isEmpty())) { | ||
| getLog().error(""); | ||
| getLog().error( | ||
| "In order to run the lock-packages goal there have to be python packages declared in the graalpy-maven-plugin configuration."); | ||
| getLog().error(""); | ||
| getLog().error( | ||
| "NOTE that the <configuration> section has to be declared for the whole graalpy-maven-plugin"); | ||
| getLog().error("and not specifically for the process-graalpy-resources execution goal."); | ||
| getLog().error(""); | ||
| getLog().error("Please add the <packages> section to your configuration as follows:"); | ||
| getLog().error("<plugin>"); | ||
| getLog().error(" <groupId>org.graalvm.python</groupId>"); | ||
| getLog().error(" <artifactId>graalpy-maven-plugin</artifactId>"); | ||
| getLog().error(" <configuration>"); | ||
| getLog().error(" <packages>"); | ||
| getLog().error(" <package>{package_name}=={package_version}</package>"); | ||
| getLog().error(" </packages>"); | ||
| getLog().error(" ..."); | ||
| getLog().error(" </configuration>"); | ||
| getLog().error(""); | ||
|
|
||
| getLog().error( | ||
| "For more information, please refer to https://github.com/oracle/graalpython/blob/master/docs/user/Embedding-Build-Tools.md"); | ||
| getLog().error(""); | ||
|
|
||
| throw new MojoExecutionException("missing python packages in plugin configuration"); | ||
| } | ||
| } | ||
| private void checkEmptyPackages() throws MojoExecutionException { | ||
| Path reqFilePath = resolveReqFile(); | ||
| boolean emptyPackages = packages == null || packages.isEmpty(); | ||
| boolean requirementsExists = reqFilePath != null; | ||
| if (emptyPackages && !requirementsExists) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want to show this error when
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also agree — I’ll try to update the condition today so that the error is shown when either emptyPackages or requirementsExists is true, ensuring this goal is disallowed when a requirements file is present. |
||
| getLog().error(""); | ||
| getLog().error(MISSING_DEPENDENCY_CONFIGURATION_ERROR); | ||
| getLog().error(""); | ||
| throw new MojoExecutionException("Missing Python dependency configuration."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. | ||
| DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
|
|
||
| The Universal Permissive License (UPL), Version 1.0 | ||
|
|
||
| Subject to the condition set forth below, permission is hereby granted to any | ||
| person obtaining a copy of this software, associated documentation and/or | ||
| data (collectively the "Software"), free of charge and under any and all | ||
| copyright rights in the Software, and any and all patent rights owned or | ||
| freely licensable by each licensor hereunder covering either (i) the | ||
| unmodified Software as contributed to or provided by such licensor, or (ii) | ||
| the Larger Works (as defined below), to deal in both | ||
|
|
||
| (a) the Software, and | ||
|
|
||
| (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if | ||
| one is included with the Software each a "Larger Work" to which the Software | ||
| is contributed by such licensors), | ||
|
|
||
| without restriction, including without limitation the rights to copy, create | ||
| derivative works of, display, perform, and distribute the Software and make, | ||
| use, sell, offer for sale, import, export, have made, and have sold the | ||
| Software and the Larger Work(s), and to sublicense the foregoing rights on | ||
| either these or other terms. | ||
|
|
||
| This license is subject to the following condition: | ||
|
|
||
| The above copyright notice and either this complete permission notice or at a | ||
| minimum a reference to the UPL must be included in all copies or substantial | ||
| portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <groupId>org.apache.maven.plugin.my.unit</groupId> | ||
| <artifactId>project-prepare-venv</artifactId> | ||
| <version>1.0-SNAPSHOT</version> | ||
| <packaging>jar</packaging> | ||
| <name>Test MyMojo</name> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <version>3.8.1</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.graalvm.polyglot</groupId> | ||
| <artifactId>python</artifactId> | ||
| <version>${env.GRAALPY_VERSION}</version> | ||
| <type>pom</type> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.graalvm.python</groupId> | ||
| <artifactId>python-launcher</artifactId> | ||
| <version>${env.GRAALPY_VERSION}</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.graalvm.python</groupId> | ||
| <artifactId>graalpy-maven-plugin</artifactId> | ||
| <version>${env.GRAALPY_VERSION}</version> | ||
| <executions> | ||
| <execution> | ||
| <goals> | ||
| <goal>process-graalpy-resources</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| <configuration> | ||
| <requirementsFile>requirements.txt</requirementsFile> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think the fallback to default location is useful? I would find it surprising. I'd just give error if
<requirementsFile>points to a non-existing file.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, agreed. I’ll drop the default fallback and raise an error when requirementsFile points to a non-existing file.