atomicwrites-homeassistant


Nameatomicwrites-homeassistant JSON
Version 1.4.1 PyPI version JSON
download
home_pagehttps://github.com/untitaker/python-atomicwrites
SummaryAtomic file writes.
upload_time2022-07-08 20:56:46
maintainer
docs_urlNone
authorMarkus Unterwaditzer
requires_python>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            ===================
python-atomicwrites
===================

.. image:: https://travis-ci.com/untitaker/python-atomicwrites.svg?branch=master
    :target: https://travis-ci.com/untitaker/python-atomicwrites
.. image:: https://ci.appveyor.com/api/projects/status/vadc4le3c27to59x/branch/master?svg=true
   :target: https://ci.appveyor.com/project/untitaker/python-atomicwrites/branch/master
.. image:: https://readthedocs.org/projects/python-atomicwrites/badge/?version=latest
   :target: https://python-atomicwrites.readthedocs.io/en/latest/?badge=latest
   :alt: Documentation Status

**Atomic file writes.**

Fork because the original package is unmaintained.

.. code-block:: python

    from atomicwrites import atomic_write

    with atomic_write('foo.txt', overwrite=True) as f:
        f.write('Hello world.')
        # "foo.txt" doesn't exist yet.

    # Now it does.

See `API documentation <https://python-atomicwrites.readthedocs.io/en/latest/#api>`_ for more
low-level interfaces.

Features that distinguish it from other similar libraries (see `Alternatives and Credit`_):

- Race-free assertion that the target file doesn't yet exist. This can be
  controlled with the ``overwrite`` parameter.

- Windows support, although not well-tested. The MSDN resources are not very
  explicit about which operations are atomic. I'm basing my assumptions off `a
  comment
  <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>`_
  by `Doug Cook
  <https://social.msdn.microsoft.com/Profile/doug%20e.%20cook>`_, who appears
  to be a Microsoft employee:

      Question: Is MoveFileEx atomic if the existing and new
      files are both on the same drive?

      The simple answer is "usually, but in some cases it will silently fall-back
      to a non-atomic method, so don't count on it".

      The implementation of MoveFileEx looks something like this: [...]

      The problem is if the rename fails, you might end up with a CopyFile, which
      is definitely not atomic.

      If you really need atomic-or-nothing, you can try calling
      NtSetInformationFile, which is unsupported but is much more likely to be
      atomic.

- Simple high-level API that wraps a very flexible class-based API.

- Consistent error handling across platforms.


How it works
============

It uses a temporary file in the same directory as the given path. This ensures
that the temporary file resides on the same filesystem.

The temporary file will then be atomically moved to the target location: On
POSIX, it will use ``rename`` if files should be overwritten, otherwise a
combination of ``link`` and ``unlink``. On Windows, it uses MoveFileEx_ through
stdlib's ``ctypes`` with the appropriate flags.

Note that with ``link`` and ``unlink``, there's a timewindow where the file
might be available under two entries in the filesystem: The name of the
temporary file, and the name of the target file.

Also note that the permissions of the target file may change this way. In some
situations a ``chmod`` can be issued without any concurrency problems, but
since that is not always the case, this library doesn't do it by itself.

.. _MoveFileEx: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx

fsync
-----

On POSIX, ``fsync`` is invoked on the temporary file after it is written (to
flush file content and metadata), and on the parent directory after the file is
moved (to flush filename).

``fsync`` does not take care of disks' internal buffers, but there don't seem
to be any standard POSIX APIs for that. On OS X, ``fcntl`` is used with
``F_FULLFSYNC`` instead of ``fsync`` for that reason.

On Windows, `_commit <https://msdn.microsoft.com/en-us/library/17618685.aspx>`_
is used, but there are no guarantees about disk internal buffers.

Alternatives and Credit
=======================

Atomicwrites is directly inspired by the following libraries (and shares a
minimal amount of code):

- The Trac project's `utility functions
  <http://www.edgewall.org/docs/tags-trac-0.11.7/epydoc/trac.util-pysrc.html>`_,
  also used in `Werkzeug <http://werkzeug.pocoo.org/>`_ and
  `mitsuhiko/python-atomicfile
  <https://github.com/mitsuhiko/python-atomicfile>`_. The idea to use
  ``ctypes`` instead of ``PyWin32`` originated there.

