loud-laptop-89838
12/09/2022, 6:03 PM.env
file, but hardcoding the file into a BUILD
file doesn't work well since .env
isn't tracked in version control, so CI tests throw warnings. I'm wondering whether a better approach is a plugin that explicitly loads the .env
variables as environment variables for the test, then run that plugin as a command line argument to test? That way I could run it locally, but not include it in CI.
Two things I'm wondering about:
1. would this approach work? I know tests are "hermetic", so would building a plugin that loads the variables work?
2. Can you "stack" targets; e.g. call the .env
plugin prior to test so that they work together?enough-analyst-54434
12/09/2022, 6:14 PM.pants.bootstrap
is a hidden thing. That can be arbitrary bash, but should really just stick to setting env vars../pants
and it supports that but also loads .env
.pants.bootstrap
tides you over?[subprocess-environment] env_vars
,python_tests.extra_env_vars
etc.busy-vase-39202
12/09/2022, 6:42 PMloud-laptop-89838
12/09/2022, 7:16 PMpants.bootstrap
and in it I put, for example HOSTNAME=localhost
, then in pants.toml I have
[test]
extra_env_vars = ["HOSTNAME"]
Now my tests should have $HOSTNAME
available as an environment variable?enough-analyst-54434
12/09/2022, 7:20 PM.pants.bootstrap
- leading dot.pants
bash script to a `scie-pants`native binary to support. The .env
support should cover most cases and that should be documented once it lands but I'd hope we can wean away from `.pants.bootstrap`once the GIT_COMMIT case is solved.loud-laptop-89838
12/09/2022, 7:24 PM.pants.bootstrap
and I have the variable defined in the pants.toml. But when I run the test in python os.environ["HOSTNAME"]
throws a key error because it can't find the environment variableenough-analyst-54434
12/09/2022, 7:25 PMloud-laptop-89838
12/09/2022, 7:29 PMextra_env_vars
as just an array of strings, which match the values set in the bootstrap fileenough-analyst-54434
12/09/2022, 7:30 PMloud-laptop-89838
12/09/2022, 7:31 PMextra_env_vars=["HOSTNAME=123"]
that should add the env var to the test right?enough-analyst-54434
12/09/2022, 7:32 PMpex_binary
and then use it in integration tests:
and$ cat tools/tests/BUILD
python_test_utils(
name="test_utils",
)
python_tests(
runtime_package_dependencies=[
"//tools"
],
extra_env_vars=[
"TOOLS_PEX=tools/tools.pex",
],
)
loud-laptop-89838
12/09/2022, 7:34 PMos.environ
when it fails and it shows HOSTNAME=123enough-analyst-54434
12/09/2022, 7:35 PMloud-laptop-89838
12/09/2022, 7:35 PMenough-analyst-54434
12/09/2022, 7:35 PMloud-laptop-89838
12/09/2022, 7:35 PMenough-analyst-54434
12/09/2022, 7:35 PMloud-laptop-89838
12/09/2022, 7:36 PMenough-analyst-54434
12/09/2022, 7:37 PM[test]
extra_env_vars = ["HOSTNAME=%(env.HOSTNAME)s"]
loud-laptop-89838
12/09/2022, 7:38 PMexport
at the start of the lines in bootstrap. I just copied from .env.enough-analyst-54434
12/09/2022, 7:38 PMloud-laptop-89838
12/09/2022, 7:39 PMenough-analyst-54434
12/09/2022, 7:39 PMloud-laptop-89838
12/09/2022, 7:39 PMenough-analyst-54434
12/09/2022, 7:51 PM./pants
replacement thing? That'll be a new pantsbuild/scie-pants repo later today. I'd just like to finish the new update capability ~ SCIE_BOOT=update-scie-pants pants
to self-update the new "pants" script, which will just be a scie-pants
binary anywhere on your PATH
. I'm afraid without the update capability folks will start using it and then not get fixes for this very new thing easily if there are issues.loud-laptop-89838
12/09/2022, 8:07 PMenough-analyst-54434
12/09/2022, 8:52 PMscie-pants
./pants
replacement experiment is ready for testing. If you're interested in trying it out and providing feedback, please give this a read: https://github.com/pantsbuild/scie-pants/blob/main/README.md
In short, download scie-pants
, mark it executable, put it on your PATH and use scie-pants
instead of ./pants
.
Thanks in advance for your testing and feedback.wide-midnight-78598
12/20/2022, 1:31 AMIf you runSuch a "small" thing, but SUCH a huge quality of life improvementin a directory where Pants is not already set up, it will prompt you, and you can let it set up the latest Pants stable version for your project.scie-pants
enough-analyst-54434
12/20/2022, 2:12 AMloud-laptop-89838
12/20/2022, 1:38 PMscie-pants
. Does this mean for all python projects as well? Or just the pants internals? Ie how does this interact with, eg pyenv
?wide-midnight-78598
12/20/2022, 1:44 PMPython 3.7, 3.8, or 3.9 discoverable on yourHere's a long-running tracking issue: https://github.com/pantsbuild/pants/issues/7369PATH
loud-laptop-89838
12/20/2022, 1:47 PMtest
for example on a python project? I would still need a python interpreter for my project. It's just that pants has one for it's own internals.wide-midnight-78598
12/20/2022, 1:54 PMscie-pants
doesn't care, as it'll just grab it again).loud-laptop-89838
12/20/2022, 1:56 PMwide-midnight-78598
12/20/2022, 1:56 PMgoal
, like ./pants package xyz
scie
plugin for packaging.
https://github.com/pantsbuild/pants/compare/main...sureshjoshi:pants:scie-jump
However, in thinking about it, on this hypothetical "blank" system, you still need an interpreter to run your ./pants tests ::
So, yeah, in summary - I'm guessing you'll need the correct system python (or pyenv
or whatever), unless we start to download standalone interpreters to run user's interpreter_constraints
🤯loud-laptop-89838
12/20/2022, 2:08 PMpyenv
as a backend. Then you could just get whatever the user specifies as a constraint and easily manage any number of different version constraints in the monorepo. Not saying I want to do it 😆 but maybe sometime in the future. In the meantime I'm just looking forward to testing this!wide-midnight-78598
12/20/2022, 2:10 PMscie-pants
today - I've been using it since yesterdayenough-analyst-54434
12/20/2022, 3:04 PMloud-laptop-89838
12/20/2022, 5:15 PMenough-analyst-54434
12/20/2022, 5:20 PMscie-pants init
and the scie-pants
part of that would see you don't have a pants.toml
and it would set that up, which would launch pants, which would interpret the init
goal and run that to further initialize the setup. Etc. So scie-pants got out of the way quick there and delegated everything fancy to the Pants init
goal - a full fledged goal with rules and all the fancy complicated logic..env
support. Now available in 0.2.0: https://github.com/pantsbuild/scie-pants/releases/tag/v0.2.0