-
-
Notifications
You must be signed in to change notification settings - Fork 307
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
Prevent matching bogus parent gitignores #1643
base: master
Are you sure you want to change the base?
Conversation
3e12180
to
891d20a
Compare
891d20a
to
10d2308
Compare
@ofek Think you could take a look at this? |
FYI tests on master are currently broken same as here so I don't think this is introducing any regressions. |
Hi there, I just spent some time on trying to fix my project not to produce empty wheels until I stumbled over this issue. Why I am writing here is because it was surprising me that such simple condition (at least as appearing to me) like "do not cross project root when scanning for certain files" really is a concern here. My first thought was: Wouldn't it be enough to simply stop scanning upwards the file tree when we encounter a Markus |
Technically that would also prevent the issue I was seeing...however that would differ from git's normal gitignore behavior so it may not be desirable.
If the python project root is in a subdirectory of a git project root directory it's possible that someone may want to use the gitignore above the python project root subdirectory but within the git project root directory to ignore specific files, so there may be a use case here for wanting to try and replicate git's behavior more closely. The logic of this check as I implemented it should only filter out the use of gitignore in cases where the python project root directory is itself entirely ignored(a case where it is effectively guaranteed that the python project is not tracked by git at all), while still allowing for files within the project root directory to be ignored if needed using gitignores above the project root. |
I see that there are valid use cases for having a relevant In my case, the situation was a bit special, since the python project I was working on was completely unrelated to any VCS. It was just a random project sitting in my user's home. Ages ago, I decided (and almost forgot about) to put some of the config files in my home under version control with git (literally making my whole home a git repo). Now, to not have random stuff under version control, I used kind of inverse git-ignore logic with a
I absolutely admit that this is a very rare case, and I also know that there are better/other ways today to manage user configuration. I just wanted to point out that there might be use cases that involve What if in some completely unrelated
I assume this still would break things. What would have helped me a lot to spot the issue in a straighter fashion:
|
This is designed to handle cases like that, it's designed for really any case where the project root is itself ignored. Does it not work for you?
I mean, that's effectively what this was designed for, in my case I have a fully ignored python project root build directory inside a meta build system.
Yeah, it's not very obvious, so much so that this sort of behavior of matching bogus parent gitignore files was even independently re-implemented in virtually every newer pep517 build backend in some form or another. I managed to fix most of them already but hatch and flit(but not flit-core so there's much less real world issues for downstream integrators) AFAIU are the only ones remaining with fixes pending for this type of bug.
If the project root is ignored then this change should disable the use of |
Up to know, I just assumed that it would work 🙂. But to confirm that, I ran a quick test by installing your version directly from git inside a virtualenv.
As you can see, there are no package files contained in the wheel (there should be a package named If I either remove my
in
It looks like your fix indeed does not work for my case. Did I miss something? |
Hmm, try with |
I think this is your issue, you forgot to actually install my change from this PR, the change is part of the I tried replicating your environment and it seems that was the issue, also I'm not sure which Currently doesn't work:
Works:
|
Thanks for testing with respect to my setup. I fixed my test environment and now have:
I installed in editable mode from a local working copy in order to be able to quickly switch branches. Hereby I can confirm:
I verified that none of the both calls above works when running from I investigated a bit more what code actually runs when using
In my estimation, using |
Ok, it took me a while, but here are my findings. The reason why I did not dig deeper into the code of As a test, I forcibly installed your patched version of As a conclusion:
Update: Just after writing this, I found the following way to make Set the following in your [build-system]
requires = ["hatchling @ file:///path/to/your/local/hatch/backend"]
build-backend = "hatchling.build" |
If our project root directory is matched by an exclude pattern we should assume the pattern is invalid as our project root is likely in an ignored build directory of another project.
10d2308
to
253a549
Compare
rebased |
If our project root directory is matched by an exclude pattern we should assume the pattern is invalid as our project root is likely in an ignored build directory of another project.
Should fix: #1641
This is essentially a port of the same technique I used to fix a similar poetry core bug.