- `abarnert/fatomic <https://github.com/abarnert/fatomic>`_. Windows support
  (based on ``PyWin32``) was originally taken from there.

Other alternatives to atomicwrites include:

- `sashka/atomicfile <https://github.com/sashka/atomicfile>`_. Originally I
  considered using that, but at the time it was lacking a lot of features I
  needed (Windows support, overwrite-parameter, overriding behavior through
  subclassing).

- The `Boltons library collection <https://github.com/mahmoud/boltons>`_
  features a class for atomic file writes, which seems to have a very similar
  ``overwrite`` parameter. It is lacking Windows support though.

License
=======

Licensed under the MIT, see ``LICENSE``.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/untitaker/python-atomicwrites",
    "name": "atomicwrites-homeassistant",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
    "maintainer_email": "",
    "keywords": "",
    "author": "Markus Unterwaditzer",
    "author_email": "markus@unterwaditzer.net",
    "download_url": "https://files.pythonhosted.org/packages/9a/5a/10ff0fd9aa04f78a0b31bb617c8d29796a12bea33f1e48aa54687d635e44/atomicwrites-homeassistant-1.4.1.tar.gz",
    "platform": null,
    "description": "===================\npython-atomicwrites\n===================\n\n.. image:: https://travis-ci.com/untitaker/python-atomicwrites.svg?branch=master\n    :target: https://travis-ci.com/untitaker/python-atomicwrites\n.. image:: https://ci.appveyor.com/api/projects/status/vadc4le3c27to59x/branch/master?svg=true\n   :target: https://ci.appveyor.com/project/untitaker/python-atomicwrites/branch/master\n.. image:: https://readthedocs.org/projects/python-atomicwrites/badge/?version=latest\n   :target: https://python-atomicwrites.readthedocs.io/en/latest/?badge=latest\n   :alt: Documentation Status\n\n**Atomic file writes.**\n\nFork because the original package is unmaintained.\n\n.. code-block:: python\n\n    from atomicwrites import atomic_write\n\n    with atomic_write('foo.txt', overwrite=True) as f:\n        f.write('Hello world.')\n        # \"foo.txt\" doesn't exist yet.\n\n    # Now it does.\n\nSee `API documentation <https://python-atomicwrites.readthedocs.io/en/latest/#api>`_ for more\nlow-level interfaces.\n\nFeatures that distinguish it from other similar libraries (see `Alternatives and Credit`_):\n\n- Race-free assertion that the target file doesn't yet exist. This can be\n  controlled with the ``overwrite`` parameter.\n\n- Windows support, although not well-tested. The MSDN resources are not very\n  explicit about which operations are atomic. I'm basing my assumptions off `a\n  comment\n  <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>`_\n  by `Doug Cook\n  <https://social.msdn.microsoft.com/Profile/doug%20e.%20cook>`_, who appears\n  to be a Microsoft employee:\n\n      Question: Is MoveFileEx atomic if the existing and new\n      files are both on the same drive?\n\n      The simple answer is \"usually, but in some cases it will silently fall-back\n      to a non-atomic method, so don't count on it\".\n\n      The implementation of MoveFileEx looks something like this: [...]\n\n      The problem is if the rename fails, you might end up with a CopyFile, which\n      is definitely not atomic.\n\n      If you really need atomic-or-nothing, you can try calling\n      NtSetInformationFile, which is unsupported but is much more likely to be\n      atomic.\n\n- Simple high-level API that wraps a very flexible class-based API.\n\n- Consistent error handling across platforms.\n\n\nHow it works\n============\n\nIt uses a temporary file in the same directory as the given path. This ensures\nthat the temporary file resides on the same filesystem.\n\nThe temporary file will then be atomically moved to the target location: On\nPOSIX, it will use ``rename`` if files should be overwritten, otherwise a\ncombination of ``link`` and ``unlink``. On Windows, it uses MoveFileEx_ through\nstdlib's ``ctypes`` with the appropriate flags.\n\nNote that with ``link`` and ``unlink``, there's a timewindow where the file\nmight be available under two entries in the filesystem: The name of the\ntemporary file, and the name of the target file.\n\nAlso note that the permissions of the target file may change this way. In some\nsituations a ``chmod`` can be issued without any concurrency problems, but\nsince that is not always the case, this library doesn't do it by itself.\n\n.. _MoveFileEx: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240%28v=vs.85%29.aspx\n\nfsync\n-----\n\nOn POSIX, ``fsync`` is invoked on the temporary file after it is written (to\nflush file content and metadata), and on the parent directory after the file is\nmoved (to flush filename).\n\n``fsync`` does not take care of disks' internal buffers, but there don't seem\nto be any standard POSIX APIs for that. On OS X, ``fcntl`` is used with\n``F_FULLFSYNC`` instead of ``fsync`` for that reason.\n\nOn Windows, `_commit <https://msdn.microsoft.com/en-us/library/17618685.aspx>`_\nis used, but there are no guarantees about disk internal buffers.\n\nAlternatives and Credit\n=======================\n\nAtomicwrites is directly inspired by the following libraries (and shares a\nminimal amount of code):\n\n- The Trac project's `utility functions\n  <http://www.edgewall.org/docs/tags-trac-0.11.7/epydoc/trac.util-pysrc.html>`_,\n  also used in `Werkzeug <http://werkzeug.pocoo.org/>`_ and\n  `mitsuhiko/python-atomicfile\n  <https://github.com/mitsuhiko/python-atomicfile>`_. The idea to use\n  ``ctypes`` instead of ``PyWin32`` originated there.\n\n- `abarnert/fatomic <https://github.com/abarnert/fatomic>`_. Windows support\n  (based on ``PyWin32``) was originally taken from there.\n\nOther alternatives to atomicwrites include:\n\n- `sashka/atomicfile <https://github.com/sashka/atomicfile>`_. Originally I\n  considered using that, but at the time it was lacking a lot of features I\n  needed (Windows support, overwrite-parameter, overriding behavior through\n  subclassing).\n\n- The `Boltons library collection <https://github.com/mahmoud/boltons>`_\n  features a class for atomic file writes, which seems to have a very similar\n  ``overwrite`` parameter. It is lacking Windows support though.\n\nLicense\n=======\n\nLicensed under the MIT, see ``LICENSE``.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Atomic file writes.",
    "version": "1.4.1",
    "project_urls": {
        "Homepage": "https://github.com/untitaker/python-atomicwrites"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4e1b872dd3b11939edb4c0a27d2569a9b7e77d3b88995a45a331f376e13528c0",
                "md5": "8775e4a5e54408989dc49b2d6ac13b2c",
                "sha256": "01457de800961db7d5b575f3c92e7fb56e435d88512c366afb0873f4f092bb0d"
            },
            "downloads": -1,
            "filename": "atomicwrites_homeassistant-1.4.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8775e4a5e54408989dc49b2d6ac13b2c",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 7128,
            "upload_time": "2022-07-08T20:56:44",
            "upload_time_iso_8601": "2022-07-08T20:56:44.186581Z",
            "url": "https://files.pythonhosted.org/packages/4e/1b/872dd3b11939edb4c0a27d2569a9b7e77d3b88995a45a331f376e13528c0/atomicwrites_homeassistant-1.4.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a5a10ff0fd9aa04f78a0b31bb617c8d29796a12bea33f1e48aa54687d635e44",
                "md5": "fcc36e72ede8c6b4c8c0a672bdaa9120",
                "sha256": "256a672106f16745445228d966240b77b55f46a096d20305901a57aa5d1f4c2f"
            },
            "downloads": -1,
            "filename": "atomicwrites-homeassistant-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "fcc36e72ede8c6b4c8c0a672bdaa9120",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*",
            "size": 12223,
            "upload_time": "2022-07-08T20:56:46",
            "upload_time_iso_8601": "2022-07-08T20:56:46.350518Z",
            "url": "https://files.pythonhosted.org/packages/9a/5a/10ff0fd9aa04f78a0b31bb617c8d29796a12bea33f1e48aa54687d635e44/atomicwrites-homeassistant-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-07-08 20:56:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "untitaker",
    "github_project": "python-atomicwrites",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "tox": true,
    "lcname": "atomicwrites-homeassistant"
}
        
Elapsed time: 0.22479s