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

Drop atomicwrites dependency #10116

Closed

Conversation

nicoddemus
Copy link
Member

I took care of adding the files unchanged in the first commit, so we can track the exact changes that were done.

Closes #10114

os.close(fd)

def _replace_atomic(src, dst):
os.rename(src, dst)
Copy link
Member Author

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.

@The-Compiler
Copy link
Member

Have you seen #10115? There at least the CI seems to pass, though I have no idea to what extent we have tests for #3008/#3390.

@nicoddemus
Copy link
Member Author

Argh no I didn't!

@nicoddemus
Copy link
Member Author

Closing in favor of #10115

@nicoddemus nicoddemus closed this Jul 8, 2022
@nicoddemus nicoddemus deleted the get-rid-atomitc-writes-10114 branch July 8, 2022 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get rid of atomicwrites (unmaintained)
2 participants