-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix issue 7280 - issue warning after retry #7546
Conversation
- Try to delete the temporary directory, as most of the time this works - If it fails on windows due to an Access error, it clearly is not an Access error because we just created the directory. Warn the user and continue.
- Add issue description file
- Provide a class that manages a sub-process which can open a file and monkey with pip's abiliity to remove a file on windows. - This class can function as both a context manager and/or a pytest fixture.
- TempDirectory() tries to delete the directory as normal - if cleanup fails on Windows due to EACCES, warn about virus scanner - This is a more specific error than previous error, but does not change the behavior when a user is attempting to pip uninstall in a system directory - This changes the messaging, but risks leaving the directory behind. - Leaving the directory behind, however, is what is already happening - The fix for pypa#7479 gives the Virus scanner more time to finish its work, but there is still a possibility for a race condition that leaves the impression that there is an error in pip itself.
- IOError persists as an issue in Python 2.7.17 on win32
- TempDirectory() tries to delete the directory as normal - if cleanup fails on Windows due to EACCES, warn about virus scanner - This is a more specific error than previous error, but does not change the behavior when a user is attempting to pip uninstall in a system directory - This changes the messaging, but risks leaving the directory behind. - Leaving the directory behind, however, is what is already happening - The fix for pypa#7479 gives the Virus scanner more time to finish its work, but there is still a possibility for a race condition that leaves the impression that there is an error in pip itself.
@pfmoore @chrahunt, I am completely confused about the appveyor failure. This status response from psutil isn't one of the ones present in psutil statuses, and ignoring by adding something like this didn't seem to show the latest code: latest_children = [child for child in process.children() if child.status() != 'terminated'] It does seem to me to indicate that the exception for a missing file is not properly caught and printed, but I have not been able to reproduce that on my own. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests look great, exactly the kind of thing I was talking about in #7280 (comment)!
A few things:
- Can we limit this PR to only the Windows/Python API tests? That way we can focus on each one piece individually and not block the additional tests on review of the behavior change in TempDirectory.
- Can we add tests involving processes under different users? I think it would be good to try to do it in this PR since I suspect we will need to make some fundamental changes to how we are running the child process in order to accommodate it.
- It's generally good to not put the issue number in your commit titles/messages, otherwise it spams the issue.
# Now path is open and we wait for signal to exit | ||
conn.recv() | ||
finally: | ||
if f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggested change did not work for me, and caused the sub-process or main process to hang. In general, I liked it more that the sub-process was using primitive parts of Python, and was independent of pip's own infrastructure, so I thought I'd raise that as a good thing before we potentially figure out what I did wrong :)
tests/unit/test_utils_filesystem.py
Outdated
@@ -59,3 +70,53 @@ def test_copy2_fixed_raises_appropriate_errors(create, error_type, tmpdir): | |||
copy2_fixed(src, dest) | |||
|
|||
assert not dest.exists() | |||
|
|||
|
|||
def test_file_opener_no_file(process): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These FileOpener
tests would be better in tests/lib/test_filesystem.py
. This file is really for tests of functionality in pip/_internal/utils/filesystem.py
.
tests/unit/test_utils_filesystem.py
Outdated
|
||
|
||
@skip_unless_windows | ||
def test_file_opener_produces_unlink_error(tmpdir, process): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these tests are more against Python/Windows than anything in pip/_internal/utils/filesystem.py
, I would put them in tests/functional/test_windows.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think moving them to tests/lib/test_lib_filesystem.py
is hopefully enough. Since producing these errors was the whole point, I'd rather not separate these tests from the other tests. Please resolve if you think this is OK.
- Remove "action" since currently it is basically unused - Move tests of FileOpener to tests/lib/test_filesystem - Use path.write_text to initialize file - Avoid comment in changes to requirements
- The test should look for the correct error on PY2 or PY3
@chrahunt, I've done some of the work to make this pull request only about the new tests, rather than about issue #7280, with the following exceptions:
I think I've addressed the issues with the pull you raised. I named the test file as tests/lib/test_lib_filesystem, just because that is clearer to me when I enter pytest -k test_lib, I get all the tests on tests/lib. I am very open to changing that; it just seemed a small bit better to me. |
I have pull request fatigue. All of this works on my Desktop, both as davisda4 and as a local administrator. I've run tox -e py35, tox -e py36, and tox -e py27. |
I spoke too quickly. I have run these specific unit tests, but I am now re-running the entire suite with Python 3.6 on Windows, and we'll see. |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
Hi @danizen! Is there anything we can help you with to move this PR forward? |
Hello! I am an automated bot and I have noticed that this pull request is not currently able to be merged. If you are able to either merge the |
I was mostly interested in issue #7280, which we are no longer seeing since pip 20. I think the main work I and the other contributor did is to clarify the issue, but moving the TemporaryDirectory clean-up for the wheel to the end (by making it global), ended up fixing the issue. As a contractor, I've pushed my government boss as far as I can to get her to let me do open source contributions. The agreement we worked out was that submitting issues and clarifying them is something they'll pay for, but fixing them I'm on my own. So, I think I'm done. There is no reason I would want to make Windows easier and more foolproof except for my employer preferring Windows development boxes. |
Isn't this largely superseded (especially during installing) with #7882? |
tests\lib\fileystem.py
designed to help create multi-process race conditions of this kind. Tests for test utility are intests\unit\test_utils_filesystem.py
tests\unit\test_util_temp_dir.py
src\pip\_internal\util\temp_dir.py
and issuing a warning.