kind-dusk-88649
01/16/2025, 7:11 PMfrom pathlib import Path
from git import Repo
def get_repo_path() -> Path:
repo = Repo(".", search_parent_directories=True)
return Path(repo.git.rev_parse("--show-toplevel"))
I have not gotten this to work in pants (probably missing .git/HEAD) and have not been able to fix it. Is there a recommended way of getting repo path when using pants?happy-kitchen-89482
01/17/2025, 2:24 AMhappy-kitchen-89482
01/17/2025, 2:24 AMkind-dusk-88649
01/17/2025, 2:38 AMfrom somewhere import get_repo_path
def test_readme_exist_at_root() -> None:
assert (
get_repo_path() / "README.md"
).exists(), "README.md not found at root of repository"
Which is part of a python_test target. I then run:
pants test ::
This fails, and I believe since the git files are not included in the sandbox, it cannot find root. I have tried to fix this but I realized that this is probably a common thing to do, there might be a better way to do this?happy-kitchen-89482
01/17/2025, 5:54 AMhappy-kitchen-89482
01/17/2025, 5:54 AMhappy-kitchen-89482
01/17/2025, 5:55 AMhappy-kitchen-89482
01/17/2025, 5:55 AMacceptable-balloon-2043
01/17/2025, 11:08 AM.git
folder and add it as a manual dependency on get_repo_path()
module if the code expects some notion of the real history beside the file pathhappy-kitchen-89482
01/18/2025, 12:18 AMhappy-kitchen-89482
01/18/2025, 12:19 AMhappy-kitchen-89482
01/18/2025, 12:19 AMkind-dusk-88649
01/18/2025, 12:59 AMhappy-kitchen-89482
01/18/2025, 2:27 AMkind-dusk-88649
01/18/2025, 3:23 AMPath(__file__)
for now.happy-kitchen-89482
01/19/2025, 1:31 AM