METADATA 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. Metadata-Version: 2.1
  2. Name: atomicwrites
  3. Version: 1.3.0
  4. Summary: Atomic file writes.
  5. Home-page: https://github.com/untitaker/python-atomicwrites
  6. Author: Markus Unterwaditzer
  7. Author-email: markus@unterwaditzer.net
  8. License: MIT
  9. Platform: UNKNOWN
  10. Classifier: License :: OSI Approved :: MIT License
  11. Classifier: Programming Language :: Python :: 2
  12. Classifier: Programming Language :: Python :: 2.7
  13. Classifier: Programming Language :: Python :: 3
  14. Classifier: Programming Language :: Python :: 3.4
  15. Classifier: Programming Language :: Python :: 3.5
  16. Classifier: Programming Language :: Python :: 3.6
  17. Classifier: Programming Language :: Python :: Implementation :: CPython
  18. Requires-Python: >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  19. ===================
  20. python-atomicwrites
  21. ===================
  22. .. image:: https://travis-ci.org/untitaker/python-atomicwrites.svg?branch=master
  23. :target: https://travis-ci.org/untitaker/python-atomicwrites
  24. .. image:: https://ci.appveyor.com/api/projects/status/vadc4le3c27to59x/branch/master?svg=true
  25. :target: https://ci.appveyor.com/project/untitaker/python-atomicwrites/branch/master
  26. Atomic file writes.
  27. .. code-block:: python
  28. from atomicwrites import atomic_write
  29. with atomic_write('foo.txt', overwrite=True) as f:
  30. f.write('Hello world.')
  31. # "foo.txt" doesn't exist yet.
  32. # Now it does.
  33. Features that distinguish it from other similar libraries (see `Alternatives and Credit`_):
  34. - Race-free assertion that the target file doesn't yet exist. This can be
  35. controlled with the ``overwrite`` parameter.
  36. - Windows support, although not well-tested. The MSDN resources are not very
  37. explicit about which operations are atomic. I'm basing my assumptions off `a
  38. comment
  39. <https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/449bb49d-8acc-48dc-a46f-0760ceddbfc3/movefileexmovefilereplaceexisting-ntfs-same-volume-atomic?forum=windowssdk#a239bc26-eaf0-4920-9f21-440bd2be9cc8>`_
  40. by `Doug Crook
  41. <https://social.msdn.microsoft.com/Profile/doug%20e.%20cook>`_, who appears
  42. to be a Microsoft employee:
  43. FAQ: Is MoveFileEx atomic
  44. Frequently asked question: Is MoveFileEx atomic if the existing and new
  45. files are both on the same drive?
  46. The simple answer is "usually, but in some cases it will silently fall-back
  47. to a non-atomic method, so don't count on it".
  48. The implementation of MoveFileEx looks something like this: [...]
  49. The problem is if the rename fails, you might end up with a CopyFile, which
  50. is definitely not atomic.
  51. If you really need atomic-or-nothing, you can try calling
  52. NtSetInformationFile, which is unsupported but is much more likely to be
  53. atomic.
  54. - Simple high-level API that wraps a very flexible class-based API.
  55. - Consistent error handling across platforms.
  56. How it works
  57. ============
  58. It uses a temporary file in the same directory as the given path. This ensures
  59. that the temporary file resides on the same filesystem.
  60. The temporary file will then be atomically moved to the target location: On
  61. POSIX, it will use ``rename`` if files should be overwritten, otherwise a
  62. combination of ``link`` and ``unlink``. On Windows, it uses MoveFileEx_ through
  63. stdlib's ``ctypes`` with the appropriate flags.
  64. Note that with ``link`` and ``unlink``, there's a timewindow where the file
  65. might be available under two entries in the filesystem: The name of the
  66. temporary file, and the name of the target file.
  67. Also note that the permissions of the target file may change this way. In some
  68. situations a ``chmod`` can be issued without any concurrency problems, but
  69. since that is not always the case, this library doesn't do it by itself.
  70. .. _MoveFileEx: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx
  71. fsync
  72. -----
  73. On POSIX, ``fsync`` is invoked on the temporary file after it is written (to
  74. flush file content and metadata), and on the parent directory after the file is
  75. moved (to flush filename).
  76. ``fsync`` does not take care of disks' internal buffers, but there don't seem
  77. to be any standard POSIX APIs for that. On OS X, ``fcntl`` is used with
  78. ``F_FULLFSYNC`` instead of ``fsync`` for that reason.
  79. On Windows, `_commit <https://msdn.microsoft.com/en-us/library/17618685.aspx>`_
  80. is used, but there are no guarantees about disk internal buffers.
  81. Alternatives and Credit
  82. =======================
  83. Atomicwrites is directly inspired by the following libraries (and shares a
  84. minimal amount of code):
  85. - The Trac project's `utility functions
  86. <http://www.edgewall.org/docs/tags-trac-0.11.7/epydoc/trac.util-pysrc.html>`_,
  87. also used in `Werkzeug <http://werkzeug.pocoo.org/>`_ and
  88. `mitsuhiko/python-atomicfile
  89. <https://github.com/mitsuhiko/python-atomicfile>`_. The idea to use
  90. ``ctypes`` instead of ``PyWin32`` originated there.
  91. - `abarnert/fatomic <https://github.com/abarnert/fatomic>`_. Windows support
  92. (based on ``PyWin32``) was originally taken from there.
  93. Other alternatives to atomicwrites include:
  94. - `sashka/atomicfile <https://github.com/sashka/atomicfile>`_. Originally I
  95. considered using that, but at the time it was lacking a lot of features I
  96. needed (Windows support, overwrite-parameter, overriding behavior through
  97. subclassing).
  98. - The `Boltons library collection <https://github.com/mahmoud/boltons>`_
  99. features a class for atomic file writes, which seems to have a very similar
  100. ``overwrite`` parameter. It is lacking Windows support though.
  101. License
  102. =======
  103. Licensed under the MIT, see ``LICENSE``.