Skip to content

Commit 97c79f8

Browse files
authored
Merge pull request #343 from mathstuf/no-atomicwrites
2 parents ed88fb5 + 921782a commit 97c79f8

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jobs:
1818
python-version: ${{ matrix.python-version }}
1919
- name: Install dependencies
2020
run: |
21+
sudo apt-get update
2122
sudo apt-get install -y locales-all
2223
python -m pip install --upgrade pip
2324
python -m pip install flake8
@@ -37,11 +38,6 @@ jobs:
3738
run: |
3839
python -m pip install --upgrade pip
3940
python -m pip install .[typing]
40-
- name: Ignore a strange type error that only happens in CI
41-
# This error only happens in CI and I can not reproduce it in the nix
42-
# check or locally:
43-
# khard/khard.py:658: error: Argument "policy" to "message_from_string" has incompatible type "EmailPolicy[EmailMessage]"; expected "Policy[Message[str, str]]" [arg-type]
44-
run: "sed -i '/message = message_from_string/s/$/#type: ignore[arg-type]/' khard/khard.py"
4541
- name: Run the type checker
4642
run: mypy
4743

flake.nix

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,7 @@
1616
doc ? true,
1717
typing ? false,
1818
}: let
19-
packageOverrides = final: prev: {
20-
types-atomicwrites = python3.pkgs.buildPythonPackage rec {
21-
pname = "types-atomicwrites";
22-
version = "1.4.5.1";
23-
src = pkgs.fetchPypi {
24-
inherit pname version;
25-
hash = "sha256-np8JI+v5NSSyi87OWiOsjDgg85sGDfKfZxk20uS8BLw=";
26-
};
27-
};
28-
};
29-
attrs = project.renderers.buildPythonPackage {
30-
python = python3.override {inherit packageOverrides;};
31-
};
19+
attrs = project.renderers.buildPythonPackage {python = python3;};
3220
overrides = {
3321
version = "0.dev+${self.shortRev or self.dirtyShortRev}";
3422
build-system =

khard/contacts.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
- device: https://tools.ietf.org/html/rfc6869
1212
"""
1313

14+
import contextlib
1415
import copy
1516
import datetime
1617
import io
1718
import locale
1819
import logging
1920
import os
2021
import re
22+
import tempfile
2123
import time
22-
from typing import Any, Callable, Literal, Optional, TypeVar, Union, \
23-
Sequence, overload
24+
from typing import Any, Callable, IO, Iterator, Literal, Optional, TypeVar, \
25+
Union, Sequence, overload
2426

25-
from atomicwrites import atomic_write
2627
from ruamel import yaml
2728
from ruamel.yaml import YAML
2829
import vobject
@@ -1342,6 +1343,35 @@ def to_yaml(self) -> str:
13421343
return stream.getvalue() + "\n"
13431344

13441345

1346+
@contextlib.contextmanager
1347+
def atomic_write(dest: str, overwrite: bool = False) -> Iterator[IO[str]]:
1348+
"""Atomically write to the destination file.
1349+
1350+
Optionally overwrite the path (using rename) rather than using `os.link`.
1351+
"""
1352+
fd, src = tempfile.mkstemp(prefix=os.path.basename(dest), dir=os.path.dirname(dest))
1353+
file = os.fdopen(fd, mode='w')
1354+
try:
1355+
yield file
1356+
except Exception:
1357+
try:
1358+
file.close()
1359+
os.unlink(src)
1360+
except Exception:
1361+
pass
1362+
raise
1363+
else:
1364+
file.flush()
1365+
file.close()
1366+
if overwrite:
1367+
os.rename(src, dest)
1368+
else:
1369+
try:
1370+
os.link(src, dest)
1371+
finally:
1372+
os.unlink(src)
1373+
1374+
13451375
class Contact(YAMLEditable):
13461376

13471377
def __init__(self, vcard: vobject.base.Component,

pyproject.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ keywords = ["vcard", "console", "addressbook"]
2323
license = {text = "GPL"}
2424

2525
dependencies = [
26-
"atomicwrites == 1.4.1",
2726
"configobj == 5.*, >= 5.0.6",
2827
"ruamel.yaml >= 0.17.0",
2928
"vobject ~= 0.9.7",
@@ -38,7 +37,6 @@ doc = [
3837
]
3938
typing = [
4039
"mypy",
41-
"types-atomicwrites",
4240
# vobject does fancy dynamic stuff that is hard to type-check
4341
#"types-vobject",
4442
]

0 commit comments

Comments
 (0)