Skip to content

Commit 8b063c3

Browse files
mathstufWhyNotHugo
authored andcommitted
atomicwrites: remove dependency on abandoned library
1 parent 12a0691 commit 8b063c3

File tree

9 files changed

+35
-10
lines changed

9 files changed

+35
-10
lines changed

.builds/tests-archlinux.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ packages:
1010
- python-installer
1111
- python-setuptools-scm
1212
# Runtime dependencies:
13-
- python-atomicwrites
1413
- python-click
1514
- python-click-log
1615
- python-click-threading

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ repos:
2121
- types-setuptools
2222
- types-docutils
2323
- types-requests
24-
- types-atomicwrites
2524
- repo: https://github.com/charliermarsh/ruff-pre-commit
2625
rev: 'v0.2.2'
2726
hooks:

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Package maintainers and users who have to manually update their installation
99
may want to subscribe to `GitHub's tag feed
1010
<https://github.com/pimutils/vdirsyncer/tags.atom>`_.
1111

12+
Version 0.19.4
13+
==============
14+
15+
- Remove dependency on abandoned ``atomicwrites`` library.
16+
1217
Version 0.19.3
1318
==============
1419

setup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
"click>=5.0,<9.0",
1717
"click-log>=0.3.0, <0.5.0",
1818
"requests >=2.20.0",
19-
# https://github.com/untitaker/python-atomicwrites/commit/4d12f23227b6a944ab1d99c507a69fdbc7c9ed6d # noqa
20-
"atomicwrites>=0.1.7",
2119
"aiohttp>=3.8.2,<4.0.0",
2220
"aiostream>=0.4.3,<0.5.0",
2321
]

vdirsyncer/cli/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import aiohttp
1212
import click
13-
from atomicwrites import atomic_write
1413

1514
from .. import BUGTRACKER_HOME
1615
from .. import DOCS_HOME
@@ -21,6 +20,7 @@
2120
from ..sync.exceptions import StorageEmpty
2221
from ..sync.exceptions import SyncConflict
2322
from ..sync.status import SqliteStatus
23+
from ..utils import atomic_write
2424
from ..utils import expand_path
2525
from ..utils import get_storage_init_args
2626
from . import cli_logger

vdirsyncer/storage/filesystem.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
import os
66
import subprocess
77

8-
from atomicwrites import atomic_write
9-
108
from .. import exceptions
9+
from ..utils import atomic_write
1110
from ..utils import checkdir
1211
from ..utils import expand_path
1312
from ..utils import generate_href

vdirsyncer/storage/google.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
import aiohttp
1313
import click
14-
from atomicwrites import atomic_write
1514

1615
from .. import exceptions
16+
from ..utils import atomic_write
1717
from ..utils import checkdir
1818
from ..utils import expand_path
1919
from ..utils import open_graphical_browser

vdirsyncer/storage/singlefile.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
import os
99
from typing import Iterable
1010

11-
from atomicwrites import atomic_write
12-
1311
from .. import exceptions
12+
from ..utils import atomic_write
1413
from ..utils import checkfile
1514
from ..utils import expand_path
1615
from ..utils import get_etag_from_file

vdirsyncer/utils.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from __future__ import annotations
22

3+
import contextlib
34
import functools
45
import os
56
import sys
7+
import tempfile
68
import uuid
79
from inspect import getfullargspec
810
from typing import Callable
@@ -220,3 +222,27 @@ def open_graphical_browser(url, new=0, autoraise=True):
220222
return
221223

222224
raise RuntimeError("No graphical browser found. Please open the URL " "manually.")
225+
226+
227+
@contextlib.contextmanager
228+
def atomic_write(dest, mode="wb", overwrite=False):
229+
if "w" not in mode:
230+
raise RuntimeError("`atomic_write` requires write access")
231+
232+
fd, src = tempfile.mkstemp(prefix=os.path.basename(dest), dir=os.path.dirname(dest))
233+
file = os.fdopen(fd, mode=mode)
234+
235+
try:
236+
yield file
237+
except Exception:
238+
os.unlink(src)
239+
raise
240+
else:
241+
file.flush()
242+
file.close()
243+
244+
if overwrite:
245+
os.rename(src, dest)
246+
else:
247+
os.link(src, dest)
248+
os.unlink(src)

0 commit comments

Comments
 (0)