Skip to content

_get_repo_root() in noxfile.py can fail when .git does not exist at project root #792

@anguillanneuf

Description

@anguillanneuf

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".

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions