METADATA 5.8 KB

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