-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
849 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Do not edit directly! | ||
// This file was generated by camel-quarkus-maven-plugin:update-extension-doc-page | ||
[id="extensions-python"] | ||
= python | ||
:page-aliases: extensions/python.adoc | ||
:linkattrs: | ||
:cq-artifact-id: camel-quarkus-python | ||
:cq-native-supported: true | ||
:cq-status: Stable | ||
:cq-status-deprecation: Stable | ||
:cq-description: Evaluate a Python script | ||
:cq-deprecated: false | ||
:cq-jvm-since: 1.0.0 | ||
:cq-native-since: 3.2.0 | ||
|
||
ifeval::[{doc-show-badges} == true] | ||
[.badges] | ||
[.badge-key]##JVM since##[.badge-supported]##1.0.0## [.badge-key]##Native since##[.badge-supported]##3.2.0## | ||
endif::[] | ||
|
||
Evaluate a python script | ||
|
||
[id="extensions-python-whats-inside"] | ||
== What's inside | ||
|
||
* xref:{cq-camel-components}:languages:python-language.adoc[python language] | ||
|
||
Please refer to the above link for usage and configuration details. | ||
|
||
[id="extensions-python-maven-coordinates"] | ||
== Maven coordinates | ||
|
||
https://{link-quarkus-code-generator}/?extension-search=camel-quarkus-python[Create a new project with this extension on {link-quarkus-code-generator}, window="_blank"] | ||
|
||
Or add the coordinates to your existing project: | ||
|
||
[source,xml] | ||
---- | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-python</artifactId> | ||
</dependency> | ||
---- | ||
ifeval::[{doc-show-user-guide-link} == true] | ||
Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications. | ||
endif::[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<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> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-python-parent</artifactId> | ||
<version>3.14.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-python-deployment</artifactId> | ||
<name>Camel Quarkus :: Python :: Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-core-deployment</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-python</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-support-language-deployment</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${quarkus.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
40 changes: 40 additions & 0 deletions
40
...g/apache/camel/quarkus/component/python/deployment/PythonCompiledExpressionBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.python.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import org.python.core.PyCode; | ||
|
||
public final class PythonCompiledExpressionBuildItem extends MultiBuildItem { | ||
|
||
private final String sourceCode; | ||
|
||
private final PyCode compiledCode; | ||
|
||
public PythonCompiledExpressionBuildItem(String sourceCode, PyCode compiledCode) { | ||
this.sourceCode = sourceCode; | ||
this.compiledCode = compiledCode; | ||
} | ||
|
||
public String getSourceCode() { | ||
return sourceCode; | ||
} | ||
|
||
public PyCode getCompiledCode() { | ||
return compiledCode; | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
...t/src/main/java/org/apache/camel/quarkus/component/python/deployment/PythonProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.python.deployment; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.annotations.ExecutionTime; | ||
import io.quarkus.deployment.annotations.Record; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.deployment.pkg.steps.NativeOrNativeSourcesBuild; | ||
import io.quarkus.runtime.RuntimeValue; | ||
import org.apache.camel.ExpressionIllegalSyntaxException; | ||
import org.apache.camel.language.python.PythonLanguage; | ||
import org.apache.camel.quarkus.component.python.PythonExpressionRecorder; | ||
import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem; | ||
import org.apache.camel.quarkus.support.language.deployment.ExpressionBuildItem; | ||
import org.apache.camel.quarkus.support.language.deployment.ExpressionExtractionResultBuildItem; | ||
import org.apache.camel.quarkus.support.language.deployment.ScriptBuildItem; | ||
import org.python.core.PyCode; | ||
import org.python.util.PythonInterpreter; | ||
|
||
class PythonProcessor { | ||
|
||
private static final String FEATURE = "camel-python"; | ||
|
||
@BuildStep | ||
FeatureBuildItem feature() { | ||
return new FeatureBuildItem(FEATURE); | ||
} | ||
|
||
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) | ||
void compileExpressions(ExpressionExtractionResultBuildItem result, | ||
List<ExpressionBuildItem> expressions, | ||
List<ScriptBuildItem> scripts, | ||
BuildProducer<PythonCompiledExpressionBuildItem> producer) { | ||
if (result.isSuccess()) { | ||
List<ExpressionBuildItem> pythonExpressions = expressions.stream() | ||
.filter(exp -> "python".equals(exp.getLanguage())).toList(); | ||
List<ScriptBuildItem> pythonScripts = scripts.stream() | ||
.filter(exp -> "python".equals(exp.getLanguage())).toList(); | ||
if (pythonExpressions.isEmpty() && pythonScripts.isEmpty()) { | ||
return; | ||
} | ||
|
||
try (PythonInterpreter compiler = new PythonInterpreter()) { | ||
for (ExpressionBuildItem pythonExpression : pythonExpressions) { | ||
producer.produce(createPythonExpressionBuildItem(compiler, pythonExpression.getExpression())); | ||
} | ||
for (ScriptBuildItem pythonScript : pythonScripts) { | ||
producer.produce(createPythonExpressionBuildItem(compiler, pythonScript.getLoadedContent())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Record(ExecutionTime.STATIC_INIT) | ||
@BuildStep(onlyIf = NativeOrNativeSourcesBuild.class) | ||
CamelBeanBuildItem configureLanguage( | ||
PythonExpressionRecorder recorder, | ||
ExpressionExtractionResultBuildItem result, | ||
List<PythonCompiledExpressionBuildItem> sources) { | ||
|
||
if (result.isSuccess() && !sources.isEmpty()) { | ||
RuntimeValue<PythonLanguage.Builder> builder = recorder.languageBuilder(); | ||
for (PythonCompiledExpressionBuildItem source : sources) { | ||
recorder.addScript( | ||
builder, | ||
source.getSourceCode(), | ||
source.getCompiledCode()); | ||
} | ||
final RuntimeValue<PythonLanguage> language = recorder.languageNewInstance(builder); | ||
return new CamelBeanBuildItem("python", PythonLanguage.class.getName(), language); | ||
} | ||
return null; | ||
} | ||
|
||
private PythonCompiledExpressionBuildItem createPythonExpressionBuildItem(PythonInterpreter compiler, String expression) { | ||
PyCode compiledExpression; | ||
try { | ||
compiledExpression = compiler.compile(expression); | ||
} catch (Exception e) { | ||
throw new ExpressionIllegalSyntaxException(expression, e); | ||
} | ||
return new PythonCompiledExpressionBuildItem(expression, compiledExpression); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<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> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-extensions</artifactId> | ||
<version>3.14.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-python-parent</artifactId> | ||
<name>Camel Quarkus :: Python</name> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>deployment</module> | ||
<module>runtime</module> | ||
</modules> | ||
</project> |
Oops, something went wrong.