Using .git to search for the project root only works in repos that have a .git folder present.
|
def _get_repo_root(): |
|
""" Returns the root folder of the project. """ |
|
# Get root of this repository. Assume we don't have directories nested deeper than 10 items. |
|
p = Path(os.getcwd()) |
|
for i in range(10): |
|
if p is None: |
|
break |
|
if Path(p / ".git").exists(): |
|
return str(p) |
|
p = p.parent |
|
raise Exception("Unable to detect repository root.") |
But many of our repos don't have a .git folder at the project root level, including:
Using .gitignore is probably better.
TL;DR - I came across this problem when using Cloud Build for python-pubsublite samples testing. Cloud Build copies all the files in a repo to a folder named workspace/. When I cd into samples/snippets/ and do pip install -e .., I keep getting an error that says "Unable to detect repository root".
Using
.gitto search for the project root only works in repos that have a.gitfolder present.synthtool/synthtool/gcp/templates/python_samples/noxfile.py.j2
Lines 195 to 205 in 487eba7
But many of our repos don't have a
.gitfolder at the project root level, including:Using
.gitignoreis probably better.TL;DR - I came across this problem when using Cloud Build for
python-pubsublitesamples testing. Cloud Build copies all the files in a repo to a folder namedworkspace/. When Icdintosamples/snippets/and dopip install -e .., I keep getting an error that says "Unable to detect repository root".