Hi. I need a folder at the top level of my package...
# general
f
Hi. I need a folder at the top level of my package to be included despite containing no python code. I've tried using files and resources, however these have their scope limited to the folder of the BUILd they are declared in. I have code that needs to extract the git hash for the repo, and therefore needs the .git to be present in the sandbox. Any advice? Details in the thread.
folder structure:
Copy code
project/
- .git/
- code/
-- get_hash.py
- tests/
-- test_get_hash.py
I've tried putting the files or resources into the python_sources at project/BUILD but it doesn't seem to be doing anything when i run the tests. The tests fail as there is no .git folder.
Copy code
python_sources(
    name="root",
    dependencies=[":git_folder"],
)

files(
    name="git_folder",
    sources=[".git:"],
)
I get this warning:
Copy code
10:28:29.58 [WARN] Unmatched glob from //:git_folder's `sources` field: ".git/:"

Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to <https://www.pantsbuild.org/v2.16/docs/troubleshooting#pants-cannot-find-a-file-in-your-project>.
However i've explicitly set .git to be included and ensure it's not ignored by pants.
Copy code
[GLOBAL]
pants_version = "2.16.0"
pants_ignore=[
  "/dist/",
  "__pycache__",
  "!.git"
]
perhaps because there are no .py files in there?
f
You should use a recursive file globs for
sources
field and not the target-like syntax which you were using. For example:
Copy code
files(
    name="git_folder",
    sources=[".git/**"],
)
I.e.,
.git/**
versus
.git:
The first is a file glob; the second might be a target address (if there happened to be a BUILD file in that
.git
directory)
f
even with an explicit file it wasn't working though. I tried just getting one file in there e.g. .git/config and that wasn't pulled in.
f
Have you checked the pants-ignore setting?
f
Copy code
pants_ignore_use_gitignore = false
pants_ignore=[
  "/dist/",
  "__pycache__",
  "!.git"
]
f
yeah, the setting above is from that page
any other ideas on how to include non-python files from outside the same folder as BUILD but in the project folder?
g
It sounds like maybe
vcs_version
could be helpful for you? https://www.pantsbuild.org/docs/generating-version-tags
f
Thanks it would be if i just needed the git hash. I actually need the code to extract more information than just the githash and so couldn't use vcs_version as a replacement. But a good suggestion if i only needed the git hash/
Sorry, i still haven't found a way to include files in the sandbox that exist in a directory structure above the code that depends on it. I.e. how to define dependency above the BUILD file where it is used. Any ideas?