如何从Maven运行python代码,其中python可能在路径中,也可能不在路径中

2024-04-25 04:28:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从我的Maven模块运行一些Python单元测试。我有一个设置与执行插件工作,但我遇到了一个障碍。如果Python不在路径中,则失败。理想情况下,我希望有一种方法来修改运行时路径并向其添加已知良好的提示,但在运行时路径中找到它。在

这是我的exec插件设置

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
        <execution>
            <configuration>
                <executable>python</executable>
                <workingDirectory>src/main/config/bus/pythonlib</workingDirectory>
                <arguments>
                  <argument>run_all_tests.py</argument>
                </arguments>
            </configuration>
            <id>python-test</id>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Maven有更好的方法吗?有没有办法用变量代替python可执行文件,或者修改路径?在


Tags: 方法路径插件argumentpluginargumentsconfigurationexec
1条回答
网友
1楼 · 发布于 2024-04-25 04:28:59

到目前为止,我想出的唯一方法就是创建一个Python.bat在运行路径之前将提示添加到路径的工作目录中的文件。如果python在路径中,它会找到它并执行它,否则它会找到bat脚本,然后用修改后的路径尝试它。在

一个黑客,但它是有效的,你把提示放在一个PYTHON_hints环境变量中

@echo off
rem Work around for developers whose setup does not have python in their path.
setlocal
set PATH=%PATH%;%PYTHON_HINTS%
python.exe %1 %2 %3 %4 %5 %6 %7 %8 %9

相关问题 更多 >