Using %TAP_PATH% in package action steps

I’d like my OpenTAP package to install Python dependencies specified in a requirements.txt file within the install action. I’m currently using Windows.

The following works fine:

    <ActionStep ExeFile="pip" Arguments='install -r "C:\Program Files\OpenTAP\Packages\Python\my_plugin_name\requirements.txt"' ActionName="install" />

However, when I use "%TAP_PATH%\Packages\Python\my_plugin_name\requirements.txt" instead of hardcoding the path, I’m getting the following error:

13:23:05.582 Plugin ERROR: Could not open requirements file: [Errno 2] No such file or directory: '%TAP_PATH%\\Packages\\Python\\my_plugin_name\\requirements.txt'

Using pip install -r "%TAP_PATH%\Packages\Python\my_plugin_name\requirements.txt" from cmd line doesn’t cause any issues.

I also tried a few more things:

… but nothing seems to work except for the full hardcoded path. Am I missing something?

It should work using a relative path, since package install actions are always executed from the directory containing the tap executable. Did you try Packages/Python/my_plugin_name/requirements.txt ? If that doesn’t work I would call it a bug.

And I should add that environment variables are never expanded in ActionStep elements, so %TAP_PATH% / $TAP_PATH will be treated as a literal string

Thanks for the clarification about the env variables in action steps.

Regarding the relative path, I’ve already tried that as documentation suggests this way indeed. It causes a similar error: 14:19:54.191 Plugin ERROR: Could not open requirements file: [Errno 2] No such file or directory: 'Packages/Python/my_plugin_name/requirements.txt'

I just created a small example package to test this, and it seems to work fine for me:

<?xml version="1.0" encoding="UTF-8"?>
<Package Name="MyPythonPlugin" xmlns="" InfoLink="" Version="0.1.0-alpha" OS="Windows,Linux">
    <Description>This is my OpenTAP plugin package.</Description>
        <File Path="Packages/Python/MyPlugin/requirements.txt" SourcePath="requirements.txt"/>
        <ActionStep ExeFile="pip" Arguments="install -r Packages/Python/MyPlugin/requirements.txt" ActionName="install"></ActionStep>

Can you share your package.xml file?

1 Like

Looking at your example I was able to spot the difference: you added the requirements.txt explicitly whereas I forgot. I was not getting errors when using the full path because the file was present in this folder due to a directory junction from my source code. My guess it was not taken into account by Package manager as it was not “owning” it.

Thanks for your help!

1 Like

Great, I’m glad you worked it out.

Happy tapping!