Search code examples
python-poetry

Get Poetry to create a .bat/.exe file in addition to .cmd


When installing my application for running unit tests (poetry install --with dev), Poetry creates a .cmd file in the Scripts folder (D:\a\locust\locust\.tox\fail_fast_test_main\Scripts\locust.cmd when running in tox, on GH).

However, my tests need to verify the behavior of the installed command, like subprocess.Popen(["locust", ...]

This works fine on Linux, but on windows the PATH is not searched unless I use shell=True (which introduces other issues, particularly on Linux)

If I could get Poetry to make a .bat (or even .exe - on windows there's a bunch of .exe:s for other Python applications in there, which I suppose are just wrappers with a similar purpose as the .cmd), I could call it directly, like D:\a\locust\locust\.tox\fail_fast_test_main\Scripts\locust.bat.

Is there a way to make Poetry generate such a file?

The .cmd file cannot be directly executed (in order to run a .cmd I'd need to run Popen(['cmd', '/c', 'D:\a\locust\locust\.tox\fail_fast_test_main\Scripts\locust.cmd']), which is essentially the same as running shell=True)


Solution

  • My solution ended up being to run a plain pip install .

    On Windows, this places a locust.exe in my Scripts folder and I can run it just fine with subprocess.Popen(["locust"])