1

I have the following exec commands in my gradle.build file.

exec {
        workingDir System.getProperty("user.dir")
        commandLine 'python3.6', 'buildscript.py'
    }
exec {
    workingDir System.getProperty("user.dir")
    commandLine 'python3.6', '-m', 'virtualenv', 'env'
}


exec {
    workingDir System.getProperty("user.dir")
    commandLine 'source', 'env/bin/activate'
}

exec {
    workingDir System.getProperty("user.dir")
    commandLine 'pip3.6', 'install', 'pybuilder'
}

exec {
    workingDir System.getProperty("user.dir")
    commandLine 'pyb', '-E', 'env', '-X'
}

These are all within a build task that runs when executing gradle build. Theoretically this should run a script I created that creates all of the files necessary for building my python program, it should then create a virtual environment, activate it, install pybuilder to it, and then run pybuilder. However, the command:

exec {
        workingDir System.getProperty("user.dir")
        commandLine 'source', 'env/bin/activate'
    }

Seems to be failing. It claims that the directory/file does not exist despite it working via command line. I'm not sure why this is the case. The whole point of this is to force Pybuilder to install my programs dependencies to the virtual environment I create. pyb -E env should technically be activating the virtual environment for me, but for whatever reason it's not installing my dependencies to that virtual environment. On our Jenkins node this is a problem as we don't want these installed globally, not to mention, I don't have root user privileges anyways.

Any help would be greatly greatly appreciated. If you know of another way to get Pybuilder to work correctly, that would be equally good.

4

3 回答 3

2

临时解决方案:我最终创建了一个小 shell 脚本来创建和激活虚拟环境。然后我从 gradle 执行该脚本。

于 2018-02-27T20:42:03.037 回答
2

调用只是在做 shell 魔术来连接变量sourceactivate你不需要总是打电话activate(在这种情况下可能不能)。相反,您应该在您的pip3.6pyb命令前加上env/bin直接调用二进制文件的前缀。因此,它将是

exec {
   workingDir System.getProperty("user.dir")
   commandLine 'env/bin/pip3.6', 'install', 'pybuilder'
}

exec {
   workingDir System.getProperty("user.dir")
   commandLine 'env/bin/pyb', '-E', 'env', '-X'
}
于 2019-05-22T19:43:32.647 回答
0

首先,您应该像这样创建环境。所以你的环境会创造

exec {
    workingDir System.getProperty("user.dir")
    commandLine 'python', '-m', 'virtualenv', 'env'
}

现在您应该以这种方式激活您的环境并执行命令(例如 PyBuilder)

对于 Windows:

exec {
    workingDir System.getProperty("user.dir")
    commandLine 'cmd','activate','env','&&','pip','install','pybuilder'
}

对于壳牌:

exec {
        workingDir System.getProperty("user.dir")
        commandLine 'source','env/bin/activate','env','&&','pip','install','pybuilder'
    }
于 2022-02-18T13:31:01.377 回答