Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
anguillanneuf opened this issue Oct 8, 2020 · 2 comments · Fixed by #795
Closed
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@anguillanneuf
Copy link

anguillanneuf commented Oct 8, 2020

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

@busunkim96
Copy link
Contributor

Does Cloud Build copy the repo instead of cloning the repo? .git is a folder that git itself uses. If you clone a repo it is always in the root. (https://stackoverflow.com/questions/29217859/what-is-the-git-folder) I think that's why it was chosen for the repo root detection code.

I think we could try looking for multiple things. .git and something else that only is in the root. setup.py maybe? Technically a repo can have .gitignores in nested directories.

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Oct 9, 2020
@busunkim96 busunkim96 added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Oct 9, 2020
@anguillanneuf
Copy link
Author

anguillanneuf commented Oct 9, 2020

Indeed they don't include .git: GoogleCloudPlatform/cloud-builders#236
Public bug: https://b.corp.google.com/issues/136435027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants