proud-dentist-22844
09/11/2024, 2:12 AMpython_test
target needs the git metadata? I don't see any fields that obviously enable that...
Background: The repo that has pants.toml
includes a git submodule specifically for this test, as the code under test basically runs git worktree
on that git submodule to make it accessible from a tmp directory. The test runs several permutations of that using various tags in that submodule's git repo. So, now I need a way to make git metadata available in the pants-built pytest sandbox.broad-processor-92400
09/11/2024, 3:12 AMtest
, if applicable) consult this field." so nevermind.
Wild idea: have the test work with the submodule directly, something like:
1. pull the whole submodule git directory into the sandbox with files()
or similar (and appropriate de-ignoring of its .git
etc.)
2. invoke git
commands within the submodule directly
Dno if that's at all possible or sensbleelegant-florist-94385
09/11/2024, 9:50 AMsrc/test/integration
, that I could run locally (after bringing up a docker compose stack), I also wanted to be able to create a pex containing everything in src/test/integration
recursively, so I could copy it into a docker image and run the tests not just locally, but also inside our application docker image to verify environment setup and inter container networking kinds of stuff.
Overall, it was quite a bit of a pain, but I made it work by having a "glob-everything-target" like python_sources(sources="***/**.py")
that could be used as a dependency for the pex. I had to do a bunch of explicit dependency ignoring in the "glob-everything-target" and in the regular, per-directory target generators so that they wouldn't get in each other's way and see multiple targets owning the same files.
(Not exactly a solution, but maybe my anecdote helps you along) 🤞curved-manchester-66006
09/11/2024, 1:03 PMproud-dentist-22844
09/11/2024, 10:17 PMresources(sources=[".git/modules/**"])
since .git
is ignored. Adding !.git/modules/
to pants_ignrore.add
didn't work either.proud-dentist-22844
09/12/2024, 12:36 AMexperimental_workspace_environment
+ system_binary(binary_name="true")
+ adhoc_tool(output_directories=[".git/modules"]
to try and get the .git/modules
directory as a digest that can be materialized in a sandbox.
But that didn't work. I can capture .gitmodules
, but I can't capture anything in .git/
. So, it seems that output collection or digest creation filters the files based on pants_ignore 😞proud-dentist-22844
09/12/2024, 2:33 AM.git/
directory is not present in any of the .gitignore
files or in pants_ignore
(as verified by pants help PANTS_IGNORE
).
Even git check-ignore .git/
says that .git itself is not ignored. So, there must be something other than pants_ignore
that is excluding .git
from output digests.proud-dentist-22844
09/12/2024, 6:08 PM.git/modules
copied into a sandbox!
The key insight is that experimental_workspace_environment
STILL HAS a temporary sandbox directory, even though it is running in the workspace. The output files/dirs are captured from that sandbox directory, not from the workspace.
So, both methods use experimental_workspace_environment(name="in_repo")
and then:
1. system_binary(binary_name="cp")
+ adhoc_tool(environment="in_repo", runnable=":cp", args=["-r", ".git/modules", "{chroot}/.git"], output_directories=[".git/modules"])
2. shell_command(environment="in_repo", command="cp -r .git/modules {chroot}/.git", output_directories=[".git/modules"])
.
I updated my gist, so you can see both methods in the revisions with shell_command
in the latest revision. https://gist.github.com/cognifloyd/ff9a43fc54971233384acff50c262088/revisionsproud-dentist-22844
09/12/2024, 6:10 PMrun_shell_command
would not work, because it cannot capture output. But workspace_environment + shell_command seems fairly clean. 🙂
One thing that makes using cp
on .git/modules
is that the submodule is extremely small at around 200K for the .git/modules directory. For a large repo, it might not be wise to copy the entire .git
directory without serious performance penalties.curved-manchester-66006
09/12/2024, 8:16 PMproud-dentist-22844
09/12/2024, 8:37 PMopen()
to grab all the files and put them in a digest since I thought they were getting filtered out somewhere else...
So, I'm happy with how succinct this solution is 😛 Terrifying and cringy, sure, but its purpose is hopefully clear within the BUILD files.proud-dentist-22844
09/13/2024, 4:16 AM.gitmodules
stored the commit sha of the submodules, but no. That's a file at the location of the git module that gets replaced by a directory with the cloned submodule repo. Sad, but oh well.