METADATA 5.5 KB

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