Hi, I'm wondering how I can work with 3rd-party ex...
# general
h
Hi, I'm wondering how I can work with 3rd-party executable modules within the sandbox. I have a package added to my
pyproject.toml
called
project-dbdumper
which is a command line executable called
dbdumper
. I have a session scoped fixture that will restore the dump before tests start using
subprocess.call(dbdumper --database X --dump Y)
For all my test BUILD files, I have added the package as a dependency:
Copy code
dependencies=[
    "//:root#project-dbdumper",
    ....
]
I have two questions: • If I just execute
pants test ::
it will not find the
dbdumper
executable, and fail. How can I reference the dependency within the sandbox? • If I source the exported pants
.venv
before executing
pants test ::
my
PATH
contains
PATH=.venv/bin
and the tests will find the exectuable
dbdumper
. But I find this behavior strange. How can it be hermetic if it honors the current
PATH
set for the user when executing
pants test ::
am I missing something?
āœ… 1
I see that the
pyest_runner.pex_pex_shim.sh
in the sandbox sets a
virtualenv
variable inside the script
venv_dir="$(adjust_relative_paths .cache/pex_root/venvs/.....)"
which is where the
dbdumper
bin files is located, but I cannot see that it exports this path for usage.
And after som thinking I realized that this is actually a monorepo, so I added the
project-dbdumper
to the repository, created a
pex_binary
target, and added it as a
runtime_package_dependencies
for my
python_tests
and it works perfectly! Woo! I can then reference the local pex in my fixture like this:
./dbdumper.pex ...
.
šŸ™Œ 1
c
Is your
project-dbdumper
a executable (packagable) target? if so take a look at https://www.pantsbuild.org/docs/reference-python_tests#coderuntime_package_dependenciescode Ah, yes, you found out, great! šŸ˜„
ā¤ļø 1