How to run Python code from Maven where python may or may not be in path

I want to run some Python unit tests from my Maven module. I have a setup with an exec plugin that works, however I ran into a problem. If Python is not in the path, it won't work. Ideally I would like to change the execution path and add a known good hint to it, but otherwise find it in the execution path.

This is my exec plugin setup

<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>

      

Is there a better way to do this from Maven? Is there a way to replace the variable for the python executable or change the path?

+3


source to share


1 answer


The only way I came up with was to create a python.bat file in the working directory which will add hints to the path before running it. If python is in the path it will find it and execute it, otherwise it will find the bat script and then try it with the changed path.

Hack, but it works, you put hints in the PYTHON_HINTS environment variable



@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

      

+3


source







All Articles