-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Drop atomicwrites dependency #10116
Drop atomicwrites dependency #10116
Conversation
os.close(fd) | ||
|
||
def _replace_atomic(src, dst): | ||
os.rename(src, dst) |
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 did try to replace this call with os.replace
and using this implementation on windows (as suggested in #10114 (comment)), however I get test failures:
λ pytest testing\test_atomic_writes.py
======================== test session starts ========================
platform win32 -- Python 3.9.8, pytest-7.2.0.dev91+g1689b3886.d20220613, pluggy-1.0.0
rootdir: e:\projects\pytest, configfile: pyproject.toml
plugins: hypothesis-6.34.1, flake8-1.0.7, flakes-4.0.5
collected 6 items
testing\test_atomic_writes.py F.F..F [100%]
============================= FAILURES ==============================
_________________________ test_atomic_write _________________________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_atomic_write0')
def test_atomic_write(tmp_path: Path) -> None:
fname = tmp_path.joinpath("ha")
for i in range(2):
with atomic_write(str(fname), overwrite=True) as f:
> f.write("hoho")
testing\test_atomic_writes.py:19:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_atomic_write0'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_atomic_write0'
src\_pytest\atomic_writes.py:28: PermissionError
_____________ test_replace_simultaneously_created_file ______________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_replace_simultaneously_cr0')
def test_replace_simultaneously_created_file(tmp_path: Path) -> None:
fname = tmp_path.joinpath("ha")
with atomic_write(str(fname), overwrite=True) as f:
f.write("hoho")
fname.write_text("harhar")
> assert fname.read_text() == "harhar"
testing\test_atomic_writes.py:45:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_replace_simultaneously_cr0'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-of-Pichau\\pytest-3049\\test_replace_simultaneously_cr0'
src\_pytest\atomic_writes.py:28: PermissionError
_____________________ test_atomic_write_in_pwd ______________________
tmp_path = WindowsPath('E:/.tmp/pytest-of-Pichau/pytest-3049/test_atomic_write_in_pwd0')
def test_atomic_write_in_pwd(tmp_path: Path) -> None:
orig_curdir = os.getcwd()
try:
os.chdir(str(tmp_path))
fname = "ha"
for i in range(2):
with atomic_write(str(fname), overwrite=True) as f:
> f.write("hoho")
testing\test_atomic_writes.py:86:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
C:\Python39\lib\contextlib.py:126: in __exit__
next(self.gen)
src\_pytest\atomic_writes.py:146: in _open
self.commit(f)
src\_pytest\atomic_writes.py:181: in commit
replace_atomic(f.name, self._path)
src\_pytest\atomic_writes.py:80: in replace_atomic
return _replace_atomic(src, dst)
src\_pytest\atomic_writes.py:36: in _replace_atomic
_sync_directory(os.path.normpath(os.path.dirname(dst)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
directory = '.'
def _sync_directory(directory):
# Ensure that filenames are written to disk
> fd = os.open(directory, 0)
E PermissionError: [Errno 13] Permission denied: '.'
src\_pytest\atomic_writes.py:28: PermissionError
====================== short test summary info ======================
FAILED testing/test_atomic_writes.py::test_atomic_write - PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-...
FAILED testing/test_atomic_writes.py::test_replace_simultaneously_created_file - PermissionError: [Errno 13] Permission denied: 'E:\\.tmp\\pytest-...
FAILED testing/test_atomic_writes.py::test_atomic_write_in_pwd - PermissionError: [Errno 13] Permission denied: '.'
==================== 3 failed, 3 passed in 0.20s ====================
Decided to leave this as is instead of investigating further, but suggestions are welcome.
Argh no I didn't! |
Closing in favor of #10115 |
I took care of adding the files unchanged in the first commit, so we can track the exact changes that were done.
Closes #10114