Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .cache/pip/http-v2/3/4/e/4/e/34e4ed9f6da78ec378e04be04de734c69a68c889dbef86cb0f5f498a +0 -0
- .cache/pip/http-v2/3/4/e/4/e/34e4ed9f6da78ec378e04be04de734c69a68c889dbef86cb0f5f498a.body +0 -0
- .cache/pip/http-v2/3/5/a/0/6/35a0615e0411edd59492c90e8f5cd0a1a0554d6f7d1dec5be2b30560 +0 -0
- .cache/pip/http-v2/3/5/a/0/6/35a0615e0411edd59492c90e8f5cd0a1a0554d6f7d1dec5be2b30560.body +97 -0
- .cache/pip/http-v2/3/7/c/5/1/37c518ffee828550acec5a0fd158a5f1d852928eea13df9d077b428b +0 -0
- .cache/pip/http-v2/3/7/c/5/1/37c518ffee828550acec5a0fd158a5f1d852928eea13df9d077b428b.body +0 -0
- .cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d +0 -0
- .cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d.body +0 -0
- .cache/pip/http-v2/3/8/9/2/7/389270eb64d5d655add63491064e7e833611004a96c2fb8b19caa5fb +0 -0
- .cache/pip/http-v2/3/8/9/2/7/389270eb64d5d655add63491064e7e833611004a96c2fb8b19caa5fb.body +321 -0
- .cache/pip/http-v2/3/8/c/c/8/38cc8209283ecb2d228ea8086bb74fbdc5d4872485c51a94fdb9c6cb +0 -0
- .cache/pip/http-v2/4/4/a/d/5/44ad51ab4fe732177892254938ca19df59a19add805fe17b3b22c658 +0 -0
- .cache/pip/http-v2/4/4/a/d/5/44ad51ab4fe732177892254938ca19df59a19add805fe17b3b22c658.body +1595 -0
- .cache/pip/http-v2/4/6/5/f/3/465f3fcecb7ed980c1b4d56b4f1ac8b2ae4685d32a696bbd51a25fb9 +0 -0
- .cache/pip/http-v2/4/6/5/f/3/465f3fcecb7ed980c1b4d56b4f1ac8b2ae4685d32a696bbd51a25fb9.body +329 -0
- .cache/pip/http-v2/4/a/5/b/6/4a5b6f0d76201de4cfd4884f5e95617a1848cf81c8357be4d12cbf6a +0 -0
- .cache/pip/http-v2/4/a/5/b/6/4a5b6f0d76201de4cfd4884f5e95617a1848cf81c8357be4d12cbf6a.body +86 -0
- .cache/pip/http-v2/4/d/c/8/d/4dc8d567db4bc55c0684404c85a6b4572f87a99306be24cab65fbfae +0 -0
- .cache/pip/http-v2/4/d/c/8/d/4dc8d567db4bc55c0684404c85a6b4572f87a99306be24cab65fbfae.body +0 -0
- .cache/pip/http-v2/4/f/3/2/1/4f3214a3fad8d38cb17e7de04e5671458da4f4634932269127d53af7 +0 -0
- .cache/pip/http-v2/9/b/5/1/6/9b51619e20a708f99372afefd7dbe20a1b5e42ae213f02bf27267976 +0 -0
- .cache/pip/http-v2/c/3/a/e/f/c3aefa2552222433000010e47def822725a77e3cf762f96a15f09d26 +0 -0
- .cache/pip/http-v2/c/3/a/e/f/c3aefa2552222433000010e47def822725a77e3cf762f96a15f09d26.body +907 -0
- .cache/pip/http-v2/c/6/3/0/6/c6306d205b48faecb62eb823053e850df036f38e59b11523829f5c31 +0 -0
- .cache/pip/http-v2/c/6/3/0/6/c6306d205b48faecb62eb823053e850df036f38e59b11523829f5c31.body +0 -0
- .cache/pip/http-v2/c/8/4/4/6/c84464fe37be1d534151bcdb9cc17e882f3b79853f43ffdb6425f333 +0 -0
- .cache/pip/http-v2/c/8/4/4/6/c84464fe37be1d534151bcdb9cc17e882f3b79853f43ffdb6425f333.body +1086 -0
- .cache/pip/http-v2/c/c/c/b/4/cccb41730ba9dcdb4cb7127715ba43b53bfd809d6ff652fe215567a3 +0 -0
- .cache/pip/http-v2/c/c/c/b/4/cccb41730ba9dcdb4cb7127715ba43b53bfd809d6ff652fe215567a3.body +300 -0
- .cache/pip/http-v2/c/d/5/d/e/cd5de44b899cbe1869765c21b55cffc53c0c0ffa9d3c6f1fd40a42a2 +0 -0
- .cache/pip/http-v2/f/9/5/d/2/f95d294c2281f9705ab34177ee4732e524880c56ef894e620cf4cb95 +0 -0
- .cache/pip/http-v2/f/9/5/d/2/f95d294c2281f9705ab34177ee4732e524880c56ef894e620cf4cb95.body +0 -0
- .cache/pip/http-v2/f/c/6/8/7/fc687abc6120c7bc7cfd867fe3788604e9f8e9dcf17e51396d803e25 +0 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/METADATA +38 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/RECORD +19 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/WHEEL +4 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/licenses/LICENSE +21 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/__init__.py +93 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_api.py +582 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_async_read_write.py +207 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_error.py +30 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_read_write.py +364 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_soft.py +214 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_soft_rw/_async.py +213 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_soft_rw/_sync.py +847 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_unix.py +116 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_util.py +53 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_windows.py +111 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/asyncio.py +385 -0
- .cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/py.typed +0 -0
.cache/pip/http-v2/3/4/e/4/e/34e4ed9f6da78ec378e04be04de734c69a68c889dbef86cb0f5f498a
ADDED
|
Binary file (1.86 kB). View file
|
|
|
.cache/pip/http-v2/3/4/e/4/e/34e4ed9f6da78ec378e04be04de734c69a68c889dbef86cb0f5f498a.body
ADDED
|
Binary file (21.5 kB). View file
|
|
|
.cache/pip/http-v2/3/5/a/0/6/35a0615e0411edd59492c90e8f5cd0a1a0554d6f7d1dec5be2b30560
ADDED
|
Binary file (1.25 kB). View file
|
|
|
.cache/pip/http-v2/3/5/a/0/6/35a0615e0411edd59492c90e8f5cd0a1a0554d6f7d1dec5be2b30560.body
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: kiwisolver
|
| 3 |
+
Version: 1.5.0
|
| 4 |
+
Summary: A fast implementation of the Cassowary constraint solver
|
| 5 |
+
Author-email: The Nucleic Development Team <sccolbert@gmail.com>
|
| 6 |
+
Maintainer-email: "Matthieu C. Dartiailh" <m.dartiailh@gmail.com>
|
| 7 |
+
License: =========================
|
| 8 |
+
The Kiwi licensing terms
|
| 9 |
+
=========================
|
| 10 |
+
Kiwi is licensed under the terms of the Modified BSD License (also known as
|
| 11 |
+
New or Revised BSD), as follows:
|
| 12 |
+
|
| 13 |
+
Copyright (c) 2013-2026, Nucleic Development Team
|
| 14 |
+
|
| 15 |
+
All rights reserved.
|
| 16 |
+
|
| 17 |
+
Redistribution and use in source and binary forms, with or without
|
| 18 |
+
modification, are permitted provided that the following conditions are met:
|
| 19 |
+
|
| 20 |
+
Redistributions of source code must retain the above copyright notice, this
|
| 21 |
+
list of conditions and the following disclaimer.
|
| 22 |
+
|
| 23 |
+
Redistributions in binary form must reproduce the above copyright notice, this
|
| 24 |
+
list of conditions and the following disclaimer in the documentation and/or
|
| 25 |
+
other materials provided with the distribution.
|
| 26 |
+
|
| 27 |
+
Neither the name of the Nucleic Development Team nor the names of its
|
| 28 |
+
contributors may be used to endorse or promote products derived from this
|
| 29 |
+
software without specific prior written permission.
|
| 30 |
+
|
| 31 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
| 32 |
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
| 33 |
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 34 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
| 35 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 36 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 37 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 38 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 39 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 40 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 41 |
+
|
| 42 |
+
About Kiwi
|
| 43 |
+
----------
|
| 44 |
+
Chris Colbert began the Kiwi project in December 2013 in an effort to
|
| 45 |
+
create a blisteringly fast UI constraint solver. Chris is still the
|
| 46 |
+
project lead.
|
| 47 |
+
|
| 48 |
+
The Nucleic Development Team is the set of all contributors to the Nucleic
|
| 49 |
+
project and its subprojects.
|
| 50 |
+
|
| 51 |
+
The core team that coordinates development on GitHub can be found here:
|
| 52 |
+
http://github.com/nucleic. The current team consists of:
|
| 53 |
+
|
| 54 |
+
* Chris Colbert
|
| 55 |
+
|
| 56 |
+
Our Copyright Policy
|
| 57 |
+
--------------------
|
| 58 |
+
Nucleic uses a shared copyright model. Each contributor maintains copyright
|
| 59 |
+
over their contributions to Nucleic. But, it is important to note that these
|
| 60 |
+
contributions are typically only changes to the repositories. Thus, the Nucleic
|
| 61 |
+
source code, in its entirety is not the copyright of any single person or
|
| 62 |
+
institution. Instead, it is the collective copyright of the entire Nucleic
|
| 63 |
+
Development Team. If individual contributors want to maintain a record of what
|
| 64 |
+
changes/contributions they have specific copyright on, they should indicate
|
| 65 |
+
their copyright in the commit message of the change, when they commit the
|
| 66 |
+
change to one of the Nucleic repositories.
|
| 67 |
+
|
| 68 |
+
With this in mind, the following banner should be used in any source code file
|
| 69 |
+
to indicate the copyright and license terms:
|
| 70 |
+
|
| 71 |
+
#------------------------------------------------------------------------------
|
| 72 |
+
# Copyright (c) 2013-2026, Nucleic Development Team.
|
| 73 |
+
#
|
| 74 |
+
# Distributed under the terms of the Modified BSD License.
|
| 75 |
+
#
|
| 76 |
+
# The full license is in the file LICENSE, distributed with this software.
|
| 77 |
+
#------------------------------------------------------------------------------
|
| 78 |
+
|
| 79 |
+
Project-URL: homepage, https://github.com/nucleic/kiwi
|
| 80 |
+
Project-URL: documentation, https://kiwisolver.readthedocs.io/en/latest/
|
| 81 |
+
Project-URL: repository, https://github.com/nucleic/kiwi
|
| 82 |
+
Project-URL: changelog, https://github.com/nucleic/kiwi/blob/main/releasenotes.rst
|
| 83 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 84 |
+
Classifier: Programming Language :: Python
|
| 85 |
+
Classifier: Programming Language :: Python :: 3
|
| 86 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 87 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 88 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 89 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 90 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 91 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 92 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 93 |
+
Classifier: Programming Language :: Python :: Implementation :: GraalPy
|
| 94 |
+
Requires-Python: >=3.10
|
| 95 |
+
Description-Content-Type: text/x-rst
|
| 96 |
+
License-File: LICENSE
|
| 97 |
+
Dynamic: license-file
|
.cache/pip/http-v2/3/7/c/5/1/37c518ffee828550acec5a0fd158a5f1d852928eea13df9d077b428b
ADDED
|
Binary file (1.22 kB). View file
|
|
|
.cache/pip/http-v2/3/7/c/5/1/37c518ffee828550acec5a0fd158a5f1d852928eea13df9d077b428b.body
ADDED
|
Binary file (78.4 kB). View file
|
|
|
.cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d
ADDED
|
Binary file (1.85 kB). View file
|
|
|
.cache/pip/http-v2/3/8/6/0/e/3860e4de9ae53c79d2fd61419e9049df314ccc8b640782c02c6e2e2d.body
ADDED
|
Binary file (42.1 kB). View file
|
|
|
.cache/pip/http-v2/3/8/9/2/7/389270eb64d5d655add63491064e7e833611004a96c2fb8b19caa5fb
ADDED
|
Binary file (1.28 kB). View file
|
|
|
.cache/pip/http-v2/3/8/9/2/7/389270eb64d5d655add63491064e7e833611004a96c2fb8b19caa5fb.body
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: colorlog
|
| 3 |
+
Version: 6.10.1
|
| 4 |
+
Summary: Add colours to the output of Python's logging module.
|
| 5 |
+
Home-page: https://github.com/borntyping/python-colorlog
|
| 6 |
+
Author: Sam Clements
|
| 7 |
+
Author-email: sam@borntyping.co.uk
|
| 8 |
+
License: MIT License
|
| 9 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 10 |
+
Classifier: Environment :: Console
|
| 11 |
+
Classifier: Intended Audience :: Developers
|
| 12 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 13 |
+
Classifier: Operating System :: OS Independent
|
| 14 |
+
Classifier: Programming Language :: Python
|
| 15 |
+
Classifier: Programming Language :: Python :: 3
|
| 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 :: 3.9
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 24 |
+
Classifier: Topic :: Terminals
|
| 25 |
+
Classifier: Topic :: Utilities
|
| 26 |
+
Requires-Python: >=3.6
|
| 27 |
+
Description-Content-Type: text/markdown
|
| 28 |
+
License-File: LICENSE
|
| 29 |
+
Requires-Dist: colorama; sys_platform == "win32"
|
| 30 |
+
Provides-Extra: development
|
| 31 |
+
Requires-Dist: black; extra == "development"
|
| 32 |
+
Requires-Dist: flake8; extra == "development"
|
| 33 |
+
Requires-Dist: mypy; extra == "development"
|
| 34 |
+
Requires-Dist: pytest; extra == "development"
|
| 35 |
+
Requires-Dist: types-colorama; extra == "development"
|
| 36 |
+
Dynamic: author
|
| 37 |
+
Dynamic: author-email
|
| 38 |
+
Dynamic: classifier
|
| 39 |
+
Dynamic: description
|
| 40 |
+
Dynamic: description-content-type
|
| 41 |
+
Dynamic: home-page
|
| 42 |
+
Dynamic: license
|
| 43 |
+
Dynamic: license-file
|
| 44 |
+
Dynamic: provides-extra
|
| 45 |
+
Dynamic: requires-python
|
| 46 |
+
Dynamic: summary
|
| 47 |
+
|
| 48 |
+
# Log formatting with colors!
|
| 49 |
+
|
| 50 |
+
[](https://pypi.org/project/colorlog/)
|
| 51 |
+
[](https://pypi.org/project/colorlog/)
|
| 52 |
+
|
| 53 |
+
Add colours to the output of Python's `logging` module.
|
| 54 |
+
|
| 55 |
+
* [Source on GitHub](https://github.com/borntyping/python-colorlog)
|
| 56 |
+
* [Packages on PyPI](https://pypi.org/pypi/colorlog/)
|
| 57 |
+
|
| 58 |
+
## Status
|
| 59 |
+
|
| 60 |
+
colorlog currently requires Python 3.6 or higher. Older versions (below 5.x.x)
|
| 61 |
+
support Python 2.6 and above.
|
| 62 |
+
|
| 63 |
+
* colorlog 6.x requires Python 3.6 or higher.
|
| 64 |
+
* colorlog 5.x is an interim version that will warn Python 2 users to downgrade.
|
| 65 |
+
* colorlog 4.x is the final version supporting Python 2.
|
| 66 |
+
|
| 67 |
+
[colorama] is included as a required dependency and initialised when using
|
| 68 |
+
colorlog on Windows.
|
| 69 |
+
|
| 70 |
+
This library is over a decade old and supported a wide set of Python versions
|
| 71 |
+
for most of its life, which has made it a difficult library to add new features
|
| 72 |
+
to. colorlog 6 may break backwards compatibility so that newer features
|
| 73 |
+
can be added more easily, but may still not accept all changes or feature
|
| 74 |
+
requests. colorlog 4 might accept essential bugfixes but should not be
|
| 75 |
+
considered actively maintained and will not accept any major changes or new
|
| 76 |
+
features.
|
| 77 |
+
|
| 78 |
+
## Installation
|
| 79 |
+
|
| 80 |
+
Install from PyPI with:
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
pip install colorlog
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
Several Linux distributions provide official packages ([Debian], [Arch], [Fedora],
|
| 87 |
+
[Gentoo], [OpenSuse] and [Ubuntu]), and others have user provided packages
|
| 88 |
+
([BSD ports], [Conda]).
|
| 89 |
+
|
| 90 |
+
## Usage
|
| 91 |
+
|
| 92 |
+
```python
|
| 93 |
+
import colorlog
|
| 94 |
+
|
| 95 |
+
handler = colorlog.StreamHandler()
|
| 96 |
+
handler.setFormatter(colorlog.ColoredFormatter(
|
| 97 |
+
'%(log_color)s%(levelname)s:%(name)s:%(message)s'))
|
| 98 |
+
|
| 99 |
+
logger = colorlog.getLogger('example')
|
| 100 |
+
logger.addHandler(handler)
|
| 101 |
+
```
|
| 102 |
+
|
| 103 |
+
The `ColoredFormatter` class takes several arguments:
|
| 104 |
+
|
| 105 |
+
- `format`: The format string used to output the message (required).
|
| 106 |
+
- `datefmt`: An optional date format passed to the base class. See [`logging.Formatter`][Formatter].
|
| 107 |
+
- `reset`: Implicitly adds a color reset code to the message output, unless the output already ends with one. Defaults to `True`.
|
| 108 |
+
- `log_colors`: A mapping of record level names to color names. The defaults can be found in `colorlog.default_log_colors`, or the below example.
|
| 109 |
+
- `secondary_log_colors`: A mapping of names to `log_colors` style mappings, defining additional colors that can be used in format strings. See below for an example.
|
| 110 |
+
- `style`: Available on Python 3.2 and above. See [`logging.Formatter`][Formatter].
|
| 111 |
+
|
| 112 |
+
Color escape codes can be selected based on the log records level, by adding
|
| 113 |
+
parameters to the format string:
|
| 114 |
+
|
| 115 |
+
- `log_color`: Return the color associated with the records level.
|
| 116 |
+
- `<name>_log_color`: Return another color based on the records level if the formatter has secondary colors configured (see `secondary_log_colors` below).
|
| 117 |
+
|
| 118 |
+
Multiple escape codes can be used at once by joining them with commas when
|
| 119 |
+
configuring the color for a log level (but can't be used directly in the format
|
| 120 |
+
string). For example, `black,bg_white` would use the escape codes for black
|
| 121 |
+
text on a white background.
|
| 122 |
+
|
| 123 |
+
The following escape codes are made available for use in the format string:
|
| 124 |
+
|
| 125 |
+
- `{color}`, `fg_{color}`, `bg_{color}`: Foreground and background colors.
|
| 126 |
+
- `bold`, `bold_{color}`, `fg_bold_{color}`, `bg_bold_{color}`: Bold/bright colors.
|
| 127 |
+
- `thin`, `thin_{color}`, `fg_thin_{color}`: Thin colors (terminal dependent).
|
| 128 |
+
- `reset`: Clear all formatting (both foreground and background colors).
|
| 129 |
+
|
| 130 |
+
The available color names are:
|
| 131 |
+
|
| 132 |
+
- `black`
|
| 133 |
+
- `red`
|
| 134 |
+
- `green`
|
| 135 |
+
- `yellow`
|
| 136 |
+
- `blue`,
|
| 137 |
+
- `purple`
|
| 138 |
+
- `cyan`
|
| 139 |
+
- `white`
|
| 140 |
+
|
| 141 |
+
You can also use "bright" colors. These aren't standard ANSI codes, and
|
| 142 |
+
support for these varies wildly across different terminals.
|
| 143 |
+
|
| 144 |
+
- `light_black`
|
| 145 |
+
- `light_red`
|
| 146 |
+
- `light_green`
|
| 147 |
+
- `light_yellow`
|
| 148 |
+
- `light_blue`
|
| 149 |
+
- `light_purple`
|
| 150 |
+
- `light_cyan`
|
| 151 |
+
- `light_white`
|
| 152 |
+
|
| 153 |
+
## Examples
|
| 154 |
+
|
| 155 |
+

|
| 156 |
+
|
| 157 |
+
The following code creates a `ColoredFormatter` for use in a logging setup,
|
| 158 |
+
using the default values for each argument.
|
| 159 |
+
|
| 160 |
+
```python
|
| 161 |
+
from colorlog import ColoredFormatter
|
| 162 |
+
|
| 163 |
+
formatter = ColoredFormatter(
|
| 164 |
+
"%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s",
|
| 165 |
+
datefmt=None,
|
| 166 |
+
reset=True,
|
| 167 |
+
log_colors={
|
| 168 |
+
'DEBUG': 'cyan',
|
| 169 |
+
'INFO': 'green',
|
| 170 |
+
'WARNING': 'yellow',
|
| 171 |
+
'ERROR': 'red',
|
| 172 |
+
'CRITICAL': 'red,bg_white',
|
| 173 |
+
},
|
| 174 |
+
secondary_log_colors={},
|
| 175 |
+
style='%'
|
| 176 |
+
)
|
| 177 |
+
```
|
| 178 |
+
|
| 179 |
+
### Using `secondary_log_colors`
|
| 180 |
+
|
| 181 |
+
Secondary log colors are a way to have more than one color that is selected
|
| 182 |
+
based on the log level. Each key in `secondary_log_colors` adds an attribute
|
| 183 |
+
that can be used in format strings (`message` becomes `message_log_color`), and
|
| 184 |
+
has a corresponding value that is identical in format to the `log_colors`
|
| 185 |
+
argument.
|
| 186 |
+
|
| 187 |
+
The following example highlights the level name using the default log colors,
|
| 188 |
+
and highlights the message in red for `error` and `critical` level log messages.
|
| 189 |
+
|
| 190 |
+
```python
|
| 191 |
+
from colorlog import ColoredFormatter
|
| 192 |
+
|
| 193 |
+
formatter = ColoredFormatter(
|
| 194 |
+
"%(log_color)s%(levelname)-8s%(reset)s %(message_log_color)s%(message)s",
|
| 195 |
+
secondary_log_colors={
|
| 196 |
+
'message': {
|
| 197 |
+
'ERROR': 'red',
|
| 198 |
+
'CRITICAL': 'red'
|
| 199 |
+
}
|
| 200 |
+
}
|
| 201 |
+
)
|
| 202 |
+
```
|
| 203 |
+
|
| 204 |
+
### With [`dictConfig`][dictConfig]
|
| 205 |
+
|
| 206 |
+
```python
|
| 207 |
+
logging.config.dictConfig({
|
| 208 |
+
'formatters': {
|
| 209 |
+
'colored': {
|
| 210 |
+
'()': 'colorlog.ColoredFormatter',
|
| 211 |
+
'format': "%(log_color)s%(levelname)-8s%(reset)s %(blue)s%(message)s"
|
| 212 |
+
}
|
| 213 |
+
}
|
| 214 |
+
})
|
| 215 |
+
```
|
| 216 |
+
|
| 217 |
+
A full example dictionary can be found in `tests/test_colorlog.py`.
|
| 218 |
+
|
| 219 |
+
### With [`fileConfig`][fileConfig]
|
| 220 |
+
|
| 221 |
+
```ini
|
| 222 |
+
...
|
| 223 |
+
|
| 224 |
+
[formatters]
|
| 225 |
+
keys=color
|
| 226 |
+
|
| 227 |
+
[formatter_color]
|
| 228 |
+
class=colorlog.ColoredFormatter
|
| 229 |
+
format=%(log_color)s%(levelname)-8s%(reset)s %(bg_blue)s[%(name)s]%(reset)s %(message)s from fileConfig
|
| 230 |
+
datefmt=%m-%d %H:%M:%S
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
An instance of ColoredFormatter created with those arguments will then be used
|
| 234 |
+
by any handlers that are configured to use the `color` formatter.
|
| 235 |
+
|
| 236 |
+
A full example configuration can be found in `tests/test_config.ini`.
|
| 237 |
+
|
| 238 |
+
### With custom log levels
|
| 239 |
+
|
| 240 |
+
ColoredFormatter will work with custom log levels added with
|
| 241 |
+
[`logging.addLevelName`][addLevelName]:
|
| 242 |
+
|
| 243 |
+
```python
|
| 244 |
+
import logging, colorlog
|
| 245 |
+
TRACE = 5
|
| 246 |
+
logging.addLevelName(TRACE, 'TRACE')
|
| 247 |
+
formatter = colorlog.ColoredFormatter(log_colors={'TRACE': 'yellow'})
|
| 248 |
+
handler = logging.StreamHandler()
|
| 249 |
+
handler.setFormatter(formatter)
|
| 250 |
+
logger = logging.getLogger('example')
|
| 251 |
+
logger.addHandler(handler)
|
| 252 |
+
logger.setLevel('TRACE')
|
| 253 |
+
logger.log(TRACE, 'a message using a custom level')
|
| 254 |
+
```
|
| 255 |
+
|
| 256 |
+
## Tests
|
| 257 |
+
|
| 258 |
+
Tests similar to the above examples are found in `tests/test_colorlog.py`.
|
| 259 |
+
|
| 260 |
+
## Status
|
| 261 |
+
|
| 262 |
+
colorlog is in maintenance mode. I try and ensure bugfixes are published,
|
| 263 |
+
but compatibility a wide set of Python versions makes this a difficult
|
| 264 |
+
codebase to add features to. Any changes that might break backwards
|
| 265 |
+
compatibility for existing users will not be considered.
|
| 266 |
+
|
| 267 |
+
## Alternatives
|
| 268 |
+
|
| 269 |
+
There are some more modern libraries for improving Python logging you may
|
| 270 |
+
find useful.
|
| 271 |
+
|
| 272 |
+
- [structlog]
|
| 273 |
+
- [jsonlog]
|
| 274 |
+
|
| 275 |
+
## Projects using colorlog
|
| 276 |
+
|
| 277 |
+
GitHub provides [a list of projects that depend on colorlog][dependents].
|
| 278 |
+
|
| 279 |
+
Some early adopters included [Errbot], [Pythran], and [zenlog].
|
| 280 |
+
|
| 281 |
+
## Licence
|
| 282 |
+
|
| 283 |
+
Copyright (c) 2012-2025 Sam Clements <sam@borntyping.co.uk>
|
| 284 |
+
|
| 285 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
| 286 |
+
this software and associated documentation files (the "Software"), to deal in
|
| 287 |
+
the Software without restriction, including without limitation the rights to
|
| 288 |
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
| 289 |
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
| 290 |
+
subject to the following conditions:
|
| 291 |
+
|
| 292 |
+
The above copyright notice and this permission notice shall be included in all
|
| 293 |
+
copies or substantial portions of the Software.
|
| 294 |
+
|
| 295 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 296 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
| 297 |
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
| 298 |
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
| 299 |
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
| 300 |
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 301 |
+
|
| 302 |
+
[dictConfig]: http://docs.python.org/3/library/logging.config.html#logging.config.dictConfig
|
| 303 |
+
[fileConfig]: http://docs.python.org/3/library/logging.config.html#logging.config.fileConfig
|
| 304 |
+
[addLevelName]: https://docs.python.org/3/library/logging.html#logging.addLevelName
|
| 305 |
+
[Formatter]: http://docs.python.org/3/library/logging.html#logging.Formatter
|
| 306 |
+
[tox]: http://tox.readthedocs.org/
|
| 307 |
+
[Arch]: https://archlinux.org/packages/extra/any/python-colorlog/
|
| 308 |
+
[BSD ports]: https://www.freshports.org/devel/py-colorlog/
|
| 309 |
+
[colorama]: https://pypi.python.org/pypi/colorama
|
| 310 |
+
[Conda]: https://anaconda.org/conda-forge/colorlog
|
| 311 |
+
[Debian]: [https://packages.debian.org/buster/python3-colorlog](https://packages.debian.org/buster/python3-colorlog)
|
| 312 |
+
[Errbot]: http://errbot.io/
|
| 313 |
+
[Fedora]: https://src.fedoraproject.org/rpms/python-colorlog
|
| 314 |
+
[Gentoo]: https://packages.gentoo.org/packages/dev-python/colorlog
|
| 315 |
+
[OpenSuse]: http://rpm.pbone.net/index.php3?stat=3&search=python-colorlog&srodzaj=3
|
| 316 |
+
[Pythran]: https://github.com/serge-sans-paille/pythran
|
| 317 |
+
[Ubuntu]: https://launchpad.net/python-colorlog
|
| 318 |
+
[zenlog]: https://github.com/ManufacturaInd/python-zenlog
|
| 319 |
+
[structlog]: https://www.structlog.org/en/stable/
|
| 320 |
+
[jsonlog]: https://github.com/borntyping/jsonlog
|
| 321 |
+
[dependents]: https://github.com/borntyping/python-colorlog/network/dependents?package_id=UGFja2FnZS01MDk3NDcyMQ%3D%3D
|
.cache/pip/http-v2/3/8/c/c/8/38cc8209283ecb2d228ea8086bb74fbdc5d4872485c51a94fdb9c6cb
ADDED
|
Binary file (1.2 kB). View file
|
|
|
.cache/pip/http-v2/4/4/a/d/5/44ad51ab4fe732177892254938ca19df59a19add805fe17b3b22c658
ADDED
|
Binary file (1.27 kB). View file
|
|
|
.cache/pip/http-v2/4/4/a/d/5/44ad51ab4fe732177892254938ca19df59a19add805fe17b3b22c658.body
ADDED
|
@@ -0,0 +1,1595 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: tqdm
|
| 3 |
+
Version: 4.67.3
|
| 4 |
+
Summary: Fast, Extensible Progress Meter
|
| 5 |
+
Maintainer-email: tqdm developers <devs@tqdm.ml>
|
| 6 |
+
License: MPL-2.0 AND MIT
|
| 7 |
+
Project-URL: homepage, https://tqdm.github.io
|
| 8 |
+
Project-URL: repository, https://github.com/tqdm/tqdm
|
| 9 |
+
Project-URL: changelog, https://tqdm.github.io/releases
|
| 10 |
+
Project-URL: wiki, https://github.com/tqdm/tqdm/wiki
|
| 11 |
+
Keywords: progressbar,progressmeter,progress,bar,meter,rate,eta,console,terminal,time
|
| 12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 13 |
+
Classifier: Environment :: Console
|
| 14 |
+
Classifier: Environment :: MacOS X
|
| 15 |
+
Classifier: Environment :: Other Environment
|
| 16 |
+
Classifier: Environment :: Win32 (MS Windows)
|
| 17 |
+
Classifier: Environment :: X11 Applications
|
| 18 |
+
Classifier: Framework :: IPython
|
| 19 |
+
Classifier: Framework :: Jupyter
|
| 20 |
+
Classifier: Intended Audience :: Developers
|
| 21 |
+
Classifier: Intended Audience :: Education
|
| 22 |
+
Classifier: Intended Audience :: End Users/Desktop
|
| 23 |
+
Classifier: Intended Audience :: Other Audience
|
| 24 |
+
Classifier: Intended Audience :: System Administrators
|
| 25 |
+
Classifier: Operating System :: MacOS
|
| 26 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 27 |
+
Classifier: Operating System :: Microsoft
|
| 28 |
+
Classifier: Operating System :: Microsoft :: MS-DOS
|
| 29 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 30 |
+
Classifier: Operating System :: POSIX
|
| 31 |
+
Classifier: Operating System :: POSIX :: BSD
|
| 32 |
+
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
|
| 33 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 34 |
+
Classifier: Operating System :: POSIX :: SunOS/Solaris
|
| 35 |
+
Classifier: Operating System :: Unix
|
| 36 |
+
Classifier: Programming Language :: Python
|
| 37 |
+
Classifier: Programming Language :: Python :: 3
|
| 38 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 39 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 40 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 41 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 42 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 43 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 44 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 45 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 46 |
+
Classifier: Programming Language :: Python :: Implementation
|
| 47 |
+
Classifier: Programming Language :: Python :: Implementation :: IronPython
|
| 48 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 49 |
+
Classifier: Programming Language :: Unix Shell
|
| 50 |
+
Classifier: Topic :: Desktop Environment
|
| 51 |
+
Classifier: Topic :: Education :: Computer Aided Instruction (CAI)
|
| 52 |
+
Classifier: Topic :: Education :: Testing
|
| 53 |
+
Classifier: Topic :: Office/Business
|
| 54 |
+
Classifier: Topic :: Other/Nonlisted Topic
|
| 55 |
+
Classifier: Topic :: Software Development :: Build Tools
|
| 56 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 57 |
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
| 58 |
+
Classifier: Topic :: Software Development :: Pre-processors
|
| 59 |
+
Classifier: Topic :: Software Development :: User Interfaces
|
| 60 |
+
Classifier: Topic :: System :: Installation/Setup
|
| 61 |
+
Classifier: Topic :: System :: Logging
|
| 62 |
+
Classifier: Topic :: System :: Monitoring
|
| 63 |
+
Classifier: Topic :: System :: Shells
|
| 64 |
+
Classifier: Topic :: Terminals
|
| 65 |
+
Classifier: Topic :: Utilities
|
| 66 |
+
Requires-Python: >=3.7
|
| 67 |
+
Description-Content-Type: text/x-rst
|
| 68 |
+
License-File: LICENCE
|
| 69 |
+
Requires-Dist: colorama; platform_system == "Windows"
|
| 70 |
+
Requires-Dist: importlib_metadata; python_version < "3.8"
|
| 71 |
+
Provides-Extra: dev
|
| 72 |
+
Requires-Dist: pytest>=6; extra == "dev"
|
| 73 |
+
Requires-Dist: pytest-cov; extra == "dev"
|
| 74 |
+
Requires-Dist: pytest-timeout; extra == "dev"
|
| 75 |
+
Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
|
| 76 |
+
Requires-Dist: nbval; extra == "dev"
|
| 77 |
+
Provides-Extra: discord
|
| 78 |
+
Requires-Dist: requests; extra == "discord"
|
| 79 |
+
Provides-Extra: slack
|
| 80 |
+
Requires-Dist: slack-sdk; extra == "slack"
|
| 81 |
+
Provides-Extra: telegram
|
| 82 |
+
Requires-Dist: requests; extra == "telegram"
|
| 83 |
+
Provides-Extra: notebook
|
| 84 |
+
Requires-Dist: ipywidgets>=6; extra == "notebook"
|
| 85 |
+
Dynamic: license-file
|
| 86 |
+
|
| 87 |
+
|Logo|
|
| 88 |
+
|
| 89 |
+
tqdm
|
| 90 |
+
====
|
| 91 |
+
|
| 92 |
+
|Py-Versions| |Versions| |Conda-Forge-Status| |Docker| |Snapcraft|
|
| 93 |
+
|
| 94 |
+
|Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
|
| 95 |
+
|
| 96 |
+
|LICENCE| |OpenHub-Status| |binder-demo| |awesome-python|
|
| 97 |
+
|
| 98 |
+
``tqdm`` derives from the Arabic word *taqaddum* (تقدّم) which can mean "progress,"
|
| 99 |
+
and is an abbreviation for "I love you so much" in Spanish (*te quiero demasiado*).
|
| 100 |
+
|
| 101 |
+
Instantly make your loops show a smart progress meter - just wrap any
|
| 102 |
+
iterable with ``tqdm(iterable)``, and you're done!
|
| 103 |
+
|
| 104 |
+
.. code:: python
|
| 105 |
+
|
| 106 |
+
from tqdm import tqdm
|
| 107 |
+
for i in tqdm(range(10000)):
|
| 108 |
+
...
|
| 109 |
+
|
| 110 |
+
``76%|████████████████████████ | 7568/10000 [00:33<00:10, 229.00it/s]``
|
| 111 |
+
|
| 112 |
+
``trange(N)`` can be also used as a convenient shortcut for
|
| 113 |
+
``tqdm(range(N))``.
|
| 114 |
+
|
| 115 |
+
|Screenshot|
|
| 116 |
+
|Video| |Slides| |Merch|
|
| 117 |
+
|
| 118 |
+
It can also be executed as a module with pipes:
|
| 119 |
+
|
| 120 |
+
.. code:: sh
|
| 121 |
+
|
| 122 |
+
$ seq 9999999 | tqdm --bytes | wc -l
|
| 123 |
+
75.2MB [00:00, 217MB/s]
|
| 124 |
+
9999999
|
| 125 |
+
|
| 126 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
| 127 |
+
> backup.tgz
|
| 128 |
+
32%|██████████▍ | 8.89G/27.9G [00:42<01:31, 223MB/s]
|
| 129 |
+
|
| 130 |
+
Overhead is low -- about 60ns per iteration (80ns with ``tqdm.gui``), and is
|
| 131 |
+
unit tested against performance regression.
|
| 132 |
+
By comparison, the well-established
|
| 133 |
+
`ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
|
| 134 |
+
an 800ns/iter overhead.
|
| 135 |
+
|
| 136 |
+
In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
|
| 137 |
+
the remaining time and to skip unnecessary iteration displays, which allows
|
| 138 |
+
for a negligible overhead in most cases.
|
| 139 |
+
|
| 140 |
+
``tqdm`` works on any platform
|
| 141 |
+
(Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
|
| 142 |
+
in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
|
| 143 |
+
|
| 144 |
+
``tqdm`` does not require any dependencies (not even ``curses``!), just
|
| 145 |
+
Python and an environment supporting ``carriage return \r`` and
|
| 146 |
+
``line feed \n`` control characters.
|
| 147 |
+
|
| 148 |
+
------------------------------------------
|
| 149 |
+
|
| 150 |
+
.. contents:: Table of contents
|
| 151 |
+
:backlinks: top
|
| 152 |
+
:local:
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
Installation
|
| 156 |
+
------------
|
| 157 |
+
|
| 158 |
+
Latest PyPI stable release
|
| 159 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 160 |
+
|
| 161 |
+
|Versions| |PyPI-Downloads| |Libraries-Dependents|
|
| 162 |
+
|
| 163 |
+
.. code:: sh
|
| 164 |
+
|
| 165 |
+
pip install tqdm
|
| 166 |
+
|
| 167 |
+
Latest development release on GitHub
|
| 168 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 169 |
+
|
| 170 |
+
|GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
|
| 171 |
+
|
| 172 |
+
Pull and install pre-release ``devel`` branch:
|
| 173 |
+
|
| 174 |
+
.. code:: sh
|
| 175 |
+
|
| 176 |
+
pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"
|
| 177 |
+
|
| 178 |
+
Latest Conda release
|
| 179 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 180 |
+
|
| 181 |
+
|Conda-Forge-Status|
|
| 182 |
+
|
| 183 |
+
.. code:: sh
|
| 184 |
+
|
| 185 |
+
conda install -c conda-forge tqdm
|
| 186 |
+
|
| 187 |
+
Latest Snapcraft release
|
| 188 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 189 |
+
|
| 190 |
+
|Snapcraft|
|
| 191 |
+
|
| 192 |
+
There are 3 channels to choose from:
|
| 193 |
+
|
| 194 |
+
.. code:: sh
|
| 195 |
+
|
| 196 |
+
snap install tqdm # implies --stable, i.e. latest tagged release
|
| 197 |
+
snap install tqdm --candidate # master branch
|
| 198 |
+
snap install tqdm --edge # devel branch
|
| 199 |
+
|
| 200 |
+
Note that ``snap`` binaries are purely for CLI use (not ``import``-able), and
|
| 201 |
+
automatically set up ``bash`` tab-completion.
|
| 202 |
+
|
| 203 |
+
Latest Docker release
|
| 204 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 205 |
+
|
| 206 |
+
|Docker|
|
| 207 |
+
|
| 208 |
+
.. code:: sh
|
| 209 |
+
|
| 210 |
+
docker pull tqdm/tqdm
|
| 211 |
+
docker run -i --rm tqdm/tqdm --help
|
| 212 |
+
|
| 213 |
+
Other
|
| 214 |
+
~~~~~
|
| 215 |
+
|
| 216 |
+
There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use:
|
| 217 |
+
|
| 218 |
+
|Repology|
|
| 219 |
+
|
| 220 |
+
.. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg
|
| 221 |
+
:target: https://repology.org/project/python:tqdm/versions
|
| 222 |
+
|
| 223 |
+
Changelog
|
| 224 |
+
---------
|
| 225 |
+
|
| 226 |
+
The list of all changes is available either on GitHub's Releases:
|
| 227 |
+
|GitHub-Status|, on the
|
| 228 |
+
`wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
|
| 229 |
+
`website <https://tqdm.github.io/releases>`__.
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
Usage
|
| 233 |
+
-----
|
| 234 |
+
|
| 235 |
+
``tqdm`` is very versatile and can be used in a number of ways.
|
| 236 |
+
The three main ones are given below.
|
| 237 |
+
|
| 238 |
+
Iterable-based
|
| 239 |
+
~~~~~~~~~~~~~~
|
| 240 |
+
|
| 241 |
+
Wrap ``tqdm()`` around any iterable:
|
| 242 |
+
|
| 243 |
+
.. code:: python
|
| 244 |
+
|
| 245 |
+
from tqdm import tqdm
|
| 246 |
+
from time import sleep
|
| 247 |
+
|
| 248 |
+
text = ""
|
| 249 |
+
for char in tqdm(["a", "b", "c", "d"]):
|
| 250 |
+
sleep(0.25)
|
| 251 |
+
text = text + char
|
| 252 |
+
|
| 253 |
+
``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
|
| 254 |
+
|
| 255 |
+
.. code:: python
|
| 256 |
+
|
| 257 |
+
from tqdm import trange
|
| 258 |
+
|
| 259 |
+
for i in trange(100):
|
| 260 |
+
sleep(0.01)
|
| 261 |
+
|
| 262 |
+
Instantiation outside of the loop allows for manual control over ``tqdm()``:
|
| 263 |
+
|
| 264 |
+
.. code:: python
|
| 265 |
+
|
| 266 |
+
pbar = tqdm(["a", "b", "c", "d"])
|
| 267 |
+
for char in pbar:
|
| 268 |
+
sleep(0.25)
|
| 269 |
+
pbar.set_description("Processing %s" % char)
|
| 270 |
+
|
| 271 |
+
Manual
|
| 272 |
+
~~~~~~
|
| 273 |
+
|
| 274 |
+
Manual control of ``tqdm()`` updates using a ``with`` statement:
|
| 275 |
+
|
| 276 |
+
.. code:: python
|
| 277 |
+
|
| 278 |
+
with tqdm(total=100) as pbar:
|
| 279 |
+
for i in range(10):
|
| 280 |
+
sleep(0.1)
|
| 281 |
+
pbar.update(10)
|
| 282 |
+
|
| 283 |
+
If the optional variable ``total`` (or an iterable with ``len()``) is
|
| 284 |
+
provided, predictive stats are displayed.
|
| 285 |
+
|
| 286 |
+
``with`` is also optional (you can just assign ``tqdm()`` to a variable,
|
| 287 |
+
but in this case don't forget to ``del`` or ``close()`` at the end:
|
| 288 |
+
|
| 289 |
+
.. code:: python
|
| 290 |
+
|
| 291 |
+
pbar = tqdm(total=100)
|
| 292 |
+
for i in range(10):
|
| 293 |
+
sleep(0.1)
|
| 294 |
+
pbar.update(10)
|
| 295 |
+
pbar.close()
|
| 296 |
+
|
| 297 |
+
Module
|
| 298 |
+
~~~~~~
|
| 299 |
+
|
| 300 |
+
Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
|
| 301 |
+
line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
|
| 302 |
+
through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
|
| 303 |
+
|
| 304 |
+
The example below demonstrate counting the number of lines in all Python files
|
| 305 |
+
in the current directory, with timing information included.
|
| 306 |
+
|
| 307 |
+
.. code:: sh
|
| 308 |
+
|
| 309 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | wc -l
|
| 310 |
+
857365
|
| 311 |
+
|
| 312 |
+
real 0m3.458s
|
| 313 |
+
user 0m0.274s
|
| 314 |
+
sys 0m3.325s
|
| 315 |
+
|
| 316 |
+
$ time find . -name '*.py' -type f -exec cat \{} \; | tqdm | wc -l
|
| 317 |
+
857366it [00:03, 246471.31it/s]
|
| 318 |
+
857365
|
| 319 |
+
|
| 320 |
+
real 0m3.585s
|
| 321 |
+
user 0m0.862s
|
| 322 |
+
sys 0m3.358s
|
| 323 |
+
|
| 324 |
+
Note that the usual arguments for ``tqdm`` can also be specified.
|
| 325 |
+
|
| 326 |
+
.. code:: sh
|
| 327 |
+
|
| 328 |
+
$ find . -name '*.py' -type f -exec cat \{} \; |
|
| 329 |
+
tqdm --unit loc --unit_scale --total 857366 >> /dev/null
|
| 330 |
+
100%|█████████████████████████████████| 857K/857K [00:04<00:00, 246Kloc/s]
|
| 331 |
+
|
| 332 |
+
Backing up a large directory?
|
| 333 |
+
|
| 334 |
+
.. code:: sh
|
| 335 |
+
|
| 336 |
+
$ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
|
| 337 |
+
> backup.tgz
|
| 338 |
+
44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s]
|
| 339 |
+
|
| 340 |
+
This can be beautified further:
|
| 341 |
+
|
| 342 |
+
.. code:: sh
|
| 343 |
+
|
| 344 |
+
$ BYTES=$(du -sb docs/ | cut -f1)
|
| 345 |
+
$ tar -cf - docs/ \
|
| 346 |
+
| tqdm --bytes --total "$BYTES" --desc Processing | gzip \
|
| 347 |
+
| tqdm --bytes --total "$BYTES" --desc Compressed --position 1 \
|
| 348 |
+
> ~/backup.tgz
|
| 349 |
+
Processing: 100%|██████████████████████| 352M/352M [00:14<00:00, 30.2MB/s]
|
| 350 |
+
Compressed: 42%|█████████▎ | 148M/352M [00:14<00:19, 10.9MB/s]
|
| 351 |
+
|
| 352 |
+
Or done on a file level using 7-zip:
|
| 353 |
+
|
| 354 |
+
.. code:: sh
|
| 355 |
+
|
| 356 |
+
$ 7z a -bd -r backup.7z docs/ | grep Compressing \
|
| 357 |
+
| tqdm --total $(find docs/ -type f | wc -l) --unit files \
|
| 358 |
+
| grep -v Compressing
|
| 359 |
+
100%|██████████████████████████▉| 15327/15327 [01:00<00:00, 712.96files/s]
|
| 360 |
+
|
| 361 |
+
Pre-existing CLI programs already outputting basic progress information will
|
| 362 |
+
benefit from ``tqdm``'s ``--update`` and ``--update_to`` flags:
|
| 363 |
+
|
| 364 |
+
.. code:: sh
|
| 365 |
+
|
| 366 |
+
$ seq 3 0.1 5 | tqdm --total 5 --update_to --null
|
| 367 |
+
100%|████████████████████████████████████| 5.0/5 [00:00<00:00, 9673.21it/s]
|
| 368 |
+
$ seq 10 | tqdm --update --null # 1 + 2 + ... + 10 = 55 iterations
|
| 369 |
+
55it [00:00, 90006.52it/s]
|
| 370 |
+
|
| 371 |
+
FAQ and Known Issues
|
| 372 |
+
--------------------
|
| 373 |
+
|
| 374 |
+
|GitHub-Issues|
|
| 375 |
+
|
| 376 |
+
The most common issues relate to excessive output on multiple lines, instead
|
| 377 |
+
of a neat one-line progress bar.
|
| 378 |
+
|
| 379 |
+
- Consoles in general: require support for carriage return (``CR``, ``\r``).
|
| 380 |
+
|
| 381 |
+
* Some cloud logging consoles which don't support ``\r`` properly
|
| 382 |
+
(`cloudwatch <https://github.com/tqdm/tqdm/issues/966>`__,
|
| 383 |
+
`K8s <https://github.com/tqdm/tqdm/issues/1319>`__) may benefit from
|
| 384 |
+
``export TQDM_POSITION=-1``.
|
| 385 |
+
|
| 386 |
+
- Nested progress bars:
|
| 387 |
+
|
| 388 |
+
* Consoles in general: require support for moving cursors up to the
|
| 389 |
+
previous line. For example,
|
| 390 |
+
`IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
|
| 391 |
+
`ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
|
| 392 |
+
`PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
|
| 393 |
+
`here <https://github.com/tqdm/tqdm/issues/208>`__,
|
| 394 |
+
`here <https://github.com/tqdm/tqdm/issues/307>`__, and
|
| 395 |
+
`here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
|
| 396 |
+
lack full support.
|
| 397 |
+
* Windows: additionally may require the Python module ``colorama``
|
| 398 |
+
to ensure nested bars stay within their respective lines.
|
| 399 |
+
|
| 400 |
+
- Unicode:
|
| 401 |
+
|
| 402 |
+
* Environments which report that they support unicode will have solid smooth
|
| 403 |
+
progressbars. The fallback is an ``ascii``-only bar.
|
| 404 |
+
* Windows consoles often only partially support unicode and thus
|
| 405 |
+
`often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
|
| 406 |
+
(also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
|
| 407 |
+
either normal-width unicode characters being incorrectly displayed as
|
| 408 |
+
"wide", or some unicode characters not rendering.
|
| 409 |
+
|
| 410 |
+
- Wrapping generators:
|
| 411 |
+
|
| 412 |
+
* Generator wrapper functions tend to hide the length of iterables.
|
| 413 |
+
``tqdm`` does not.
|
| 414 |
+
* Replace ``tqdm(enumerate(...))`` with ``enumerate(tqdm(...))`` or
|
| 415 |
+
``tqdm(enumerate(x), total=len(x), ...)``.
|
| 416 |
+
The same applies to ``numpy.ndenumerate``.
|
| 417 |
+
* Replace ``tqdm(zip(a, b))`` with ``zip(tqdm(a), b)`` or even
|
| 418 |
+
``zip(tqdm(a), tqdm(b))``.
|
| 419 |
+
* The same applies to ``itertools``.
|
| 420 |
+
* Some useful convenience functions can be found under ``tqdm.contrib``.
|
| 421 |
+
|
| 422 |
+
- `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
|
| 423 |
+
use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.
|
| 424 |
+
|
| 425 |
+
- Overriding defaults via environment variables:
|
| 426 |
+
e.g. in CI/cloud jobs, ``export TQDM_MININTERVAL=5`` to avoid log spam.
|
| 427 |
+
This override logic is handled by the ``tqdm.utils.envwrap`` decorator
|
| 428 |
+
(useful independent of ``tqdm``).
|
| 429 |
+
|
| 430 |
+
If you come across any other difficulties, browse and file |GitHub-Issues|.
|
| 431 |
+
|
| 432 |
+
Documentation
|
| 433 |
+
-------------
|
| 434 |
+
|
| 435 |
+
|Py-Versions| |README-Hits| (Since 19 May 2016)
|
| 436 |
+
|
| 437 |
+
.. code:: python
|
| 438 |
+
|
| 439 |
+
class tqdm():
|
| 440 |
+
"""
|
| 441 |
+
Decorate an iterable object, returning an iterator which acts exactly
|
| 442 |
+
like the original iterable, but prints a dynamically updating
|
| 443 |
+
progressbar every time a value is requested.
|
| 444 |
+
"""
|
| 445 |
+
|
| 446 |
+
@envwrap("TQDM_") # override defaults via env vars
|
| 447 |
+
def __init__(self, iterable=None, desc=None, total=None, leave=True,
|
| 448 |
+
file=None, ncols=None, mininterval=0.1,
|
| 449 |
+
maxinterval=10.0, miniters=None, ascii=None, disable=False,
|
| 450 |
+
unit='it', unit_scale=False, dynamic_ncols=False,
|
| 451 |
+
smoothing=0.3, bar_format=None, initial=0, position=None,
|
| 452 |
+
postfix=None, unit_divisor=1000, write_bytes=False,
|
| 453 |
+
lock_args=None, nrows=None, colour=None, delay=0):
|
| 454 |
+
|
| 455 |
+
Parameters
|
| 456 |
+
~~~~~~~~~~
|
| 457 |
+
|
| 458 |
+
* iterable : iterable, optional
|
| 459 |
+
Iterable to decorate with a progressbar.
|
| 460 |
+
Leave blank to manually manage the updates.
|
| 461 |
+
* desc : str, optional
|
| 462 |
+
Prefix for the progressbar.
|
| 463 |
+
* total : int or float, optional
|
| 464 |
+
The number of expected iterations. If unspecified,
|
| 465 |
+
len(iterable) is used if possible. If float("inf") or as a last
|
| 466 |
+
resort, only basic progress statistics are displayed
|
| 467 |
+
(no ETA, no progressbar).
|
| 468 |
+
If ``gui`` is True and this parameter needs subsequent updating,
|
| 469 |
+
specify an initial arbitrary large positive number,
|
| 470 |
+
e.g. 9e9.
|
| 471 |
+
* leave : bool, optional
|
| 472 |
+
If [default: True], keeps all traces of the progressbar
|
| 473 |
+
upon termination of iteration.
|
| 474 |
+
If ``None``, will leave only if ``position`` is ``0``.
|
| 475 |
+
* file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
|
| 476 |
+
Specifies where to output the progress messages
|
| 477 |
+
(default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
|
| 478 |
+
methods. For encoding, see ``write_bytes``.
|
| 479 |
+
* ncols : int, optional
|
| 480 |
+
The width of the entire output message. If specified,
|
| 481 |
+
dynamically resizes the progressbar to stay within this bound.
|
| 482 |
+
If unspecified, attempts to use environment width. The
|
| 483 |
+
fallback is a meter width of 10 and no limit for the counter and
|
| 484 |
+
statistics. If 0, will not print any meter (only stats).
|
| 485 |
+
* mininterval : float, optional
|
| 486 |
+
Minimum progress display update interval [default: 0.1] seconds.
|
| 487 |
+
* maxinterval : float, optional
|
| 488 |
+
Maximum progress display update interval [default: 10] seconds.
|
| 489 |
+
Automatically adjusts ``miniters`` to correspond to ``mininterval``
|
| 490 |
+
after long display update lag. Only works if ``dynamic_miniters``
|
| 491 |
+
or monitor thread is enabled.
|
| 492 |
+
* miniters : int or float, optional
|
| 493 |
+
Minimum progress display update interval, in iterations.
|
| 494 |
+
If 0 and ``dynamic_miniters``, will automatically adjust to equal
|
| 495 |
+
``mininterval`` (more CPU efficient, good for tight loops).
|
| 496 |
+
If > 0, will skip display of specified number of iterations.
|
| 497 |
+
Tweak this and ``mininterval`` to get very efficient loops.
|
| 498 |
+
If your progress is erratic with both fast and slow iterations
|
| 499 |
+
(network, skipping items, etc) you should set miniters=1.
|
| 500 |
+
* ascii : bool or str, optional
|
| 501 |
+
If unspecified or False, use unicode (smooth blocks) to fill
|
| 502 |
+
the meter. The fallback is to use ASCII characters " 123456789#".
|
| 503 |
+
* disable : bool, optional
|
| 504 |
+
Whether to disable the entire progressbar wrapper
|
| 505 |
+
[default: False]. If set to None, disable on non-TTY.
|
| 506 |
+
* unit : str, optional
|
| 507 |
+
String that will be used to define the unit of each iteration
|
| 508 |
+
[default: it].
|
| 509 |
+
* unit_scale : bool or int or float, optional
|
| 510 |
+
If 1 or True, the number of iterations will be reduced/scaled
|
| 511 |
+
automatically and a metric prefix following the
|
| 512 |
+
International System of Units standard will be added
|
| 513 |
+
(kilo, mega, etc.) [default: False]. If any other non-zero
|
| 514 |
+
number, will scale ``total`` and ``n``.
|
| 515 |
+
* dynamic_ncols : bool, optional
|
| 516 |
+
If set, constantly alters ``ncols`` and ``nrows`` to the
|
| 517 |
+
environment (allowing for window resizes) [default: False].
|
| 518 |
+
* smoothing : float, optional
|
| 519 |
+
Exponential moving average smoothing factor for speed estimates
|
| 520 |
+
(ignored in GUI mode). Ranges from 0 (average speed) to 1
|
| 521 |
+
(current/instantaneous speed) [default: 0.3].
|
| 522 |
+
* bar_format : str, optional
|
| 523 |
+
Specify a custom bar string formatting. May impact performance.
|
| 524 |
+
[default: '{l_bar}{bar}{r_bar}'], where
|
| 525 |
+
l_bar='{desc}: {percentage:3.0f}%|' and
|
| 526 |
+
r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
|
| 527 |
+
'{rate_fmt}{postfix}]'
|
| 528 |
+
Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
|
| 529 |
+
percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
|
| 530 |
+
rate, rate_fmt, rate_noinv, rate_noinv_fmt,
|
| 531 |
+
rate_inv, rate_inv_fmt, postfix, unit_divisor,
|
| 532 |
+
remaining, remaining_s, eta.
|
| 533 |
+
Note that a trailing ": " is automatically removed after {desc}
|
| 534 |
+
if the latter is empty.
|
| 535 |
+
* initial : int or float, optional
|
| 536 |
+
The initial counter value. Useful when restarting a progress
|
| 537 |
+
bar [default: 0]. If using float, consider specifying ``{n:.3f}``
|
| 538 |
+
or similar in ``bar_format``, or specifying ``unit_scale``.
|
| 539 |
+
* position : int, optional
|
| 540 |
+
Specify the line offset to print this bar (starting from 0)
|
| 541 |
+
Automatic if unspecified.
|
| 542 |
+
Useful to manage multiple bars at once (eg, from threads).
|
| 543 |
+
* postfix : dict or ``*``, optional
|
| 544 |
+
Specify additional stats to display at the end of the bar.
|
| 545 |
+
Calls ``set_postfix(**postfix)`` if possible (dict).
|
| 546 |
+
* unit_divisor : float, optional
|
| 547 |
+
[default: 1000], ignored unless ``unit_scale`` is True.
|
| 548 |
+
* write_bytes : bool, optional
|
| 549 |
+
Whether to write bytes. If (default: False) will write unicode.
|
| 550 |
+
* lock_args : tuple, optional
|
| 551 |
+
Passed to ``refresh`` for intermediate output
|
| 552 |
+
(initialisation, iterating, and updating).
|
| 553 |
+
* nrows : int, optional
|
| 554 |
+
The screen height. If specified, hides nested bars outside this
|
| 555 |
+
bound. If unspecified, attempts to use environment height.
|
| 556 |
+
The fallback is 20.
|
| 557 |
+
* colour : str, optional
|
| 558 |
+
Bar colour (e.g. 'green', '#00ff00').
|
| 559 |
+
* delay : float, optional
|
| 560 |
+
Don't display until [default: 0] seconds have elapsed.
|
| 561 |
+
|
| 562 |
+
Extra CLI Options
|
| 563 |
+
~~~~~~~~~~~~~~~~~
|
| 564 |
+
|
| 565 |
+
* delim : chr, optional
|
| 566 |
+
Delimiting character [default: '\n']. Use '\0' for null.
|
| 567 |
+
N.B.: on Windows systems, Python converts '\n' to '\r\n'.
|
| 568 |
+
* buf_size : int, optional
|
| 569 |
+
String buffer size in bytes [default: 256]
|
| 570 |
+
used when ``delim`` is specified.
|
| 571 |
+
* bytes : bool, optional
|
| 572 |
+
If true, will count bytes, ignore ``delim``, and default
|
| 573 |
+
``unit_scale`` to True, ``unit_divisor`` to 1024, and ``unit`` to 'B'.
|
| 574 |
+
* tee : bool, optional
|
| 575 |
+
If true, passes ``stdin`` to both ``stderr`` and ``stdout``.
|
| 576 |
+
* update : bool, optional
|
| 577 |
+
If true, will treat input as newly elapsed iterations,
|
| 578 |
+
i.e. numbers to pass to ``update()``. Note that this is slow
|
| 579 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 580 |
+
* update_to : bool, optional
|
| 581 |
+
If true, will treat input as total elapsed iterations,
|
| 582 |
+
i.e. numbers to assign to ``self.n``. Note that this is slow
|
| 583 |
+
(~2e5 it/s) since every input must be decoded as a number.
|
| 584 |
+
* null : bool, optional
|
| 585 |
+
If true, will discard input (no stdout).
|
| 586 |
+
* manpath : str, optional
|
| 587 |
+
Directory in which to install tqdm man pages.
|
| 588 |
+
* comppath : str, optional
|
| 589 |
+
Directory in which to place tqdm completion.
|
| 590 |
+
* log : str, optional
|
| 591 |
+
CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
|
| 592 |
+
|
| 593 |
+
Returns
|
| 594 |
+
~~~~~~~
|
| 595 |
+
|
| 596 |
+
* out : decorated iterator.
|
| 597 |
+
|
| 598 |
+
.. code:: python
|
| 599 |
+
|
| 600 |
+
class tqdm():
|
| 601 |
+
def update(self, n=1):
|
| 602 |
+
"""
|
| 603 |
+
Manually update the progress bar, useful for streams
|
| 604 |
+
such as reading files.
|
| 605 |
+
E.g.:
|
| 606 |
+
>>> t = tqdm(total=filesize) # Initialise
|
| 607 |
+
>>> for current_buffer in stream:
|
| 608 |
+
... ...
|
| 609 |
+
... t.update(len(current_buffer))
|
| 610 |
+
>>> t.close()
|
| 611 |
+
The last line is highly recommended, but possibly not necessary if
|
| 612 |
+
``t.update()`` will be called in such a way that ``filesize`` will be
|
| 613 |
+
exactly reached and printed.
|
| 614 |
+
|
| 615 |
+
Parameters
|
| 616 |
+
----------
|
| 617 |
+
n : int or float, optional
|
| 618 |
+
Increment to add to the internal counter of iterations
|
| 619 |
+
[default: 1]. If using float, consider specifying ``{n:.3f}``
|
| 620 |
+
or similar in ``bar_format``, or specifying ``unit_scale``.
|
| 621 |
+
|
| 622 |
+
Returns
|
| 623 |
+
-------
|
| 624 |
+
out : bool or None
|
| 625 |
+
True if a ``display()`` was triggered.
|
| 626 |
+
"""
|
| 627 |
+
|
| 628 |
+
def close(self):
|
| 629 |
+
"""Cleanup and (if leave=False) close the progressbar."""
|
| 630 |
+
|
| 631 |
+
def clear(self, nomove=False):
|
| 632 |
+
"""Clear current bar display."""
|
| 633 |
+
|
| 634 |
+
def refresh(self):
|
| 635 |
+
"""
|
| 636 |
+
Force refresh the display of this bar.
|
| 637 |
+
|
| 638 |
+
Parameters
|
| 639 |
+
----------
|
| 640 |
+
nolock : bool, optional
|
| 641 |
+
If ``True``, does not lock.
|
| 642 |
+
If [default: ``False``]: calls ``acquire()`` on internal lock.
|
| 643 |
+
lock_args : tuple, optional
|
| 644 |
+
Passed to internal lock's ``acquire()``.
|
| 645 |
+
If specified, will only ``display()`` if ``acquire()`` returns ``True``.
|
| 646 |
+
"""
|
| 647 |
+
|
| 648 |
+
def unpause(self):
|
| 649 |
+
"""Restart tqdm timer from last print time."""
|
| 650 |
+
|
| 651 |
+
def reset(self, total=None):
|
| 652 |
+
"""
|
| 653 |
+
Resets to 0 iterations for repeated use.
|
| 654 |
+
|
| 655 |
+
Consider combining with ``leave=True``.
|
| 656 |
+
|
| 657 |
+
Parameters
|
| 658 |
+
----------
|
| 659 |
+
total : int or float, optional. Total to use for the new bar.
|
| 660 |
+
"""
|
| 661 |
+
|
| 662 |
+
def set_description(self, desc=None, refresh=True):
|
| 663 |
+
"""
|
| 664 |
+
Set/modify description of the progress bar.
|
| 665 |
+
|
| 666 |
+
Parameters
|
| 667 |
+
----------
|
| 668 |
+
desc : str, optional
|
| 669 |
+
refresh : bool, optional
|
| 670 |
+
Forces refresh [default: True].
|
| 671 |
+
"""
|
| 672 |
+
|
| 673 |
+
def set_postfix(self, ordered_dict=None, refresh=True, **tqdm_kwargs):
|
| 674 |
+
"""
|
| 675 |
+
Set/modify postfix (additional stats)
|
| 676 |
+
with automatic formatting based on datatype.
|
| 677 |
+
|
| 678 |
+
Parameters
|
| 679 |
+
----------
|
| 680 |
+
ordered_dict : dict or OrderedDict, optional
|
| 681 |
+
refresh : bool, optional
|
| 682 |
+
Forces refresh [default: True].
|
| 683 |
+
kwargs : dict, optional
|
| 684 |
+
"""
|
| 685 |
+
|
| 686 |
+
@classmethod
|
| 687 |
+
def write(cls, s, file=sys.stdout, end="\n"):
|
| 688 |
+
"""Print a message via tqdm (without overlap with bars)."""
|
| 689 |
+
|
| 690 |
+
@property
|
| 691 |
+
def format_dict(self):
|
| 692 |
+
"""Public API for read-only member access."""
|
| 693 |
+
|
| 694 |
+
def display(self, msg=None, pos=None):
|
| 695 |
+
"""
|
| 696 |
+
Use ``self.sp`` to display ``msg`` in the specified ``pos``.
|
| 697 |
+
|
| 698 |
+
Consider overloading this function when inheriting to use e.g.:
|
| 699 |
+
``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
|
| 700 |
+
|
| 701 |
+
Parameters
|
| 702 |
+
----------
|
| 703 |
+
msg : str, optional. What to display (default: ``repr(self)``).
|
| 704 |
+
pos : int, optional. Position to ``moveto``
|
| 705 |
+
(default: ``abs(self.pos)``).
|
| 706 |
+
"""
|
| 707 |
+
|
| 708 |
+
@classmethod
|
| 709 |
+
@contextmanager
|
| 710 |
+
def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
|
| 711 |
+
"""
|
| 712 |
+
stream : file-like object.
|
| 713 |
+
method : str, "read" or "write". The result of ``read()`` and
|
| 714 |
+
the first argument of ``write()`` should have a ``len()``.
|
| 715 |
+
|
| 716 |
+
>>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
|
| 717 |
+
... while True:
|
| 718 |
+
... chunk = fobj.read(chunk_size)
|
| 719 |
+
... if not chunk:
|
| 720 |
+
... break
|
| 721 |
+
"""
|
| 722 |
+
|
| 723 |
+
@classmethod
|
| 724 |
+
def pandas(cls, *targs, **tqdm_kwargs):
|
| 725 |
+
"""Registers the current `tqdm` class with `pandas`."""
|
| 726 |
+
|
| 727 |
+
def trange(*args, **tqdm_kwargs):
|
| 728 |
+
"""Shortcut for `tqdm(range(*args), **tqdm_kwargs)`."""
|
| 729 |
+
|
| 730 |
+
Convenience Functions
|
| 731 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 732 |
+
|
| 733 |
+
.. code:: python
|
| 734 |
+
|
| 735 |
+
def tqdm.contrib.tenumerate(iterable, start=0, total=None,
|
| 736 |
+
tqdm_class=tqdm.auto.tqdm, **tqdm_kwargs):
|
| 737 |
+
"""Equivalent of `numpy.ndenumerate` or builtin `enumerate`."""
|
| 738 |
+
|
| 739 |
+
def tqdm.contrib.tzip(iter1, *iter2plus, **tqdm_kwargs):
|
| 740 |
+
"""Equivalent of builtin `zip`."""
|
| 741 |
+
|
| 742 |
+
def tqdm.contrib.tmap(function, *sequences, **tqdm_kwargs):
|
| 743 |
+
"""Equivalent of builtin `map`."""
|
| 744 |
+
|
| 745 |
+
Submodules
|
| 746 |
+
~~~~~~~~~~
|
| 747 |
+
|
| 748 |
+
.. code:: python
|
| 749 |
+
|
| 750 |
+
class tqdm.notebook.tqdm(tqdm.tqdm):
|
| 751 |
+
"""IPython/Jupyter Notebook widget."""
|
| 752 |
+
|
| 753 |
+
class tqdm.auto.tqdm(tqdm.tqdm):
|
| 754 |
+
"""Automatically chooses beween `tqdm.notebook` and `tqdm.tqdm`."""
|
| 755 |
+
|
| 756 |
+
class tqdm.asyncio.tqdm(tqdm.tqdm):
|
| 757 |
+
"""Asynchronous version."""
|
| 758 |
+
@classmethod
|
| 759 |
+
def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
|
| 760 |
+
**tqdm_kwargs):
|
| 761 |
+
"""Wrapper for `asyncio.as_completed`."""
|
| 762 |
+
|
| 763 |
+
class tqdm.gui.tqdm(tqdm.tqdm):
|
| 764 |
+
"""Matplotlib GUI version."""
|
| 765 |
+
|
| 766 |
+
class tqdm.tk.tqdm(tqdm.tqdm):
|
| 767 |
+
"""Tkinter GUI version."""
|
| 768 |
+
|
| 769 |
+
class tqdm.rich.tqdm(tqdm.tqdm):
|
| 770 |
+
"""`rich.progress` version."""
|
| 771 |
+
|
| 772 |
+
class tqdm.keras.TqdmCallback(keras.callbacks.Callback):
|
| 773 |
+
"""Keras callback for epoch and batch progress."""
|
| 774 |
+
|
| 775 |
+
class tqdm.dask.TqdmCallback(dask.callbacks.Callback):
|
| 776 |
+
"""Dask callback for task progress."""
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
``contrib``
|
| 780 |
+
+++++++++++
|
| 781 |
+
|
| 782 |
+
The ``tqdm.contrib`` package also contains experimental modules:
|
| 783 |
+
|
| 784 |
+
- ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
|
| 785 |
+
- ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
|
| 786 |
+
- ``tqdm.contrib.slack``: Posts to `Slack <https://slack.com>`__ bots
|
| 787 |
+
- ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com>`__ bots
|
| 788 |
+
- ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org>`__ bots
|
| 789 |
+
- ``tqdm.contrib.bells``: Automagically enables all optional features
|
| 790 |
+
|
| 791 |
+
* ``auto``, ``pandas``, ``slack``, ``discord``, ``telegram``
|
| 792 |
+
|
| 793 |
+
Examples and Advanced Usage
|
| 794 |
+
---------------------------
|
| 795 |
+
|
| 796 |
+
- See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
| 797 |
+
folder;
|
| 798 |
+
- import the module and run ``help()``;
|
| 799 |
+
- consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__;
|
| 800 |
+
|
| 801 |
+
* this has an
|
| 802 |
+
`excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
|
| 803 |
+
on how to make a **great** progressbar;
|
| 804 |
+
|
| 805 |
+
- check out the `slides from PyData London <https://tqdm.github.io/PyData2019/slides.html>`__, or
|
| 806 |
+
- run the |binder-demo|.
|
| 807 |
+
|
| 808 |
+
Description and additional stats
|
| 809 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 810 |
+
|
| 811 |
+
Custom information can be displayed and updated dynamically on ``tqdm`` bars
|
| 812 |
+
with the ``desc`` and ``postfix`` arguments:
|
| 813 |
+
|
| 814 |
+
.. code:: python
|
| 815 |
+
|
| 816 |
+
from tqdm import tqdm, trange
|
| 817 |
+
from random import random, randint
|
| 818 |
+
from time import sleep
|
| 819 |
+
|
| 820 |
+
with trange(10) as t:
|
| 821 |
+
for i in t:
|
| 822 |
+
# Description will be displayed on the left
|
| 823 |
+
t.set_description('GEN %i' % i)
|
| 824 |
+
# Postfix will be displayed on the right,
|
| 825 |
+
# formatted automatically based on argument's datatype
|
| 826 |
+
t.set_postfix(loss=random(), gen=randint(1,999), str='h',
|
| 827 |
+
lst=[1, 2])
|
| 828 |
+
sleep(0.1)
|
| 829 |
+
|
| 830 |
+
with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
|
| 831 |
+
postfix=["Batch", {"value": 0}]) as t:
|
| 832 |
+
for i in range(10):
|
| 833 |
+
sleep(0.1)
|
| 834 |
+
t.postfix[1]["value"] = i / 2
|
| 835 |
+
t.update()
|
| 836 |
+
|
| 837 |
+
Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
|
| 838 |
+
|
| 839 |
+
- ``postfix`` also needs to be passed as an initial argument in a compatible
|
| 840 |
+
format, and
|
| 841 |
+
- ``postfix`` will be auto-converted to a string if it is a ``dict``-like
|
| 842 |
+
object. To prevent this behaviour, insert an extra item into the dictionary
|
| 843 |
+
where the key is not a string.
|
| 844 |
+
|
| 845 |
+
Additional ``bar_format`` parameters may also be defined by overriding
|
| 846 |
+
``format_dict``, and the bar itself may be modified using ``ascii``:
|
| 847 |
+
|
| 848 |
+
.. code:: python
|
| 849 |
+
|
| 850 |
+
from tqdm import tqdm
|
| 851 |
+
class TqdmExtraFormat(tqdm):
|
| 852 |
+
"""Provides a `total_time` format parameter"""
|
| 853 |
+
@property
|
| 854 |
+
def format_dict(self):
|
| 855 |
+
d = super().format_dict
|
| 856 |
+
total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
|
| 857 |
+
d.update(total_time=self.format_interval(total_time) + " in total")
|
| 858 |
+
return d
|
| 859 |
+
|
| 860 |
+
for i in TqdmExtraFormat(
|
| 861 |
+
range(9), ascii=" .oO0",
|
| 862 |
+
bar_format="{total_time}: {percentage:.0f}%|{bar}{r_bar}"):
|
| 863 |
+
if i == 4:
|
| 864 |
+
break
|
| 865 |
+
|
| 866 |
+
.. code::
|
| 867 |
+
|
| 868 |
+
00:00 in total: 44%|0000. | 4/9 [00:00<00:00, 962.93it/s]
|
| 869 |
+
|
| 870 |
+
Note that ``{bar}`` also supports a format specifier ``[width][type]``.
|
| 871 |
+
|
| 872 |
+
- ``width``
|
| 873 |
+
|
| 874 |
+
* unspecified (default): automatic to fill ``ncols``
|
| 875 |
+
* ``int >= 0``: fixed width overriding ``ncols`` logic
|
| 876 |
+
* ``int < 0``: subtract from the automatic default
|
| 877 |
+
|
| 878 |
+
- ``type``
|
| 879 |
+
|
| 880 |
+
* ``a``: ascii (``ascii=True`` override)
|
| 881 |
+
* ``u``: unicode (``ascii=False`` override)
|
| 882 |
+
* ``b``: blank (``ascii=" "`` override)
|
| 883 |
+
|
| 884 |
+
This means a fixed bar with right-justified text may be created by using:
|
| 885 |
+
``bar_format="{l_bar}{bar:10}|{bar:-10b}right-justified"``
|
| 886 |
+
|
| 887 |
+
Nested progress bars
|
| 888 |
+
~~~~~~~~~~~~~~~~~~~~
|
| 889 |
+
|
| 890 |
+
``tqdm`` supports nested progress bars. Here's an example:
|
| 891 |
+
|
| 892 |
+
.. code:: python
|
| 893 |
+
|
| 894 |
+
from tqdm.auto import trange
|
| 895 |
+
from time import sleep
|
| 896 |
+
|
| 897 |
+
for i in trange(4, desc='1st loop'):
|
| 898 |
+
for j in trange(5, desc='2nd loop'):
|
| 899 |
+
for k in trange(50, desc='3rd loop', leave=False):
|
| 900 |
+
sleep(0.01)
|
| 901 |
+
|
| 902 |
+
For manual control over positioning (e.g. for multi-processing use),
|
| 903 |
+
you may specify ``position=n`` where ``n=0`` for the outermost bar,
|
| 904 |
+
``n=1`` for the next, and so on.
|
| 905 |
+
However, it's best to check if ``tqdm`` can work without manual ``position``
|
| 906 |
+
first.
|
| 907 |
+
|
| 908 |
+
.. code:: python
|
| 909 |
+
|
| 910 |
+
from time import sleep
|
| 911 |
+
from tqdm import trange, tqdm
|
| 912 |
+
from multiprocessing import Pool, RLock, freeze_support
|
| 913 |
+
|
| 914 |
+
L = list(range(9))
|
| 915 |
+
|
| 916 |
+
def progresser(n):
|
| 917 |
+
interval = 0.001 / (n + 2)
|
| 918 |
+
total = 5000
|
| 919 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
| 920 |
+
for _ in trange(total, desc=text, position=n):
|
| 921 |
+
sleep(interval)
|
| 922 |
+
|
| 923 |
+
if __name__ == '__main__':
|
| 924 |
+
freeze_support() # for Windows support
|
| 925 |
+
tqdm.set_lock(RLock()) # for managing output contention
|
| 926 |
+
p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))
|
| 927 |
+
p.map(progresser, L)
|
| 928 |
+
|
| 929 |
+
Note that in Python 3, ``tqdm.write`` is thread-safe:
|
| 930 |
+
|
| 931 |
+
.. code:: python
|
| 932 |
+
|
| 933 |
+
from time import sleep
|
| 934 |
+
from tqdm import tqdm, trange
|
| 935 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 936 |
+
|
| 937 |
+
L = list(range(9))
|
| 938 |
+
|
| 939 |
+
def progresser(n):
|
| 940 |
+
interval = 0.001 / (n + 2)
|
| 941 |
+
total = 5000
|
| 942 |
+
text = f"#{n}, est. {interval * total:<04.2}s"
|
| 943 |
+
for _ in trange(total, desc=text):
|
| 944 |
+
sleep(interval)
|
| 945 |
+
if n == 6:
|
| 946 |
+
tqdm.write("n == 6 completed.")
|
| 947 |
+
tqdm.write("`tqdm.write()` is thread-safe in py3!")
|
| 948 |
+
|
| 949 |
+
if __name__ == '__main__':
|
| 950 |
+
with ThreadPoolExecutor() as p:
|
| 951 |
+
p.map(progresser, L)
|
| 952 |
+
|
| 953 |
+
Hooks and callbacks
|
| 954 |
+
~~~~~~~~~~~~~~~~~~~
|
| 955 |
+
|
| 956 |
+
``tqdm`` can easily support callbacks/hooks and manual updates.
|
| 957 |
+
Here's an example with ``urllib``:
|
| 958 |
+
|
| 959 |
+
**``urllib.urlretrieve`` documentation**
|
| 960 |
+
|
| 961 |
+
| [...]
|
| 962 |
+
| If present, the hook function will be called once
|
| 963 |
+
| on establishment of the network connection and once after each block read
|
| 964 |
+
| thereafter. The hook will be passed three arguments; a count of blocks
|
| 965 |
+
| transferred so far, a block size in bytes, and the total size of the file.
|
| 966 |
+
| [...]
|
| 967 |
+
|
| 968 |
+
.. code:: python
|
| 969 |
+
|
| 970 |
+
import urllib, os
|
| 971 |
+
from tqdm import tqdm
|
| 972 |
+
urllib = getattr(urllib, 'request', urllib)
|
| 973 |
+
|
| 974 |
+
class TqdmUpTo(tqdm):
|
| 975 |
+
"""Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
|
| 976 |
+
def update_to(self, b=1, bsize=1, tsize=None):
|
| 977 |
+
"""
|
| 978 |
+
b : int, optional
|
| 979 |
+
Number of blocks transferred so far [default: 1].
|
| 980 |
+
bsize : int, optional
|
| 981 |
+
Size of each block (in tqdm units) [default: 1].
|
| 982 |
+
tsize : int, optional
|
| 983 |
+
Total size (in tqdm units). If [default: None] remains unchanged.
|
| 984 |
+
"""
|
| 985 |
+
if tsize is not None:
|
| 986 |
+
self.total = tsize
|
| 987 |
+
return self.update(b * bsize - self.n) # also sets self.n = b * bsize
|
| 988 |
+
|
| 989 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
| 990 |
+
with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
|
| 991 |
+
desc=eg_link.split('/')[-1]) as t: # all optional kwargs
|
| 992 |
+
urllib.urlretrieve(eg_link, filename=os.devnull,
|
| 993 |
+
reporthook=t.update_to, data=None)
|
| 994 |
+
t.total = t.n
|
| 995 |
+
|
| 996 |
+
Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
|
| 997 |
+
Functional alternative in
|
| 998 |
+
`examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
|
| 999 |
+
|
| 1000 |
+
It is recommend to use ``miniters=1`` whenever there is potentially
|
| 1001 |
+
large differences in iteration speed (e.g. downloading a file over
|
| 1002 |
+
a patchy connection).
|
| 1003 |
+
|
| 1004 |
+
**Wrapping read/write methods**
|
| 1005 |
+
|
| 1006 |
+
To measure throughput through a file-like object's ``read`` or ``write``
|
| 1007 |
+
methods, use ``CallbackIOWrapper``:
|
| 1008 |
+
|
| 1009 |
+
.. code:: python
|
| 1010 |
+
|
| 1011 |
+
from tqdm.auto import tqdm
|
| 1012 |
+
from tqdm.utils import CallbackIOWrapper
|
| 1013 |
+
|
| 1014 |
+
with tqdm(total=file_obj.size,
|
| 1015 |
+
unit='B', unit_scale=True, unit_divisor=1024) as t:
|
| 1016 |
+
fobj = CallbackIOWrapper(t.update, file_obj, "read")
|
| 1017 |
+
while True:
|
| 1018 |
+
chunk = fobj.read(chunk_size)
|
| 1019 |
+
if not chunk:
|
| 1020 |
+
break
|
| 1021 |
+
t.reset()
|
| 1022 |
+
# ... continue to use `t` for something else
|
| 1023 |
+
|
| 1024 |
+
Alternatively, use the even simpler ``wrapattr`` convenience function,
|
| 1025 |
+
which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
|
| 1026 |
+
down to:
|
| 1027 |
+
|
| 1028 |
+
.. code:: python
|
| 1029 |
+
|
| 1030 |
+
import urllib, os
|
| 1031 |
+
from tqdm import tqdm
|
| 1032 |
+
|
| 1033 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
| 1034 |
+
response = getattr(urllib, 'request', urllib).urlopen(eg_link)
|
| 1035 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
| 1036 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
| 1037 |
+
total=getattr(response, 'length', None)) as fout:
|
| 1038 |
+
for chunk in response:
|
| 1039 |
+
fout.write(chunk)
|
| 1040 |
+
|
| 1041 |
+
The ``requests`` equivalent is nearly identical:
|
| 1042 |
+
|
| 1043 |
+
.. code:: python
|
| 1044 |
+
|
| 1045 |
+
import requests, os
|
| 1046 |
+
from tqdm import tqdm
|
| 1047 |
+
|
| 1048 |
+
eg_link = "https://caspersci.uk.to/matryoshka.zip"
|
| 1049 |
+
response = requests.get(eg_link, stream=True)
|
| 1050 |
+
with tqdm.wrapattr(open(os.devnull, "wb"), "write",
|
| 1051 |
+
miniters=1, desc=eg_link.split('/')[-1],
|
| 1052 |
+
total=int(response.headers.get('content-length', 0))) as fout:
|
| 1053 |
+
for chunk in response.iter_content(chunk_size=4096):
|
| 1054 |
+
fout.write(chunk)
|
| 1055 |
+
|
| 1056 |
+
**Custom callback**
|
| 1057 |
+
|
| 1058 |
+
``tqdm`` is known for intelligently skipping unnecessary displays. To make a
|
| 1059 |
+
custom callback take advantage of this, simply use the return value of
|
| 1060 |
+
``update()``. This is set to ``True`` if a ``display()`` was triggered.
|
| 1061 |
+
|
| 1062 |
+
.. code:: python
|
| 1063 |
+
|
| 1064 |
+
from tqdm.auto import tqdm as std_tqdm
|
| 1065 |
+
|
| 1066 |
+
def external_callback(*args, **kwargs):
|
| 1067 |
+
...
|
| 1068 |
+
|
| 1069 |
+
class TqdmExt(std_tqdm):
|
| 1070 |
+
def update(self, n=1):
|
| 1071 |
+
displayed = super().update(n)
|
| 1072 |
+
if displayed:
|
| 1073 |
+
external_callback(**self.format_dict)
|
| 1074 |
+
return displayed
|
| 1075 |
+
|
| 1076 |
+
``asyncio``
|
| 1077 |
+
~~~~~~~~~~~
|
| 1078 |
+
|
| 1079 |
+
Note that ``break`` isn't currently caught by asynchronous iterators.
|
| 1080 |
+
This means that ``tqdm`` cannot clean up after itself in this case:
|
| 1081 |
+
|
| 1082 |
+
.. code:: python
|
| 1083 |
+
|
| 1084 |
+
from tqdm.asyncio import tqdm
|
| 1085 |
+
|
| 1086 |
+
async for i in tqdm(range(9)):
|
| 1087 |
+
if i == 2:
|
| 1088 |
+
break
|
| 1089 |
+
|
| 1090 |
+
Instead, either call ``pbar.close()`` manually or use the context manager syntax:
|
| 1091 |
+
|
| 1092 |
+
.. code:: python
|
| 1093 |
+
|
| 1094 |
+
from tqdm.asyncio import tqdm
|
| 1095 |
+
|
| 1096 |
+
with tqdm(range(9)) as pbar:
|
| 1097 |
+
async for i in pbar:
|
| 1098 |
+
if i == 2:
|
| 1099 |
+
break
|
| 1100 |
+
|
| 1101 |
+
Pandas Integration
|
| 1102 |
+
~~~~~~~~~~~~~~~~~~
|
| 1103 |
+
|
| 1104 |
+
Due to popular demand we've added support for ``pandas`` -- here's an example
|
| 1105 |
+
for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
|
| 1106 |
+
|
| 1107 |
+
.. code:: python
|
| 1108 |
+
|
| 1109 |
+
import pandas as pd
|
| 1110 |
+
import numpy as np
|
| 1111 |
+
from tqdm import tqdm
|
| 1112 |
+
|
| 1113 |
+
df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
|
| 1114 |
+
|
| 1115 |
+
# Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
|
| 1116 |
+
# (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)
|
| 1117 |
+
tqdm.pandas(desc="my bar!")
|
| 1118 |
+
|
| 1119 |
+
# Now you can use `progress_apply` instead of `apply`
|
| 1120 |
+
# and `progress_map` instead of `map`
|
| 1121 |
+
df.progress_apply(lambda x: x**2)
|
| 1122 |
+
# can also groupby:
|
| 1123 |
+
# df.groupby(0).progress_apply(lambda x: x**2)
|
| 1124 |
+
|
| 1125 |
+
In case you're interested in how this works (and how to modify it for your
|
| 1126 |
+
own callbacks), see the
|
| 1127 |
+
`examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
|
| 1128 |
+
folder or import the module and run ``help()``.
|
| 1129 |
+
|
| 1130 |
+
Keras Integration
|
| 1131 |
+
~~~~~~~~~~~~~~~~~
|
| 1132 |
+
|
| 1133 |
+
A ``keras`` callback is also available:
|
| 1134 |
+
|
| 1135 |
+
.. code:: python
|
| 1136 |
+
|
| 1137 |
+
from tqdm.keras import TqdmCallback
|
| 1138 |
+
|
| 1139 |
+
...
|
| 1140 |
+
|
| 1141 |
+
model.fit(..., verbose=0, callbacks=[TqdmCallback()])
|
| 1142 |
+
|
| 1143 |
+
Dask Integration
|
| 1144 |
+
~~~~~~~~~~~~~~~~
|
| 1145 |
+
|
| 1146 |
+
A ``dask`` callback is also available:
|
| 1147 |
+
|
| 1148 |
+
.. code:: python
|
| 1149 |
+
|
| 1150 |
+
from tqdm.dask import TqdmCallback
|
| 1151 |
+
|
| 1152 |
+
with TqdmCallback(desc="compute"):
|
| 1153 |
+
...
|
| 1154 |
+
arr.compute()
|
| 1155 |
+
|
| 1156 |
+
# or use callback globally
|
| 1157 |
+
cb = TqdmCallback(desc="global")
|
| 1158 |
+
cb.register()
|
| 1159 |
+
arr.compute()
|
| 1160 |
+
|
| 1161 |
+
IPython/Jupyter Integration
|
| 1162 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1163 |
+
|
| 1164 |
+
IPython/Jupyter is supported via the ``tqdm.notebook`` submodule:
|
| 1165 |
+
|
| 1166 |
+
.. code:: python
|
| 1167 |
+
|
| 1168 |
+
from tqdm.notebook import trange, tqdm
|
| 1169 |
+
from time import sleep
|
| 1170 |
+
|
| 1171 |
+
for i in trange(3, desc='1st loop'):
|
| 1172 |
+
for j in tqdm(range(100), desc='2nd loop'):
|
| 1173 |
+
sleep(0.01)
|
| 1174 |
+
|
| 1175 |
+
In addition to ``tqdm`` features, the submodule provides a native Jupyter
|
| 1176 |
+
widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
|
| 1177 |
+
and colour hints (blue: normal, green: completed, red: error/interrupt,
|
| 1178 |
+
light blue: no ETA); as demonstrated below.
|
| 1179 |
+
|
| 1180 |
+
|Screenshot-Jupyter1|
|
| 1181 |
+
|Screenshot-Jupyter2|
|
| 1182 |
+
|Screenshot-Jupyter3|
|
| 1183 |
+
|
| 1184 |
+
The ``notebook`` version supports percentage or pixels for overall width
|
| 1185 |
+
(e.g.: ``ncols='100%'`` or ``ncols='480px'``).
|
| 1186 |
+
|
| 1187 |
+
It is also possible to let ``tqdm`` automatically choose between
|
| 1188 |
+
console or notebook versions by using the ``autonotebook`` submodule:
|
| 1189 |
+
|
| 1190 |
+
.. code:: python
|
| 1191 |
+
|
| 1192 |
+
from tqdm.autonotebook import tqdm
|
| 1193 |
+
tqdm.pandas()
|
| 1194 |
+
|
| 1195 |
+
Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
|
| 1196 |
+
since it is not meant to be possible to distinguish between ``jupyter notebook``
|
| 1197 |
+
and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
|
| 1198 |
+
this warning.
|
| 1199 |
+
|
| 1200 |
+
Note that notebooks will display the bar in the cell where it was created.
|
| 1201 |
+
This may be a different cell from the one where it is used.
|
| 1202 |
+
If this is not desired, either
|
| 1203 |
+
|
| 1204 |
+
- delay the creation of the bar to the cell where it must be displayed, or
|
| 1205 |
+
- create the bar with ``display=False``, and in a later cell call
|
| 1206 |
+
``display(bar.container)``:
|
| 1207 |
+
|
| 1208 |
+
.. code:: python
|
| 1209 |
+
|
| 1210 |
+
from tqdm.notebook import tqdm
|
| 1211 |
+
pbar = tqdm(..., display=False)
|
| 1212 |
+
|
| 1213 |
+
.. code:: python
|
| 1214 |
+
|
| 1215 |
+
# different cell
|
| 1216 |
+
display(pbar.container)
|
| 1217 |
+
|
| 1218 |
+
The ``keras`` callback has a ``display()`` method which can be used likewise:
|
| 1219 |
+
|
| 1220 |
+
.. code:: python
|
| 1221 |
+
|
| 1222 |
+
from tqdm.keras import TqdmCallback
|
| 1223 |
+
cbk = TqdmCallback(display=False)
|
| 1224 |
+
|
| 1225 |
+
.. code:: python
|
| 1226 |
+
|
| 1227 |
+
# different cell
|
| 1228 |
+
cbk.display()
|
| 1229 |
+
model.fit(..., verbose=0, callbacks=[cbk])
|
| 1230 |
+
|
| 1231 |
+
Another possibility is to have a single bar (near the top of the notebook)
|
| 1232 |
+
which is constantly re-used (using ``reset()`` rather than ``close()``).
|
| 1233 |
+
For this reason, the notebook version (unlike the CLI version) does not
|
| 1234 |
+
automatically call ``close()`` upon ``Exception``.
|
| 1235 |
+
|
| 1236 |
+
.. code:: python
|
| 1237 |
+
|
| 1238 |
+
from tqdm.notebook import tqdm
|
| 1239 |
+
pbar = tqdm()
|
| 1240 |
+
|
| 1241 |
+
.. code:: python
|
| 1242 |
+
|
| 1243 |
+
# different cell
|
| 1244 |
+
iterable = range(100)
|
| 1245 |
+
pbar.reset(total=len(iterable)) # initialise with new `total`
|
| 1246 |
+
for i in iterable:
|
| 1247 |
+
pbar.update()
|
| 1248 |
+
pbar.refresh() # force print final status but don't `close()`
|
| 1249 |
+
|
| 1250 |
+
Custom Integration
|
| 1251 |
+
~~~~~~~~~~~~~~~~~~
|
| 1252 |
+
|
| 1253 |
+
To change the default arguments (such as making ``dynamic_ncols=True``),
|
| 1254 |
+
simply use built-in Python magic:
|
| 1255 |
+
|
| 1256 |
+
.. code:: python
|
| 1257 |
+
|
| 1258 |
+
from functools import partial
|
| 1259 |
+
from tqdm import tqdm as std_tqdm
|
| 1260 |
+
tqdm = partial(std_tqdm, dynamic_ncols=True)
|
| 1261 |
+
|
| 1262 |
+
For further customisation,
|
| 1263 |
+
``tqdm`` may be inherited from to create custom callbacks (as with the
|
| 1264 |
+
``TqdmUpTo`` example `above <#hooks-and-callbacks>`__) or for custom frontends
|
| 1265 |
+
(e.g. GUIs such as notebook or plotting packages). In the latter case:
|
| 1266 |
+
|
| 1267 |
+
1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
|
| 1268 |
+
terminal ``status_printer`` creation.
|
| 1269 |
+
2. Redefine: ``close()``, ``clear()``, ``display()``.
|
| 1270 |
+
|
| 1271 |
+
Consider overloading ``display()`` to use e.g.
|
| 1272 |
+
``self.frontend(**self.format_dict)`` instead of ``self.sp(repr(self))``.
|
| 1273 |
+
|
| 1274 |
+
Some submodule examples of inheritance:
|
| 1275 |
+
|
| 1276 |
+
- `tqdm/notebook.py <https://github.com/tqdm/tqdm/blob/master/tqdm/notebook.py>`__
|
| 1277 |
+
- `tqdm/gui.py <https://github.com/tqdm/tqdm/blob/master/tqdm/gui.py>`__
|
| 1278 |
+
- `tqdm/tk.py <https://github.com/tqdm/tqdm/blob/master/tqdm/tk.py>`__
|
| 1279 |
+
- `tqdm/contrib/slack.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/slack.py>`__
|
| 1280 |
+
- `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__
|
| 1281 |
+
- `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
|
| 1282 |
+
|
| 1283 |
+
Dynamic Monitor/Meter
|
| 1284 |
+
~~~~~~~~~~~~~~~~~~~~~
|
| 1285 |
+
|
| 1286 |
+
You can use a ``tqdm`` as a meter which is not monotonically increasing.
|
| 1287 |
+
This could be because ``n`` decreases (e.g. a CPU usage monitor) or ``total``
|
| 1288 |
+
changes.
|
| 1289 |
+
|
| 1290 |
+
One example would be recursively searching for files. The ``total`` is the
|
| 1291 |
+
number of objects found so far, while ``n`` is the number of those objects which
|
| 1292 |
+
are files (rather than folders):
|
| 1293 |
+
|
| 1294 |
+
.. code:: python
|
| 1295 |
+
|
| 1296 |
+
from tqdm import tqdm
|
| 1297 |
+
import os.path
|
| 1298 |
+
|
| 1299 |
+
def find_files_recursively(path, show_progress=True):
|
| 1300 |
+
files = []
|
| 1301 |
+
# total=1 assumes `path` is a file
|
| 1302 |
+
t = tqdm(total=1, unit="file", disable=not show_progress)
|
| 1303 |
+
if not os.path.exists(path):
|
| 1304 |
+
raise IOError("Cannot find:" + path)
|
| 1305 |
+
|
| 1306 |
+
def append_found_file(f):
|
| 1307 |
+
files.append(f)
|
| 1308 |
+
t.update()
|
| 1309 |
+
|
| 1310 |
+
def list_found_dir(path):
|
| 1311 |
+
"""returns os.listdir(path) assuming os.path.isdir(path)"""
|
| 1312 |
+
listing = os.listdir(path)
|
| 1313 |
+
# subtract 1 since a "file" we found was actually this directory
|
| 1314 |
+
t.total += len(listing) - 1
|
| 1315 |
+
# fancy way to give info without forcing a refresh
|
| 1316 |
+
t.set_postfix(dir=path[-10:], refresh=False)
|
| 1317 |
+
t.update(0) # may trigger a refresh
|
| 1318 |
+
return listing
|
| 1319 |
+
|
| 1320 |
+
def recursively_search(path):
|
| 1321 |
+
if os.path.isdir(path):
|
| 1322 |
+
for f in list_found_dir(path):
|
| 1323 |
+
recursively_search(os.path.join(path, f))
|
| 1324 |
+
else:
|
| 1325 |
+
append_found_file(path)
|
| 1326 |
+
|
| 1327 |
+
recursively_search(path)
|
| 1328 |
+
t.set_postfix(dir=path)
|
| 1329 |
+
t.close()
|
| 1330 |
+
return files
|
| 1331 |
+
|
| 1332 |
+
Using ``update(0)`` is a handy way to let ``tqdm`` decide when to trigger a
|
| 1333 |
+
display refresh to avoid console spamming.
|
| 1334 |
+
|
| 1335 |
+
Writing messages
|
| 1336 |
+
~~~~~~~~~~~~~~~~
|
| 1337 |
+
|
| 1338 |
+
This is a work in progress (see
|
| 1339 |
+
`#737 <https://github.com/tqdm/tqdm/issues/737>`__).
|
| 1340 |
+
|
| 1341 |
+
Since ``tqdm`` uses a simple printing mechanism to display progress bars,
|
| 1342 |
+
you should not write any message in the terminal using ``print()`` while
|
| 1343 |
+
a progressbar is open.
|
| 1344 |
+
|
| 1345 |
+
To write messages in the terminal without any collision with ``tqdm`` bar
|
| 1346 |
+
display, a ``.write()`` method is provided:
|
| 1347 |
+
|
| 1348 |
+
.. code:: python
|
| 1349 |
+
|
| 1350 |
+
from tqdm.auto import tqdm, trange
|
| 1351 |
+
from time import sleep
|
| 1352 |
+
|
| 1353 |
+
bar = trange(10)
|
| 1354 |
+
for i in bar:
|
| 1355 |
+
# Print using tqdm class method .write()
|
| 1356 |
+
sleep(0.1)
|
| 1357 |
+
if not (i % 3):
|
| 1358 |
+
tqdm.write("Done task %i" % i)
|
| 1359 |
+
# Can also use bar.write()
|
| 1360 |
+
|
| 1361 |
+
By default, this will print to standard output ``sys.stdout``. but you can
|
| 1362 |
+
specify any file-like object using the ``file`` argument. For example, this
|
| 1363 |
+
can be used to redirect the messages writing to a log file or class.
|
| 1364 |
+
|
| 1365 |
+
Redirecting writing
|
| 1366 |
+
~~~~~~~~~~~~~~~~~~~
|
| 1367 |
+
|
| 1368 |
+
If using a library that can print messages to the console, editing the library
|
| 1369 |
+
by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
|
| 1370 |
+
In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
|
| 1371 |
+
|
| 1372 |
+
To redirect ``sys.stdout``, create a file-like class that will write
|
| 1373 |
+
any input string to ``tqdm.write()``, and supply the arguments
|
| 1374 |
+
``file=sys.stdout, dynamic_ncols=True``.
|
| 1375 |
+
|
| 1376 |
+
A reusable canonical example is given below:
|
| 1377 |
+
|
| 1378 |
+
.. code:: python
|
| 1379 |
+
|
| 1380 |
+
from time import sleep
|
| 1381 |
+
import contextlib
|
| 1382 |
+
import sys
|
| 1383 |
+
from tqdm import tqdm
|
| 1384 |
+
from tqdm.contrib import DummyTqdmFile
|
| 1385 |
+
|
| 1386 |
+
|
| 1387 |
+
@contextlib.contextmanager
|
| 1388 |
+
def std_out_err_redirect_tqdm():
|
| 1389 |
+
orig_out_err = sys.stdout, sys.stderr
|
| 1390 |
+
try:
|
| 1391 |
+
sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
|
| 1392 |
+
yield orig_out_err[0]
|
| 1393 |
+
# Relay exceptions
|
| 1394 |
+
except Exception as exc:
|
| 1395 |
+
raise exc
|
| 1396 |
+
# Always restore sys.stdout/err if necessary
|
| 1397 |
+
finally:
|
| 1398 |
+
sys.stdout, sys.stderr = orig_out_err
|
| 1399 |
+
|
| 1400 |
+
def some_fun(i):
|
| 1401 |
+
print("Fee, fi, fo,".split()[i])
|
| 1402 |
+
|
| 1403 |
+
# Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
|
| 1404 |
+
with std_out_err_redirect_tqdm() as orig_stdout:
|
| 1405 |
+
# tqdm needs the original stdout
|
| 1406 |
+
# and dynamic_ncols=True to autodetect console width
|
| 1407 |
+
for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
|
| 1408 |
+
sleep(.5)
|
| 1409 |
+
some_fun(i)
|
| 1410 |
+
|
| 1411 |
+
# After the `with`, printing is restored
|
| 1412 |
+
print("Done!")
|
| 1413 |
+
|
| 1414 |
+
Redirecting ``logging``
|
| 1415 |
+
~~~~~~~~~~~~~~~~~~~~~~~
|
| 1416 |
+
|
| 1417 |
+
Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
|
| 1418 |
+
may also be redirected to ``tqdm.write()``.
|
| 1419 |
+
|
| 1420 |
+
Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
|
| 1421 |
+
redirect ``logging`` first if needed.
|
| 1422 |
+
|
| 1423 |
+
Helper methods are available in ``tqdm.contrib.logging``. For example:
|
| 1424 |
+
|
| 1425 |
+
.. code:: python
|
| 1426 |
+
|
| 1427 |
+
import logging
|
| 1428 |
+
from tqdm import trange
|
| 1429 |
+
from tqdm.contrib.logging import logging_redirect_tqdm
|
| 1430 |
+
|
| 1431 |
+
LOG = logging.getLogger(__name__)
|
| 1432 |
+
|
| 1433 |
+
if __name__ == '__main__':
|
| 1434 |
+
logging.basicConfig(level=logging.INFO)
|
| 1435 |
+
with logging_redirect_tqdm():
|
| 1436 |
+
for i in trange(9):
|
| 1437 |
+
if i == 4:
|
| 1438 |
+
LOG.info("console logging redirected to `tqdm.write()`")
|
| 1439 |
+
# logging restored
|
| 1440 |
+
|
| 1441 |
+
Monitoring thread, intervals and miniters
|
| 1442 |
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1443 |
+
|
| 1444 |
+
``tqdm`` implements a few tricks to increase efficiency and reduce overhead.
|
| 1445 |
+
|
| 1446 |
+
- Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
|
| 1447 |
+
to wait between each refresh. ``tqdm`` always gets updated in the background,
|
| 1448 |
+
but it will display only every ``mininterval``.
|
| 1449 |
+
- Reduce number of calls to check system clock/time.
|
| 1450 |
+
- ``mininterval`` is more intuitive to configure than ``miniters``.
|
| 1451 |
+
A clever adjustment system ``dynamic_miniters`` will automatically adjust
|
| 1452 |
+
``miniters`` to the amount of iterations that fit into time ``mininterval``.
|
| 1453 |
+
Essentially, ``tqdm`` will check if it's time to print without actually
|
| 1454 |
+
checking time. This behaviour can be still be bypassed by manually setting
|
| 1455 |
+
``miniters``.
|
| 1456 |
+
|
| 1457 |
+
However, consider a case with a combination of fast and slow iterations.
|
| 1458 |
+
After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
|
| 1459 |
+
large number. When iteration rate subsequently slows, ``miniters`` will
|
| 1460 |
+
remain large and thus reduce display update frequency. To address this:
|
| 1461 |
+
|
| 1462 |
+
- ``maxinterval`` defines the maximum time between display refreshes.
|
| 1463 |
+
A concurrent monitoring thread checks for overdue updates and forces one
|
| 1464 |
+
where necessary.
|
| 1465 |
+
|
| 1466 |
+
The monitoring thread should not have a noticeable overhead, and guarantees
|
| 1467 |
+
updates at least every 10 seconds by default.
|
| 1468 |
+
This value can be directly changed by setting the ``monitor_interval`` of
|
| 1469 |
+
any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
|
| 1470 |
+
The monitor thread may be disabled application-wide by setting
|
| 1471 |
+
``tqdm.tqdm.monitor_interval = 0`` before instantiation of any ``tqdm`` bar.
|
| 1472 |
+
|
| 1473 |
+
|
| 1474 |
+
Merch
|
| 1475 |
+
-----
|
| 1476 |
+
|
| 1477 |
+
You can buy `tqdm branded merch <https://tqdm.github.io/merch>`__ now!
|
| 1478 |
+
|
| 1479 |
+
Contributions
|
| 1480 |
+
-------------
|
| 1481 |
+
|
| 1482 |
+
|GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices|
|
| 1483 |
+
|
| 1484 |
+
All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
|
| 1485 |
+
Contributions are welcome.
|
| 1486 |
+
|
| 1487 |
+
See the
|
| 1488 |
+
`CONTRIBUTING <https://github.com/tqdm/tqdm/blob/master/CONTRIBUTING.md>`__
|
| 1489 |
+
file for more information.
|
| 1490 |
+
|
| 1491 |
+
Developers who have made significant contributions, ranked by *SLoC*
|
| 1492 |
+
(surviving lines of code,
|
| 1493 |
+
`git fame <https://github.com/casperdcl/git-fame>`__ ``-wMC --excl '\.(png|gif|jpg)$'``),
|
| 1494 |
+
are:
|
| 1495 |
+
|
| 1496 |
+
==================== ======================================================== ==== ================================
|
| 1497 |
+
Name ID SLoC Notes
|
| 1498 |
+
==================== ======================================================== ==== ================================
|
| 1499 |
+
Casper da Costa-Luis `casperdcl <https://github.com/casperdcl>`__ ~80% primary maintainer |Gift-Casper|
|
| 1500 |
+
Stephen Larroque `lrq3000 <https://github.com/lrq3000>`__ ~9% team member
|
| 1501 |
+
Martin Zugnoni `martinzugnoni <https://github.com/martinzugnoni>`__ ~3%
|
| 1502 |
+
Daniel Ecer `de-code <https://github.com/de-code>`__ ~2%
|
| 1503 |
+
Richard Sheridan `richardsheridan <https://github.com/richardsheridan>`__ ~1%
|
| 1504 |
+
Guangshuo Chen `chengs <https://github.com/chengs>`__ ~1%
|
| 1505 |
+
Helio Machado `0x2b3bfa0 <https://github.com/0x2b3bfa0>`__ ~1%
|
| 1506 |
+
Kyle Altendorf `altendky <https://github.com/altendky>`__ <1%
|
| 1507 |
+
Noam Yorav-Raphael `noamraph <https://github.com/noamraph>`__ <1% original author
|
| 1508 |
+
Matthew Stevens `mjstevens777 <https://github.com/mjstevens777>`__ <1%
|
| 1509 |
+
Hadrien Mary `hadim <https://github.com/hadim>`__ <1% team member
|
| 1510 |
+
Mikhail Korobov `kmike <https://github.com/kmike>`__ <1% team member
|
| 1511 |
+
==================== ======================================================== ==== ================================
|
| 1512 |
+
|
| 1513 |
+
Ports to Other Languages
|
| 1514 |
+
~~~~~~~~~~~~~~~~~~~~~~~~
|
| 1515 |
+
|
| 1516 |
+
A list is available on
|
| 1517 |
+
`this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
|
| 1518 |
+
|
| 1519 |
+
|
| 1520 |
+
LICENCE
|
| 1521 |
+
-------
|
| 1522 |
+
|
| 1523 |
+
Open Source (OSI approved): |LICENCE|
|
| 1524 |
+
|
| 1525 |
+
Citation information: |DOI|
|
| 1526 |
+
|
| 1527 |
+
|README-Hits| (Since 19 May 2016)
|
| 1528 |
+
|
| 1529 |
+
.. |Logo| image:: https://tqdm.github.io/img/logo.gif
|
| 1530 |
+
.. |Screenshot| image:: https://tqdm.github.io/img/tqdm.gif
|
| 1531 |
+
.. |Video| image:: https://tqdm.github.io/img/video.jpg
|
| 1532 |
+
:target: https://tqdm.github.io/video
|
| 1533 |
+
.. |Slides| image:: https://tqdm.github.io/img/slides.jpg
|
| 1534 |
+
:target: https://tqdm.github.io/PyData2019/slides.html
|
| 1535 |
+
.. |Merch| image:: https://tqdm.github.io/img/merch.jpg
|
| 1536 |
+
:target: https://tqdm.github.io/merch
|
| 1537 |
+
.. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/tqdm/tqdm/test.yml?branch=master&label=tqdm&logo=GitHub
|
| 1538 |
+
:target: https://github.com/tqdm/tqdm/actions/workflows/test.yml
|
| 1539 |
+
.. |Coverage-Status| image:: https://img.shields.io/coveralls/github/tqdm/tqdm/master?logo=coveralls
|
| 1540 |
+
:target: https://coveralls.io/github/tqdm/tqdm
|
| 1541 |
+
.. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
|
| 1542 |
+
:target: https://codecov.io/gh/tqdm/tqdm
|
| 1543 |
+
.. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
|
| 1544 |
+
:target: https://www.codacy.com/gh/tqdm/tqdm/dashboard
|
| 1545 |
+
.. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge
|
| 1546 |
+
:target: https://bestpractices.coreinfrastructure.org/projects/3264
|
| 1547 |
+
.. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white
|
| 1548 |
+
:target: https://github.com/tqdm/tqdm/releases
|
| 1549 |
+
.. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1550 |
+
:target: https://github.com/tqdm/tqdm/network
|
| 1551 |
+
.. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1552 |
+
:target: https://github.com/tqdm/tqdm/stargazers
|
| 1553 |
+
.. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg?logo=git&logoColor=white
|
| 1554 |
+
:target: https://github.com/tqdm/tqdm/graphs/commit-activity
|
| 1555 |
+
.. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1556 |
+
:target: https://github.com/tqdm/tqdm/issues?q=
|
| 1557 |
+
.. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1558 |
+
:target: https://github.com/tqdm/tqdm/pulls
|
| 1559 |
+
.. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg?logo=github&logoColor=white
|
| 1560 |
+
:target: https://github.com/tqdm/tqdm/graphs/contributors
|
| 1561 |
+
.. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/tqdm/tqdm/master.svg?logo=github&logoColor=white&label=pushed
|
| 1562 |
+
:target: https://github.com/tqdm/tqdm/pulse
|
| 1563 |
+
.. |Gift-Casper| image:: https://img.shields.io/badge/dynamic/json.svg?color=ff69b4&label=gifts%20received&prefix=%C2%A3&query=%24..sum&url=https%3A%2F%2Fcaspersci.uk.to%2Fgifts.json
|
| 1564 |
+
:target: https://cdcl.ml/sponsor
|
| 1565 |
+
.. |Versions| image:: https://img.shields.io/pypi/v/tqdm.svg
|
| 1566 |
+
:target: https://tqdm.github.io/releases
|
| 1567 |
+
.. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/tqdm.svg?label=pypi%20downloads&logo=PyPI&logoColor=white
|
| 1568 |
+
:target: https://pepy.tech/project/tqdm
|
| 1569 |
+
.. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg?logo=python&logoColor=white
|
| 1570 |
+
:target: https://pypi.org/project/tqdm
|
| 1571 |
+
.. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/tqdm.svg?label=conda-forge&logo=conda-forge
|
| 1572 |
+
:target: https://anaconda.org/conda-forge/tqdm
|
| 1573 |
+
.. |Snapcraft| image:: https://img.shields.io/badge/snap-install-82BEA0.svg?logo=snapcraft
|
| 1574 |
+
:target: https://snapcraft.io/tqdm
|
| 1575 |
+
.. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
|
| 1576 |
+
:target: https://hub.docker.com/r/tqdm/tqdm
|
| 1577 |
+
.. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/tqdm.svg?logo=koding&logoColor=white
|
| 1578 |
+
:target: https://libraries.io/pypi/tqdm
|
| 1579 |
+
.. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/tqdm.svg?logo=koding&logoColor=white
|
| 1580 |
+
:target: https://github.com/tqdm/tqdm/network/dependents
|
| 1581 |
+
.. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
|
| 1582 |
+
:target: https://www.openhub.net/p/tqdm?ref=Thin+badge
|
| 1583 |
+
.. |awesome-python| image:: https://awesome.re/mentioned-badge.svg
|
| 1584 |
+
:target: https://github.com/vinta/awesome-python
|
| 1585 |
+
.. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
|
| 1586 |
+
:target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
|
| 1587 |
+
.. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg
|
| 1588 |
+
:target: https://doi.org/10.5281/zenodo.595120
|
| 1589 |
+
.. |binder-demo| image:: https://mybinder.org/badge_logo.svg
|
| 1590 |
+
:target: https://mybinder.org/v2/gh/tqdm/tqdm/master?filepath=DEMO.ipynb
|
| 1591 |
+
.. |Screenshot-Jupyter1| image:: https://tqdm.github.io/img/jupyter-1.gif
|
| 1592 |
+
.. |Screenshot-Jupyter2| image:: https://tqdm.github.io/img/jupyter-2.gif
|
| 1593 |
+
.. |Screenshot-Jupyter3| image:: https://tqdm.github.io/img/jupyter-3.gif
|
| 1594 |
+
.. |README-Hits| image:: https://cgi.cdcl.ml/hits?q=tqdm&style=social&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif
|
| 1595 |
+
:target: https://cgi.cdcl.ml/hits?q=tqdm&a=plot&r=https://github.com/tqdm/tqdm&l=https://tqdm.github.io/img/favicon.png&f=https://tqdm.github.io/img/logo.gif&style=social
|
.cache/pip/http-v2/4/6/5/f/3/465f3fcecb7ed980c1b4d56b4f1ac8b2ae4685d32a696bbd51a25fb9
ADDED
|
Binary file (1.27 kB). View file
|
|
|
.cache/pip/http-v2/4/6/5/f/3/465f3fcecb7ed980c1b4d56b4f1ac8b2ae4685d32a696bbd51a25fb9.body
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: huggingface_hub
|
| 3 |
+
Version: 1.16.4
|
| 4 |
+
Summary: Client library to download and publish models, datasets and other repos on the huggingface.co hub
|
| 5 |
+
Home-page: https://github.com/huggingface/huggingface_hub
|
| 6 |
+
Author: Hugging Face, Inc.
|
| 7 |
+
Author-email: julien@huggingface.co
|
| 8 |
+
License: Apache-2.0
|
| 9 |
+
Keywords: model-hub machine-learning models natural-language-processing deep-learning pytorch pretrained-models
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: Intended Audience :: Education
|
| 12 |
+
Classifier: Intended Audience :: Science/Research
|
| 13 |
+
Classifier: License :: OSI Approved :: Apache Software License
|
| 14 |
+
Classifier: Operating System :: OS Independent
|
| 15 |
+
Classifier: Programming Language :: Python :: 3
|
| 16 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 17 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 22 |
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
| 23 |
+
Requires-Python: >=3.10.0
|
| 24 |
+
Description-Content-Type: text/markdown
|
| 25 |
+
License-File: LICENSE
|
| 26 |
+
Requires-Dist: click>=8.4.0
|
| 27 |
+
Requires-Dist: filelock>=3.10.0
|
| 28 |
+
Requires-Dist: fsspec>=2023.5.0
|
| 29 |
+
Requires-Dist: hf-xet<2.0.0,>=1.4.3; platform_machine == "x86_64" or platform_machine == "amd64" or platform_machine == "AMD64" or platform_machine == "arm64" or platform_machine == "aarch64"
|
| 30 |
+
Requires-Dist: httpx<1,>=0.23.0
|
| 31 |
+
Requires-Dist: packaging>=20.9
|
| 32 |
+
Requires-Dist: pyyaml>=5.1
|
| 33 |
+
Requires-Dist: tqdm>=4.42.1
|
| 34 |
+
Requires-Dist: typer<0.26.0,>=0.20.0
|
| 35 |
+
Requires-Dist: typing-extensions>=4.1.0
|
| 36 |
+
Provides-Extra: oauth
|
| 37 |
+
Requires-Dist: authlib>=1.3.2; extra == "oauth"
|
| 38 |
+
Requires-Dist: fastapi; extra == "oauth"
|
| 39 |
+
Requires-Dist: httpx; extra == "oauth"
|
| 40 |
+
Requires-Dist: itsdangerous; extra == "oauth"
|
| 41 |
+
Provides-Extra: torch
|
| 42 |
+
Requires-Dist: torch; extra == "torch"
|
| 43 |
+
Requires-Dist: safetensors[torch]; extra == "torch"
|
| 44 |
+
Provides-Extra: fastai
|
| 45 |
+
Requires-Dist: toml; extra == "fastai"
|
| 46 |
+
Requires-Dist: fastai>=2.4; extra == "fastai"
|
| 47 |
+
Requires-Dist: fastcore>=1.3.27; extra == "fastai"
|
| 48 |
+
Provides-Extra: hf-xet
|
| 49 |
+
Requires-Dist: hf-xet<2.0.0,>=1.4.3; extra == "hf-xet"
|
| 50 |
+
Provides-Extra: mcp
|
| 51 |
+
Requires-Dist: mcp>=1.8.0; extra == "mcp"
|
| 52 |
+
Provides-Extra: testing
|
| 53 |
+
Requires-Dist: authlib>=1.3.2; extra == "testing"
|
| 54 |
+
Requires-Dist: fastapi; extra == "testing"
|
| 55 |
+
Requires-Dist: httpx; extra == "testing"
|
| 56 |
+
Requires-Dist: itsdangerous; extra == "testing"
|
| 57 |
+
Requires-Dist: jedi; extra == "testing"
|
| 58 |
+
Requires-Dist: Jinja2; extra == "testing"
|
| 59 |
+
Requires-Dist: pytest>=8.4.2; extra == "testing"
|
| 60 |
+
Requires-Dist: pytest-cov; extra == "testing"
|
| 61 |
+
Requires-Dist: pytest-env; extra == "testing"
|
| 62 |
+
Requires-Dist: pytest-xdist; extra == "testing"
|
| 63 |
+
Requires-Dist: pytest-vcr; extra == "testing"
|
| 64 |
+
Requires-Dist: pytest-asyncio; extra == "testing"
|
| 65 |
+
Requires-Dist: pytest-rerunfailures<16.0; extra == "testing"
|
| 66 |
+
Requires-Dist: pytest-mock; extra == "testing"
|
| 67 |
+
Requires-Dist: urllib3<2.0; extra == "testing"
|
| 68 |
+
Requires-Dist: soundfile; extra == "testing"
|
| 69 |
+
Requires-Dist: Pillow; extra == "testing"
|
| 70 |
+
Requires-Dist: numpy; extra == "testing"
|
| 71 |
+
Requires-Dist: duckdb; extra == "testing"
|
| 72 |
+
Requires-Dist: fastapi; extra == "testing"
|
| 73 |
+
Provides-Extra: gradio
|
| 74 |
+
Requires-Dist: gradio>=5.0.0; extra == "gradio"
|
| 75 |
+
Requires-Dist: requests; extra == "gradio"
|
| 76 |
+
Provides-Extra: typing
|
| 77 |
+
Requires-Dist: typing-extensions>=4.8.0; extra == "typing"
|
| 78 |
+
Requires-Dist: types-PyYAML; extra == "typing"
|
| 79 |
+
Requires-Dist: types-simplejson; extra == "typing"
|
| 80 |
+
Requires-Dist: types-toml; extra == "typing"
|
| 81 |
+
Requires-Dist: types-tqdm; extra == "typing"
|
| 82 |
+
Requires-Dist: types-urllib3; extra == "typing"
|
| 83 |
+
Provides-Extra: quality
|
| 84 |
+
Requires-Dist: ruff>=0.9.0; extra == "quality"
|
| 85 |
+
Requires-Dist: mypy==1.15.0; extra == "quality"
|
| 86 |
+
Requires-Dist: libcst>=1.4.0; extra == "quality"
|
| 87 |
+
Requires-Dist: ty; extra == "quality"
|
| 88 |
+
Provides-Extra: all
|
| 89 |
+
Requires-Dist: authlib>=1.3.2; extra == "all"
|
| 90 |
+
Requires-Dist: fastapi; extra == "all"
|
| 91 |
+
Requires-Dist: httpx; extra == "all"
|
| 92 |
+
Requires-Dist: itsdangerous; extra == "all"
|
| 93 |
+
Requires-Dist: jedi; extra == "all"
|
| 94 |
+
Requires-Dist: Jinja2; extra == "all"
|
| 95 |
+
Requires-Dist: pytest>=8.4.2; extra == "all"
|
| 96 |
+
Requires-Dist: pytest-cov; extra == "all"
|
| 97 |
+
Requires-Dist: pytest-env; extra == "all"
|
| 98 |
+
Requires-Dist: pytest-xdist; extra == "all"
|
| 99 |
+
Requires-Dist: pytest-vcr; extra == "all"
|
| 100 |
+
Requires-Dist: pytest-asyncio; extra == "all"
|
| 101 |
+
Requires-Dist: pytest-rerunfailures<16.0; extra == "all"
|
| 102 |
+
Requires-Dist: pytest-mock; extra == "all"
|
| 103 |
+
Requires-Dist: urllib3<2.0; extra == "all"
|
| 104 |
+
Requires-Dist: soundfile; extra == "all"
|
| 105 |
+
Requires-Dist: Pillow; extra == "all"
|
| 106 |
+
Requires-Dist: numpy; extra == "all"
|
| 107 |
+
Requires-Dist: duckdb; extra == "all"
|
| 108 |
+
Requires-Dist: fastapi; extra == "all"
|
| 109 |
+
Requires-Dist: ruff>=0.9.0; extra == "all"
|
| 110 |
+
Requires-Dist: mypy==1.15.0; extra == "all"
|
| 111 |
+
Requires-Dist: libcst>=1.4.0; extra == "all"
|
| 112 |
+
Requires-Dist: ty; extra == "all"
|
| 113 |
+
Requires-Dist: typing-extensions>=4.8.0; extra == "all"
|
| 114 |
+
Requires-Dist: types-PyYAML; extra == "all"
|
| 115 |
+
Requires-Dist: types-simplejson; extra == "all"
|
| 116 |
+
Requires-Dist: types-toml; extra == "all"
|
| 117 |
+
Requires-Dist: types-tqdm; extra == "all"
|
| 118 |
+
Requires-Dist: types-urllib3; extra == "all"
|
| 119 |
+
Provides-Extra: dev
|
| 120 |
+
Requires-Dist: authlib>=1.3.2; extra == "dev"
|
| 121 |
+
Requires-Dist: fastapi; extra == "dev"
|
| 122 |
+
Requires-Dist: httpx; extra == "dev"
|
| 123 |
+
Requires-Dist: itsdangerous; extra == "dev"
|
| 124 |
+
Requires-Dist: jedi; extra == "dev"
|
| 125 |
+
Requires-Dist: Jinja2; extra == "dev"
|
| 126 |
+
Requires-Dist: pytest>=8.4.2; extra == "dev"
|
| 127 |
+
Requires-Dist: pytest-cov; extra == "dev"
|
| 128 |
+
Requires-Dist: pytest-env; extra == "dev"
|
| 129 |
+
Requires-Dist: pytest-xdist; extra == "dev"
|
| 130 |
+
Requires-Dist: pytest-vcr; extra == "dev"
|
| 131 |
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
| 132 |
+
Requires-Dist: pytest-rerunfailures<16.0; extra == "dev"
|
| 133 |
+
Requires-Dist: pytest-mock; extra == "dev"
|
| 134 |
+
Requires-Dist: urllib3<2.0; extra == "dev"
|
| 135 |
+
Requires-Dist: soundfile; extra == "dev"
|
| 136 |
+
Requires-Dist: Pillow; extra == "dev"
|
| 137 |
+
Requires-Dist: numpy; extra == "dev"
|
| 138 |
+
Requires-Dist: duckdb; extra == "dev"
|
| 139 |
+
Requires-Dist: fastapi; extra == "dev"
|
| 140 |
+
Requires-Dist: ruff>=0.9.0; extra == "dev"
|
| 141 |
+
Requires-Dist: mypy==1.15.0; extra == "dev"
|
| 142 |
+
Requires-Dist: libcst>=1.4.0; extra == "dev"
|
| 143 |
+
Requires-Dist: ty; extra == "dev"
|
| 144 |
+
Requires-Dist: typing-extensions>=4.8.0; extra == "dev"
|
| 145 |
+
Requires-Dist: types-PyYAML; extra == "dev"
|
| 146 |
+
Requires-Dist: types-simplejson; extra == "dev"
|
| 147 |
+
Requires-Dist: types-toml; extra == "dev"
|
| 148 |
+
Requires-Dist: types-tqdm; extra == "dev"
|
| 149 |
+
Requires-Dist: types-urllib3; extra == "dev"
|
| 150 |
+
Dynamic: author
|
| 151 |
+
Dynamic: author-email
|
| 152 |
+
Dynamic: classifier
|
| 153 |
+
Dynamic: description
|
| 154 |
+
Dynamic: description-content-type
|
| 155 |
+
Dynamic: home-page
|
| 156 |
+
Dynamic: keywords
|
| 157 |
+
Dynamic: license
|
| 158 |
+
Dynamic: license-file
|
| 159 |
+
Dynamic: provides-extra
|
| 160 |
+
Dynamic: requires-dist
|
| 161 |
+
Dynamic: requires-python
|
| 162 |
+
Dynamic: summary
|
| 163 |
+
|
| 164 |
+
<p align="center">
|
| 165 |
+
<picture>
|
| 166 |
+
<source media="(prefers-color-scheme: dark)" srcset="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/huggingface_hub-dark.svg">
|
| 167 |
+
<source media="(prefers-color-scheme: light)" srcset="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/huggingface_hub.svg">
|
| 168 |
+
<img alt="huggingface_hub library logo" src="https://huggingface.co/datasets/huggingface/documentation-images/raw/main/huggingface_hub.svg" width="352" height="59" style="max-width: 100%">
|
| 169 |
+
</picture>
|
| 170 |
+
<br/>
|
| 171 |
+
<br/>
|
| 172 |
+
</p>
|
| 173 |
+
|
| 174 |
+
<p align="center">
|
| 175 |
+
<i>The official Python client for the Huggingface Hub.</i>
|
| 176 |
+
</p>
|
| 177 |
+
|
| 178 |
+
<p align="center">
|
| 179 |
+
<a href="https://huggingface.co/docs/huggingface_hub/en/index"><img alt="Documentation" src="https://img.shields.io/website/http/huggingface.co/docs/huggingface_hub/index.svg?down_color=red&down_message=offline&up_message=online&label=doc"></a>
|
| 180 |
+
<a href="https://github.com/huggingface/huggingface_hub/releases"><img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/huggingface_hub.svg"></a>
|
| 181 |
+
<a href="https://github.com/huggingface/huggingface_hub"><img alt="PyPi version" src="https://img.shields.io/pypi/pyversions/huggingface_hub.svg"></a>
|
| 182 |
+
<a href="https://pypi.org/project/huggingface-hub"><img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/huggingface_hub"></a>
|
| 183 |
+
<a href="https://codecov.io/gh/huggingface/huggingface_hub"><img alt="Code coverage" src="https://codecov.io/gh/huggingface/huggingface_hub/branch/main/graph/badge.svg?token=RXP95LE2XL"></a>
|
| 184 |
+
</p>
|
| 185 |
+
|
| 186 |
+
<h4 align="center">
|
| 187 |
+
<p>
|
| 188 |
+
<b>English</b> |
|
| 189 |
+
<a href="https://github.com/huggingface/huggingface_hub/blob/main/i18n/README_de.md">Deutsch</a> |
|
| 190 |
+
<a href="https://github.com/huggingface/huggingface_hub/blob/main/i18n/README_fr.md">Français</a> |
|
| 191 |
+
<a href="https://github.com/huggingface/huggingface_hub/blob/main/i18n/README_hi.md">हिंदी</a> |
|
| 192 |
+
<a href="https://github.com/huggingface/huggingface_hub/blob/main/i18n/README_ko.md">한국어</a> |
|
| 193 |
+
<a href="https://github.com/huggingface/huggingface_hub/blob/main/i18n/README_cn.md">中文 (简体)</a>
|
| 194 |
+
<p>
|
| 195 |
+
</h4>
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
**Documentation**: <a href="https://hf.co/docs/huggingface_hub" target="_blank">https://hf.co/docs/huggingface_hub</a>
|
| 200 |
+
|
| 201 |
+
**Source Code**: <a href="https://github.com/huggingface/huggingface_hub" target="_blank">https://github.com/huggingface/huggingface_hub</a>
|
| 202 |
+
|
| 203 |
+
---
|
| 204 |
+
|
| 205 |
+
## Welcome to the huggingface_hub library
|
| 206 |
+
|
| 207 |
+
The `huggingface_hub` library allows you to interact with the [Hugging Face Hub](https://huggingface.co/), a platform democratizing open-source Machine Learning for creators and collaborators. Discover pre-trained models and datasets for your projects or play with the thousands of machine learning apps hosted on the Hub. You can also create and share your own models, datasets and demos with the community. The `huggingface_hub` library provides a simple way to do all these things with Python.
|
| 208 |
+
|
| 209 |
+
## Key features
|
| 210 |
+
|
| 211 |
+
- [Download files](https://huggingface.co/docs/huggingface_hub/en/guides/download) from the Hub.
|
| 212 |
+
- [Upload files](https://huggingface.co/docs/huggingface_hub/en/guides/upload) to the Hub.
|
| 213 |
+
- [Manage your repositories](https://huggingface.co/docs/huggingface_hub/en/guides/repository).
|
| 214 |
+
- [Run Inference](https://huggingface.co/docs/huggingface_hub/en/guides/inference) on deployed models.
|
| 215 |
+
- [Search](https://huggingface.co/docs/huggingface_hub/en/guides/search) for models, datasets and Spaces.
|
| 216 |
+
- [Share Model Cards](https://huggingface.co/docs/huggingface_hub/en/guides/model-cards) to document your models.
|
| 217 |
+
- [Engage with the community](https://huggingface.co/docs/huggingface_hub/en/guides/community) through PRs and comments.
|
| 218 |
+
|
| 219 |
+
## Installation
|
| 220 |
+
|
| 221 |
+
Install the `huggingface_hub` package with [pip](https://pypi.org/project/huggingface-hub/):
|
| 222 |
+
|
| 223 |
+
```bash
|
| 224 |
+
pip install huggingface_hub
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
We recommend using [`uv`](https://docs.astral.sh/uv/) for a fast and reliable install:
|
| 228 |
+
|
| 229 |
+
```bash
|
| 230 |
+
uv pip install huggingface_hub
|
| 231 |
+
```
|
| 232 |
+
|
| 233 |
+
In order to keep the package minimal by default, `huggingface_hub` comes with optional dependencies useful for some use cases. For example, if you want to use the MCP module, run:
|
| 234 |
+
|
| 235 |
+
```bash
|
| 236 |
+
pip install "huggingface_hub[mcp]"
|
| 237 |
+
```
|
| 238 |
+
|
| 239 |
+
To learn more about installation and optional dependencies, check out the [installation guide](https://huggingface.co/docs/huggingface_hub/en/installation).
|
| 240 |
+
|
| 241 |
+
## Quick start
|
| 242 |
+
|
| 243 |
+
### Download files
|
| 244 |
+
|
| 245 |
+
Download a single file
|
| 246 |
+
|
| 247 |
+
```py
|
| 248 |
+
from huggingface_hub import hf_hub_download
|
| 249 |
+
|
| 250 |
+
hf_hub_download(repo_id="tiiuae/falcon-7b-instruct", filename="config.json")
|
| 251 |
+
```
|
| 252 |
+
|
| 253 |
+
Or an entire repository
|
| 254 |
+
|
| 255 |
+
```py
|
| 256 |
+
from huggingface_hub import snapshot_download
|
| 257 |
+
|
| 258 |
+
snapshot_download("stabilityai/stable-diffusion-2-1")
|
| 259 |
+
```
|
| 260 |
+
|
| 261 |
+
Files will be downloaded in a local cache folder. More details in [this guide](https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache).
|
| 262 |
+
|
| 263 |
+
### Login
|
| 264 |
+
|
| 265 |
+
The Hugging Face Hub uses tokens to authenticate applications (see [docs](https://huggingface.co/docs/hub/security-tokens)). To log in your machine, run the following CLI:
|
| 266 |
+
|
| 267 |
+
```bash
|
| 268 |
+
hf auth login
|
| 269 |
+
# or using an environment variable
|
| 270 |
+
hf auth login --token $HUGGINGFACE_TOKEN
|
| 271 |
+
```
|
| 272 |
+
|
| 273 |
+
### Create a repository
|
| 274 |
+
|
| 275 |
+
```py
|
| 276 |
+
from huggingface_hub import create_repo
|
| 277 |
+
|
| 278 |
+
create_repo(repo_id="super-cool-model")
|
| 279 |
+
```
|
| 280 |
+
|
| 281 |
+
### Upload files
|
| 282 |
+
|
| 283 |
+
Upload a single file
|
| 284 |
+
|
| 285 |
+
```py
|
| 286 |
+
from huggingface_hub import upload_file
|
| 287 |
+
|
| 288 |
+
upload_file(
|
| 289 |
+
path_or_fileobj="/home/lysandre/dummy-test/README.md",
|
| 290 |
+
path_in_repo="README.md",
|
| 291 |
+
repo_id="lysandre/test-model",
|
| 292 |
+
)
|
| 293 |
+
```
|
| 294 |
+
|
| 295 |
+
Or an entire folder
|
| 296 |
+
|
| 297 |
+
```py
|
| 298 |
+
from huggingface_hub import upload_folder
|
| 299 |
+
|
| 300 |
+
upload_folder(
|
| 301 |
+
folder_path="/path/to/local/space",
|
| 302 |
+
repo_id="username/my-cool-space",
|
| 303 |
+
repo_type="space",
|
| 304 |
+
)
|
| 305 |
+
```
|
| 306 |
+
|
| 307 |
+
For details in the [upload guide](https://huggingface.co/docs/huggingface_hub/en/guides/upload).
|
| 308 |
+
|
| 309 |
+
## Integrating to the Hub.
|
| 310 |
+
|
| 311 |
+
We're partnering with cool open source ML libraries to provide free model hosting and versioning. You can find the existing integrations [here](https://huggingface.co/docs/hub/libraries).
|
| 312 |
+
|
| 313 |
+
The advantages are:
|
| 314 |
+
|
| 315 |
+
- Free model or dataset hosting for libraries and their users.
|
| 316 |
+
- Built-in file versioning, even with very large files, thanks to a git-based approach.
|
| 317 |
+
- In-browser widgets to play with the uploaded models.
|
| 318 |
+
- Anyone can upload a new model for your library, they just need to add the corresponding tag for the model to be discoverable.
|
| 319 |
+
- Fast downloads! We use Cloudfront (a CDN) to geo-replicate downloads so they're blazing fast from anywhere on the globe.
|
| 320 |
+
- Usage stats and more features to come.
|
| 321 |
+
|
| 322 |
+
If you would like to integrate your library, feel free to open an issue to begin the discussion. We wrote a [step-by-step guide](https://huggingface.co/docs/hub/adding-a-library) with ❤️ showing how to do this integration.
|
| 323 |
+
|
| 324 |
+
## Contributions (feature requests, bugs, etc.) are super welcome 💙💚💛💜🧡❤️
|
| 325 |
+
|
| 326 |
+
Everyone is welcome to contribute, and we value everybody's contribution. Code is not the only way to help the community.
|
| 327 |
+
Answering questions, helping others, reaching out and improving the documentations are immensely valuable to the community.
|
| 328 |
+
We wrote a [contribution guide](https://github.com/huggingface/huggingface_hub/blob/main/CONTRIBUTING.md) to summarize
|
| 329 |
+
how to get started to contribute to this repository.
|
.cache/pip/http-v2/4/a/5/b/6/4a5b6f0d76201de4cfd4884f5e95617a1848cf81c8357be4d12cbf6a
ADDED
|
Binary file (1.28 kB). View file
|
|
|
.cache/pip/http-v2/4/a/5/b/6/4a5b6f0d76201de4cfd4884f5e95617a1848cf81c8357be4d12cbf6a.body
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: openpyxl
|
| 3 |
+
Version: 3.1.5
|
| 4 |
+
Summary: A Python library to read/write Excel 2010 xlsx/xlsm files
|
| 5 |
+
Home-page: https://openpyxl.readthedocs.io
|
| 6 |
+
Author: See AUTHORS
|
| 7 |
+
Author-email: charlie.clark@clark-consulting.eu
|
| 8 |
+
License: MIT
|
| 9 |
+
Project-URL: Documentation, https://openpyxl.readthedocs.io/en/stable/
|
| 10 |
+
Project-URL: Source, https://foss.heptapod.net/openpyxl/openpyxl
|
| 11 |
+
Project-URL: Tracker, https://foss.heptapod.net/openpyxl/openpyxl/-/issues
|
| 12 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 13 |
+
Classifier: Operating System :: MacOS :: MacOS X
|
| 14 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 15 |
+
Classifier: Operating System :: POSIX
|
| 16 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 17 |
+
Classifier: Programming Language :: Python
|
| 18 |
+
Classifier: Programming Language :: Python :: 3.6
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.7
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.8
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.9
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 24 |
+
Requires-Python: >=3.8
|
| 25 |
+
License-File: LICENCE.rst
|
| 26 |
+
Requires-Dist: et-xmlfile
|
| 27 |
+
|
| 28 |
+
.. image:: https://coveralls.io/repos/bitbucket/openpyxl/openpyxl/badge.svg?branch=default
|
| 29 |
+
:target: https://coveralls.io/bitbucket/openpyxl/openpyxl?branch=default
|
| 30 |
+
:alt: coverage status
|
| 31 |
+
|
| 32 |
+
Introduction
|
| 33 |
+
------------
|
| 34 |
+
|
| 35 |
+
openpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.
|
| 36 |
+
|
| 37 |
+
It was born from lack of existing library to read/write natively from Python
|
| 38 |
+
the Office Open XML format.
|
| 39 |
+
|
| 40 |
+
All kudos to the PHPExcel team as openpyxl was initially based on PHPExcel.
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Security
|
| 44 |
+
--------
|
| 45 |
+
|
| 46 |
+
By default openpyxl does not guard against quadratic blowup or billion laughs
|
| 47 |
+
xml attacks. To guard against these attacks install defusedxml.
|
| 48 |
+
|
| 49 |
+
Mailing List
|
| 50 |
+
------------
|
| 51 |
+
|
| 52 |
+
The user list can be found on http://groups.google.com/group/openpyxl-users
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
Sample code::
|
| 56 |
+
|
| 57 |
+
from openpyxl import Workbook
|
| 58 |
+
wb = Workbook()
|
| 59 |
+
|
| 60 |
+
# grab the active worksheet
|
| 61 |
+
ws = wb.active
|
| 62 |
+
|
| 63 |
+
# Data can be assigned directly to cells
|
| 64 |
+
ws['A1'] = 42
|
| 65 |
+
|
| 66 |
+
# Rows can also be appended
|
| 67 |
+
ws.append([1, 2, 3])
|
| 68 |
+
|
| 69 |
+
# Python types will automatically be converted
|
| 70 |
+
import datetime
|
| 71 |
+
ws['A2'] = datetime.datetime.now()
|
| 72 |
+
|
| 73 |
+
# Save the file
|
| 74 |
+
wb.save("sample.xlsx")
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
Documentation
|
| 78 |
+
-------------
|
| 79 |
+
|
| 80 |
+
The documentation is at: https://openpyxl.readthedocs.io
|
| 81 |
+
|
| 82 |
+
* installation methods
|
| 83 |
+
* code examples
|
| 84 |
+
* instructions for contributing
|
| 85 |
+
|
| 86 |
+
Release notes: https://openpyxl.readthedocs.io/en/stable/changes.html
|
.cache/pip/http-v2/4/d/c/8/d/4dc8d567db4bc55c0684404c85a6b4572f87a99306be24cab65fbfae
ADDED
|
Binary file (1.85 kB). View file
|
|
|
.cache/pip/http-v2/4/d/c/8/d/4dc8d567db4bc55c0684404c85a6b4572f87a99306be24cab65fbfae.body
ADDED
|
Binary file (16.2 kB). View file
|
|
|
.cache/pip/http-v2/4/f/3/2/1/4f3214a3fad8d38cb17e7de04e5671458da4f4634932269127d53af7
ADDED
|
Binary file (1.21 kB). View file
|
|
|
.cache/pip/http-v2/9/b/5/1/6/9b51619e20a708f99372afefd7dbe20a1b5e42ae213f02bf27267976
ADDED
|
Binary file (1.87 kB). View file
|
|
|
.cache/pip/http-v2/c/3/a/e/f/c3aefa2552222433000010e47def822725a77e3cf762f96a15f09d26
ADDED
|
Binary file (1.29 kB). View file
|
|
|
.cache/pip/http-v2/c/3/a/e/f/c3aefa2552222433000010e47def822725a77e3cf762f96a15f09d26.body
ADDED
|
@@ -0,0 +1,907 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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1
|
| 2 |
+
Name: matplotlib
|
| 3 |
+
Version: 3.10.9
|
| 4 |
+
Summary: Python plotting package
|
| 5 |
+
Author: John D. Hunter, Michael Droettboom
|
| 6 |
+
Author-Email: Unknown <matplotlib-users@python.org>
|
| 7 |
+
License: License agreement for matplotlib versions 1.3.0 and later
|
| 8 |
+
=========================================================
|
| 9 |
+
|
| 10 |
+
1. This LICENSE AGREEMENT is between the Matplotlib Development Team
|
| 11 |
+
("MDT"), and the Individual or Organization ("Licensee") accessing and
|
| 12 |
+
otherwise using matplotlib software in source or binary form and its
|
| 13 |
+
associated documentation.
|
| 14 |
+
|
| 15 |
+
2. Subject to the terms and conditions of this License Agreement, MDT
|
| 16 |
+
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
|
| 17 |
+
to reproduce, analyze, test, perform and/or display publicly, prepare
|
| 18 |
+
derivative works, distribute, and otherwise use matplotlib
|
| 19 |
+
alone or in any derivative version, provided, however, that MDT's
|
| 20 |
+
License Agreement and MDT's notice of copyright, i.e., "Copyright (c)
|
| 21 |
+
2012- Matplotlib Development Team; All Rights Reserved" are retained in
|
| 22 |
+
matplotlib alone or in any derivative version prepared by
|
| 23 |
+
Licensee.
|
| 24 |
+
|
| 25 |
+
3. In the event Licensee prepares a derivative work that is based on or
|
| 26 |
+
incorporates matplotlib or any part thereof, and wants to
|
| 27 |
+
make the derivative work available to others as provided herein, then
|
| 28 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 29 |
+
the changes made to matplotlib .
|
| 30 |
+
|
| 31 |
+
4. MDT is making matplotlib available to Licensee on an "AS
|
| 32 |
+
IS" basis. MDT MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 33 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, MDT MAKES NO AND
|
| 34 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 35 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
|
| 36 |
+
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
|
| 37 |
+
|
| 38 |
+
5. MDT SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
|
| 39 |
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
|
| 40 |
+
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
|
| 41 |
+
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
|
| 42 |
+
THE POSSIBILITY THEREOF.
|
| 43 |
+
|
| 44 |
+
6. This License Agreement will automatically terminate upon a material
|
| 45 |
+
breach of its terms and conditions.
|
| 46 |
+
|
| 47 |
+
7. Nothing in this License Agreement shall be deemed to create any
|
| 48 |
+
relationship of agency, partnership, or joint venture between MDT and
|
| 49 |
+
Licensee. This License Agreement does not grant permission to use MDT
|
| 50 |
+
trademarks or trade name in a trademark sense to endorse or promote
|
| 51 |
+
products or services of Licensee, or any third party.
|
| 52 |
+
|
| 53 |
+
8. By copying, installing or otherwise using matplotlib ,
|
| 54 |
+
Licensee agrees to be bound by the terms and conditions of this License
|
| 55 |
+
Agreement.
|
| 56 |
+
|
| 57 |
+
License agreement for matplotlib versions prior to 1.3.0
|
| 58 |
+
========================================================
|
| 59 |
+
|
| 60 |
+
1. This LICENSE AGREEMENT is between John D. Hunter ("JDH"), and the
|
| 61 |
+
Individual or Organization ("Licensee") accessing and otherwise using
|
| 62 |
+
matplotlib software in source or binary form and its associated
|
| 63 |
+
documentation.
|
| 64 |
+
|
| 65 |
+
2. Subject to the terms and conditions of this License Agreement, JDH
|
| 66 |
+
hereby grants Licensee a nonexclusive, royalty-free, world-wide license
|
| 67 |
+
to reproduce, analyze, test, perform and/or display publicly, prepare
|
| 68 |
+
derivative works, distribute, and otherwise use matplotlib
|
| 69 |
+
alone or in any derivative version, provided, however, that JDH's
|
| 70 |
+
License Agreement and JDH's notice of copyright, i.e., "Copyright (c)
|
| 71 |
+
2002-2011 John D. Hunter; All Rights Reserved" are retained in
|
| 72 |
+
matplotlib alone or in any derivative version prepared by
|
| 73 |
+
Licensee.
|
| 74 |
+
|
| 75 |
+
3. In the event Licensee prepares a derivative work that is based on or
|
| 76 |
+
incorporates matplotlib or any part thereof, and wants to
|
| 77 |
+
make the derivative work available to others as provided herein, then
|
| 78 |
+
Licensee hereby agrees to include in any such work a brief summary of
|
| 79 |
+
the changes made to matplotlib.
|
| 80 |
+
|
| 81 |
+
4. JDH is making matplotlib available to Licensee on an "AS
|
| 82 |
+
IS" basis. JDH MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
| 83 |
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, JDH MAKES NO AND
|
| 84 |
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
| 85 |
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF MATPLOTLIB
|
| 86 |
+
WILL NOT INFRINGE ANY THIRD PARTY RIGHTS.
|
| 87 |
+
|
| 88 |
+
5. JDH SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF MATPLOTLIB
|
| 89 |
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR
|
| 90 |
+
LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING
|
| 91 |
+
MATPLOTLIB , OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF
|
| 92 |
+
THE POSSIBILITY THEREOF.
|
| 93 |
+
|
| 94 |
+
6. This License Agreement will automatically terminate upon a material
|
| 95 |
+
breach of its terms and conditions.
|
| 96 |
+
|
| 97 |
+
7. Nothing in this License Agreement shall be deemed to create any
|
| 98 |
+
relationship of agency, partnership, or joint venture between JDH and
|
| 99 |
+
Licensee. This License Agreement does not grant permission to use JDH
|
| 100 |
+
trademarks or trade name in a trademark sense to endorse or promote
|
| 101 |
+
products or services of Licensee, or any third party.
|
| 102 |
+
|
| 103 |
+
8. By copying, installing or otherwise using matplotlib,
|
| 104 |
+
Licensee agrees to be bound by the terms and conditions of this License
|
| 105 |
+
Agreement.
|
| 106 |
+
----
|
| 107 |
+
|
| 108 |
+
This binary distrubution of Matplotlib can also bundle the following software
|
| 109 |
+
(depending on the build):
|
| 110 |
+
|
| 111 |
+
Name: AMS Fonts
|
| 112 |
+
Files: matplotlib/tests/cmr10.pfb
|
| 113 |
+
Description: Type-1 version of one of Knuth's Computer Modern fonts
|
| 114 |
+
License: OFL-1.1
|
| 115 |
+
The cmr10.pfb file is a Type-1 version of one of Knuth's Computer Modern fonts.
|
| 116 |
+
It is included here as test data only, but the following license applies.
|
| 117 |
+
|
| 118 |
+
Copyright (c) 1997, 2009, American Mathematical Society (http://www.ams.org).
|
| 119 |
+
All Rights Reserved.
|
| 120 |
+
|
| 121 |
+
"cmb10" is a Reserved Font Name for this Font Software.
|
| 122 |
+
"cmbsy10" is a Reserved Font Name for this Font Software.
|
| 123 |
+
"cmbsy5" is a Reserved Font Name for this Font Software.
|
| 124 |
+
"cmbsy6" is a Reserved Font Name for this Font Software.
|
| 125 |
+
"cmbsy7" is a Reserved Font Name for this Font Software.
|
| 126 |
+
"cmbsy8" is a Reserved Font Name for this Font Software.
|
| 127 |
+
"cmbsy9" is a Reserved Font Name for this Font Software.
|
| 128 |
+
"cmbx10" is a Reserved Font Name for this Font Software.
|
| 129 |
+
"cmbx12" is a Reserved Font Name for this Font Software.
|
| 130 |
+
"cmbx5" is a Reserved Font Name for this Font Software.
|
| 131 |
+
"cmbx6" is a Reserved Font Name for this Font Software.
|
| 132 |
+
"cmbx7" is a Reserved Font Name for this Font Software.
|
| 133 |
+
"cmbx8" is a Reserved Font Name for this Font Software.
|
| 134 |
+
"cmbx9" is a Reserved Font Name for this Font Software.
|
| 135 |
+
"cmbxsl10" is a Reserved Font Name for this Font Software.
|
| 136 |
+
"cmbxti10" is a Reserved Font Name for this Font Software.
|
| 137 |
+
"cmcsc10" is a Reserved Font Name for this Font Software.
|
| 138 |
+
"cmcsc8" is a Reserved Font Name for this Font Software.
|
| 139 |
+
"cmcsc9" is a Reserved Font Name for this Font Software.
|
| 140 |
+
"cmdunh10" is a Reserved Font Name for this Font Software.
|
| 141 |
+
"cmex10" is a Reserved Font Name for this Font Software.
|
| 142 |
+
"cmex7" is a Reserved Font Name for this Font Software.
|
| 143 |
+
"cmex8" is a Reserved Font Name for this Font Software.
|
| 144 |
+
"cmex9" is a Reserved Font Name for this Font Software.
|
| 145 |
+
"cmff10" is a Reserved Font Name for this Font Software.
|
| 146 |
+
"cmfi10" is a Reserved Font Name for this Font Software.
|
| 147 |
+
"cmfib8" is a Reserved Font Name for this Font Software.
|
| 148 |
+
"cminch" is a Reserved Font Name for this Font Software.
|
| 149 |
+
"cmitt10" is a Reserved Font Name for this Font Software.
|
| 150 |
+
"cmmi10" is a Reserved Font Name for this Font Software.
|
| 151 |
+
"cmmi12" is a Reserved Font Name for this Font Software.
|
| 152 |
+
"cmmi5" is a Reserved Font Name for this Font Software.
|
| 153 |
+
"cmmi6" is a Reserved Font Name for this Font Software.
|
| 154 |
+
"cmmi7" is a Reserved Font Name for this Font Software.
|
| 155 |
+
"cmmi8" is a Reserved Font Name for this Font Software.
|
| 156 |
+
"cmmi9" is a Reserved Font Name for this Font Software.
|
| 157 |
+
"cmmib10" is a Reserved Font Name for this Font Software.
|
| 158 |
+
"cmmib5" is a Reserved Font Name for this Font Software.
|
| 159 |
+
"cmmib6" is a Reserved Font Name for this Font Software.
|
| 160 |
+
"cmmib7" is a Reserved Font Name for this Font Software.
|
| 161 |
+
"cmmib8" is a Reserved Font Name for this Font Software.
|
| 162 |
+
"cmmib9" is a Reserved Font Name for this Font Software.
|
| 163 |
+
"cmr10" is a Reserved Font Name for this Font Software.
|
| 164 |
+
"cmr12" is a Reserved Font Name for this Font Software.
|
| 165 |
+
"cmr17" is a Reserved Font Name for this Font Software.
|
| 166 |
+
"cmr5" is a Reserved Font Name for this Font Software.
|
| 167 |
+
"cmr6" is a Reserved Font Name for this Font Software.
|
| 168 |
+
"cmr7" is a Reserved Font Name for this Font Software.
|
| 169 |
+
"cmr8" is a Reserved Font Name for this Font Software.
|
| 170 |
+
"cmr9" is a Reserved Font Name for this Font Software.
|
| 171 |
+
"cmsl10" is a Reserved Font Name for this Font Software.
|
| 172 |
+
"cmsl12" is a Reserved Font Name for this Font Software.
|
| 173 |
+
"cmsl8" is a Reserved Font Name for this Font Software.
|
| 174 |
+
"cmsl9" is a Reserved Font Name for this Font Software.
|
| 175 |
+
"cmsltt10" is a Reserved Font Name for this Font Software.
|
| 176 |
+
"cmss10" is a Reserved Font Name for this Font Software.
|
| 177 |
+
"cmss12" is a Reserved Font Name for this Font Software.
|
| 178 |
+
"cmss17" is a Reserved Font Name for this Font Software.
|
| 179 |
+
"cmss8" is a Reserved Font Name for this Font Software.
|
| 180 |
+
"cmss9" is a Reserved Font Name for this Font Software.
|
| 181 |
+
"cmssbx10" is a Reserved Font Name for this Font Software.
|
| 182 |
+
"cmssdc10" is a Reserved Font Name for this Font Software.
|
| 183 |
+
"cmssi10" is a Reserved Font Name for this Font Software.
|
| 184 |
+
"cmssi12" is a Reserved Font Name for this Font Software.
|
| 185 |
+
"cmssi17" is a Reserved Font Name for this Font Software.
|
| 186 |
+
"cmssi8" is a Reserved Font Name for this Font Software.
|
| 187 |
+
"cmssi9" is a Reserved Font Name for this Font Software.
|
| 188 |
+
"cmssq8" is a Reserved Font Name for this Font Software.
|
| 189 |
+
"cmssqi8" is a Reserved Font Name for this Font Software.
|
| 190 |
+
"cmsy10" is a Reserved Font Name for this Font Software.
|
| 191 |
+
"cmsy5" is a Reserved Font Name for this Font Software.
|
| 192 |
+
"cmsy6" is a Reserved Font Name for this Font Software.
|
| 193 |
+
"cmsy7" is a Reserved Font Name for this Font Software.
|
| 194 |
+
"cmsy8" is a Reserved Font Name for this Font Software.
|
| 195 |
+
"cmsy9" is a Reserved Font Name for this Font Software.
|
| 196 |
+
"cmtcsc10" is a Reserved Font Name for this Font Software.
|
| 197 |
+
"cmtex10" is a Reserved Font Name for this Font Software.
|
| 198 |
+
"cmtex8" is a Reserved Font Name for this Font Software.
|
| 199 |
+
"cmtex9" is a Reserved Font Name for this Font Software.
|
| 200 |
+
"cmti10" is a Reserved Font Name for this Font Software.
|
| 201 |
+
"cmti12" is a Reserved Font Name for this Font Software.
|
| 202 |
+
"cmti7" is a Reserved Font Name for this Font Software.
|
| 203 |
+
"cmti8" is a Reserved Font Name for this Font Software.
|
| 204 |
+
"cmti9" is a Reserved Font Name for this Font Software.
|
| 205 |
+
"cmtt10" is a Reserved Font Name for this Font Software.
|
| 206 |
+
"cmtt12" is a Reserved Font Name for this Font Software.
|
| 207 |
+
"cmtt8" is a Reserved Font Name for this Font Software.
|
| 208 |
+
"cmtt9" is a Reserved Font Name for this Font Software.
|
| 209 |
+
"cmu10" is a Reserved Font Name for this Font Software.
|
| 210 |
+
"cmvtt10" is a Reserved Font Name for this Font Software.
|
| 211 |
+
"euex10" is a Reserved Font Name for this Font Software.
|
| 212 |
+
"euex7" is a Reserved Font Name for this Font Software.
|
| 213 |
+
"euex8" is a Reserved Font Name for this Font Software.
|
| 214 |
+
"euex9" is a Reserved Font Name for this Font Software.
|
| 215 |
+
"eufb10" is a Reserved Font Name for this Font Software.
|
| 216 |
+
"eufb5" is a Reserved Font Name for this Font Software.
|
| 217 |
+
"eufb7" is a Reserved Font Name for this Font Software.
|
| 218 |
+
"eufm10" is a Reserved Font Name for this Font Software.
|
| 219 |
+
"eufm5" is a Reserved Font Name for this Font Software.
|
| 220 |
+
"eufm7" is a Reserved Font Name for this Font Software.
|
| 221 |
+
"eurb10" is a Reserved Font Name for this Font Software.
|
| 222 |
+
"eurb5" is a Reserved Font Name for this Font Software.
|
| 223 |
+
"eurb7" is a Reserved Font Name for this Font Software.
|
| 224 |
+
"eurm10" is a Reserved Font Name for this Font Software.
|
| 225 |
+
"eurm5" is a Reserved Font Name for this Font Software.
|
| 226 |
+
"eurm7" is a Reserved Font Name for this Font Software.
|
| 227 |
+
"eusb10" is a Reserved Font Name for this Font Software.
|
| 228 |
+
"eusb5" is a Reserved Font Name for this Font Software.
|
| 229 |
+
"eusb7" is a Reserved Font Name for this Font Software.
|
| 230 |
+
"eusm10" is a Reserved Font Name for this Font Software.
|
| 231 |
+
"eusm5" is a Reserved Font Name for this Font Software.
|
| 232 |
+
"eusm7" is a Reserved Font Name for this Font Software.
|
| 233 |
+
"lasy10" is a Reserved Font Name for this Font Software.
|
| 234 |
+
"lasy5" is a Reserved Font Name for this Font Software.
|
| 235 |
+
"lasy6" is a Reserved Font Name for this Font Software.
|
| 236 |
+
"lasy7" is a Reserved Font Name for this Font Software.
|
| 237 |
+
"lasy8" is a Reserved Font Name for this Font Software.
|
| 238 |
+
"lasy9" is a Reserved Font Name for this Font Software.
|
| 239 |
+
"lasyb10" is a Reserved Font Name for this Font Software.
|
| 240 |
+
"lcircle1" is a Reserved Font Name for this Font Software.
|
| 241 |
+
"lcirclew" is a Reserved Font Name for this Font Software.
|
| 242 |
+
"lcmss8" is a Reserved Font Name for this Font Software.
|
| 243 |
+
"lcmssb8" is a Reserved Font Name for this Font Software.
|
| 244 |
+
"lcmssi8" is a Reserved Font Name for this Font Software.
|
| 245 |
+
"line10" is a Reserved Font Name for this Font Software.
|
| 246 |
+
"linew10" is a Reserved Font Name for this Font Software.
|
| 247 |
+
"msam10" is a Reserved Font Name for this Font Software.
|
| 248 |
+
"msam5" is a Reserved Font Name for this Font Software.
|
| 249 |
+
"msam6" is a Reserved Font Name for this Font Software.
|
| 250 |
+
"msam7" is a Reserved Font Name for this Font Software.
|
| 251 |
+
"msam8" is a Reserved Font Name for this Font Software.
|
| 252 |
+
"msam9" is a Reserved Font Name for this Font Software.
|
| 253 |
+
"msbm10" is a Reserved Font Name for this Font Software.
|
| 254 |
+
"msbm5" is a Reserved Font Name for this Font Software.
|
| 255 |
+
"msbm6" is a Reserved Font Name for this Font Software.
|
| 256 |
+
"msbm7" is a Reserved Font Name for this Font Software.
|
| 257 |
+
"msbm8" is a Reserved Font Name for this Font Software.
|
| 258 |
+
"msbm9" is a Reserved Font Name for this Font Software.
|
| 259 |
+
"wncyb10" is a Reserved Font Name for this Font Software.
|
| 260 |
+
"wncyi10" is a Reserved Font Name for this Font Software.
|
| 261 |
+
"wncyr10" is a Reserved Font Name for this Font Software.
|
| 262 |
+
"wncysc10" is a Reserved Font Name for this Font Software.
|
| 263 |
+
"wncyss10" is a Reserved Font Name for this Font Software.
|
| 264 |
+
|
| 265 |
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
| 266 |
+
This license is copied below, and is also available with a FAQ at:
|
| 267 |
+
http://scripts.sil.org/OFL
|
| 268 |
+
|
| 269 |
+
-----------------------------------------------------------
|
| 270 |
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
| 271 |
+
-----------------------------------------------------------
|
| 272 |
+
|
| 273 |
+
PREAMBLE
|
| 274 |
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
| 275 |
+
development of collaborative font projects, to support the font creation
|
| 276 |
+
efforts of academic and linguistic communities, and to provide a free and
|
| 277 |
+
open framework in which fonts may be shared and improved in partnership
|
| 278 |
+
with others.
|
| 279 |
+
|
| 280 |
+
The OFL allows the licensed fonts to be used, studied, modified and
|
| 281 |
+
redistributed freely as long as they are not sold by themselves. The
|
| 282 |
+
fonts, including any derivative works, can be bundled, embedded,
|
| 283 |
+
redistributed and/or sold with any software provided that any reserved
|
| 284 |
+
names are not used by derivative works. The fonts and derivatives,
|
| 285 |
+
however, cannot be released under any other type of license. The
|
| 286 |
+
requirement for fonts to remain under this license does not apply
|
| 287 |
+
to any document created using the fonts or their derivatives.
|
| 288 |
+
|
| 289 |
+
DEFINITIONS
|
| 290 |
+
"Font Software" refers to the set of files released by the Copyright
|
| 291 |
+
Holder(s) under this license and clearly marked as such. This may
|
| 292 |
+
include source files, build scripts and documentation.
|
| 293 |
+
|
| 294 |
+
"Reserved Font Name" refers to any names specified as such after the
|
| 295 |
+
copyright statement(s).
|
| 296 |
+
|
| 297 |
+
"Original Version" refers to the collection of Font Software components as
|
| 298 |
+
distributed by the Copyright Holder(s).
|
| 299 |
+
|
| 300 |
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
| 301 |
+
or substituting -- in part or in whole -- any of the components of the
|
| 302 |
+
Original Version, by changing formats or by porting the Font Software to a
|
| 303 |
+
new environment.
|
| 304 |
+
|
| 305 |
+
"Author" refers to any designer, engineer, programmer, technical
|
| 306 |
+
writer or other person who contributed to the Font Software.
|
| 307 |
+
|
| 308 |
+
PERMISSION & CONDITIONS
|
| 309 |
+
Permission is hereby granted, free of charge, to any person obtaining
|
| 310 |
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
| 311 |
+
redistribute, and sell modified and unmodified copies of the Font
|
| 312 |
+
Software, subject to the following conditions:
|
| 313 |
+
|
| 314 |
+
1) Neither the Font Software nor any of its individual components,
|
| 315 |
+
in Original or Modified Versions, may be sold by itself.
|
| 316 |
+
|
| 317 |
+
2) Original or Modified Versions of the Font Software may be bundled,
|
| 318 |
+
redistributed and/or sold with any software, provided that each copy
|
| 319 |
+
contains the above copyright notice and this license. These can be
|
| 320 |
+
included either as stand-alone text files, human-readable headers or
|
| 321 |
+
in the appropriate machine-readable metadata fields within text or
|
| 322 |
+
binary files as long as those fields can be easily viewed by the user.
|
| 323 |
+
|
| 324 |
+
3) No Modified Version of the Font Software may use the Reserved Font
|
| 325 |
+
Name(s) unless explicit written permission is granted by the corresponding
|
| 326 |
+
Copyright Holder. This restriction only applies to the primary font name as
|
| 327 |
+
presented to the users.
|
| 328 |
+
|
| 329 |
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
| 330 |
+
Software shall not be used to promote, endorse or advertise any
|
| 331 |
+
Modified Version, except to acknowledge the contribution(s) of the
|
| 332 |
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
| 333 |
+
permission.
|
| 334 |
+
|
| 335 |
+
5) The Font Software, modified or unmodified, in part or in whole,
|
| 336 |
+
must be distributed entirely under this license, and must not be
|
| 337 |
+
distributed under any other license. The requirement for fonts to
|
| 338 |
+
remain under this license does not apply to any document created
|
| 339 |
+
using the Font Software.
|
| 340 |
+
|
| 341 |
+
TERMINATION
|
| 342 |
+
This license becomes null and void if any of the above conditions are
|
| 343 |
+
not met.
|
| 344 |
+
|
| 345 |
+
DISCLAIMER
|
| 346 |
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 347 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
| 348 |
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
| 349 |
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
| 350 |
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 351 |
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
| 352 |
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 353 |
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
| 354 |
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
| 355 |
+
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
Name: BaKoMa Fonts
|
| 359 |
+
Files: matplotlib/mpl-data/fonts/ttf/cm*.ttf matplotlib/mpl-data/fonts/afm/cm*.afm
|
| 360 |
+
Description: Computer Modern Fonts in PostScript Type 1 and TrueType font formats.
|
| 361 |
+
License: BaKoMa Fonts Licence
|
| 362 |
+
BaKoMa Fonts Licence
|
| 363 |
+
--------------------
|
| 364 |
+
|
| 365 |
+
This licence covers two font packs (known as BaKoMa Fonts Collection,
|
| 366 |
+
which is available at `CTAN:fonts/cm/ps-type1/bakoma/'):
|
| 367 |
+
|
| 368 |
+
1) BaKoMa-CM (1.1/12-Nov-94)
|
| 369 |
+
Computer Modern Fonts in PostScript Type 1 and TrueType font formats.
|
| 370 |
+
|
| 371 |
+
2) BaKoMa-AMS (1.2/19-Jan-95)
|
| 372 |
+
AMS TeX fonts in PostScript Type 1 and TrueType font formats.
|
| 373 |
+
|
| 374 |
+
Copyright (C) 1994, 1995, Basil K. Malyshev. All Rights Reserved.
|
| 375 |
+
|
| 376 |
+
Permission to copy and distribute these fonts for any purpose is
|
| 377 |
+
hereby granted without fee, provided that the above copyright notice,
|
| 378 |
+
author statement and this permission notice appear in all copies of
|
| 379 |
+
these fonts and related documentation.
|
| 380 |
+
|
| 381 |
+
Permission to modify and distribute modified fonts for any purpose is
|
| 382 |
+
hereby granted without fee, provided that the copyright notice,
|
| 383 |
+
author statement, this permission notice and location of original
|
| 384 |
+
fonts (http://www.ctan.org/tex-archive/fonts/cm/ps-type1/bakoma)
|
| 385 |
+
appear in all copies of modified fonts and related documentation.
|
| 386 |
+
|
| 387 |
+
Permission to use these fonts (embedding into PostScript, PDF, SVG
|
| 388 |
+
and printing by using any software) is hereby granted without fee.
|
| 389 |
+
It is not required to provide any notices about using these fonts.
|
| 390 |
+
|
| 391 |
+
Basil K. Malyshev
|
| 392 |
+
INSTITUTE FOR HIGH ENERGY PHYSICS
|
| 393 |
+
IHEP, OMVT
|
| 394 |
+
Moscow Region
|
| 395 |
+
142281 PROTVINO
|
| 396 |
+
RUSSIA
|
| 397 |
+
|
| 398 |
+
E-Mail: bakoma@mail.ru
|
| 399 |
+
or malyshev@mail.ihep.ru
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
|
| 404 |
+
Name: ColorBrewer Color Schemes
|
| 405 |
+
Files: lib/matplotlib/_cm.py
|
| 406 |
+
Description: Color schemes from ColorBrewer
|
| 407 |
+
License: Apache-2.0
|
| 408 |
+
Apache-Style Software License for ColorBrewer software and ColorBrewer Color Schemes
|
| 409 |
+
|
| 410 |
+
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
|
| 411 |
+
|
| 412 |
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
|
| 413 |
+
You may obtain a copy of the License at
|
| 414 |
+
|
| 415 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 416 |
+
|
| 417 |
+
Unless required by applicable law or agreed to in writing, software distributed
|
| 418 |
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
| 419 |
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
| 420 |
+
specific language governing permissions and limitations under the License.
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
Name: Courier 10
|
| 424 |
+
Files: matplotlib/tests/Courier10PitchBT-Bold.pfb
|
| 425 |
+
Description: Courier 10 font, used in tests.
|
| 426 |
+
License: Bitstream-Charter
|
| 427 |
+
The Courier10PitchBT-Bold.pfb file is a Type-1 version of
|
| 428 |
+
Courier 10 Pitch BT Bold by Bitstream, obtained from
|
| 429 |
+
<https://ctan.org/tex-archive/fonts/courierten>. It is included
|
| 430 |
+
here as test data only, but the following license applies.
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
(c) Copyright 1989-1992, Bitstream Inc., Cambridge, MA.
|
| 434 |
+
|
| 435 |
+
You are hereby granted permission under all Bitstream propriety rights
|
| 436 |
+
to use, copy, modify, sublicense, sell, and redistribute the 4 Bitstream
|
| 437 |
+
Charter (r) Type 1 outline fonts and the 4 Courier Type 1 outline fonts
|
| 438 |
+
for any purpose and without restriction; provided, that this notice is
|
| 439 |
+
left intact on all copies of such fonts and that Bitstream's trademark
|
| 440 |
+
is acknowledged as shown below on all unmodified copies of the 4 Charter
|
| 441 |
+
Type 1 fonts.
|
| 442 |
+
|
| 443 |
+
BITSTREAM CHARTER is a registered trademark of Bitstream Inc.
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
Name: JSXTools resize observer
|
| 448 |
+
Files:
|
| 449 |
+
Description: Minimal polyfill for the ResizeObserver API
|
| 450 |
+
License: CC0-1.0
|
| 451 |
+
# CC0 1.0 Universal
|
| 452 |
+
|
| 453 |
+
## Statement of Purpose
|
| 454 |
+
|
| 455 |
+
The laws of most jurisdictions throughout the world automatically confer
|
| 456 |
+
exclusive Copyright and Related Rights (defined below) upon the creator and
|
| 457 |
+
subsequent owner(s) (each and all, an “owner”) of an original work of
|
| 458 |
+
authorship and/or a database (each, a “Work”).
|
| 459 |
+
|
| 460 |
+
Certain owners wish to permanently relinquish those rights to a Work for the
|
| 461 |
+
purpose of contributing to a commons of creative, cultural and scientific works
|
| 462 |
+
(“Commons”) that the public can reliably and without fear of later claims of
|
| 463 |
+
infringement build upon, modify, incorporate in other works, reuse and
|
| 464 |
+
redistribute as freely as possible in any form whatsoever and for any purposes,
|
| 465 |
+
including without limitation commercial purposes. These owners may contribute
|
| 466 |
+
to the Commons to promote the ideal of a free culture and the further
|
| 467 |
+
production of creative, cultural and scientific works, or to gain reputation or
|
| 468 |
+
greater distribution for their Work in part through the use and efforts of
|
| 469 |
+
others.
|
| 470 |
+
|
| 471 |
+
For these and/or other purposes and motivations, and without any expectation of
|
| 472 |
+
additional consideration or compensation, the person associating CC0 with a
|
| 473 |
+
Work (the “Affirmer”), to the extent that he or she is an owner of Copyright
|
| 474 |
+
and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and
|
| 475 |
+
publicly distribute the Work under its terms, with knowledge of his or her
|
| 476 |
+
Copyright and Related Rights in the Work and the meaning and intended legal
|
| 477 |
+
effect of CC0 on those rights.
|
| 478 |
+
|
| 479 |
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
| 480 |
+
protected by copyright and related or neighboring rights (“Copyright and
|
| 481 |
+
Related Rights”). Copyright and Related Rights include, but are not limited
|
| 482 |
+
to, the following:
|
| 483 |
+
1. the right to reproduce, adapt, distribute, perform, display, communicate,
|
| 484 |
+
and translate a Work;
|
| 485 |
+
2. moral rights retained by the original author(s) and/or performer(s);
|
| 486 |
+
3. publicity and privacy rights pertaining to a person’s image or likeness
|
| 487 |
+
depicted in a Work;
|
| 488 |
+
4. rights protecting against unfair competition in regards to a Work,
|
| 489 |
+
subject to the limitations in paragraph 4(i), below;
|
| 490 |
+
5. rights protecting the extraction, dissemination, use and reuse of data in
|
| 491 |
+
a Work;
|
| 492 |
+
6. database rights (such as those arising under Directive 96/9/EC of the
|
| 493 |
+
European Parliament and of the Council of 11 March 1996 on the legal
|
| 494 |
+
protection of databases, and under any national implementation thereof,
|
| 495 |
+
including any amended or successor version of such directive); and
|
| 496 |
+
7. other similar, equivalent or corresponding rights throughout the world
|
| 497 |
+
based on applicable law or treaty, and any national implementations
|
| 498 |
+
thereof.
|
| 499 |
+
|
| 500 |
+
2. Waiver. To the greatest extent permitted by, but not in contravention of,
|
| 501 |
+
applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
|
| 502 |
+
unconditionally waives, abandons, and surrenders all of Affirmer’s Copyright
|
| 503 |
+
and Related Rights and associated claims and causes of action, whether now
|
| 504 |
+
known or unknown (including existing as well as future claims and causes of
|
| 505 |
+
action), in the Work (i) in all territories worldwide, (ii) for the maximum
|
| 506 |
+
duration provided by applicable law or treaty (including future time
|
| 507 |
+
extensions), (iii) in any current or future medium and for any number of
|
| 508 |
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
| 509 |
+
commercial, advertising or promotional purposes (the “Waiver”). Affirmer
|
| 510 |
+
makes the Waiver for the benefit of each member of the public at large and
|
| 511 |
+
to the detriment of Affirmer’s heirs and successors, fully intending that
|
| 512 |
+
such Waiver shall not be subject to revocation, rescission, cancellation,
|
| 513 |
+
termination, or any other legal or equitable action to disrupt the quiet
|
| 514 |
+
enjoyment of the Work by the public as contemplated by Affirmer’s express
|
| 515 |
+
Statement of Purpose.
|
| 516 |
+
|
| 517 |
+
3. Public License Fallback. Should any part of the Waiver for any reason be
|
| 518 |
+
judged legally invalid or ineffective under applicable law, then the Waiver
|
| 519 |
+
shall be preserved to the maximum extent permitted taking into account
|
| 520 |
+
Affirmer’s express Statement of Purpose. In addition, to the extent the
|
| 521 |
+
Waiver is so judged Affirmer hereby grants to each affected person a
|
| 522 |
+
royalty-free, non transferable, non sublicensable, non exclusive,
|
| 523 |
+
irrevocable and unconditional license to exercise Affirmer’s Copyright and
|
| 524 |
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
| 525 |
+
maximum duration provided by applicable law or treaty (including future time
|
| 526 |
+
extensions), (iii) in any current or future medium and for any number of
|
| 527 |
+
copies, and (iv) for any purpose whatsoever, including without limitation
|
| 528 |
+
commercial, advertising or promotional purposes (the “License”). The License
|
| 529 |
+
shall be deemed effective as of the date CC0 was applied by Affirmer to the
|
| 530 |
+
Work. Should any part of the License for any reason be judged legally
|
| 531 |
+
invalid or ineffective under applicable law, such partial invalidity or
|
| 532 |
+
ineffectiveness shall not invalidate the remainder of the License, and in
|
| 533 |
+
such case Affirmer hereby affirms that he or she will not (i) exercise any
|
| 534 |
+
of his or her remaining Copyright and Related Rights in the Work or (ii)
|
| 535 |
+
assert any associated claims and causes of action with respect to the Work,
|
| 536 |
+
in either case contrary to Affirmer’s express Statement of Purpose.
|
| 537 |
+
|
| 538 |
+
4. Limitations and Disclaimers.
|
| 539 |
+
1. No trademark or patent rights held by Affirmer are waived, abandoned,
|
| 540 |
+
surrendered, licensed or otherwise affected by this document.
|
| 541 |
+
2. Affirmer offers the Work as-is and makes no representations or warranties
|
| 542 |
+
of any kind concerning the Work, express, implied, statutory or
|
| 543 |
+
otherwise, including without limitation warranties of title,
|
| 544 |
+
merchantability, fitness for a particular purpose, non infringement, or
|
| 545 |
+
the absence of latent or other defects, accuracy, or the present or
|
| 546 |
+
absence of errors, whether or not discoverable, all to the greatest
|
| 547 |
+
extent permissible under applicable law.
|
| 548 |
+
3. Affirmer disclaims responsibility for clearing rights of other persons
|
| 549 |
+
that may apply to the Work or any use thereof, including without
|
| 550 |
+
limitation any person’s Copyright and Related Rights in the Work.
|
| 551 |
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
| 552 |
+
consents, permissions or other rights required for any use of the Work.
|
| 553 |
+
4. Affirmer understands and acknowledges that Creative Commons is not a
|
| 554 |
+
party to this document and has no duty or obligation with respect to this
|
| 555 |
+
CC0 or use of the Work.
|
| 556 |
+
|
| 557 |
+
For more information, please see
|
| 558 |
+
http://creativecommons.org/publicdomain/zero/1.0/.
|
| 559 |
+
|
| 560 |
+
|
| 561 |
+
Name: QHull
|
| 562 |
+
Files: matplotlib/_qhull.*.so
|
| 563 |
+
Description: Convex hull, Delaunay triangulation, Voronoi diagrams, Halfspace intersection
|
| 564 |
+
License: Qhull
|
| 565 |
+
Qhull, Copyright (c) 1993-2020
|
| 566 |
+
|
| 567 |
+
C.B. Barber
|
| 568 |
+
Arlington, MA
|
| 569 |
+
|
| 570 |
+
and
|
| 571 |
+
|
| 572 |
+
The National Science and Technology Research Center for
|
| 573 |
+
Computation and Visualization of Geometric Structures
|
| 574 |
+
(The Geometry Center)
|
| 575 |
+
University of Minnesota
|
| 576 |
+
|
| 577 |
+
email: qhull@qhull.org
|
| 578 |
+
|
| 579 |
+
This software includes Qhull from C.B. Barber and The Geometry Center.
|
| 580 |
+
Files derived from Qhull 1.0 are copyrighted by the Geometry Center. The
|
| 581 |
+
remaining files are copyrighted by C.B. Barber. Qhull is free software
|
| 582 |
+
and may be obtained via http from www.qhull.org. It may be freely copied,
|
| 583 |
+
modified, and redistributed under the following conditions:
|
| 584 |
+
|
| 585 |
+
1. All copyright notices must remain intact in all files.
|
| 586 |
+
|
| 587 |
+
2. A copy of this text file must be distributed along with any copies
|
| 588 |
+
of Qhull that you redistribute; this includes copies that you have
|
| 589 |
+
modified, or copies of programs or other software products that
|
| 590 |
+
include Qhull.
|
| 591 |
+
|
| 592 |
+
3. If you modify Qhull, you must include a notice giving the
|
| 593 |
+
name of the person performing the modification, the date of
|
| 594 |
+
modification, and the reason for such modification.
|
| 595 |
+
|
| 596 |
+
4. When distributing modified versions of Qhull, or other software
|
| 597 |
+
products that include Qhull, you must provide notice that the original
|
| 598 |
+
source code may be obtained as noted above.
|
| 599 |
+
|
| 600 |
+
5. There is no warranty or other guarantee of fitness for Qhull, it is
|
| 601 |
+
provided solely "as is". Bug reports or fixes may be sent to
|
| 602 |
+
qhull_bug@qhull.org; the authors may or may not act on them as
|
| 603 |
+
they desire.
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
Name: Qt4 Editor
|
| 607 |
+
Files: matplotlib/backends/qt_editor
|
| 608 |
+
Description: Module creating PyQt4 form dialogs/layouts to edit various type of parameters
|
| 609 |
+
License: MIT
|
| 610 |
+
Module creating PyQt4 form dialogs/layouts to edit various type of parameters
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
formlayout License Agreement (MIT License)
|
| 614 |
+
------------------------------------------
|
| 615 |
+
|
| 616 |
+
Copyright (c) 2009 Pierre Raybaut
|
| 617 |
+
|
| 618 |
+
Permission is hereby granted, free of charge, to any person
|
| 619 |
+
obtaining a copy of this software and associated documentation
|
| 620 |
+
files (the "Software"), to deal in the Software without
|
| 621 |
+
restriction, including without limitation the rights to use,
|
| 622 |
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 623 |
+
copies of the Software, and to permit persons to whom the
|
| 624 |
+
Software is furnished to do so, subject to the following
|
| 625 |
+
conditions:
|
| 626 |
+
|
| 627 |
+
The above copyright notice and this permission notice shall be
|
| 628 |
+
included in all copies or substantial portions of the Software.
|
| 629 |
+
|
| 630 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 631 |
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
| 632 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
| 633 |
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
| 634 |
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
| 635 |
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
| 636 |
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
| 637 |
+
OTHER DEALINGS IN THE SOFTWARE.
|
| 638 |
+
"""
|
| 639 |
+
|
| 640 |
+
|
| 641 |
+
Name: Solarized
|
| 642 |
+
Files: matplotlib/mpl-data/stylelib/Solarize_Light2.mplstyle
|
| 643 |
+
Description: Solarized color scheme/style
|
| 644 |
+
License: MIT
|
| 645 |
+
https://github.com/altercation/solarized/blob/master/LICENSE
|
| 646 |
+
Copyright (c) 2011 Ethan Schoonover
|
| 647 |
+
|
| 648 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 649 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 650 |
+
in the Software without restriction, including without limitation the rights
|
| 651 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 652 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 653 |
+
furnished to do so, subject to the following conditions:
|
| 654 |
+
|
| 655 |
+
The above copyright notice and this permission notice shall be included in
|
| 656 |
+
all copies or substantial portions of the Software.
|
| 657 |
+
|
| 658 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 659 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 660 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 661 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 662 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 663 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 664 |
+
THE SOFTWARE.
|
| 665 |
+
|
| 666 |
+
|
| 667 |
+
Name: Stix fonts
|
| 668 |
+
Files: matplotlib/mpl-data/fonts/ttf/STIX*.ttf
|
| 669 |
+
Description: STIX fonts
|
| 670 |
+
License:
|
| 671 |
+
TERMS AND CONDITIONS
|
| 672 |
+
|
| 673 |
+
1. Permission is hereby granted, free of charge, to any person
|
| 674 |
+
obtaining a copy of the STIX Fonts-TM set accompanying this license
|
| 675 |
+
(collectively, the "Fonts") and the associated documentation files
|
| 676 |
+
(collectively with the Fonts, the "Font Software"), to reproduce and
|
| 677 |
+
distribute the Font Software, including the rights to use, copy, merge
|
| 678 |
+
and publish copies of the Font Software, and to permit persons to whom
|
| 679 |
+
the Font Software is furnished to do so same, subject to the following
|
| 680 |
+
terms and conditions (the "License").
|
| 681 |
+
|
| 682 |
+
2. The following copyright and trademark notice and these Terms and
|
| 683 |
+
Conditions shall be included in all copies of one or more of the Font
|
| 684 |
+
typefaces and any derivative work created as permitted under this
|
| 685 |
+
License:
|
| 686 |
+
|
| 687 |
+
Copyright (c) 2001-2005 by the STI Pub Companies, consisting of
|
| 688 |
+
the American Institute of Physics, the American Chemical Society, the
|
| 689 |
+
American Mathematical Society, the American Physical Society, Elsevier,
|
| 690 |
+
Inc., and The Institute of Electrical and Electronic Engineers, Inc.
|
| 691 |
+
Portions copyright (c) 1998-2003 by MicroPress, Inc. Portions copyright
|
| 692 |
+
(c) 1990 by Elsevier, Inc. All rights reserved. STIX Fonts-TM is a
|
| 693 |
+
trademark of The Institute of Electrical and Electronics Engineers, Inc.
|
| 694 |
+
|
| 695 |
+
3. You may (a) convert the Fonts from one format to another (e.g.,
|
| 696 |
+
from TrueType to PostScript), in which case the normal and reasonable
|
| 697 |
+
distortion that occurs during such conversion shall be permitted and (b)
|
| 698 |
+
embed or include a subset of the Fonts in a document for the purposes of
|
| 699 |
+
allowing users to read text in the document that utilizes the Fonts. In
|
| 700 |
+
each case, you may use the STIX Fonts-TM mark to designate the resulting
|
| 701 |
+
Fonts or subset of the Fonts.
|
| 702 |
+
|
| 703 |
+
4. You may also (a) add glyphs or characters to the Fonts, or modify
|
| 704 |
+
the shape of existing glyphs, so long as the base set of glyphs is not
|
| 705 |
+
removed and (b) delete glyphs or characters from the Fonts, provided
|
| 706 |
+
that the resulting font set is distributed with the following
|
| 707 |
+
disclaimer: "This [name] font does not include all the Unicode points
|
| 708 |
+
covered in the STIX Fonts-TM set but may include others." In each case,
|
| 709 |
+
the name used to denote the resulting font set shall not include the
|
| 710 |
+
term "STIX" or any similar term.
|
| 711 |
+
|
| 712 |
+
5. You may charge a fee in connection with the distribution of the
|
| 713 |
+
Font Software, provided that no copy of one or more of the individual
|
| 714 |
+
Font typefaces that form the STIX Fonts-TM set may be sold by itself.
|
| 715 |
+
|
| 716 |
+
6. THE FONT SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY
|
| 717 |
+
KIND, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTIES
|
| 718 |
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
| 719 |
+
OF COPYRIGHT, PATENT, TRADEMARK OR OTHER RIGHT. IN NO EVENT SHALL
|
| 720 |
+
MICROPRESS OR ANY OF THE STI PUB COMPANIES BE LIABLE FOR ANY CLAIM,
|
| 721 |
+
DAMAGES OR OTHER LIABILITY, INCLUDING, BUT NOT LIMITED TO, ANY GENERAL,
|
| 722 |
+
SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
|
| 723 |
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM OR OUT OF THE USE OR
|
| 724 |
+
INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT
|
| 725 |
+
SOFTWARE.
|
| 726 |
+
|
| 727 |
+
7. Except as contained in the notice set forth in Section 2, the
|
| 728 |
+
names MicroPress Inc. and STI Pub Companies, as well as the names of the
|
| 729 |
+
companies/organizations that compose the STI Pub Companies, shall not be
|
| 730 |
+
used in advertising or otherwise to promote the sale, use or other
|
| 731 |
+
dealings in the Font Software without the prior written consent of the
|
| 732 |
+
respective company or organization.
|
| 733 |
+
|
| 734 |
+
8. This License shall become null and void in the event of any
|
| 735 |
+
material breach of the Terms and Conditions herein by licensee.
|
| 736 |
+
|
| 737 |
+
9. A substantial portion of the STIX Fonts set was developed by
|
| 738 |
+
MicroPress Inc. for the STI Pub Companies. To obtain additional
|
| 739 |
+
mathematical fonts, please contact MicroPress, Inc., 68-30 Harrow
|
| 740 |
+
Street, Forest Hills, NY 11375, USA - Phone: (718) 575-1816.
|
| 741 |
+
|
| 742 |
+
|
| 743 |
+
Name: Yorick Colormaps
|
| 744 |
+
Files: lib/matplotlib/_cm.py
|
| 745 |
+
Description: Gist/Yorick colormaps
|
| 746 |
+
License:
|
| 747 |
+
BSD-style license for gist/yorick colormaps.
|
| 748 |
+
|
| 749 |
+
Copyright:
|
| 750 |
+
|
| 751 |
+
Copyright (c) 1996. The Regents of the University of California.
|
| 752 |
+
All rights reserved.
|
| 753 |
+
|
| 754 |
+
Permission to use, copy, modify, and distribute this software for any
|
| 755 |
+
purpose without fee is hereby granted, provided that this entire
|
| 756 |
+
notice is included in all copies of any software which is or includes
|
| 757 |
+
a copy or modification of this software and in all copies of the
|
| 758 |
+
supporting documentation for such software.
|
| 759 |
+
|
| 760 |
+
This work was produced at the University of California, Lawrence
|
| 761 |
+
Livermore National Laboratory under contract no. W-7405-ENG-48 between
|
| 762 |
+
the U.S. Department of Energy and The Regents of the University of
|
| 763 |
+
California for the operation of UC LLNL.
|
| 764 |
+
|
| 765 |
+
|
| 766 |
+
DISCLAIMER
|
| 767 |
+
|
| 768 |
+
This software was prepared as an account of work sponsored by an
|
| 769 |
+
agency of the United States Government. Neither the United States
|
| 770 |
+
Government nor the University of California nor any of their
|
| 771 |
+
employees, makes any warranty, express or implied, or assumes any
|
| 772 |
+
liability or responsibility for the accuracy, completeness, or
|
| 773 |
+
usefulness of any information, apparatus, product, or process
|
| 774 |
+
disclosed, or represents that its use would not infringe
|
| 775 |
+
privately-owned rights. Reference herein to any specific commercial
|
| 776 |
+
products, process, or service by trade name, trademark, manufacturer,
|
| 777 |
+
or otherwise, does not necessarily constitute or imply its
|
| 778 |
+
endorsement, recommendation, or favoring by the United States
|
| 779 |
+
Government or the University of California. The views and opinions of
|
| 780 |
+
authors expressed herein do not necessarily state or reflect those of
|
| 781 |
+
the United States Government or the University of California, and
|
| 782 |
+
shall not be used for advertising or product endorsement purposes.
|
| 783 |
+
|
| 784 |
+
|
| 785 |
+
AUTHOR
|
| 786 |
+
|
| 787 |
+
David H. Munro wrote Yorick and Gist. Berkeley Yacc (byacc) generated
|
| 788 |
+
the Yorick parser. The routines in Math are from LAPACK and FFTPACK;
|
| 789 |
+
MathC contains C translations by David H. Munro. The algorithms for
|
| 790 |
+
Yorick's random number generator and several special functions in
|
| 791 |
+
Yorick/include were taken from Numerical Recipes by Press, et. al.,
|
| 792 |
+
although the Yorick implementations are unrelated to those in
|
| 793 |
+
Numerical Recipes. A small amount of code in Gist was adapted from
|
| 794 |
+
the X11R4 release, copyright M.I.T. -- the complete copyright notice
|
| 795 |
+
may be found in the (unused) file Gist/host.c.
|
| 796 |
+
|
| 797 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 798 |
+
Classifier: Framework :: Matplotlib
|
| 799 |
+
Classifier: Intended Audience :: Science/Research
|
| 800 |
+
Classifier: Intended Audience :: Education
|
| 801 |
+
Classifier: License :: OSI Approved :: Python Software Foundation License
|
| 802 |
+
Classifier: Programming Language :: Python
|
| 803 |
+
Classifier: Programming Language :: Python :: 3
|
| 804 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 805 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 806 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 807 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 808 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 809 |
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
| 810 |
+
Project-URL: Homepage, https://matplotlib.org
|
| 811 |
+
Project-URL: Download, https://matplotlib.org/stable/install/index.html
|
| 812 |
+
Project-URL: Documentation, https://matplotlib.org
|
| 813 |
+
Project-URL: Source Code, https://github.com/matplotlib/matplotlib
|
| 814 |
+
Project-URL: Bug Tracker, https://github.com/matplotlib/matplotlib/issues
|
| 815 |
+
Project-URL: Forum, https://discourse.matplotlib.org/
|
| 816 |
+
Project-URL: Donate, https://numfocus.org/donate-to-matplotlib
|
| 817 |
+
Requires-Python: >=3.10
|
| 818 |
+
Requires-Dist: contourpy>=1.0.1
|
| 819 |
+
Requires-Dist: cycler>=0.10
|
| 820 |
+
Requires-Dist: fonttools>=4.22.0
|
| 821 |
+
Requires-Dist: kiwisolver>=1.3.1
|
| 822 |
+
Requires-Dist: numpy>=1.23
|
| 823 |
+
Requires-Dist: packaging>=20.0
|
| 824 |
+
Requires-Dist: pillow>=8
|
| 825 |
+
Requires-Dist: pyparsing>=3
|
| 826 |
+
Requires-Dist: python-dateutil>=2.7
|
| 827 |
+
Provides-Extra: dev
|
| 828 |
+
Requires-Dist: meson-python<0.17.0,>=0.13.1; extra == "dev"
|
| 829 |
+
Requires-Dist: pybind11!=2.13.3,>=2.13.2; extra == "dev"
|
| 830 |
+
Requires-Dist: setuptools_scm<10,>=7; extra == "dev"
|
| 831 |
+
Requires-Dist: setuptools>=64; extra == "dev"
|
| 832 |
+
Description-Content-Type: text/markdown
|
| 833 |
+
|
| 834 |
+
[](https://pypi.org/project/matplotlib/)
|
| 835 |
+
[](https://anaconda.org/conda-forge/matplotlib)
|
| 836 |
+
[](https://pypi.org/project/matplotlib)
|
| 837 |
+
[](https://numfocus.org)
|
| 838 |
+
|
| 839 |
+
[](https://discourse.matplotlib.org)
|
| 840 |
+
[](https://gitter.im/matplotlib/matplotlib)
|
| 841 |
+
[](https://github.com/matplotlib/matplotlib/issues)
|
| 842 |
+
[](https://matplotlib.org/stable/devel/index.html)
|
| 843 |
+
|
| 844 |
+
[](https://github.com/matplotlib/matplotlib/actions?query=workflow%3ATests)
|
| 845 |
+
[](https://dev.azure.com/matplotlib/matplotlib/_build/latest?definitionId=1&branchName=main)
|
| 846 |
+
[](https://ci.appveyor.com/project/matplotlib/matplotlib)
|
| 847 |
+
[](https://app.codecov.io/gh/matplotlib/matplotlib)
|
| 848 |
+
[](https://jacobtomlinson.dev/effver)
|
| 849 |
+
|
| 850 |
+

|
| 851 |
+
|
| 852 |
+
Matplotlib is a comprehensive library for creating static, animated, and
|
| 853 |
+
interactive visualizations in Python.
|
| 854 |
+
|
| 855 |
+
Check out our [home page](https://matplotlib.org/) for more information.
|
| 856 |
+
|
| 857 |
+

|
| 858 |
+
|
| 859 |
+
Matplotlib produces publication-quality figures in a variety of hardcopy
|
| 860 |
+
formats and interactive environments across platforms. Matplotlib can be
|
| 861 |
+
used in Python scripts, Python/IPython shells, web application servers,
|
| 862 |
+
and various graphical user interface toolkits.
|
| 863 |
+
|
| 864 |
+
## Install
|
| 865 |
+
|
| 866 |
+
See the [install
|
| 867 |
+
documentation](https://matplotlib.org/stable/users/installing/index.html),
|
| 868 |
+
which is generated from `/doc/install/index.rst`
|
| 869 |
+
|
| 870 |
+
## Contribute
|
| 871 |
+
|
| 872 |
+
You've discovered a bug or something else you want to change — excellent!
|
| 873 |
+
|
| 874 |
+
You've worked out a way to fix it — even better!
|
| 875 |
+
|
| 876 |
+
You want to tell us about it — best of all!
|
| 877 |
+
|
| 878 |
+
Start at the [contributing
|
| 879 |
+
guide](https://matplotlib.org/devdocs/devel/contribute.html)!
|
| 880 |
+
|
| 881 |
+
## Contact
|
| 882 |
+
|
| 883 |
+
[Discourse](https://discourse.matplotlib.org/) is the discussion forum
|
| 884 |
+
for general questions and discussions and our recommended starting
|
| 885 |
+
point.
|
| 886 |
+
|
| 887 |
+
Our active mailing lists (which are mirrored on Discourse) are:
|
| 888 |
+
|
| 889 |
+
- [Users](https://mail.python.org/mailman/listinfo/matplotlib-users)
|
| 890 |
+
mailing list: <matplotlib-users@python.org>
|
| 891 |
+
- [Announcement](https://mail.python.org/mailman/listinfo/matplotlib-announce)
|
| 892 |
+
mailing list: <matplotlib-announce@python.org>
|
| 893 |
+
- [Development](https://mail.python.org/mailman/listinfo/matplotlib-devel)
|
| 894 |
+
mailing list: <matplotlib-devel@python.org>
|
| 895 |
+
|
| 896 |
+
[Gitter](https://gitter.im/matplotlib/matplotlib) is for coordinating
|
| 897 |
+
development and asking questions directly related to contributing to
|
| 898 |
+
matplotlib.
|
| 899 |
+
|
| 900 |
+
## Citing Matplotlib
|
| 901 |
+
|
| 902 |
+
If Matplotlib contributes to a project that leads to publication, please
|
| 903 |
+
acknowledge this by citing Matplotlib.
|
| 904 |
+
|
| 905 |
+
[A ready-made citation
|
| 906 |
+
entry](https://matplotlib.org/stable/users/project/citing.html) is
|
| 907 |
+
available.
|
.cache/pip/http-v2/c/6/3/0/6/c6306d205b48faecb62eb823053e850df036f38e59b11523829f5c31
ADDED
|
Binary file (1.86 kB). View file
|
|
|
.cache/pip/http-v2/c/6/3/0/6/c6306d205b48faecb62eb823053e850df036f38e59b11523829f5c31.body
ADDED
|
Binary file (54.9 kB). View file
|
|
|
.cache/pip/http-v2/c/8/4/4/6/c84464fe37be1d534151bcdb9cc17e882f3b79853f43ffdb6425f333
ADDED
|
Binary file (1.27 kB). View file
|
|
|
.cache/pip/http-v2/c/8/4/4/6/c84464fe37be1d534151bcdb9cc17e882f3b79853f43ffdb6425f333.body
ADDED
|
@@ -0,0 +1,1086 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.1
|
| 2 |
+
Name: scipy
|
| 3 |
+
Version: 1.17.1
|
| 4 |
+
Summary: Fundamental algorithms for scientific computing in Python
|
| 5 |
+
Maintainer-Email: SciPy Developers <scipy-dev@python.org>
|
| 6 |
+
License: Copyright (c) 2001-2002 Enthought, Inc. 2003, SciPy Developers.
|
| 7 |
+
All rights reserved.
|
| 8 |
+
|
| 9 |
+
Redistribution and use in source and binary forms, with or without
|
| 10 |
+
modification, are permitted provided that the following conditions
|
| 11 |
+
are met:
|
| 12 |
+
|
| 13 |
+
1. Redistributions of source code must retain the above copyright
|
| 14 |
+
notice, this list of conditions and the following disclaimer.
|
| 15 |
+
|
| 16 |
+
2. Redistributions in binary form must reproduce the above
|
| 17 |
+
copyright notice, this list of conditions and the following
|
| 18 |
+
disclaimer in the documentation and/or other materials provided
|
| 19 |
+
with the distribution.
|
| 20 |
+
|
| 21 |
+
3. Neither the name of the copyright holder nor the names of its
|
| 22 |
+
contributors may be used to endorse or promote products derived
|
| 23 |
+
from this software without specific prior written permission.
|
| 24 |
+
|
| 25 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 26 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 27 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 28 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 29 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 30 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 31 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 32 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 33 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 34 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 35 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 36 |
+
|
| 37 |
+
----
|
| 38 |
+
|
| 39 |
+
This binary distribution of SciPy can also bundle the following software
|
| 40 |
+
(depending on the build):
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
Name: OpenBLAS
|
| 44 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 45 |
+
Description: bundled as a dynamically linked library
|
| 46 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 47 |
+
License: BSD-3-Clause
|
| 48 |
+
Copyright (c) 2011-2014, The OpenBLAS Project
|
| 49 |
+
All rights reserved.
|
| 50 |
+
|
| 51 |
+
Redistribution and use in source and binary forms, with or without
|
| 52 |
+
modification, are permitted provided that the following conditions are
|
| 53 |
+
met:
|
| 54 |
+
|
| 55 |
+
1. Redistributions of source code must retain the above copyright
|
| 56 |
+
notice, this list of conditions and the following disclaimer.
|
| 57 |
+
|
| 58 |
+
2. Redistributions in binary form must reproduce the above copyright
|
| 59 |
+
notice, this list of conditions and the following disclaimer in
|
| 60 |
+
the documentation and/or other materials provided with the
|
| 61 |
+
distribution.
|
| 62 |
+
3. Neither the name of the OpenBLAS project nor the names of
|
| 63 |
+
its contributors may be used to endorse or promote products
|
| 64 |
+
derived from this software without specific prior written
|
| 65 |
+
permission.
|
| 66 |
+
|
| 67 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 68 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 69 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 70 |
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
| 71 |
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 72 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 73 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 74 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 75 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
| 76 |
+
USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
Name: LAPACK
|
| 80 |
+
Files: scipy.libs/libscipy_openblas*.so
|
| 81 |
+
Description: bundled in OpenBLAS
|
| 82 |
+
Availability: https://github.com/OpenMathLib/OpenBLAS/
|
| 83 |
+
License: BSD-3-Clause-Open-MPI
|
| 84 |
+
Copyright (c) 1992-2013 The University of Tennessee and The University
|
| 85 |
+
of Tennessee Research Foundation. All rights
|
| 86 |
+
reserved.
|
| 87 |
+
Copyright (c) 2000-2013 The University of California Berkeley. All
|
| 88 |
+
rights reserved.
|
| 89 |
+
Copyright (c) 2006-2013 The University of Colorado Denver. All rights
|
| 90 |
+
reserved.
|
| 91 |
+
|
| 92 |
+
$COPYRIGHT$
|
| 93 |
+
|
| 94 |
+
Additional copyrights may follow
|
| 95 |
+
|
| 96 |
+
$HEADER$
|
| 97 |
+
|
| 98 |
+
Redistribution and use in source and binary forms, with or without
|
| 99 |
+
modification, are permitted provided that the following conditions are
|
| 100 |
+
met:
|
| 101 |
+
|
| 102 |
+
- Redistributions of source code must retain the above copyright
|
| 103 |
+
notice, this list of conditions and the following disclaimer.
|
| 104 |
+
|
| 105 |
+
- Redistributions in binary form must reproduce the above copyright
|
| 106 |
+
notice, this list of conditions and the following disclaimer listed
|
| 107 |
+
in this license in the documentation and/or other materials
|
| 108 |
+
provided with the distribution.
|
| 109 |
+
|
| 110 |
+
- Neither the name of the copyright holders nor the names of its
|
| 111 |
+
contributors may be used to endorse or promote products derived from
|
| 112 |
+
this software without specific prior written permission.
|
| 113 |
+
|
| 114 |
+
The copyright holders provide no reassurances that the source code
|
| 115 |
+
provided does not infringe any patent, copyright, or any other
|
| 116 |
+
intellectual property rights of third parties. The copyright holders
|
| 117 |
+
disclaim any liability to any recipient for claims brought against
|
| 118 |
+
recipient by any third party for infringement of that parties
|
| 119 |
+
intellectual property rights.
|
| 120 |
+
|
| 121 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 122 |
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 123 |
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 124 |
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 125 |
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 126 |
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 127 |
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 128 |
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 129 |
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 130 |
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 131 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
Name: GCC runtime library
|
| 135 |
+
Files: scipy.libs/libgfortran*.so
|
| 136 |
+
Description: dynamically linked to files compiled with gcc
|
| 137 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libgfortran
|
| 138 |
+
License: GPL-3.0-or-later WITH GCC-exception-3.1
|
| 139 |
+
Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
| 140 |
+
|
| 141 |
+
Libgfortran is free software; you can redistribute it and/or modify
|
| 142 |
+
it under the terms of the GNU General Public License as published by
|
| 143 |
+
the Free Software Foundation; either version 3, or (at your option)
|
| 144 |
+
any later version.
|
| 145 |
+
|
| 146 |
+
Libgfortran is distributed in the hope that it will be useful,
|
| 147 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 148 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 149 |
+
GNU General Public License for more details.
|
| 150 |
+
|
| 151 |
+
Under Section 7 of GPL version 3, you are granted additional
|
| 152 |
+
permissions described in the GCC Runtime Library Exception, version
|
| 153 |
+
3.1, as published by the Free Software Foundation.
|
| 154 |
+
|
| 155 |
+
You should have received a copy of the GNU General Public License and
|
| 156 |
+
a copy of the GCC Runtime Library Exception along with this program;
|
| 157 |
+
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
| 158 |
+
<http://www.gnu.org/licenses/>.
|
| 159 |
+
|
| 160 |
+
----
|
| 161 |
+
|
| 162 |
+
Full text of license texts referred to above follows (that they are
|
| 163 |
+
listed below does not necessarily imply the conditions apply to the
|
| 164 |
+
present binary release):
|
| 165 |
+
|
| 166 |
+
----
|
| 167 |
+
|
| 168 |
+
GCC RUNTIME LIBRARY EXCEPTION
|
| 169 |
+
|
| 170 |
+
Version 3.1, 31 March 2009
|
| 171 |
+
|
| 172 |
+
Copyright (C) 2009 Free Software Foundation, Inc. <http://fsf.org/>
|
| 173 |
+
|
| 174 |
+
Everyone is permitted to copy and distribute verbatim copies of this
|
| 175 |
+
license document, but changing it is not allowed.
|
| 176 |
+
|
| 177 |
+
This GCC Runtime Library Exception ("Exception") is an additional
|
| 178 |
+
permission under section 7 of the GNU General Public License, version
|
| 179 |
+
3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
|
| 180 |
+
bears a notice placed by the copyright holder of the file stating that
|
| 181 |
+
the file is governed by GPLv3 along with this Exception.
|
| 182 |
+
|
| 183 |
+
When you use GCC to compile a program, GCC may combine portions of
|
| 184 |
+
certain GCC header files and runtime libraries with the compiled
|
| 185 |
+
program. The purpose of this Exception is to allow compilation of
|
| 186 |
+
non-GPL (including proprietary) programs to use, in this way, the
|
| 187 |
+
header files and runtime libraries covered by this Exception.
|
| 188 |
+
|
| 189 |
+
0. Definitions.
|
| 190 |
+
|
| 191 |
+
A file is an "Independent Module" if it either requires the Runtime
|
| 192 |
+
Library for execution after a Compilation Process, or makes use of an
|
| 193 |
+
interface provided by the Runtime Library, but is not otherwise based
|
| 194 |
+
on the Runtime Library.
|
| 195 |
+
|
| 196 |
+
"GCC" means a version of the GNU Compiler Collection, with or without
|
| 197 |
+
modifications, governed by version 3 (or a specified later version) of
|
| 198 |
+
the GNU General Public License (GPL) with the option of using any
|
| 199 |
+
subsequent versions published by the FSF.
|
| 200 |
+
|
| 201 |
+
"GPL-compatible Software" is software whose conditions of propagation,
|
| 202 |
+
modification and use would permit combination with GCC in accord with
|
| 203 |
+
the license of GCC.
|
| 204 |
+
|
| 205 |
+
"Target Code" refers to output from any compiler for a real or virtual
|
| 206 |
+
target processor architecture, in executable form or suitable for
|
| 207 |
+
input to an assembler, loader, linker and/or execution
|
| 208 |
+
phase. Notwithstanding that, Target Code does not include data in any
|
| 209 |
+
format that is used as a compiler intermediate representation, or used
|
| 210 |
+
for producing a compiler intermediate representation.
|
| 211 |
+
|
| 212 |
+
The "Compilation Process" transforms code entirely represented in
|
| 213 |
+
non-intermediate languages designed for human-written code, and/or in
|
| 214 |
+
Java Virtual Machine byte code, into Target Code. Thus, for example,
|
| 215 |
+
use of source code generators and preprocessors need not be considered
|
| 216 |
+
part of the Compilation Process, since the Compilation Process can be
|
| 217 |
+
understood as starting with the output of the generators or
|
| 218 |
+
preprocessors.
|
| 219 |
+
|
| 220 |
+
A Compilation Process is "Eligible" if it is done using GCC, alone or
|
| 221 |
+
with other GPL-compatible software, or if it is done without using any
|
| 222 |
+
work based on GCC. For example, using non-GPL-compatible Software to
|
| 223 |
+
optimize any GCC intermediate representations would not qualify as an
|
| 224 |
+
Eligible Compilation Process.
|
| 225 |
+
|
| 226 |
+
1. Grant of Additional Permission.
|
| 227 |
+
|
| 228 |
+
You have permission to propagate a work of Target Code formed by
|
| 229 |
+
combining the Runtime Library with Independent Modules, even if such
|
| 230 |
+
propagation would otherwise violate the terms of GPLv3, provided that
|
| 231 |
+
all Target Code was generated by Eligible Compilation Processes. You
|
| 232 |
+
may then convey such a combination under terms of your choice,
|
| 233 |
+
consistent with the licensing of the Independent Modules.
|
| 234 |
+
|
| 235 |
+
2. No Weakening of GCC Copyleft.
|
| 236 |
+
|
| 237 |
+
The availability of this Exception does not imply any general
|
| 238 |
+
presumption that third-party software is unaffected by the copyleft
|
| 239 |
+
requirements of the license of GCC.
|
| 240 |
+
|
| 241 |
+
----
|
| 242 |
+
|
| 243 |
+
GNU GENERAL PUBLIC LICENSE
|
| 244 |
+
Version 3, 29 June 2007
|
| 245 |
+
|
| 246 |
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
| 247 |
+
Everyone is permitted to copy and distribute verbatim copies
|
| 248 |
+
of this license document, but changing it is not allowed.
|
| 249 |
+
|
| 250 |
+
Preamble
|
| 251 |
+
|
| 252 |
+
The GNU General Public License is a free, copyleft license for
|
| 253 |
+
software and other kinds of works.
|
| 254 |
+
|
| 255 |
+
The licenses for most software and other practical works are designed
|
| 256 |
+
to take away your freedom to share and change the works. By contrast,
|
| 257 |
+
the GNU General Public License is intended to guarantee your freedom to
|
| 258 |
+
share and change all versions of a program--to make sure it remains free
|
| 259 |
+
software for all its users. We, the Free Software Foundation, use the
|
| 260 |
+
GNU General Public License for most of our software; it applies also to
|
| 261 |
+
any other work released this way by its authors. You can apply it to
|
| 262 |
+
your programs, too.
|
| 263 |
+
|
| 264 |
+
When we speak of free software, we are referring to freedom, not
|
| 265 |
+
price. Our General Public Licenses are designed to make sure that you
|
| 266 |
+
have the freedom to distribute copies of free software (and charge for
|
| 267 |
+
them if you wish), that you receive source code or can get it if you
|
| 268 |
+
want it, that you can change the software or use pieces of it in new
|
| 269 |
+
free programs, and that you know you can do these things.
|
| 270 |
+
|
| 271 |
+
To protect your rights, we need to prevent others from denying you
|
| 272 |
+
these rights or asking you to surrender the rights. Therefore, you have
|
| 273 |
+
certain responsibilities if you distribute copies of the software, or if
|
| 274 |
+
you modify it: responsibilities to respect the freedom of others.
|
| 275 |
+
|
| 276 |
+
For example, if you distribute copies of such a program, whether
|
| 277 |
+
gratis or for a fee, you must pass on to the recipients the same
|
| 278 |
+
freedoms that you received. You must make sure that they, too, receive
|
| 279 |
+
or can get the source code. And you must show them these terms so they
|
| 280 |
+
know their rights.
|
| 281 |
+
|
| 282 |
+
Developers that use the GNU GPL protect your rights with two steps:
|
| 283 |
+
(1) assert copyright on the software, and (2) offer you this License
|
| 284 |
+
giving you legal permission to copy, distribute and/or modify it.
|
| 285 |
+
|
| 286 |
+
For the developers' and authors' protection, the GPL clearly explains
|
| 287 |
+
that there is no warranty for this free software. For both users' and
|
| 288 |
+
authors' sake, the GPL requires that modified versions be marked as
|
| 289 |
+
changed, so that their problems will not be attributed erroneously to
|
| 290 |
+
authors of previous versions.
|
| 291 |
+
|
| 292 |
+
Some devices are designed to deny users access to install or run
|
| 293 |
+
modified versions of the software inside them, although the manufacturer
|
| 294 |
+
can do so. This is fundamentally incompatible with the aim of
|
| 295 |
+
protecting users' freedom to change the software. The systematic
|
| 296 |
+
pattern of such abuse occurs in the area of products for individuals to
|
| 297 |
+
use, which is precisely where it is most unacceptable. Therefore, we
|
| 298 |
+
have designed this version of the GPL to prohibit the practice for those
|
| 299 |
+
products. If such problems arise substantially in other domains, we
|
| 300 |
+
stand ready to extend this provision to those domains in future versions
|
| 301 |
+
of the GPL, as needed to protect the freedom of users.
|
| 302 |
+
|
| 303 |
+
Finally, every program is threatened constantly by software patents.
|
| 304 |
+
States should not allow patents to restrict development and use of
|
| 305 |
+
software on general-purpose computers, but in those that do, we wish to
|
| 306 |
+
avoid the special danger that patents applied to a free program could
|
| 307 |
+
make it effectively proprietary. To prevent this, the GPL assures that
|
| 308 |
+
patents cannot be used to render the program non-free.
|
| 309 |
+
|
| 310 |
+
The precise terms and conditions for copying, distribution and
|
| 311 |
+
modification follow.
|
| 312 |
+
|
| 313 |
+
TERMS AND CONDITIONS
|
| 314 |
+
|
| 315 |
+
0. Definitions.
|
| 316 |
+
|
| 317 |
+
"This License" refers to version 3 of the GNU General Public License.
|
| 318 |
+
|
| 319 |
+
"Copyright" also means copyright-like laws that apply to other kinds of
|
| 320 |
+
works, such as semiconductor masks.
|
| 321 |
+
|
| 322 |
+
"The Program" refers to any copyrightable work licensed under this
|
| 323 |
+
License. Each licensee is addressed as "you". "Licensees" and
|
| 324 |
+
"recipients" may be individuals or organizations.
|
| 325 |
+
|
| 326 |
+
To "modify" a work means to copy from or adapt all or part of the work
|
| 327 |
+
in a fashion requiring copyright permission, other than the making of an
|
| 328 |
+
exact copy. The resulting work is called a "modified version" of the
|
| 329 |
+
earlier work or a work "based on" the earlier work.
|
| 330 |
+
|
| 331 |
+
A "covered work" means either the unmodified Program or a work based
|
| 332 |
+
on the Program.
|
| 333 |
+
|
| 334 |
+
To "propagate" a work means to do anything with it that, without
|
| 335 |
+
permission, would make you directly or secondarily liable for
|
| 336 |
+
infringement under applicable copyright law, except executing it on a
|
| 337 |
+
computer or modifying a private copy. Propagation includes copying,
|
| 338 |
+
distribution (with or without modification), making available to the
|
| 339 |
+
public, and in some countries other activities as well.
|
| 340 |
+
|
| 341 |
+
To "convey" a work means any kind of propagation that enables other
|
| 342 |
+
parties to make or receive copies. Mere interaction with a user through
|
| 343 |
+
a computer network, with no transfer of a copy, is not conveying.
|
| 344 |
+
|
| 345 |
+
An interactive user interface displays "Appropriate Legal Notices"
|
| 346 |
+
to the extent that it includes a convenient and prominently visible
|
| 347 |
+
feature that (1) displays an appropriate copyright notice, and (2)
|
| 348 |
+
tells the user that there is no warranty for the work (except to the
|
| 349 |
+
extent that warranties are provided), that licensees may convey the
|
| 350 |
+
work under this License, and how to view a copy of this License. If
|
| 351 |
+
the interface presents a list of user commands or options, such as a
|
| 352 |
+
menu, a prominent item in the list meets this criterion.
|
| 353 |
+
|
| 354 |
+
1. Source Code.
|
| 355 |
+
|
| 356 |
+
The "source code" for a work means the preferred form of the work
|
| 357 |
+
for making modifications to it. "Object code" means any non-source
|
| 358 |
+
form of a work.
|
| 359 |
+
|
| 360 |
+
A "Standard Interface" means an interface that either is an official
|
| 361 |
+
standard defined by a recognized standards body, or, in the case of
|
| 362 |
+
interfaces specified for a particular programming language, one that
|
| 363 |
+
is widely used among developers working in that language.
|
| 364 |
+
|
| 365 |
+
The "System Libraries" of an executable work include anything, other
|
| 366 |
+
than the work as a whole, that (a) is included in the normal form of
|
| 367 |
+
packaging a Major Component, but which is not part of that Major
|
| 368 |
+
Component, and (b) serves only to enable use of the work with that
|
| 369 |
+
Major Component, or to implement a Standard Interface for which an
|
| 370 |
+
implementation is available to the public in source code form. A
|
| 371 |
+
"Major Component", in this context, means a major essential component
|
| 372 |
+
(kernel, window system, and so on) of the specific operating system
|
| 373 |
+
(if any) on which the executable work runs, or a compiler used to
|
| 374 |
+
produce the work, or an object code interpreter used to run it.
|
| 375 |
+
|
| 376 |
+
The "Corresponding Source" for a work in object code form means all
|
| 377 |
+
the source code needed to generate, install, and (for an executable
|
| 378 |
+
work) run the object code and to modify the work, including scripts to
|
| 379 |
+
control those activities. However, it does not include the work's
|
| 380 |
+
System Libraries, or general-purpose tools or generally available free
|
| 381 |
+
programs which are used unmodified in performing those activities but
|
| 382 |
+
which are not part of the work. For example, Corresponding Source
|
| 383 |
+
includes interface definition files associated with source files for
|
| 384 |
+
the work, and the source code for shared libraries and dynamically
|
| 385 |
+
linked subprograms that the work is specifically designed to require,
|
| 386 |
+
such as by intimate data communication or control flow between those
|
| 387 |
+
subprograms and other parts of the work.
|
| 388 |
+
|
| 389 |
+
The Corresponding Source need not include anything that users
|
| 390 |
+
can regenerate automatically from other parts of the Corresponding
|
| 391 |
+
Source.
|
| 392 |
+
|
| 393 |
+
The Corresponding Source for a work in source code form is that
|
| 394 |
+
same work.
|
| 395 |
+
|
| 396 |
+
2. Basic Permissions.
|
| 397 |
+
|
| 398 |
+
All rights granted under this License are granted for the term of
|
| 399 |
+
copyright on the Program, and are irrevocable provided the stated
|
| 400 |
+
conditions are met. This License explicitly affirms your unlimited
|
| 401 |
+
permission to run the unmodified Program. The output from running a
|
| 402 |
+
covered work is covered by this License only if the output, given its
|
| 403 |
+
content, constitutes a covered work. This License acknowledges your
|
| 404 |
+
rights of fair use or other equivalent, as provided by copyright law.
|
| 405 |
+
|
| 406 |
+
You may make, run and propagate covered works that you do not
|
| 407 |
+
convey, without conditions so long as your license otherwise remains
|
| 408 |
+
in force. You may convey covered works to others for the sole purpose
|
| 409 |
+
of having them make modifications exclusively for you, or provide you
|
| 410 |
+
with facilities for running those works, provided that you comply with
|
| 411 |
+
the terms of this License in conveying all material for which you do
|
| 412 |
+
not control copyright. Those thus making or running the covered works
|
| 413 |
+
for you must do so exclusively on your behalf, under your direction
|
| 414 |
+
and control, on terms that prohibit them from making any copies of
|
| 415 |
+
your copyrighted material outside their relationship with you.
|
| 416 |
+
|
| 417 |
+
Conveying under any other circumstances is permitted solely under
|
| 418 |
+
the conditions stated below. Sublicensing is not allowed; section 10
|
| 419 |
+
makes it unnecessary.
|
| 420 |
+
|
| 421 |
+
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
| 422 |
+
|
| 423 |
+
No covered work shall be deemed part of an effective technological
|
| 424 |
+
measure under any applicable law fulfilling obligations under article
|
| 425 |
+
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
| 426 |
+
similar laws prohibiting or restricting circumvention of such
|
| 427 |
+
measures.
|
| 428 |
+
|
| 429 |
+
When you convey a covered work, you waive any legal power to forbid
|
| 430 |
+
circumvention of technological measures to the extent such circumvention
|
| 431 |
+
is effected by exercising rights under this License with respect to
|
| 432 |
+
the covered work, and you disclaim any intention to limit operation or
|
| 433 |
+
modification of the work as a means of enforcing, against the work's
|
| 434 |
+
users, your or third parties' legal rights to forbid circumvention of
|
| 435 |
+
technological measures.
|
| 436 |
+
|
| 437 |
+
4. Conveying Verbatim Copies.
|
| 438 |
+
|
| 439 |
+
You may convey verbatim copies of the Program's source code as you
|
| 440 |
+
receive it, in any medium, provided that you conspicuously and
|
| 441 |
+
appropriately publish on each copy an appropriate copyright notice;
|
| 442 |
+
keep intact all notices stating that this License and any
|
| 443 |
+
non-permissive terms added in accord with section 7 apply to the code;
|
| 444 |
+
keep intact all notices of the absence of any warranty; and give all
|
| 445 |
+
recipients a copy of this License along with the Program.
|
| 446 |
+
|
| 447 |
+
You may charge any price or no price for each copy that you convey,
|
| 448 |
+
and you may offer support or warranty protection for a fee.
|
| 449 |
+
|
| 450 |
+
5. Conveying Modified Source Versions.
|
| 451 |
+
|
| 452 |
+
You may convey a work based on the Program, or the modifications to
|
| 453 |
+
produce it from the Program, in the form of source code under the
|
| 454 |
+
terms of section 4, provided that you also meet all of these conditions:
|
| 455 |
+
|
| 456 |
+
a) The work must carry prominent notices stating that you modified
|
| 457 |
+
it, and giving a relevant date.
|
| 458 |
+
|
| 459 |
+
b) The work must carry prominent notices stating that it is
|
| 460 |
+
released under this License and any conditions added under section
|
| 461 |
+
7. This requirement modifies the requirement in section 4 to
|
| 462 |
+
"keep intact all notices".
|
| 463 |
+
|
| 464 |
+
c) You must license the entire work, as a whole, under this
|
| 465 |
+
License to anyone who comes into possession of a copy. This
|
| 466 |
+
License will therefore apply, along with any applicable section 7
|
| 467 |
+
additional terms, to the whole of the work, and all its parts,
|
| 468 |
+
regardless of how they are packaged. This License gives no
|
| 469 |
+
permission to license the work in any other way, but it does not
|
| 470 |
+
invalidate such permission if you have separately received it.
|
| 471 |
+
|
| 472 |
+
d) If the work has interactive user interfaces, each must display
|
| 473 |
+
Appropriate Legal Notices; however, if the Program has interactive
|
| 474 |
+
interfaces that do not display Appropriate Legal Notices, your
|
| 475 |
+
work need not make them do so.
|
| 476 |
+
|
| 477 |
+
A compilation of a covered work with other separate and independent
|
| 478 |
+
works, which are not by their nature extensions of the covered work,
|
| 479 |
+
and which are not combined with it such as to form a larger program,
|
| 480 |
+
in or on a volume of a storage or distribution medium, is called an
|
| 481 |
+
"aggregate" if the compilation and its resulting copyright are not
|
| 482 |
+
used to limit the access or legal rights of the compilation's users
|
| 483 |
+
beyond what the individual works permit. Inclusion of a covered work
|
| 484 |
+
in an aggregate does not cause this License to apply to the other
|
| 485 |
+
parts of the aggregate.
|
| 486 |
+
|
| 487 |
+
6. Conveying Non-Source Forms.
|
| 488 |
+
|
| 489 |
+
You may convey a covered work in object code form under the terms
|
| 490 |
+
of sections 4 and 5, provided that you also convey the
|
| 491 |
+
machine-readable Corresponding Source under the terms of this License,
|
| 492 |
+
in one of these ways:
|
| 493 |
+
|
| 494 |
+
a) Convey the object code in, or embodied in, a physical product
|
| 495 |
+
(including a physical distribution medium), accompanied by the
|
| 496 |
+
Corresponding Source fixed on a durable physical medium
|
| 497 |
+
customarily used for software interchange.
|
| 498 |
+
|
| 499 |
+
b) Convey the object code in, or embodied in, a physical product
|
| 500 |
+
(including a physical distribution medium), accompanied by a
|
| 501 |
+
written offer, valid for at least three years and valid for as
|
| 502 |
+
long as you offer spare parts or customer support for that product
|
| 503 |
+
model, to give anyone who possesses the object code either (1) a
|
| 504 |
+
copy of the Corresponding Source for all the software in the
|
| 505 |
+
product that is covered by this License, on a durable physical
|
| 506 |
+
medium customarily used for software interchange, for a price no
|
| 507 |
+
more than your reasonable cost of physically performing this
|
| 508 |
+
conveying of source, or (2) access to copy the
|
| 509 |
+
Corresponding Source from a network server at no charge.
|
| 510 |
+
|
| 511 |
+
c) Convey individual copies of the object code with a copy of the
|
| 512 |
+
written offer to provide the Corresponding Source. This
|
| 513 |
+
alternative is allowed only occasionally and noncommercially, and
|
| 514 |
+
only if you received the object code with such an offer, in accord
|
| 515 |
+
with subsection 6b.
|
| 516 |
+
|
| 517 |
+
d) Convey the object code by offering access from a designated
|
| 518 |
+
place (gratis or for a charge), and offer equivalent access to the
|
| 519 |
+
Corresponding Source in the same way through the same place at no
|
| 520 |
+
further charge. You need not require recipients to copy the
|
| 521 |
+
Corresponding Source along with the object code. If the place to
|
| 522 |
+
copy the object code is a network server, the Corresponding Source
|
| 523 |
+
may be on a different server (operated by you or a third party)
|
| 524 |
+
that supports equivalent copying facilities, provided you maintain
|
| 525 |
+
clear directions next to the object code saying where to find the
|
| 526 |
+
Corresponding Source. Regardless of what server hosts the
|
| 527 |
+
Corresponding Source, you remain obligated to ensure that it is
|
| 528 |
+
available for as long as needed to satisfy these requirements.
|
| 529 |
+
|
| 530 |
+
e) Convey the object code using peer-to-peer transmission, provided
|
| 531 |
+
you inform other peers where the object code and Corresponding
|
| 532 |
+
Source of the work are being offered to the general public at no
|
| 533 |
+
charge under subsection 6d.
|
| 534 |
+
|
| 535 |
+
A separable portion of the object code, whose source code is excluded
|
| 536 |
+
from the Corresponding Source as a System Library, need not be
|
| 537 |
+
included in conveying the object code work.
|
| 538 |
+
|
| 539 |
+
A "User Product" is either (1) a "consumer product", which means any
|
| 540 |
+
tangible personal property which is normally used for personal, family,
|
| 541 |
+
or household purposes, or (2) anything designed or sold for incorporation
|
| 542 |
+
into a dwelling. In determining whether a product is a consumer product,
|
| 543 |
+
doubtful cases shall be resolved in favor of coverage. For a particular
|
| 544 |
+
product received by a particular user, "normally used" refers to a
|
| 545 |
+
typical or common use of that class of product, regardless of the status
|
| 546 |
+
of the particular user or of the way in which the particular user
|
| 547 |
+
actually uses, or expects or is expected to use, the product. A product
|
| 548 |
+
is a consumer product regardless of whether the product has substantial
|
| 549 |
+
commercial, industrial or non-consumer uses, unless such uses represent
|
| 550 |
+
the only significant mode of use of the product.
|
| 551 |
+
|
| 552 |
+
"Installation Information" for a User Product means any methods,
|
| 553 |
+
procedures, authorization keys, or other information required to install
|
| 554 |
+
and execute modified versions of a covered work in that User Product from
|
| 555 |
+
a modified version of its Corresponding Source. The information must
|
| 556 |
+
suffice to ensure that the continued functioning of the modified object
|
| 557 |
+
code is in no case prevented or interfered with solely because
|
| 558 |
+
modification has been made.
|
| 559 |
+
|
| 560 |
+
If you convey an object code work under this section in, or with, or
|
| 561 |
+
specifically for use in, a User Product, and the conveying occurs as
|
| 562 |
+
part of a transaction in which the right of possession and use of the
|
| 563 |
+
User Product is transferred to the recipient in perpetuity or for a
|
| 564 |
+
fixed term (regardless of how the transaction is characterized), the
|
| 565 |
+
Corresponding Source conveyed under this section must be accompanied
|
| 566 |
+
by the Installation Information. But this requirement does not apply
|
| 567 |
+
if neither you nor any third party retains the ability to install
|
| 568 |
+
modified object code on the User Product (for example, the work has
|
| 569 |
+
been installed in ROM).
|
| 570 |
+
|
| 571 |
+
The requirement to provide Installation Information does not include a
|
| 572 |
+
requirement to continue to provide support service, warranty, or updates
|
| 573 |
+
for a work that has been modified or installed by the recipient, or for
|
| 574 |
+
the User Product in which it has been modified or installed. Access to a
|
| 575 |
+
network may be denied when the modification itself materially and
|
| 576 |
+
adversely affects the operation of the network or violates the rules and
|
| 577 |
+
protocols for communication across the network.
|
| 578 |
+
|
| 579 |
+
Corresponding Source conveyed, and Installation Information provided,
|
| 580 |
+
in accord with this section must be in a format that is publicly
|
| 581 |
+
documented (and with an implementation available to the public in
|
| 582 |
+
source code form), and must require no special password or key for
|
| 583 |
+
unpacking, reading or copying.
|
| 584 |
+
|
| 585 |
+
7. Additional Terms.
|
| 586 |
+
|
| 587 |
+
"Additional permissions" are terms that supplement the terms of this
|
| 588 |
+
License by making exceptions from one or more of its conditions.
|
| 589 |
+
Additional permissions that are applicable to the entire Program shall
|
| 590 |
+
be treated as though they were included in this License, to the extent
|
| 591 |
+
that they are valid under applicable law. If additional permissions
|
| 592 |
+
apply only to part of the Program, that part may be used separately
|
| 593 |
+
under those permissions, but the entire Program remains governed by
|
| 594 |
+
this License without regard to the additional permissions.
|
| 595 |
+
|
| 596 |
+
When you convey a copy of a covered work, you may at your option
|
| 597 |
+
remove any additional permissions from that copy, or from any part of
|
| 598 |
+
it. (Additional permissions may be written to require their own
|
| 599 |
+
removal in certain cases when you modify the work.) You may place
|
| 600 |
+
additional permissions on material, added by you to a covered work,
|
| 601 |
+
for which you have or can give appropriate copyright permission.
|
| 602 |
+
|
| 603 |
+
Notwithstanding any other provision of this License, for material you
|
| 604 |
+
add to a covered work, you may (if authorized by the copyright holders of
|
| 605 |
+
that material) supplement the terms of this License with terms:
|
| 606 |
+
|
| 607 |
+
a) Disclaiming warranty or limiting liability differently from the
|
| 608 |
+
terms of sections 15 and 16 of this License; or
|
| 609 |
+
|
| 610 |
+
b) Requiring preservation of specified reasonable legal notices or
|
| 611 |
+
author attributions in that material or in the Appropriate Legal
|
| 612 |
+
Notices displayed by works containing it; or
|
| 613 |
+
|
| 614 |
+
c) Prohibiting misrepresentation of the origin of that material, or
|
| 615 |
+
requiring that modified versions of such material be marked in
|
| 616 |
+
reasonable ways as different from the original version; or
|
| 617 |
+
|
| 618 |
+
d) Limiting the use for publicity purposes of names of licensors or
|
| 619 |
+
authors of the material; or
|
| 620 |
+
|
| 621 |
+
e) Declining to grant rights under trademark law for use of some
|
| 622 |
+
trade names, trademarks, or service marks; or
|
| 623 |
+
|
| 624 |
+
f) Requiring indemnification of licensors and authors of that
|
| 625 |
+
material by anyone who conveys the material (or modified versions of
|
| 626 |
+
it) with contractual assumptions of liability to the recipient, for
|
| 627 |
+
any liability that these contractual assumptions directly impose on
|
| 628 |
+
those licensors and authors.
|
| 629 |
+
|
| 630 |
+
All other non-permissive additional terms are considered "further
|
| 631 |
+
restrictions" within the meaning of section 10. If the Program as you
|
| 632 |
+
received it, or any part of it, contains a notice stating that it is
|
| 633 |
+
governed by this License along with a term that is a further
|
| 634 |
+
restriction, you may remove that term. If a license document contains
|
| 635 |
+
a further restriction but permits relicensing or conveying under this
|
| 636 |
+
License, you may add to a covered work material governed by the terms
|
| 637 |
+
of that license document, provided that the further restriction does
|
| 638 |
+
not survive such relicensing or conveying.
|
| 639 |
+
|
| 640 |
+
If you add terms to a covered work in accord with this section, you
|
| 641 |
+
must place, in the relevant source files, a statement of the
|
| 642 |
+
additional terms that apply to those files, or a notice indicating
|
| 643 |
+
where to find the applicable terms.
|
| 644 |
+
|
| 645 |
+
Additional terms, permissive or non-permissive, may be stated in the
|
| 646 |
+
form of a separately written license, or stated as exceptions;
|
| 647 |
+
the above requirements apply either way.
|
| 648 |
+
|
| 649 |
+
8. Termination.
|
| 650 |
+
|
| 651 |
+
You may not propagate or modify a covered work except as expressly
|
| 652 |
+
provided under this License. Any attempt otherwise to propagate or
|
| 653 |
+
modify it is void, and will automatically terminate your rights under
|
| 654 |
+
this License (including any patent licenses granted under the third
|
| 655 |
+
paragraph of section 11).
|
| 656 |
+
|
| 657 |
+
However, if you cease all violation of this License, then your
|
| 658 |
+
license from a particular copyright holder is reinstated (a)
|
| 659 |
+
provisionally, unless and until the copyright holder explicitly and
|
| 660 |
+
finally terminates your license, and (b) permanently, if the copyright
|
| 661 |
+
holder fails to notify you of the violation by some reasonable means
|
| 662 |
+
prior to 60 days after the cessation.
|
| 663 |
+
|
| 664 |
+
Moreover, your license from a particular copyright holder is
|
| 665 |
+
reinstated permanently if the copyright holder notifies you of the
|
| 666 |
+
violation by some reasonable means, this is the first time you have
|
| 667 |
+
received notice of violation of this License (for any work) from that
|
| 668 |
+
copyright holder, and you cure the violation prior to 30 days after
|
| 669 |
+
your receipt of the notice.
|
| 670 |
+
|
| 671 |
+
Termination of your rights under this section does not terminate the
|
| 672 |
+
licenses of parties who have received copies or rights from you under
|
| 673 |
+
this License. If your rights have been terminated and not permanently
|
| 674 |
+
reinstated, you do not qualify to receive new licenses for the same
|
| 675 |
+
material under section 10.
|
| 676 |
+
|
| 677 |
+
9. Acceptance Not Required for Having Copies.
|
| 678 |
+
|
| 679 |
+
You are not required to accept this License in order to receive or
|
| 680 |
+
run a copy of the Program. Ancillary propagation of a covered work
|
| 681 |
+
occurring solely as a consequence of using peer-to-peer transmission
|
| 682 |
+
to receive a copy likewise does not require acceptance. However,
|
| 683 |
+
nothing other than this License grants you permission to propagate or
|
| 684 |
+
modify any covered work. These actions infringe copyright if you do
|
| 685 |
+
not accept this License. Therefore, by modifying or propagating a
|
| 686 |
+
covered work, you indicate your acceptance of this License to do so.
|
| 687 |
+
|
| 688 |
+
10. Automatic Licensing of Downstream Recipients.
|
| 689 |
+
|
| 690 |
+
Each time you convey a covered work, the recipient automatically
|
| 691 |
+
receives a license from the original licensors, to run, modify and
|
| 692 |
+
propagate that work, subject to this License. You are not responsible
|
| 693 |
+
for enforcing compliance by third parties with this License.
|
| 694 |
+
|
| 695 |
+
An "entity transaction" is a transaction transferring control of an
|
| 696 |
+
organization, or substantially all assets of one, or subdividing an
|
| 697 |
+
organization, or merging organizations. If propagation of a covered
|
| 698 |
+
work results from an entity transaction, each party to that
|
| 699 |
+
transaction who receives a copy of the work also receives whatever
|
| 700 |
+
licenses to the work the party's predecessor in interest had or could
|
| 701 |
+
give under the previous paragraph, plus a right to possession of the
|
| 702 |
+
Corresponding Source of the work from the predecessor in interest, if
|
| 703 |
+
the predecessor has it or can get it with reasonable efforts.
|
| 704 |
+
|
| 705 |
+
You may not impose any further restrictions on the exercise of the
|
| 706 |
+
rights granted or affirmed under this License. For example, you may
|
| 707 |
+
not impose a license fee, royalty, or other charge for exercise of
|
| 708 |
+
rights granted under this License, and you may not initiate litigation
|
| 709 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
| 710 |
+
any patent claim is infringed by making, using, selling, offering for
|
| 711 |
+
sale, or importing the Program or any portion of it.
|
| 712 |
+
|
| 713 |
+
11. Patents.
|
| 714 |
+
|
| 715 |
+
A "contributor" is a copyright holder who authorizes use under this
|
| 716 |
+
License of the Program or a work on which the Program is based. The
|
| 717 |
+
work thus licensed is called the contributor's "contributor version".
|
| 718 |
+
|
| 719 |
+
A contributor's "essential patent claims" are all patent claims
|
| 720 |
+
owned or controlled by the contributor, whether already acquired or
|
| 721 |
+
hereafter acquired, that would be infringed by some manner, permitted
|
| 722 |
+
by this License, of making, using, or selling its contributor version,
|
| 723 |
+
but do not include claims that would be infringed only as a
|
| 724 |
+
consequence of further modification of the contributor version. For
|
| 725 |
+
purposes of this definition, "control" includes the right to grant
|
| 726 |
+
patent sublicenses in a manner consistent with the requirements of
|
| 727 |
+
this License.
|
| 728 |
+
|
| 729 |
+
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
| 730 |
+
patent license under the contributor's essential patent claims, to
|
| 731 |
+
make, use, sell, offer for sale, import and otherwise run, modify and
|
| 732 |
+
propagate the contents of its contributor version.
|
| 733 |
+
|
| 734 |
+
In the following three paragraphs, a "patent license" is any express
|
| 735 |
+
agreement or commitment, however denominated, not to enforce a patent
|
| 736 |
+
(such as an express permission to practice a patent or covenant not to
|
| 737 |
+
sue for patent infringement). To "grant" such a patent license to a
|
| 738 |
+
party means to make such an agreement or commitment not to enforce a
|
| 739 |
+
patent against the party.
|
| 740 |
+
|
| 741 |
+
If you convey a covered work, knowingly relying on a patent license,
|
| 742 |
+
and the Corresponding Source of the work is not available for anyone
|
| 743 |
+
to copy, free of charge and under the terms of this License, through a
|
| 744 |
+
publicly available network server or other readily accessible means,
|
| 745 |
+
then you must either (1) cause the Corresponding Source to be so
|
| 746 |
+
available, or (2) arrange to deprive yourself of the benefit of the
|
| 747 |
+
patent license for this particular work, or (3) arrange, in a manner
|
| 748 |
+
consistent with the requirements of this License, to extend the patent
|
| 749 |
+
license to downstream recipients. "Knowingly relying" means you have
|
| 750 |
+
actual knowledge that, but for the patent license, your conveying the
|
| 751 |
+
covered work in a country, or your recipient's use of the covered work
|
| 752 |
+
in a country, would infringe one or more identifiable patents in that
|
| 753 |
+
country that you have reason to believe are valid.
|
| 754 |
+
|
| 755 |
+
If, pursuant to or in connection with a single transaction or
|
| 756 |
+
arrangement, you convey, or propagate by procuring conveyance of, a
|
| 757 |
+
covered work, and grant a patent license to some of the parties
|
| 758 |
+
receiving the covered work authorizing them to use, propagate, modify
|
| 759 |
+
or convey a specific copy of the covered work, then the patent license
|
| 760 |
+
you grant is automatically extended to all recipients of the covered
|
| 761 |
+
work and works based on it.
|
| 762 |
+
|
| 763 |
+
A patent license is "discriminatory" if it does not include within
|
| 764 |
+
the scope of its coverage, prohibits the exercise of, or is
|
| 765 |
+
conditioned on the non-exercise of one or more of the rights that are
|
| 766 |
+
specifically granted under this License. You may not convey a covered
|
| 767 |
+
work if you are a party to an arrangement with a third party that is
|
| 768 |
+
in the business of distributing software, under which you make payment
|
| 769 |
+
to the third party based on the extent of your activity of conveying
|
| 770 |
+
the work, and under which the third party grants, to any of the
|
| 771 |
+
parties who would receive the covered work from you, a discriminatory
|
| 772 |
+
patent license (a) in connection with copies of the covered work
|
| 773 |
+
conveyed by you (or copies made from those copies), or (b) primarily
|
| 774 |
+
for and in connection with specific products or compilations that
|
| 775 |
+
contain the covered work, unless you entered into that arrangement,
|
| 776 |
+
or that patent license was granted, prior to 28 March 2007.
|
| 777 |
+
|
| 778 |
+
Nothing in this License shall be construed as excluding or limiting
|
| 779 |
+
any implied license or other defenses to infringement that may
|
| 780 |
+
otherwise be available to you under applicable patent law.
|
| 781 |
+
|
| 782 |
+
12. No Surrender of Others' Freedom.
|
| 783 |
+
|
| 784 |
+
If conditions are imposed on you (whether by court order, agreement or
|
| 785 |
+
otherwise) that contradict the conditions of this License, they do not
|
| 786 |
+
excuse you from the conditions of this License. If you cannot convey a
|
| 787 |
+
covered work so as to satisfy simultaneously your obligations under this
|
| 788 |
+
License and any other pertinent obligations, then as a consequence you may
|
| 789 |
+
not convey it at all. For example, if you agree to terms that obligate you
|
| 790 |
+
to collect a royalty for further conveying from those to whom you convey
|
| 791 |
+
the Program, the only way you could satisfy both those terms and this
|
| 792 |
+
License would be to refrain entirely from conveying the Program.
|
| 793 |
+
|
| 794 |
+
13. Use with the GNU Affero General Public License.
|
| 795 |
+
|
| 796 |
+
Notwithstanding any other provision of this License, you have
|
| 797 |
+
permission to link or combine any covered work with a work licensed
|
| 798 |
+
under version 3 of the GNU Affero General Public License into a single
|
| 799 |
+
combined work, and to convey the resulting work. The terms of this
|
| 800 |
+
License will continue to apply to the part which is the covered work,
|
| 801 |
+
but the special requirements of the GNU Affero General Public License,
|
| 802 |
+
section 13, concerning interaction through a network will apply to the
|
| 803 |
+
combination as such.
|
| 804 |
+
|
| 805 |
+
14. Revised Versions of this License.
|
| 806 |
+
|
| 807 |
+
The Free Software Foundation may publish revised and/or new versions of
|
| 808 |
+
the GNU General Public License from time to time. Such new versions will
|
| 809 |
+
be similar in spirit to the present version, but may differ in detail to
|
| 810 |
+
address new problems or concerns.
|
| 811 |
+
|
| 812 |
+
Each version is given a distinguishing version number. If the
|
| 813 |
+
Program specifies that a certain numbered version of the GNU General
|
| 814 |
+
Public License "or any later version" applies to it, you have the
|
| 815 |
+
option of following the terms and conditions either of that numbered
|
| 816 |
+
version or of any later version published by the Free Software
|
| 817 |
+
Foundation. If the Program does not specify a version number of the
|
| 818 |
+
GNU General Public License, you may choose any version ever published
|
| 819 |
+
by the Free Software Foundation.
|
| 820 |
+
|
| 821 |
+
If the Program specifies that a proxy can decide which future
|
| 822 |
+
versions of the GNU General Public License can be used, that proxy's
|
| 823 |
+
public statement of acceptance of a version permanently authorizes you
|
| 824 |
+
to choose that version for the Program.
|
| 825 |
+
|
| 826 |
+
Later license versions may give you additional or different
|
| 827 |
+
permissions. However, no additional obligations are imposed on any
|
| 828 |
+
author or copyright holder as a result of your choosing to follow a
|
| 829 |
+
later version.
|
| 830 |
+
|
| 831 |
+
15. Disclaimer of Warranty.
|
| 832 |
+
|
| 833 |
+
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
| 834 |
+
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
| 835 |
+
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
| 836 |
+
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
| 837 |
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
| 838 |
+
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
| 839 |
+
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
| 840 |
+
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
| 841 |
+
|
| 842 |
+
16. Limitation of Liability.
|
| 843 |
+
|
| 844 |
+
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
| 845 |
+
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
| 846 |
+
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
| 847 |
+
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
| 848 |
+
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
| 849 |
+
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
| 850 |
+
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
| 851 |
+
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
| 852 |
+
SUCH DAMAGES.
|
| 853 |
+
|
| 854 |
+
17. Interpretation of Sections 15 and 16.
|
| 855 |
+
|
| 856 |
+
If the disclaimer of warranty and limitation of liability provided
|
| 857 |
+
above cannot be given local legal effect according to their terms,
|
| 858 |
+
reviewing courts shall apply local law that most closely approximates
|
| 859 |
+
an absolute waiver of all civil liability in connection with the
|
| 860 |
+
Program, unless a warranty or assumption of liability accompanies a
|
| 861 |
+
copy of the Program in return for a fee.
|
| 862 |
+
|
| 863 |
+
END OF TERMS AND CONDITIONS
|
| 864 |
+
|
| 865 |
+
How to Apply These Terms to Your New Programs
|
| 866 |
+
|
| 867 |
+
If you develop a new program, and you want it to be of the greatest
|
| 868 |
+
possible use to the public, the best way to achieve this is to make it
|
| 869 |
+
free software which everyone can redistribute and change under these terms.
|
| 870 |
+
|
| 871 |
+
To do so, attach the following notices to the program. It is safest
|
| 872 |
+
to attach them to the start of each source file to most effectively
|
| 873 |
+
state the exclusion of warranty; and each file should have at least
|
| 874 |
+
the "copyright" line and a pointer to where the full notice is found.
|
| 875 |
+
|
| 876 |
+
<one line to give the program's name and a brief idea of what it does.>
|
| 877 |
+
Copyright (C) <year> <name of author>
|
| 878 |
+
|
| 879 |
+
This program is free software: you can redistribute it and/or modify
|
| 880 |
+
it under the terms of the GNU General Public License as published by
|
| 881 |
+
the Free Software Foundation, either version 3 of the License, or
|
| 882 |
+
(at your option) any later version.
|
| 883 |
+
|
| 884 |
+
This program is distributed in the hope that it will be useful,
|
| 885 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 886 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 887 |
+
GNU General Public License for more details.
|
| 888 |
+
|
| 889 |
+
You should have received a copy of the GNU General Public License
|
| 890 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 891 |
+
|
| 892 |
+
Also add information on how to contact you by electronic and paper mail.
|
| 893 |
+
|
| 894 |
+
If the program does terminal interaction, make it output a short
|
| 895 |
+
notice like this when it starts in an interactive mode:
|
| 896 |
+
|
| 897 |
+
<program> Copyright (C) <year> <name of author>
|
| 898 |
+
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
| 899 |
+
This is free software, and you are welcome to redistribute it
|
| 900 |
+
under certain conditions; type `show c' for details.
|
| 901 |
+
|
| 902 |
+
The hypothetical commands `show w' and `show c' should show the appropriate
|
| 903 |
+
parts of the General Public License. Of course, your program's commands
|
| 904 |
+
might be different; for a GUI interface, you would use an "about box".
|
| 905 |
+
|
| 906 |
+
You should also get your employer (if you work as a programmer) or school,
|
| 907 |
+
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
| 908 |
+
For more information on this, and how to apply and follow the GNU GPL, see
|
| 909 |
+
<http://www.gnu.org/licenses/>.
|
| 910 |
+
|
| 911 |
+
The GNU General Public License does not permit incorporating your program
|
| 912 |
+
into proprietary programs. If your program is a subroutine library, you
|
| 913 |
+
may consider it more useful to permit linking proprietary applications with
|
| 914 |
+
the library. If this is what you want to do, use the GNU Lesser General
|
| 915 |
+
Public License instead of this License. But first, please read
|
| 916 |
+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
Name: libquadmath
|
| 920 |
+
Files: scipy.libs/libquadmath*.so
|
| 921 |
+
Description: dynamically linked to files compiled with gcc
|
| 922 |
+
Availability: https://gcc.gnu.org/git/?p=gcc.git;a=tree;f=libquadmath
|
| 923 |
+
License: LGPL-2.1-or-later
|
| 924 |
+
|
| 925 |
+
GCC Quad-Precision Math Library
|
| 926 |
+
Copyright (C) 2010-2019 Free Software Foundation, Inc.
|
| 927 |
+
Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
|
| 928 |
+
|
| 929 |
+
This file is part of the libquadmath library.
|
| 930 |
+
Libquadmath is free software; you can redistribute it and/or
|
| 931 |
+
modify it under the terms of the GNU Library General Public
|
| 932 |
+
License as published by the Free Software Foundation; either
|
| 933 |
+
version 2.1 of the License, or (at your option) any later version.
|
| 934 |
+
|
| 935 |
+
Libquadmath is distributed in the hope that it will be useful,
|
| 936 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 937 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 938 |
+
Lesser General Public License for more details.
|
| 939 |
+
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
| 940 |
+
|
| 941 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 942 |
+
Classifier: Intended Audience :: Science/Research
|
| 943 |
+
Classifier: Intended Audience :: Developers
|
| 944 |
+
Classifier: License :: OSI Approved :: BSD License
|
| 945 |
+
Classifier: Programming Language :: C
|
| 946 |
+
Classifier: Programming Language :: Python
|
| 947 |
+
Classifier: Programming Language :: Python :: 3
|
| 948 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 949 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 950 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 951 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 952 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 953 |
+
Classifier: Topic :: Scientific/Engineering
|
| 954 |
+
Classifier: Operating System :: Microsoft :: Windows
|
| 955 |
+
Classifier: Operating System :: POSIX :: Linux
|
| 956 |
+
Classifier: Operating System :: POSIX
|
| 957 |
+
Classifier: Operating System :: Unix
|
| 958 |
+
Classifier: Operating System :: MacOS
|
| 959 |
+
Project-URL: homepage, https://scipy.org/
|
| 960 |
+
Project-URL: documentation, https://docs.scipy.org/doc/scipy/
|
| 961 |
+
Project-URL: source, https://github.com/scipy/scipy
|
| 962 |
+
Project-URL: download, https://github.com/scipy/scipy/releases
|
| 963 |
+
Project-URL: tracker, https://github.com/scipy/scipy/issues
|
| 964 |
+
Requires-Python: >=3.11
|
| 965 |
+
Requires-Dist: numpy<2.7,>=1.26.4
|
| 966 |
+
Provides-Extra: test
|
| 967 |
+
Requires-Dist: pytest>=8.0.0; extra == "test"
|
| 968 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 969 |
+
Requires-Dist: pytest-timeout; extra == "test"
|
| 970 |
+
Requires-Dist: pytest-xdist; extra == "test"
|
| 971 |
+
Requires-Dist: asv; extra == "test"
|
| 972 |
+
Requires-Dist: mpmath; extra == "test"
|
| 973 |
+
Requires-Dist: gmpy2; extra == "test"
|
| 974 |
+
Requires-Dist: threadpoolctl; extra == "test"
|
| 975 |
+
Requires-Dist: scikit-umfpack; extra == "test"
|
| 976 |
+
Requires-Dist: pooch; extra == "test"
|
| 977 |
+
Requires-Dist: hypothesis>=6.30; extra == "test"
|
| 978 |
+
Requires-Dist: array-api-strict>=2.3.1; extra == "test"
|
| 979 |
+
Requires-Dist: Cython; extra == "test"
|
| 980 |
+
Requires-Dist: meson; extra == "test"
|
| 981 |
+
Requires-Dist: ninja; sys_platform != "emscripten" and extra == "test"
|
| 982 |
+
Provides-Extra: doc
|
| 983 |
+
Requires-Dist: sphinx<8.2.0,>=5.0.0; extra == "doc"
|
| 984 |
+
Requires-Dist: intersphinx_registry; extra == "doc"
|
| 985 |
+
Requires-Dist: pydata-sphinx-theme>=0.15.2; extra == "doc"
|
| 986 |
+
Requires-Dist: sphinx-copybutton; extra == "doc"
|
| 987 |
+
Requires-Dist: sphinx-design>=0.4.0; extra == "doc"
|
| 988 |
+
Requires-Dist: matplotlib>=3.5; extra == "doc"
|
| 989 |
+
Requires-Dist: numpydoc; extra == "doc"
|
| 990 |
+
Requires-Dist: jupytext; extra == "doc"
|
| 991 |
+
Requires-Dist: myst-nb>=1.2.0; extra == "doc"
|
| 992 |
+
Requires-Dist: pooch; extra == "doc"
|
| 993 |
+
Requires-Dist: jupyterlite-sphinx>=0.19.1; extra == "doc"
|
| 994 |
+
Requires-Dist: jupyterlite-pyodide-kernel; extra == "doc"
|
| 995 |
+
Requires-Dist: linkify-it-py; extra == "doc"
|
| 996 |
+
Requires-Dist: tabulate; extra == "doc"
|
| 997 |
+
Provides-Extra: dev
|
| 998 |
+
Requires-Dist: click<8.3.0; extra == "dev"
|
| 999 |
+
Requires-Dist: spin; extra == "dev"
|
| 1000 |
+
Requires-Dist: mypy==1.10.0; extra == "dev"
|
| 1001 |
+
Requires-Dist: typing_extensions; extra == "dev"
|
| 1002 |
+
Requires-Dist: types-psutil; extra == "dev"
|
| 1003 |
+
Requires-Dist: pycodestyle; extra == "dev"
|
| 1004 |
+
Requires-Dist: ruff>=0.12.0; extra == "dev"
|
| 1005 |
+
Requires-Dist: cython-lint>=0.12.2; extra == "dev"
|
| 1006 |
+
Description-Content-Type: text/x-rst
|
| 1007 |
+
|
| 1008 |
+
.. image:: https://raw.githubusercontent.com/scipy/scipy/main/doc/source/_static/logo.svg
|
| 1009 |
+
:target: https://scipy.org
|
| 1010 |
+
:width: 110
|
| 1011 |
+
:height: 110
|
| 1012 |
+
:align: left
|
| 1013 |
+
|
| 1014 |
+
.. image:: https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A
|
| 1015 |
+
:target: https://numfocus.org
|
| 1016 |
+
|
| 1017 |
+
.. image:: https://img.shields.io/pypi/dm/scipy.svg?label=Pypi%20downloads
|
| 1018 |
+
:target: https://pypi.org/project/scipy/
|
| 1019 |
+
|
| 1020 |
+
.. image:: https://img.shields.io/conda/dn/conda-forge/scipy.svg?label=Conda%20downloads
|
| 1021 |
+
:target: https://anaconda.org/conda-forge/scipy
|
| 1022 |
+
|
| 1023 |
+
.. image:: https://img.shields.io/badge/stackoverflow-Ask%20questions-blue.svg
|
| 1024 |
+
:target: https://stackoverflow.com/questions/tagged/scipy
|
| 1025 |
+
|
| 1026 |
+
.. image:: https://img.shields.io/badge/DOI-10.1038%2Fs41592--019--0686--2-blue.svg
|
| 1027 |
+
:target: https://www.nature.com/articles/s41592-019-0686-2
|
| 1028 |
+
|
| 1029 |
+
.. image:: https://insights.linuxfoundation.org/api/badge/health-score?project=scipy
|
| 1030 |
+
:target: https://insights.linuxfoundation.org/project/scipy
|
| 1031 |
+
|
| 1032 |
+
SciPy (pronounced "Sigh Pie") is an open-source software for mathematics,
|
| 1033 |
+
science, and engineering. It includes modules for statistics, optimization,
|
| 1034 |
+
integration, linear algebra, Fourier transforms, signal and image processing,
|
| 1035 |
+
ODE solvers, and more.
|
| 1036 |
+
|
| 1037 |
+
- **Website:** https://scipy.org
|
| 1038 |
+
- **Documentation:** https://docs.scipy.org/doc/scipy/
|
| 1039 |
+
- **Development version of the documentation:** https://scipy.github.io/devdocs
|
| 1040 |
+
- **SciPy development forum:** https://discuss.scientific-python.org/c/contributor/scipy
|
| 1041 |
+
- **Stack Overflow:** https://stackoverflow.com/questions/tagged/scipy
|
| 1042 |
+
- **Source code:** https://github.com/scipy/scipy
|
| 1043 |
+
- **Contributing:** https://scipy.github.io/devdocs/dev/index.html
|
| 1044 |
+
- **Bug reports:** https://github.com/scipy/scipy/issues
|
| 1045 |
+
- **Code of Conduct:** https://docs.scipy.org/doc/scipy/dev/conduct/code_of_conduct.html
|
| 1046 |
+
- **Report a security vulnerability:** https://tidelift.com/docs/security
|
| 1047 |
+
- **Citing in your work:** https://www.scipy.org/citing-scipy/
|
| 1048 |
+
|
| 1049 |
+
SciPy is built to work with
|
| 1050 |
+
NumPy arrays, and provides many user-friendly and efficient numerical routines,
|
| 1051 |
+
such as routines for numerical integration and optimization. Together, they
|
| 1052 |
+
run on all popular operating systems, are quick to install, and are free of
|
| 1053 |
+
charge. NumPy and SciPy are easy to use, but powerful enough to be depended
|
| 1054 |
+
upon by some of the world's leading scientists and engineers. If you need to
|
| 1055 |
+
manipulate numbers on a computer and display or publish the results, give
|
| 1056 |
+
SciPy a try!
|
| 1057 |
+
|
| 1058 |
+
For the installation instructions, see `our install
|
| 1059 |
+
guide <https://scipy.org/install/>`__.
|
| 1060 |
+
|
| 1061 |
+
|
| 1062 |
+
Call for Contributions
|
| 1063 |
+
----------------------
|
| 1064 |
+
|
| 1065 |
+
We appreciate and welcome contributions. Small improvements or fixes are always appreciated; issues labeled as "good
|
| 1066 |
+
first issue" may be a good starting point. Have a look at `our contributing
|
| 1067 |
+
guide <https://scipy.github.io/devdocs/dev/index.html>`__.
|
| 1068 |
+
|
| 1069 |
+
Writing code isn’t the only way to contribute to SciPy. You can also:
|
| 1070 |
+
|
| 1071 |
+
- review pull requests
|
| 1072 |
+
- triage issues
|
| 1073 |
+
- develop tutorials, presentations, and other educational materials
|
| 1074 |
+
- maintain and improve `our website <https://github.com/scipy/scipy.org>`__
|
| 1075 |
+
- develop graphic design for our brand assets and promotional materials
|
| 1076 |
+
- help with outreach and onboard new contributors
|
| 1077 |
+
- write grant proposals and help with other fundraising efforts
|
| 1078 |
+
|
| 1079 |
+
If you’re unsure where to start or how your skills fit in, reach out! You can
|
| 1080 |
+
ask on the `forum <https://discuss.scientific-python.org/c/contributor/scipy>`__
|
| 1081 |
+
or here, on GitHub, by leaving a comment on a relevant issue that is already
|
| 1082 |
+
open.
|
| 1083 |
+
|
| 1084 |
+
If you are new to contributing to open source, `this
|
| 1085 |
+
guide <https://opensource.guide/how-to-contribute/>`__ helps explain why, what,
|
| 1086 |
+
and how to get involved.
|
.cache/pip/http-v2/c/c/c/b/4/cccb41730ba9dcdb4cb7127715ba43b53bfd809d6ff652fe215567a3
ADDED
|
Binary file (1.26 kB). View file
|
|
|
.cache/pip/http-v2/c/c/c/b/4/cccb41730ba9dcdb4cb7127715ba43b53bfd809d6ff652fe215567a3.body
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: segmentation_models_pytorch
|
| 3 |
+
Version: 0.5.0
|
| 4 |
+
Summary: Image segmentation models with pre-trained backbones. PyTorch.
|
| 5 |
+
Author-email: Pavel Iakubovskii <qubvel@gmail.com>
|
| 6 |
+
License: The MIT License
|
| 7 |
+
|
| 8 |
+
Copyright (c) 2019, Pavel Iakubovskii
|
| 9 |
+
|
| 10 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 11 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 12 |
+
in the Software without restriction, including without limitation the rights
|
| 13 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 14 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 15 |
+
furnished to do so, subject to the following conditions:
|
| 16 |
+
|
| 17 |
+
The above copyright notice and this permission notice shall be included in
|
| 18 |
+
all copies or substantial portions of the Software.
|
| 19 |
+
|
| 20 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 21 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 22 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 23 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 24 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 25 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 26 |
+
THE SOFTWARE.
|
| 27 |
+
|
| 28 |
+
Project-URL: Homepage, https://github.com/qubvel-org/segmentation_models.pytorch
|
| 29 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 30 |
+
Classifier: Programming Language :: Python
|
| 31 |
+
Classifier: Programming Language :: Python :: 3
|
| 32 |
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
| 33 |
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
| 34 |
+
Requires-Python: >=3.9
|
| 35 |
+
Description-Content-Type: text/markdown
|
| 36 |
+
License-File: LICENSE
|
| 37 |
+
Requires-Dist: huggingface-hub>=0.24
|
| 38 |
+
Requires-Dist: numpy>=1.19.3
|
| 39 |
+
Requires-Dist: pillow>=8
|
| 40 |
+
Requires-Dist: safetensors>=0.3.1
|
| 41 |
+
Requires-Dist: timm>=0.9
|
| 42 |
+
Requires-Dist: torch>=1.8
|
| 43 |
+
Requires-Dist: torchvision>=0.9
|
| 44 |
+
Requires-Dist: tqdm>=4.42.1
|
| 45 |
+
Provides-Extra: docs
|
| 46 |
+
Requires-Dist: autodocsumm; extra == "docs"
|
| 47 |
+
Requires-Dist: huggingface-hub; extra == "docs"
|
| 48 |
+
Requires-Dist: six; extra == "docs"
|
| 49 |
+
Requires-Dist: sphinx; extra == "docs"
|
| 50 |
+
Requires-Dist: sphinx-book-theme; extra == "docs"
|
| 51 |
+
Provides-Extra: test
|
| 52 |
+
Requires-Dist: gitpython; extra == "test"
|
| 53 |
+
Requires-Dist: packaging; extra == "test"
|
| 54 |
+
Requires-Dist: pytest; extra == "test"
|
| 55 |
+
Requires-Dist: pytest-cov; extra == "test"
|
| 56 |
+
Requires-Dist: pytest-xdist; extra == "test"
|
| 57 |
+
Requires-Dist: ruff>=0.9; extra == "test"
|
| 58 |
+
Requires-Dist: setuptools; extra == "test"
|
| 59 |
+
Dynamic: license-file
|
| 60 |
+
|
| 61 |
+
<div align="center">
|
| 62 |
+
|
| 63 |
+

|
| 64 |
+
**Python library with Neural Networks for Image Semantic
|
| 65 |
+
Segmentation based on [PyTorch](https://pytorch.org/).**
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
[](https://github.com/qubvel/segmentation_models.pytorch/actions/workflows/tests.yml)
|
| 69 |
+

|
| 70 |
+
[](https://smp.readthedocs.io/en/latest/)
|
| 71 |
+
<br>
|
| 72 |
+
[](https://pypi.org/project/segmentation-models-pytorch/)
|
| 73 |
+
[](https://pepy.tech/project/segmentation-models-pytorch)
|
| 74 |
+
[](https://pepy.tech/project/segmentation-models-pytorch)
|
| 75 |
+
<br>
|
| 76 |
+
[](https://github.com/qubvel/segmentation_models.pytorch/blob/main/LICENSE)
|
| 77 |
+
[](https://pepy.tech/project/segmentation-models-pytorch)
|
| 78 |
+
|
| 79 |
+
</div>
|
| 80 |
+
|
| 81 |
+
The main features of the library are:
|
| 82 |
+
|
| 83 |
+
- Super simple high-level API (just two lines to create a neural network)
|
| 84 |
+
- 12 encoder-decoder model architectures (Unet, Unet++, Segformer, DPT, ...)
|
| 85 |
+
- 800+ **pretrained** convolution- and transform-based encoders, including [timm](https://github.com/huggingface/pytorch-image-models) support
|
| 86 |
+
- Popular metrics and losses for training routines (Dice, Jaccard, Tversky, ...)
|
| 87 |
+
- ONNX export and torch script/trace/compile friendly
|
| 88 |
+
|
| 89 |
+
### Community-Driven Project, Supported By
|
| 90 |
+
<table>
|
| 91 |
+
<tr>
|
| 92 |
+
<td align="center" vertical-align="center">
|
| 93 |
+
<a href="https://withoutbg.com/?utm_source=smp&utm_medium=github_readme&utm_campaign=sponsorship" >
|
| 94 |
+
<img src="https://withoutbg.com/images/logo-social.png" width="70px;" alt="withoutBG API Logo" />
|
| 95 |
+
</a>
|
| 96 |
+
</td>
|
| 97 |
+
<td align="center" vertical-align="center">
|
| 98 |
+
<b>withoutBG API</b>
|
| 99 |
+
<br />
|
| 100 |
+
<a href="https://withoutbg.com/?utm_source=smp&utm_medium=github_readme&utm_campaign=sponsorship">https://withoutbg.com</a>
|
| 101 |
+
<br />
|
| 102 |
+
<p width="200px">
|
| 103 |
+
High-quality background removal API
|
| 104 |
+
<br/>
|
| 105 |
+
</p>
|
| 106 |
+
</td>
|
| 107 |
+
</tr>
|
| 108 |
+
</table>
|
| 109 |
+
|
| 110 |
+
### [📚 Project Documentation 📚](http://smp.readthedocs.io/)
|
| 111 |
+
|
| 112 |
+
Visit [Read The Docs Project Page](https://smp.readthedocs.io/) or read the following README to know more about Segmentation Models Pytorch (SMP for short) library
|
| 113 |
+
|
| 114 |
+
### 📋 Table of content
|
| 115 |
+
1. [Quick start](#start)
|
| 116 |
+
2. [Examples](#examples)
|
| 117 |
+
3. [Models and encoders](#models-and-encoders)
|
| 118 |
+
4. [Models API](#api)
|
| 119 |
+
1. [Input channels](#input-channels)
|
| 120 |
+
2. [Auxiliary classification output](#auxiliary-classification-output)
|
| 121 |
+
3. [Depth](#depth)
|
| 122 |
+
5. [Installation](#installation)
|
| 123 |
+
6. [Competitions won with the library](#competitions)
|
| 124 |
+
7. [Contributing](#contributing)
|
| 125 |
+
8. [Citing](#citing)
|
| 126 |
+
9. [License](#license)
|
| 127 |
+
|
| 128 |
+
## ⏳ Quick start <a name="start"></a>
|
| 129 |
+
|
| 130 |
+
#### 1. Create your first Segmentation model with SMP
|
| 131 |
+
|
| 132 |
+
The segmentation model is just a PyTorch `torch.nn.Module`, which can be created as easy as:
|
| 133 |
+
|
| 134 |
+
```python
|
| 135 |
+
import segmentation_models_pytorch as smp
|
| 136 |
+
|
| 137 |
+
model = smp.Unet(
|
| 138 |
+
encoder_name="resnet34", # choose encoder, e.g. mobilenet_v2 or efficientnet-b7
|
| 139 |
+
encoder_weights="imagenet", # use `imagenet` pre-trained weights for encoder initialization
|
| 140 |
+
in_channels=1, # model input channels (1 for gray-scale images, 3 for RGB, etc.)
|
| 141 |
+
classes=3, # model output channels (number of classes in your dataset)
|
| 142 |
+
)
|
| 143 |
+
```
|
| 144 |
+
- see [table](#architectures) with available model architectures
|
| 145 |
+
- see [table](#encoders) with available encoders and their corresponding weights
|
| 146 |
+
|
| 147 |
+
#### 2. Configure data preprocessing
|
| 148 |
+
|
| 149 |
+
All encoders have pretrained weights. Preparing your data the same way as during weights pre-training may give you better results (higher metric score and faster convergence). It is **not necessary** in case you train the whole model, not only the decoder.
|
| 150 |
+
|
| 151 |
+
```python
|
| 152 |
+
from segmentation_models_pytorch.encoders import get_preprocessing_fn
|
| 153 |
+
|
| 154 |
+
preprocess_input = get_preprocessing_fn('resnet18', pretrained='imagenet')
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
Congratulations! You are done! Now you can train your model with your favorite framework!
|
| 158 |
+
|
| 159 |
+
## 💡 Examples <a name="examples"></a>
|
| 160 |
+
|
| 161 |
+
| Name | Link | Colab |
|
| 162 |
+
|-------------------------------------------|-----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------|
|
| 163 |
+
| **Train** pets binary segmentation on OxfordPets | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/binary_segmentation_intro.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/binary_segmentation_intro.ipynb) |
|
| 164 |
+
| **Train** cars binary segmentation on CamVid | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/cars%20segmentation%20(camvid).ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/cars%20segmentation%20(camvid).ipynb) |
|
| 165 |
+
| **Train** multiclass segmentation on CamVid | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/camvid_segmentation_multiclass.ipynb) | [](https://colab.research.google.com/github/qubvel-org/segmentation_models.pytorch/blob/main/examples/camvid_segmentation_multiclass.ipynb) |
|
| 166 |
+
| **Train** clothes binary segmentation by @ternaus | [Repo](https://github.com/ternaus/cloths_segmentation) | |
|
| 167 |
+
| **Load and inference** pretrained Segformer | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/segformer_inference_pretrained.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/segformer_inference_pretrained.ipynb) |
|
| 168 |
+
| **Load and inference** pretrained DPT | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/dpt_inference_pretrained.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/dpt_inference_pretrained.ipynb) |
|
| 169 |
+
| **Load and inference** pretrained DPT | [Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/upernet_inference_pretrained.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/upernet_inference_pretrained.ipynb) |
|
| 170 |
+
| **Save and load** models locally / to HuggingFace Hub |[Notebook](https://github.com/qubvel-org/segmentation_models.pytorch/blob/main/examples/save_load_model_and_share_with_hf_hub.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/save_load_model_and_share_with_hf_hub.ipynb)
|
| 171 |
+
| **Export** trained model to ONNX | [Notebook](https://github.com/qubvel/segmentation_models.pytorch/blob/main/examples/convert_to_onnx.ipynb) | [](https://colab.research.google.com/github/qubvel/segmentation_models.pytorch/blob/main/examples/convert_to_onnx.ipynb) |
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
## 📦 Models and encoders <a name="models-and-encoders"></a>
|
| 175 |
+
|
| 176 |
+
### Architectures <a name="architectures"></a>
|
| 177 |
+
| Architecture | Paper | Documentation | Checkpoints |
|
| 178 |
+
|--------------|-------|---------------|------------|
|
| 179 |
+
| Unet | [paper](https://arxiv.org/abs/1505.04597) | [docs](https://smp.readthedocs.io/en/latest/models.html#unet) | |
|
| 180 |
+
| Unet++ | [paper](https://arxiv.org/pdf/1807.10165.pdf) | [docs](https://smp.readthedocs.io/en/latest/models.html#unetplusplus) | |
|
| 181 |
+
| MAnet | [paper](https://ieeexplore.ieee.org/abstract/document/9201310) | [docs](https://smp.readthedocs.io/en/latest/models.html#manet) | |
|
| 182 |
+
| Linknet | [paper](https://arxiv.org/abs/1707.03718) | [docs](https://smp.readthedocs.io/en/latest/models.html#linknet) | |
|
| 183 |
+
| FPN | [paper](http://presentations.cocodataset.org/COCO17-Stuff-FAIR.pdf) | [docs](https://smp.readthedocs.io/en/latest/models.html#fpn) | |
|
| 184 |
+
| PSPNet | [paper](https://arxiv.org/abs/1612.01105) | [docs](https://smp.readthedocs.io/en/latest/models.html#pspnet) | |
|
| 185 |
+
| PAN | [paper](https://arxiv.org/abs/1805.10180) | [docs](https://smp.readthedocs.io/en/latest/models.html#pan) | |
|
| 186 |
+
| DeepLabV3 | [paper](https://arxiv.org/abs/1706.05587) | [docs](https://smp.readthedocs.io/en/latest/models.html#deeplabv3) | |
|
| 187 |
+
| DeepLabV3+ | [paper](https://arxiv.org/abs/1802.02611) | [docs](https://smp.readthedocs.io/en/latest/models.html#deeplabv3plus) | |
|
| 188 |
+
| UPerNet | [paper](https://arxiv.org/abs/1807.10221) | [docs](https://smp.readthedocs.io/en/latest/models.html#upernet) | [checkpoints](https://huggingface.co/collections/smp-hub/upernet-67fadcdbe08418c6ea94f768) |
|
| 189 |
+
| Segformer | [paper](https://arxiv.org/abs/2105.15203) | [docs](https://smp.readthedocs.io/en/latest/models.html#segformer) | [checkpoints](https://huggingface.co/collections/smp-hub/segformer-6749eb4923dea2c355f29a1f) |
|
| 190 |
+
| DPT | [paper](https://arxiv.org/abs/2103.13413) | [docs](https://smp.readthedocs.io/en/latest/models.html#dpt) | [checkpoints](https://huggingface.co/collections/smp-hub/dpt-67f30487327c0599a0c62d68) |
|
| 191 |
+
|
| 192 |
+
### Encoders <a name="encoders"></a>
|
| 193 |
+
|
| 194 |
+
The library provides a wide range of **pretrained** encoders (also known as backbones) for segmentation models. Instead of using features from the final layer of a classification model, we extract **intermediate features** and feed them into the decoder for segmentation tasks.
|
| 195 |
+
|
| 196 |
+
All encoders come with **pretrained weights**, which help achieve **faster and more stable convergence** when training segmentation models.
|
| 197 |
+
|
| 198 |
+
Given the extensive selection of supported encoders, you can choose the best one for your specific use case, for example:
|
| 199 |
+
- **Lightweight encoders** for low-latency applications or real-time inference on edge devices (mobilenet/mobileone).
|
| 200 |
+
- **High-capacity architectures** for complex tasks involving a large number of segmented classes, providing superior accuracy (convnext/swin/mit).
|
| 201 |
+
|
| 202 |
+
By selecting the right encoder, you can balance **efficiency, performance, and model complexity** to suit your project needs.
|
| 203 |
+
|
| 204 |
+
All encoders and corresponding pretrained weight are listed in the documentation:
|
| 205 |
+
- [table](https://smp.readthedocs.io/en/latest/encoders.html) with natively ported encoders
|
| 206 |
+
- [table](https://smp.readthedocs.io/en/latest/encoders_timm.html) with [timm](https://github.com/huggingface/pytorch-image-models) encoders supported
|
| 207 |
+
|
| 208 |
+
## 🔁 Models API <a name="api"></a>
|
| 209 |
+
|
| 210 |
+
### Input channels
|
| 211 |
+
|
| 212 |
+
The input channels parameter allows you to create a model that can process a tensor with an arbitrary number of channels.
|
| 213 |
+
If you use pretrained weights from ImageNet, the weights of the first convolution will be reused:
|
| 214 |
+
- For the 1-channel case, it would be a sum of the weights of the first convolution layer.
|
| 215 |
+
- Otherwise, channels would be populated with weights like `new_weight[:, i] = pretrained_weight[:, i % 3]`, and then scaled with `new_weight * 3 / new_in_channels`.
|
| 216 |
+
|
| 217 |
+
```python
|
| 218 |
+
model = smp.FPN('resnet34', in_channels=1)
|
| 219 |
+
mask = model(torch.ones([1, 1, 64, 64]))
|
| 220 |
+
```
|
| 221 |
+
|
| 222 |
+
### Auxiliary classification output
|
| 223 |
+
|
| 224 |
+
All models support `aux_params` parameters, which is default set to `None`.
|
| 225 |
+
If `aux_params = None` then classification auxiliary output is not created, else
|
| 226 |
+
model produce not only `mask`, but also `label` output with shape `NC`.
|
| 227 |
+
Classification head consists of GlobalPooling->Dropout(optional)->Linear->Activation(optional) layers, which can be
|
| 228 |
+
configured by `aux_params` as follows:
|
| 229 |
+
```python
|
| 230 |
+
aux_params=dict(
|
| 231 |
+
pooling='avg', # one of 'avg', 'max'
|
| 232 |
+
dropout=0.5, # dropout ratio, default is None
|
| 233 |
+
activation='sigmoid', # activation function, default is None
|
| 234 |
+
classes=4, # define number of output labels
|
| 235 |
+
)
|
| 236 |
+
model = smp.Unet('resnet34', classes=4, aux_params=aux_params)
|
| 237 |
+
mask, label = model(x)
|
| 238 |
+
```
|
| 239 |
+
|
| 240 |
+
### Depth
|
| 241 |
+
|
| 242 |
+
Depth parameter specify a number of downsampling operations in encoder, so you can make
|
| 243 |
+
your model lighter if specify smaller `depth`.
|
| 244 |
+
```python
|
| 245 |
+
model = smp.Unet('resnet34', encoder_depth=4)
|
| 246 |
+
```
|
| 247 |
+
|
| 248 |
+
## 🛠 Installation <a name="installation"></a>
|
| 249 |
+
PyPI version:
|
| 250 |
+
|
| 251 |
+
```bash
|
| 252 |
+
$ pip install segmentation-models-pytorch
|
| 253 |
+
````
|
| 254 |
+
|
| 255 |
+
The latest version from GitHub:
|
| 256 |
+
|
| 257 |
+
```bash
|
| 258 |
+
$ pip install git+https://github.com/qubvel/segmentation_models.pytorch
|
| 259 |
+
````
|
| 260 |
+
|
| 261 |
+
## 🏆 Competitions won with the library <a name="competitions"></a>
|
| 262 |
+
|
| 263 |
+
`Segmentation Models` package is widely used in image segmentation competitions.
|
| 264 |
+
[Here](https://github.com/qubvel/segmentation_models.pytorch/blob/main/HALLOFFAME.md) you can find competitions, names of the winners and links to their solutions.
|
| 265 |
+
|
| 266 |
+
## 🤝 Contributing <a name="contributing"></a>
|
| 267 |
+
|
| 268 |
+
1. Install SMP in dev mode
|
| 269 |
+
|
| 270 |
+
```bash
|
| 271 |
+
make install_dev # Create .venv, install SMP in dev mode
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
2. Run tests and code checks
|
| 275 |
+
|
| 276 |
+
```bash
|
| 277 |
+
make test # Run tests suite with pytest
|
| 278 |
+
make fixup # Ruff for formatting and lint checks
|
| 279 |
+
```
|
| 280 |
+
|
| 281 |
+
3. Update a table (in case you added an encoder)
|
| 282 |
+
|
| 283 |
+
```bash
|
| 284 |
+
make table # Generates a table with encoders and print to stdout
|
| 285 |
+
```
|
| 286 |
+
|
| 287 |
+
## 📝 Citing <a name="citing"></a>
|
| 288 |
+
```
|
| 289 |
+
@misc{Iakubovskii:2019,
|
| 290 |
+
Author = {Pavel Iakubovskii},
|
| 291 |
+
Title = {Segmentation Models Pytorch},
|
| 292 |
+
Year = {2019},
|
| 293 |
+
Publisher = {GitHub},
|
| 294 |
+
Journal = {GitHub repository},
|
| 295 |
+
Howpublished = {\url{https://github.com/qubvel/segmentation_models.pytorch}}
|
| 296 |
+
}
|
| 297 |
+
```
|
| 298 |
+
|
| 299 |
+
## 🛡️ License <a name="license"></a>
|
| 300 |
+
The project is primarily distributed under [MIT License](https://github.com/qubvel/segmentation_models.pytorch/blob/main/LICENSE), while some files are subject to other licenses. Please refer to [LICENSES](licenses/LICENSES.md) and license statements in each file for careful check, especially for commercial use.
|
.cache/pip/http-v2/c/d/5/d/e/cd5de44b899cbe1869765c21b55cffc53c0c0ffa9d3c6f1fd40a42a2
ADDED
|
Binary file (1.87 kB). View file
|
|
|
.cache/pip/http-v2/f/9/5/d/2/f95d294c2281f9705ab34177ee4732e524880c56ef894e620cf4cb95
ADDED
|
Binary file (1.23 kB). View file
|
|
|
.cache/pip/http-v2/f/9/5/d/2/f95d294c2281f9705ab34177ee4732e524880c56ef894e620cf4cb95.body
ADDED
|
Binary file (11.7 kB). View file
|
|
|
.cache/pip/http-v2/f/c/6/8/7/fc687abc6120c7bc7cfd867fe3788604e9f8e9dcf17e51396d803e25
ADDED
|
Binary file (1.21 kB). View file
|
|
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/METADATA
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: filelock
|
| 3 |
+
Version: 3.29.0
|
| 4 |
+
Summary: A platform independent file lock.
|
| 5 |
+
Project-URL: Documentation, https://py-filelock.readthedocs.io
|
| 6 |
+
Project-URL: Homepage, https://github.com/tox-dev/py-filelock
|
| 7 |
+
Project-URL: Source, https://github.com/tox-dev/py-filelock
|
| 8 |
+
Project-URL: Tracker, https://github.com/tox-dev/py-filelock/issues
|
| 9 |
+
Maintainer-email: Bernát Gábor <gaborjbernat@gmail.com>
|
| 10 |
+
License-Expression: MIT
|
| 11 |
+
License-File: LICENSE
|
| 12 |
+
Keywords: application,cache,directory,log,user
|
| 13 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 14 |
+
Classifier: Intended Audience :: Developers
|
| 15 |
+
Classifier: License :: OSI Approved :: MIT License
|
| 16 |
+
Classifier: Operating System :: OS Independent
|
| 17 |
+
Classifier: Programming Language :: Python
|
| 18 |
+
Classifier: Programming Language :: Python :: 3 :: Only
|
| 19 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 20 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 21 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 22 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 23 |
+
Classifier: Programming Language :: Python :: 3.14
|
| 24 |
+
Classifier: Topic :: Internet
|
| 25 |
+
Classifier: Topic :: Software Development :: Libraries
|
| 26 |
+
Classifier: Topic :: System
|
| 27 |
+
Requires-Python: >=3.10
|
| 28 |
+
Description-Content-Type: text/markdown
|
| 29 |
+
|
| 30 |
+
# filelock
|
| 31 |
+
|
| 32 |
+
[](https://pypi.org/project/filelock/)
|
| 33 |
+
[](https://pypi.org/project/filelock/)
|
| 34 |
+
[](https://py-filelock.readthedocs.io/en/latest/?badge=latest)
|
| 35 |
+
[](https://pepy.tech/project/filelock)
|
| 36 |
+
[](https://github.com/tox-dev/py-filelock/actions/workflows/check.yaml)
|
| 37 |
+
|
| 38 |
+
For more information checkout the [official documentation](https://py-filelock.readthedocs.io/en/latest/index.html).
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/RECORD
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
filelock/__init__.py,sha256=Ig_QNvsAVtctz2-fkq9EUCgXmW6M5PDudiOC85szmis,2612
|
| 2 |
+
filelock/_api.py,sha256=UxKGuyzWqzb0Bji8_Czq75TVcQWIH1NTNhEHUxyx2js,21347
|
| 3 |
+
filelock/_async_read_write.py,sha256=C_cRi4sZ7_CWcqdEf0pcA5sdJ2m3EI_2tAW6kS_5P6I,7759
|
| 4 |
+
filelock/_error.py,sha256=mnelOh0EVyVeskG3rksL4kW3OArL4TMb2-PwmzQWIFg,788
|
| 5 |
+
filelock/_read_write.py,sha256=5tVPm1TDXvAu0sgva_LQJ4DH-SDo0rVxuYAFLEQGZw4,15323
|
| 6 |
+
filelock/_soft.py,sha256=t2Q3ikXjI5eVvNqNwntXH1i_Tm84_M9XSRBbtUOCrBc,7833
|
| 7 |
+
filelock/_unix.py,sha256=pbTsIi29Qv8zBtLsXqc3PzlS3wz2db53M1MIqVo9790,4579
|
| 8 |
+
filelock/_util.py,sha256=wPf-LvzmdHWHw4DinDeVJlB0GNVOYGNUeNKSnHBQuUU,1716
|
| 9 |
+
filelock/_windows.py,sha256=kJFOenaffOP6Qza2b3-yxgiPiDcyroWnzz9STGkCrgM,3943
|
| 10 |
+
filelock/asyncio.py,sha256=Hvcow3feO_EPvo24a_bgbsBoHkNeIiIqipUWoHrCWKk,14556
|
| 11 |
+
filelock/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 12 |
+
filelock/version.py,sha256=yPxgPkfVUcMLHpiiTghdwfldZS0DIKnGryve3QX7bOs,522
|
| 13 |
+
filelock/_soft_rw/__init__.py,sha256=_ktpGmVObzrvL0K1_EAV3LF7B9JarYxW-mx_eyGPhT0,370
|
| 14 |
+
filelock/_soft_rw/_async.py,sha256=3MdgJN0SBM-9-Msslt4HeikJtz2cc1tbeN1sWK9NV60,8704
|
| 15 |
+
filelock/_soft_rw/_sync.py,sha256=gBbGRLEEI42hh17uFGFB654HyAhkqJ0NJ4XFlvTX0Ac,34936
|
| 16 |
+
filelock-3.29.0.dist-info/METADATA,sha256=ITNdGUDKAIMOF1lOgentezkyEbHgPto8QRo1B79Z9Lc,1977
|
| 17 |
+
filelock-3.29.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
| 18 |
+
filelock-3.29.0.dist-info/licenses/LICENSE,sha256=YIyJ1QYK6ZIa3M8yNmlbxlSplG4SMj72wCHfoE4pTUg,1088
|
| 19 |
+
filelock-3.29.0.dist-info/RECORD,,
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/WHEEL
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Wheel-Version: 1.0
|
| 2 |
+
Generator: hatchling 1.29.0
|
| 3 |
+
Root-Is-Purelib: true
|
| 4 |
+
Tag: py3-none-any
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock-3.29.0.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2025 Bernát Gábor and contributors
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/__init__.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A platform independent file lock that supports the with-statement.
|
| 3 |
+
|
| 4 |
+
.. autodata:: filelock.__version__
|
| 5 |
+
:no-value:
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import sys
|
| 12 |
+
import warnings
|
| 13 |
+
from typing import TYPE_CHECKING
|
| 14 |
+
|
| 15 |
+
from ._api import AcquireReturnProxy, BaseFileLock
|
| 16 |
+
from ._error import Timeout
|
| 17 |
+
|
| 18 |
+
if TYPE_CHECKING:
|
| 19 |
+
from ._async_read_write import (
|
| 20 |
+
AsyncAcquireReadWriteReturnProxy,
|
| 21 |
+
AsyncReadWriteLock,
|
| 22 |
+
)
|
| 23 |
+
from ._read_write import ReadWriteLock
|
| 24 |
+
else:
|
| 25 |
+
try:
|
| 26 |
+
from ._async_read_write import AsyncAcquireReadWriteReturnProxy, AsyncReadWriteLock
|
| 27 |
+
from ._read_write import ReadWriteLock
|
| 28 |
+
except ImportError: # sqlite3 may be unavailable if Python was built without it or the C library is missing
|
| 29 |
+
AsyncAcquireReadWriteReturnProxy = None
|
| 30 |
+
AsyncReadWriteLock = None
|
| 31 |
+
ReadWriteLock = None
|
| 32 |
+
|
| 33 |
+
from ._soft import SoftFileLock
|
| 34 |
+
from ._soft_rw import AsyncAcquireSoftReadWriteReturnProxy, AsyncSoftReadWriteLock, SoftReadWriteLock
|
| 35 |
+
from ._unix import UnixFileLock, has_fcntl
|
| 36 |
+
from ._windows import WindowsFileLock
|
| 37 |
+
from .asyncio import (
|
| 38 |
+
AsyncAcquireReturnProxy,
|
| 39 |
+
AsyncSoftFileLock,
|
| 40 |
+
AsyncUnixFileLock,
|
| 41 |
+
AsyncWindowsFileLock,
|
| 42 |
+
BaseAsyncFileLock,
|
| 43 |
+
)
|
| 44 |
+
from .version import version
|
| 45 |
+
|
| 46 |
+
#: version of the project as a string
|
| 47 |
+
__version__: str = version
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 51 |
+
_FileLock: type[BaseFileLock] = WindowsFileLock
|
| 52 |
+
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncWindowsFileLock
|
| 53 |
+
else: # pragma: win32 no cover # noqa: PLR5501
|
| 54 |
+
if has_fcntl:
|
| 55 |
+
_FileLock: type[BaseFileLock] = UnixFileLock
|
| 56 |
+
_AsyncFileLock: type[BaseAsyncFileLock] = AsyncUnixFileLock
|
| 57 |
+
else:
|
| 58 |
+
_FileLock = SoftFileLock
|
| 59 |
+
_AsyncFileLock = AsyncSoftFileLock
|
| 60 |
+
if warnings is not None:
|
| 61 |
+
warnings.warn("only soft file lock is available", stacklevel=2)
|
| 62 |
+
|
| 63 |
+
if TYPE_CHECKING:
|
| 64 |
+
FileLock = SoftFileLock
|
| 65 |
+
AsyncFileLock = AsyncSoftFileLock
|
| 66 |
+
else:
|
| 67 |
+
#: Alias for the lock, which should be used for the current platform.
|
| 68 |
+
FileLock = _FileLock
|
| 69 |
+
AsyncFileLock = _AsyncFileLock
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
__all__ = [
|
| 73 |
+
"AcquireReturnProxy",
|
| 74 |
+
"AsyncAcquireReadWriteReturnProxy",
|
| 75 |
+
"AsyncAcquireReturnProxy",
|
| 76 |
+
"AsyncAcquireSoftReadWriteReturnProxy",
|
| 77 |
+
"AsyncFileLock",
|
| 78 |
+
"AsyncReadWriteLock",
|
| 79 |
+
"AsyncSoftFileLock",
|
| 80 |
+
"AsyncSoftReadWriteLock",
|
| 81 |
+
"AsyncUnixFileLock",
|
| 82 |
+
"AsyncWindowsFileLock",
|
| 83 |
+
"BaseAsyncFileLock",
|
| 84 |
+
"BaseFileLock",
|
| 85 |
+
"FileLock",
|
| 86 |
+
"ReadWriteLock",
|
| 87 |
+
"SoftFileLock",
|
| 88 |
+
"SoftReadWriteLock",
|
| 89 |
+
"Timeout",
|
| 90 |
+
"UnixFileLock",
|
| 91 |
+
"WindowsFileLock",
|
| 92 |
+
"__version__",
|
| 93 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_api.py
ADDED
|
@@ -0,0 +1,582 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import inspect
|
| 5 |
+
import logging
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
import sys
|
| 9 |
+
import time
|
| 10 |
+
import warnings
|
| 11 |
+
from abc import ABCMeta, abstractmethod
|
| 12 |
+
from dataclasses import dataclass
|
| 13 |
+
from threading import local
|
| 14 |
+
from typing import TYPE_CHECKING, Any, TypeVar
|
| 15 |
+
from weakref import WeakValueDictionary
|
| 16 |
+
|
| 17 |
+
from ._error import Timeout
|
| 18 |
+
|
| 19 |
+
#: Sentinel indicating that no explicit file permission mode was passed.
|
| 20 |
+
#: When used, lock files are created with 0o666 (letting umask and default ACLs control the final permissions)
|
| 21 |
+
#: and fchmod is skipped so that POSIX default ACL inheritance is preserved.
|
| 22 |
+
_UNSET_FILE_MODE: int = -1
|
| 23 |
+
|
| 24 |
+
if TYPE_CHECKING:
|
| 25 |
+
from collections.abc import Callable
|
| 26 |
+
from types import TracebackType
|
| 27 |
+
|
| 28 |
+
from ._read_write import ReadWriteLock
|
| 29 |
+
from ._soft_rw import SoftReadWriteLock
|
| 30 |
+
|
| 31 |
+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
|
| 32 |
+
from typing import Self
|
| 33 |
+
else: # pragma: no cover (<py311)
|
| 34 |
+
from typing_extensions import Self
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
_LOGGER = logging.getLogger("filelock")
|
| 38 |
+
|
| 39 |
+
# On Windows os.path.realpath calls CreateFileW with share_mode=0, which blocks concurrent DeleteFileW and causes
|
| 40 |
+
# livelocks under threaded contention with SoftFileLock. os.path.abspath is purely string-based and avoids this.
|
| 41 |
+
_canonical = os.path.abspath if sys.platform == "win32" else os.path.realpath
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
class _ThreadLocalRegistry(local):
|
| 45 |
+
def __init__(self) -> None:
|
| 46 |
+
super().__init__()
|
| 47 |
+
self.held: dict[str, int] = {}
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
_registry = _ThreadLocalRegistry()
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
# This is a helper class which is returned by :meth:`BaseFileLock.acquire` and wraps the lock to make sure __enter__
|
| 54 |
+
# is not called twice when entering the with statement. If we would simply return *self*, the lock would be acquired
|
| 55 |
+
# again in the *__enter__* method of the BaseFileLock, but not released again automatically. issue #37 (memory leak)
|
| 56 |
+
class AcquireReturnProxy:
|
| 57 |
+
"""A context-aware object that will release the lock file when exiting."""
|
| 58 |
+
|
| 59 |
+
def __init__(self, lock: BaseFileLock | ReadWriteLock | SoftReadWriteLock) -> None:
|
| 60 |
+
self.lock: BaseFileLock | ReadWriteLock | SoftReadWriteLock = lock
|
| 61 |
+
|
| 62 |
+
def __enter__(self) -> BaseFileLock | ReadWriteLock | SoftReadWriteLock:
|
| 63 |
+
return self.lock
|
| 64 |
+
|
| 65 |
+
def __exit__(
|
| 66 |
+
self,
|
| 67 |
+
exc_type: type[BaseException] | None,
|
| 68 |
+
exc_value: BaseException | None,
|
| 69 |
+
traceback: TracebackType | None,
|
| 70 |
+
) -> None:
|
| 71 |
+
self.lock.release()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
@dataclass
|
| 75 |
+
class FileLockContext:
|
| 76 |
+
"""A dataclass which holds the context for a ``BaseFileLock`` object."""
|
| 77 |
+
|
| 78 |
+
# The context is held in a separate class to allow optional use of thread local storage via the
|
| 79 |
+
# ThreadLocalFileContext class.
|
| 80 |
+
|
| 81 |
+
#: The path to the lock file.
|
| 82 |
+
lock_file: str
|
| 83 |
+
|
| 84 |
+
#: The default timeout value.
|
| 85 |
+
timeout: float
|
| 86 |
+
|
| 87 |
+
#: The mode for the lock files
|
| 88 |
+
mode: int
|
| 89 |
+
|
| 90 |
+
#: Whether the lock should be blocking or not
|
| 91 |
+
blocking: bool
|
| 92 |
+
|
| 93 |
+
#: The default polling interval value.
|
| 94 |
+
poll_interval: float
|
| 95 |
+
|
| 96 |
+
#: The lock lifetime in seconds; ``None`` means the lock never expires.
|
| 97 |
+
lifetime: float | None = None
|
| 98 |
+
|
| 99 |
+
#: The file descriptor for the *_lock_file* as it is returned by the os.open() function, not None when lock held
|
| 100 |
+
lock_file_fd: int | None = None
|
| 101 |
+
|
| 102 |
+
#: The lock counter is used for implementing the nested locking mechanism.
|
| 103 |
+
lock_counter: int = 0 # When the lock is acquired is increased and the lock is only released, when this value is 0
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
class ThreadLocalFileContext(FileLockContext, local):
|
| 107 |
+
"""A thread local version of the ``FileLockContext`` class."""
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
_T = TypeVar("_T", bound="BaseFileLock")
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
class FileLockMeta(ABCMeta):
|
| 114 |
+
_instances: WeakValueDictionary[str, BaseFileLock]
|
| 115 |
+
|
| 116 |
+
def __call__( # noqa: PLR0913
|
| 117 |
+
cls: type[_T],
|
| 118 |
+
lock_file: str | os.PathLike[str],
|
| 119 |
+
timeout: float = -1,
|
| 120 |
+
mode: int = _UNSET_FILE_MODE,
|
| 121 |
+
thread_local: bool = True, # noqa: FBT001, FBT002
|
| 122 |
+
*,
|
| 123 |
+
blocking: bool = True,
|
| 124 |
+
is_singleton: bool = False,
|
| 125 |
+
poll_interval: float = 0.05,
|
| 126 |
+
lifetime: float | None = None,
|
| 127 |
+
**kwargs: Any, # capture remaining kwargs for subclasses # noqa: ANN401
|
| 128 |
+
) -> _T:
|
| 129 |
+
if is_singleton:
|
| 130 |
+
instance = cls._instances.get(str(lock_file))
|
| 131 |
+
if instance:
|
| 132 |
+
params_to_check = {
|
| 133 |
+
"thread_local": (thread_local, instance.is_thread_local()),
|
| 134 |
+
"timeout": (timeout, instance.timeout),
|
| 135 |
+
"mode": (mode, instance._context.mode), # noqa: SLF001
|
| 136 |
+
"blocking": (blocking, instance.blocking),
|
| 137 |
+
"poll_interval": (poll_interval, instance.poll_interval),
|
| 138 |
+
"lifetime": (lifetime, instance.lifetime),
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
non_matching_params = {
|
| 142 |
+
name: (passed_param, set_param)
|
| 143 |
+
for name, (passed_param, set_param) in params_to_check.items()
|
| 144 |
+
if passed_param != set_param
|
| 145 |
+
}
|
| 146 |
+
if not non_matching_params:
|
| 147 |
+
return instance # ty: ignore[invalid-return-type] # https://github.com/astral-sh/ty/issues/3231
|
| 148 |
+
|
| 149 |
+
# parameters do not match; raise error
|
| 150 |
+
msg = "Singleton lock instances cannot be initialized with differing arguments"
|
| 151 |
+
msg += "\nNon-matching arguments: "
|
| 152 |
+
for param_name, (passed_param, set_param) in non_matching_params.items():
|
| 153 |
+
msg += f"\n\t{param_name} (existing lock has {set_param} but {passed_param} was passed)"
|
| 154 |
+
raise ValueError(msg)
|
| 155 |
+
|
| 156 |
+
# Workaround to make `__init__`'s params optional in subclasses
|
| 157 |
+
# E.g. virtualenv changes the signature of the `__init__` method in the `BaseFileLock` class descendant
|
| 158 |
+
# (https://github.com/tox-dev/filelock/pull/340)
|
| 159 |
+
|
| 160 |
+
all_params = {
|
| 161 |
+
"timeout": timeout,
|
| 162 |
+
"mode": mode,
|
| 163 |
+
"thread_local": thread_local,
|
| 164 |
+
"blocking": blocking,
|
| 165 |
+
"is_singleton": is_singleton,
|
| 166 |
+
"poll_interval": poll_interval,
|
| 167 |
+
"lifetime": lifetime,
|
| 168 |
+
**kwargs,
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
present_params = inspect.signature(cls.__init__).parameters
|
| 172 |
+
init_params = {key: value for key, value in all_params.items() if key in present_params}
|
| 173 |
+
|
| 174 |
+
instance = super().__call__(lock_file, **init_params)
|
| 175 |
+
|
| 176 |
+
if is_singleton:
|
| 177 |
+
cls._instances[str(lock_file)] = instance
|
| 178 |
+
|
| 179 |
+
return instance
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
class BaseFileLock(contextlib.ContextDecorator, metaclass=FileLockMeta):
|
| 183 |
+
"""
|
| 184 |
+
Abstract base class for a file lock object.
|
| 185 |
+
|
| 186 |
+
Provides a reentrant, cross-process exclusive lock backed by OS-level primitives. Subclasses implement the actual
|
| 187 |
+
locking mechanism (:class:`UnixFileLock <filelock.UnixFileLock>`, :class:`WindowsFileLock
|
| 188 |
+
<filelock.WindowsFileLock>`, :class:`SoftFileLock <filelock.SoftFileLock>`).
|
| 189 |
+
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
_instances: WeakValueDictionary[str, BaseFileLock]
|
| 193 |
+
|
| 194 |
+
def __init_subclass__(cls, **kwargs: dict[str, Any]) -> None:
|
| 195 |
+
"""Setup unique state for lock subclasses."""
|
| 196 |
+
super().__init_subclass__(**kwargs)
|
| 197 |
+
cls._instances = WeakValueDictionary()
|
| 198 |
+
|
| 199 |
+
def __init__( # noqa: PLR0913
|
| 200 |
+
self,
|
| 201 |
+
lock_file: str | os.PathLike[str],
|
| 202 |
+
timeout: float = -1,
|
| 203 |
+
mode: int = _UNSET_FILE_MODE,
|
| 204 |
+
thread_local: bool = True, # noqa: FBT001, FBT002
|
| 205 |
+
*,
|
| 206 |
+
blocking: bool = True,
|
| 207 |
+
is_singleton: bool = False,
|
| 208 |
+
poll_interval: float = 0.05,
|
| 209 |
+
lifetime: float | None = None,
|
| 210 |
+
) -> None:
|
| 211 |
+
"""
|
| 212 |
+
Create a new lock object.
|
| 213 |
+
|
| 214 |
+
:param lock_file: path to the file
|
| 215 |
+
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the
|
| 216 |
+
acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a
|
| 217 |
+
negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
|
| 218 |
+
:param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and
|
| 219 |
+
default ACLs, preserving POSIX default ACL inheritance in shared directories.
|
| 220 |
+
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to
|
| 221 |
+
``False`` then the lock will be reentrant across threads.
|
| 222 |
+
:param blocking: whether the lock should be blocking or not
|
| 223 |
+
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock
|
| 224 |
+
file. This is useful if you want to use the lock object for reentrant locking without needing to pass the
|
| 225 |
+
same object around.
|
| 226 |
+
:param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value
|
| 227 |
+
in the acquire method, if no poll_interval value (``None``) is given.
|
| 228 |
+
:param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting
|
| 229 |
+
process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the
|
| 230 |
+
default) means locks never expire.
|
| 231 |
+
|
| 232 |
+
"""
|
| 233 |
+
self._is_thread_local = thread_local
|
| 234 |
+
self._is_singleton = is_singleton
|
| 235 |
+
|
| 236 |
+
# Create the context. Note that external code should not work with the context directly and should instead use
|
| 237 |
+
# properties of this class.
|
| 238 |
+
kwargs: dict[str, Any] = {
|
| 239 |
+
"lock_file": os.fspath(lock_file),
|
| 240 |
+
"timeout": timeout,
|
| 241 |
+
"mode": mode,
|
| 242 |
+
"blocking": blocking,
|
| 243 |
+
"poll_interval": poll_interval,
|
| 244 |
+
"lifetime": lifetime,
|
| 245 |
+
}
|
| 246 |
+
self._context: FileLockContext = (ThreadLocalFileContext if thread_local else FileLockContext)(**kwargs)
|
| 247 |
+
|
| 248 |
+
def is_thread_local(self) -> bool:
|
| 249 |
+
""":returns: a flag indicating if this lock is thread local or not"""
|
| 250 |
+
return self._is_thread_local
|
| 251 |
+
|
| 252 |
+
@property
|
| 253 |
+
def is_singleton(self) -> bool:
|
| 254 |
+
"""
|
| 255 |
+
:returns: a flag indicating if this lock is singleton or not
|
| 256 |
+
|
| 257 |
+
.. versionadded:: 3.13.0
|
| 258 |
+
|
| 259 |
+
"""
|
| 260 |
+
return self._is_singleton
|
| 261 |
+
|
| 262 |
+
@property
|
| 263 |
+
def lock_file(self) -> str:
|
| 264 |
+
""":returns: path to the lock file"""
|
| 265 |
+
return self._context.lock_file
|
| 266 |
+
|
| 267 |
+
@property
|
| 268 |
+
def timeout(self) -> float:
|
| 269 |
+
"""
|
| 270 |
+
:returns: the default timeout value, in seconds
|
| 271 |
+
|
| 272 |
+
.. versionadded:: 2.0.0
|
| 273 |
+
|
| 274 |
+
"""
|
| 275 |
+
return self._context.timeout
|
| 276 |
+
|
| 277 |
+
@timeout.setter
|
| 278 |
+
def timeout(self, value: float | str) -> None:
|
| 279 |
+
"""
|
| 280 |
+
Change the default timeout value.
|
| 281 |
+
|
| 282 |
+
:param value: the new value, in seconds
|
| 283 |
+
|
| 284 |
+
"""
|
| 285 |
+
self._context.timeout = float(value)
|
| 286 |
+
|
| 287 |
+
@property
|
| 288 |
+
def blocking(self) -> bool:
|
| 289 |
+
"""
|
| 290 |
+
:returns: whether the locking is blocking or not
|
| 291 |
+
|
| 292 |
+
.. versionadded:: 3.14.0
|
| 293 |
+
|
| 294 |
+
"""
|
| 295 |
+
return self._context.blocking
|
| 296 |
+
|
| 297 |
+
@blocking.setter
|
| 298 |
+
def blocking(self, value: bool) -> None:
|
| 299 |
+
"""
|
| 300 |
+
Change the default blocking value.
|
| 301 |
+
|
| 302 |
+
:param value: the new value as bool
|
| 303 |
+
|
| 304 |
+
"""
|
| 305 |
+
self._context.blocking = value
|
| 306 |
+
|
| 307 |
+
@property
|
| 308 |
+
def poll_interval(self) -> float:
|
| 309 |
+
"""
|
| 310 |
+
:returns: the default polling interval, in seconds
|
| 311 |
+
|
| 312 |
+
.. versionadded:: 3.24.0
|
| 313 |
+
|
| 314 |
+
"""
|
| 315 |
+
return self._context.poll_interval
|
| 316 |
+
|
| 317 |
+
@poll_interval.setter
|
| 318 |
+
def poll_interval(self, value: float) -> None:
|
| 319 |
+
"""
|
| 320 |
+
Change the default polling interval.
|
| 321 |
+
|
| 322 |
+
:param value: the new value, in seconds
|
| 323 |
+
|
| 324 |
+
"""
|
| 325 |
+
self._context.poll_interval = value
|
| 326 |
+
|
| 327 |
+
@property
|
| 328 |
+
def lifetime(self) -> float | None:
|
| 329 |
+
"""
|
| 330 |
+
:returns: the lock lifetime in seconds, or ``None`` if the lock never expires
|
| 331 |
+
|
| 332 |
+
.. versionadded:: 3.24.0
|
| 333 |
+
|
| 334 |
+
"""
|
| 335 |
+
return self._context.lifetime
|
| 336 |
+
|
| 337 |
+
@lifetime.setter
|
| 338 |
+
def lifetime(self, value: float | None) -> None:
|
| 339 |
+
"""
|
| 340 |
+
Change the lock lifetime.
|
| 341 |
+
|
| 342 |
+
:param value: the new value in seconds, or ``None`` to disable expiration
|
| 343 |
+
|
| 344 |
+
"""
|
| 345 |
+
self._context.lifetime = value
|
| 346 |
+
|
| 347 |
+
@property
|
| 348 |
+
def mode(self) -> int:
|
| 349 |
+
""":returns: the file permissions for the lockfile"""
|
| 350 |
+
return 0o644 if self._context.mode == _UNSET_FILE_MODE else self._context.mode
|
| 351 |
+
|
| 352 |
+
@property
|
| 353 |
+
def has_explicit_mode(self) -> bool:
|
| 354 |
+
""":returns: whether the file permissions were explicitly set"""
|
| 355 |
+
return self._context.mode != _UNSET_FILE_MODE
|
| 356 |
+
|
| 357 |
+
def _open_mode(self) -> int:
|
| 358 |
+
""":returns: the mode for os.open() — 0o666 when unset (let umask/ACLs decide), else the explicit mode"""
|
| 359 |
+
return 0o666 if self._context.mode == _UNSET_FILE_MODE else self._context.mode
|
| 360 |
+
|
| 361 |
+
def _try_break_expired_lock(self) -> None:
|
| 362 |
+
"""Remove the lock file if its modification time exceeds the configured :attr:`lifetime`."""
|
| 363 |
+
if (lifetime := self._context.lifetime) is None:
|
| 364 |
+
return
|
| 365 |
+
with contextlib.suppress(OSError):
|
| 366 |
+
if time.time() - pathlib.Path(self.lock_file).stat().st_mtime < lifetime:
|
| 367 |
+
return
|
| 368 |
+
break_path = f"{self.lock_file}.break.{os.getpid()}"
|
| 369 |
+
pathlib.Path(self.lock_file).rename(break_path)
|
| 370 |
+
pathlib.Path(break_path).unlink()
|
| 371 |
+
|
| 372 |
+
@abstractmethod
|
| 373 |
+
def _acquire(self) -> None:
|
| 374 |
+
"""If the file lock could be acquired, self._context.lock_file_fd holds the file descriptor of the lock file."""
|
| 375 |
+
raise NotImplementedError
|
| 376 |
+
|
| 377 |
+
@abstractmethod
|
| 378 |
+
def _release(self) -> None:
|
| 379 |
+
"""Releases the lock and sets self._context.lock_file_fd to None."""
|
| 380 |
+
raise NotImplementedError
|
| 381 |
+
|
| 382 |
+
@property
|
| 383 |
+
def is_locked(self) -> bool:
|
| 384 |
+
"""
|
| 385 |
+
:returns: A boolean indicating if the lock file is holding the lock currently.
|
| 386 |
+
|
| 387 |
+
.. versionchanged:: 2.0.0
|
| 388 |
+
|
| 389 |
+
This was previously a method and is now a property.
|
| 390 |
+
|
| 391 |
+
"""
|
| 392 |
+
return self._context.lock_file_fd is not None
|
| 393 |
+
|
| 394 |
+
@property
|
| 395 |
+
def lock_counter(self) -> int:
|
| 396 |
+
""":returns: The number of times this lock has been acquired (but not yet released)."""
|
| 397 |
+
return self._context.lock_counter
|
| 398 |
+
|
| 399 |
+
@staticmethod
|
| 400 |
+
def _check_give_up( # noqa: PLR0913
|
| 401 |
+
lock_id: int,
|
| 402 |
+
lock_filename: str,
|
| 403 |
+
*,
|
| 404 |
+
blocking: bool,
|
| 405 |
+
cancel_check: Callable[[], bool] | None,
|
| 406 |
+
timeout: float,
|
| 407 |
+
start_time: float,
|
| 408 |
+
) -> bool:
|
| 409 |
+
if blocking is False:
|
| 410 |
+
_LOGGER.debug("Failed to immediately acquire lock %s on %s", lock_id, lock_filename)
|
| 411 |
+
return True
|
| 412 |
+
if cancel_check is not None and cancel_check():
|
| 413 |
+
_LOGGER.debug("Cancellation requested for lock %s on %s", lock_id, lock_filename)
|
| 414 |
+
return True
|
| 415 |
+
if 0 <= timeout < time.perf_counter() - start_time:
|
| 416 |
+
_LOGGER.debug("Timeout on acquiring lock %s on %s", lock_id, lock_filename)
|
| 417 |
+
return True
|
| 418 |
+
return False
|
| 419 |
+
|
| 420 |
+
def acquire( # noqa: C901
|
| 421 |
+
self,
|
| 422 |
+
timeout: float | None = None,
|
| 423 |
+
poll_interval: float | None = None,
|
| 424 |
+
*,
|
| 425 |
+
poll_intervall: float | None = None,
|
| 426 |
+
blocking: bool | None = None,
|
| 427 |
+
cancel_check: Callable[[], bool] | None = None,
|
| 428 |
+
) -> AcquireReturnProxy:
|
| 429 |
+
"""
|
| 430 |
+
Try to acquire the file lock.
|
| 431 |
+
|
| 432 |
+
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default :attr:`~timeout` is and
|
| 433 |
+
if ``timeout < 0``, there is no timeout and this method will block until the lock could be acquired
|
| 434 |
+
:param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default
|
| 435 |
+
:attr:`~poll_interval`
|
| 436 |
+
:param poll_intervall: deprecated, kept for backwards compatibility, use ``poll_interval`` instead
|
| 437 |
+
:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
|
| 438 |
+
first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
|
| 439 |
+
:param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
|
| 440 |
+
iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.
|
| 441 |
+
|
| 442 |
+
:returns: a context object that will unlock the file when the context is exited
|
| 443 |
+
|
| 444 |
+
:raises Timeout: if fails to acquire lock within the timeout period
|
| 445 |
+
|
| 446 |
+
.. code-block:: python
|
| 447 |
+
|
| 448 |
+
# You can use this method in the context manager (recommended)
|
| 449 |
+
with lock.acquire():
|
| 450 |
+
pass
|
| 451 |
+
|
| 452 |
+
# Or use an equivalent try-finally construct:
|
| 453 |
+
lock.acquire()
|
| 454 |
+
try:
|
| 455 |
+
pass
|
| 456 |
+
finally:
|
| 457 |
+
lock.release()
|
| 458 |
+
|
| 459 |
+
.. versionchanged:: 2.0.0
|
| 460 |
+
|
| 461 |
+
This method returns now a *proxy* object instead of *self*, so that it can be used in a with statement
|
| 462 |
+
without side effects.
|
| 463 |
+
|
| 464 |
+
"""
|
| 465 |
+
# Use the default timeout, if no timeout is provided.
|
| 466 |
+
if timeout is None:
|
| 467 |
+
timeout = self._context.timeout
|
| 468 |
+
|
| 469 |
+
if blocking is None:
|
| 470 |
+
blocking = self._context.blocking
|
| 471 |
+
|
| 472 |
+
if poll_intervall is not None:
|
| 473 |
+
msg = "use poll_interval instead of poll_intervall"
|
| 474 |
+
warnings.warn(msg, DeprecationWarning, stacklevel=2)
|
| 475 |
+
poll_interval = poll_intervall
|
| 476 |
+
|
| 477 |
+
poll_interval = poll_interval if poll_interval is not None else self._context.poll_interval
|
| 478 |
+
|
| 479 |
+
# Increment the number right at the beginning. We can still undo it, if something fails.
|
| 480 |
+
self._context.lock_counter += 1
|
| 481 |
+
|
| 482 |
+
lock_id = id(self)
|
| 483 |
+
lock_filename = self.lock_file
|
| 484 |
+
canonical = _canonical(lock_filename)
|
| 485 |
+
|
| 486 |
+
would_block = self._context.lock_counter == 1 and not self.is_locked and timeout < 0 and blocking
|
| 487 |
+
if would_block and (existing := _registry.held.get(canonical)) is not None and existing != lock_id:
|
| 488 |
+
self._context.lock_counter -= 1
|
| 489 |
+
msg = (
|
| 490 |
+
f"Deadlock: lock '{lock_filename}' is already held by a different "
|
| 491 |
+
f"FileLock instance in this thread. Use is_singleton=True to "
|
| 492 |
+
f"enable reentrant locking across instances."
|
| 493 |
+
)
|
| 494 |
+
raise RuntimeError(msg)
|
| 495 |
+
|
| 496 |
+
start_time = time.perf_counter()
|
| 497 |
+
try:
|
| 498 |
+
while True:
|
| 499 |
+
if not self.is_locked:
|
| 500 |
+
self._try_break_expired_lock()
|
| 501 |
+
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
| 502 |
+
self._acquire()
|
| 503 |
+
if self.is_locked:
|
| 504 |
+
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
| 505 |
+
break
|
| 506 |
+
if self._check_give_up(
|
| 507 |
+
lock_id,
|
| 508 |
+
lock_filename,
|
| 509 |
+
blocking=blocking,
|
| 510 |
+
cancel_check=cancel_check,
|
| 511 |
+
timeout=timeout,
|
| 512 |
+
start_time=start_time,
|
| 513 |
+
):
|
| 514 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
| 515 |
+
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
|
| 516 |
+
_LOGGER.debug(msg, lock_id, lock_filename, poll_interval)
|
| 517 |
+
time.sleep(poll_interval)
|
| 518 |
+
except BaseException:
|
| 519 |
+
self._context.lock_counter = max(0, self._context.lock_counter - 1)
|
| 520 |
+
if self._context.lock_counter == 0:
|
| 521 |
+
_registry.held.pop(canonical, None)
|
| 522 |
+
raise
|
| 523 |
+
if self._context.lock_counter == 1:
|
| 524 |
+
_registry.held[canonical] = lock_id
|
| 525 |
+
return AcquireReturnProxy(lock=self)
|
| 526 |
+
|
| 527 |
+
def release(self, force: bool = False) -> None: # noqa: FBT001, FBT002
|
| 528 |
+
"""
|
| 529 |
+
Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file
|
| 530 |
+
itself is not automatically deleted.
|
| 531 |
+
|
| 532 |
+
:param force: If true, the lock counter is ignored and the lock is released in every case.
|
| 533 |
+
|
| 534 |
+
"""
|
| 535 |
+
if self.is_locked:
|
| 536 |
+
self._context.lock_counter -= 1
|
| 537 |
+
|
| 538 |
+
if self._context.lock_counter == 0 or force:
|
| 539 |
+
lock_id, lock_filename = id(self), self.lock_file
|
| 540 |
+
|
| 541 |
+
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
| 542 |
+
self._release()
|
| 543 |
+
self._context.lock_counter = 0
|
| 544 |
+
_registry.held.pop(_canonical(lock_filename), None)
|
| 545 |
+
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
| 546 |
+
|
| 547 |
+
def __enter__(self) -> Self:
|
| 548 |
+
"""
|
| 549 |
+
Acquire the lock.
|
| 550 |
+
|
| 551 |
+
:returns: the lock object
|
| 552 |
+
|
| 553 |
+
"""
|
| 554 |
+
self.acquire()
|
| 555 |
+
return self
|
| 556 |
+
|
| 557 |
+
def __exit__(
|
| 558 |
+
self,
|
| 559 |
+
exc_type: type[BaseException] | None,
|
| 560 |
+
exc_value: BaseException | None,
|
| 561 |
+
traceback: TracebackType | None,
|
| 562 |
+
) -> None:
|
| 563 |
+
"""
|
| 564 |
+
Release the lock.
|
| 565 |
+
|
| 566 |
+
:param exc_type: the exception type if raised
|
| 567 |
+
:param exc_value: the exception value if raised
|
| 568 |
+
:param traceback: the exception traceback if raised
|
| 569 |
+
|
| 570 |
+
"""
|
| 571 |
+
self.release()
|
| 572 |
+
|
| 573 |
+
def __del__(self) -> None:
|
| 574 |
+
"""Called when the lock object is deleted."""
|
| 575 |
+
self.release(force=True)
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
__all__ = [
|
| 579 |
+
"_UNSET_FILE_MODE",
|
| 580 |
+
"AcquireReturnProxy",
|
| 581 |
+
"BaseFileLock",
|
| 582 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_async_read_write.py
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Async wrapper around :class:`ReadWriteLock` for use with ``asyncio``."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import functools
|
| 7 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 8 |
+
from contextlib import asynccontextmanager
|
| 9 |
+
from typing import TYPE_CHECKING
|
| 10 |
+
|
| 11 |
+
from ._read_write import ReadWriteLock
|
| 12 |
+
|
| 13 |
+
if TYPE_CHECKING:
|
| 14 |
+
import os
|
| 15 |
+
from collections.abc import AsyncGenerator, Callable
|
| 16 |
+
from concurrent import futures
|
| 17 |
+
from types import TracebackType
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class AsyncAcquireReadWriteReturnProxy:
|
| 21 |
+
"""Context-aware object that releases the async read/write lock on exit."""
|
| 22 |
+
|
| 23 |
+
def __init__(self, lock: AsyncReadWriteLock) -> None:
|
| 24 |
+
self.lock = lock
|
| 25 |
+
|
| 26 |
+
async def __aenter__(self) -> AsyncReadWriteLock:
|
| 27 |
+
return self.lock
|
| 28 |
+
|
| 29 |
+
async def __aexit__(
|
| 30 |
+
self,
|
| 31 |
+
exc_type: type[BaseException] | None,
|
| 32 |
+
exc_value: BaseException | None,
|
| 33 |
+
traceback: TracebackType | None,
|
| 34 |
+
) -> None:
|
| 35 |
+
await self.lock.release()
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
class AsyncReadWriteLock:
|
| 39 |
+
"""
|
| 40 |
+
Async wrapper around :class:`ReadWriteLock` for use in ``asyncio`` applications.
|
| 41 |
+
|
| 42 |
+
Because Python's :mod:`sqlite3` module has no async API, all blocking SQLite operations are dispatched to a thread
|
| 43 |
+
pool via ``loop.run_in_executor()``. Reentrancy, upgrade/downgrade rules, and singleton behavior are delegated
|
| 44 |
+
to the underlying :class:`ReadWriteLock`.
|
| 45 |
+
|
| 46 |
+
:param lock_file: path to the SQLite database file used as the lock
|
| 47 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 48 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 49 |
+
:param is_singleton: if ``True``, reuse existing :class:`ReadWriteLock` instances for the same resolved path
|
| 50 |
+
:param loop: event loop for ``run_in_executor``; ``None`` uses the running loop
|
| 51 |
+
:param executor: executor for ``run_in_executor``; ``None`` uses the default executor
|
| 52 |
+
|
| 53 |
+
.. versionadded:: 3.21.0
|
| 54 |
+
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
def __init__( # noqa: PLR0913
|
| 58 |
+
self,
|
| 59 |
+
lock_file: str | os.PathLike[str],
|
| 60 |
+
timeout: float = -1,
|
| 61 |
+
*,
|
| 62 |
+
blocking: bool = True,
|
| 63 |
+
is_singleton: bool = True,
|
| 64 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 65 |
+
executor: futures.Executor | None = None,
|
| 66 |
+
) -> None:
|
| 67 |
+
self._lock = ReadWriteLock(lock_file, timeout, blocking=blocking, is_singleton=is_singleton)
|
| 68 |
+
self._loop = loop
|
| 69 |
+
self._owns_executor = executor is None
|
| 70 |
+
self._executor = executor or ThreadPoolExecutor(max_workers=1)
|
| 71 |
+
|
| 72 |
+
@property
|
| 73 |
+
def lock_file(self) -> str:
|
| 74 |
+
""":returns: the path to the lock file."""
|
| 75 |
+
return self._lock.lock_file
|
| 76 |
+
|
| 77 |
+
@property
|
| 78 |
+
def timeout(self) -> float:
|
| 79 |
+
""":returns: the default timeout."""
|
| 80 |
+
return self._lock.timeout
|
| 81 |
+
|
| 82 |
+
@property
|
| 83 |
+
def blocking(self) -> bool:
|
| 84 |
+
""":returns: whether blocking is enabled by default."""
|
| 85 |
+
return self._lock.blocking
|
| 86 |
+
|
| 87 |
+
@property
|
| 88 |
+
def loop(self) -> asyncio.AbstractEventLoop | None:
|
| 89 |
+
""":returns: the event loop (or ``None`` for the running loop)."""
|
| 90 |
+
return self._loop
|
| 91 |
+
|
| 92 |
+
@property
|
| 93 |
+
def executor(self) -> futures.Executor | None:
|
| 94 |
+
""":returns: the executor (or ``None`` for the default)."""
|
| 95 |
+
return self._executor
|
| 96 |
+
|
| 97 |
+
async def _run(self, func: Callable[..., object], *args: object, **kwargs: object) -> object:
|
| 98 |
+
loop = self._loop or asyncio.get_running_loop()
|
| 99 |
+
return await loop.run_in_executor(self._executor, functools.partial(func, *args, **kwargs))
|
| 100 |
+
|
| 101 |
+
async def acquire_read(self, timeout: float = -1, *, blocking: bool = True) -> AsyncAcquireReadWriteReturnProxy:
|
| 102 |
+
"""
|
| 103 |
+
Acquire a shared read lock.
|
| 104 |
+
|
| 105 |
+
See :meth:`ReadWriteLock.acquire_read` for full semantics.
|
| 106 |
+
|
| 107 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 108 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 109 |
+
|
| 110 |
+
:returns: a proxy that can be used as an async context manager to release the lock
|
| 111 |
+
|
| 112 |
+
:raises RuntimeError: if a write lock is already held on this instance
|
| 113 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 114 |
+
|
| 115 |
+
"""
|
| 116 |
+
await self._run(self._lock.acquire_read, timeout, blocking=blocking)
|
| 117 |
+
return AsyncAcquireReadWriteReturnProxy(lock=self)
|
| 118 |
+
|
| 119 |
+
async def acquire_write(self, timeout: float = -1, *, blocking: bool = True) -> AsyncAcquireReadWriteReturnProxy:
|
| 120 |
+
"""
|
| 121 |
+
Acquire an exclusive write lock.
|
| 122 |
+
|
| 123 |
+
See :meth:`ReadWriteLock.acquire_write` for full semantics.
|
| 124 |
+
|
| 125 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 126 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 127 |
+
|
| 128 |
+
:returns: a proxy that can be used as an async context manager to release the lock
|
| 129 |
+
|
| 130 |
+
:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
|
| 131 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 132 |
+
|
| 133 |
+
"""
|
| 134 |
+
await self._run(self._lock.acquire_write, timeout, blocking=blocking)
|
| 135 |
+
return AsyncAcquireReadWriteReturnProxy(lock=self)
|
| 136 |
+
|
| 137 |
+
async def release(self, *, force: bool = False) -> None:
|
| 138 |
+
"""
|
| 139 |
+
Release one level of the current lock.
|
| 140 |
+
|
| 141 |
+
See :meth:`ReadWriteLock.release` for full semantics.
|
| 142 |
+
|
| 143 |
+
:param force: if ``True``, release the lock completely regardless of the current lock level
|
| 144 |
+
|
| 145 |
+
:raises RuntimeError: if no lock is currently held and *force* is ``False``
|
| 146 |
+
|
| 147 |
+
"""
|
| 148 |
+
await self._run(self._lock.release, force=force)
|
| 149 |
+
|
| 150 |
+
@asynccontextmanager
|
| 151 |
+
async def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:
|
| 152 |
+
"""
|
| 153 |
+
Async context manager that acquires and releases a shared read lock.
|
| 154 |
+
|
| 155 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 156 |
+
|
| 157 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 158 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 159 |
+
|
| 160 |
+
"""
|
| 161 |
+
if timeout is None:
|
| 162 |
+
timeout = self._lock.timeout
|
| 163 |
+
if blocking is None:
|
| 164 |
+
blocking = self._lock.blocking
|
| 165 |
+
await self.acquire_read(timeout, blocking=blocking)
|
| 166 |
+
try:
|
| 167 |
+
yield
|
| 168 |
+
finally:
|
| 169 |
+
await self.release()
|
| 170 |
+
|
| 171 |
+
@asynccontextmanager
|
| 172 |
+
async def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:
|
| 173 |
+
"""
|
| 174 |
+
Async context manager that acquires and releases an exclusive write lock.
|
| 175 |
+
|
| 176 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 177 |
+
|
| 178 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 179 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 180 |
+
|
| 181 |
+
"""
|
| 182 |
+
if timeout is None:
|
| 183 |
+
timeout = self._lock.timeout
|
| 184 |
+
if blocking is None:
|
| 185 |
+
blocking = self._lock.blocking
|
| 186 |
+
await self.acquire_write(timeout, blocking=blocking)
|
| 187 |
+
try:
|
| 188 |
+
yield
|
| 189 |
+
finally:
|
| 190 |
+
await self.release()
|
| 191 |
+
|
| 192 |
+
async def close(self) -> None:
|
| 193 |
+
"""
|
| 194 |
+
Release the lock (if held) and close the underlying SQLite connection.
|
| 195 |
+
|
| 196 |
+
After calling this method, the lock instance is no longer usable.
|
| 197 |
+
|
| 198 |
+
"""
|
| 199 |
+
await self._run(self._lock.close)
|
| 200 |
+
if self._owns_executor:
|
| 201 |
+
self._executor.shutdown(wait=False)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
__all__ = [
|
| 205 |
+
"AsyncAcquireReadWriteReturnProxy",
|
| 206 |
+
"AsyncReadWriteLock",
|
| 207 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_error.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Timeout(TimeoutError): # noqa: N818
|
| 7 |
+
"""Raised when the lock could not be acquired in *timeout* seconds."""
|
| 8 |
+
|
| 9 |
+
def __init__(self, lock_file: str) -> None:
|
| 10 |
+
super().__init__()
|
| 11 |
+
self._lock_file = lock_file
|
| 12 |
+
|
| 13 |
+
def __reduce__(self) -> str | tuple[Any, ...]:
|
| 14 |
+
return self.__class__, (self._lock_file,) # Properly pickle the exception
|
| 15 |
+
|
| 16 |
+
def __str__(self) -> str:
|
| 17 |
+
return f"The file lock '{self._lock_file}' could not be acquired."
|
| 18 |
+
|
| 19 |
+
def __repr__(self) -> str:
|
| 20 |
+
return f"{self.__class__.__name__}({self.lock_file!r})"
|
| 21 |
+
|
| 22 |
+
@property
|
| 23 |
+
def lock_file(self) -> str:
|
| 24 |
+
""":returns: The path of the file lock."""
|
| 25 |
+
return self._lock_file
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
__all__ = [
|
| 29 |
+
"Timeout",
|
| 30 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_read_write.py
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
| 10 |
+
from contextlib import contextmanager, suppress
|
| 11 |
+
from typing import TYPE_CHECKING, Literal
|
| 12 |
+
from weakref import WeakValueDictionary
|
| 13 |
+
|
| 14 |
+
from ._api import AcquireReturnProxy
|
| 15 |
+
from ._error import Timeout
|
| 16 |
+
|
| 17 |
+
if TYPE_CHECKING:
|
| 18 |
+
from collections.abc import Generator
|
| 19 |
+
|
| 20 |
+
_LOGGER = logging.getLogger("filelock")
|
| 21 |
+
|
| 22 |
+
_all_connections: set[sqlite3.Connection] = set()
|
| 23 |
+
_all_connections_lock = threading.Lock()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _cleanup_connections() -> None:
|
| 27 |
+
with _all_connections_lock:
|
| 28 |
+
for con in list(_all_connections):
|
| 29 |
+
with suppress(Exception):
|
| 30 |
+
con.close()
|
| 31 |
+
_all_connections.clear()
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
atexit.register(_cleanup_connections)
|
| 35 |
+
|
| 36 |
+
# sqlite3_busy_timeout() accepts a C int, max 2_147_483_647 on 32-bit. Use a lower value to be safe (~23 days).
|
| 37 |
+
_MAX_SQLITE_TIMEOUT_MS = 2_000_000_000 - 1
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def timeout_for_sqlite(timeout: float, *, blocking: bool, already_waited: float) -> int:
|
| 41 |
+
if blocking is False:
|
| 42 |
+
return 0
|
| 43 |
+
|
| 44 |
+
if timeout == -1:
|
| 45 |
+
return _MAX_SQLITE_TIMEOUT_MS
|
| 46 |
+
|
| 47 |
+
if timeout < 0:
|
| 48 |
+
msg = "timeout must be a non-negative number or -1"
|
| 49 |
+
raise ValueError(msg)
|
| 50 |
+
|
| 51 |
+
remaining = max(timeout - already_waited, 0) if timeout > 0 else timeout
|
| 52 |
+
timeout_ms = int(remaining * 1000)
|
| 53 |
+
if timeout_ms > _MAX_SQLITE_TIMEOUT_MS or timeout_ms < 0:
|
| 54 |
+
_LOGGER.warning("timeout %s is too large for SQLite, using %s ms instead", timeout, _MAX_SQLITE_TIMEOUT_MS)
|
| 55 |
+
return _MAX_SQLITE_TIMEOUT_MS
|
| 56 |
+
return timeout_ms
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class _ReadWriteLockMeta(type):
|
| 60 |
+
"""
|
| 61 |
+
Metaclass that handles singleton resolution when is_singleton=True.
|
| 62 |
+
|
| 63 |
+
Singleton logic lives here rather than in ReadWriteLock.get_lock so that ``ReadWriteLock(path)`` transparently
|
| 64 |
+
returns cached instances without a 2-arg ``super()`` call that type checkers cannot verify.
|
| 65 |
+
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
_instances: WeakValueDictionary[pathlib.Path, ReadWriteLock]
|
| 69 |
+
_instances_lock: threading.Lock
|
| 70 |
+
|
| 71 |
+
def __call__(
|
| 72 |
+
cls,
|
| 73 |
+
lock_file: str | os.PathLike[str],
|
| 74 |
+
timeout: float = -1,
|
| 75 |
+
*,
|
| 76 |
+
blocking: bool = True,
|
| 77 |
+
is_singleton: bool = True,
|
| 78 |
+
) -> ReadWriteLock:
|
| 79 |
+
if not is_singleton:
|
| 80 |
+
return super().__call__(lock_file, timeout, blocking=blocking, is_singleton=is_singleton)
|
| 81 |
+
|
| 82 |
+
normalized = pathlib.Path(lock_file).resolve()
|
| 83 |
+
with cls._instances_lock:
|
| 84 |
+
if normalized not in cls._instances:
|
| 85 |
+
instance = super().__call__(lock_file, timeout, blocking=blocking, is_singleton=is_singleton)
|
| 86 |
+
cls._instances[normalized] = instance
|
| 87 |
+
else:
|
| 88 |
+
instance = cls._instances[normalized]
|
| 89 |
+
|
| 90 |
+
if instance.timeout != timeout or instance.blocking != blocking:
|
| 91 |
+
msg = (
|
| 92 |
+
f"Singleton lock created with timeout={instance.timeout}, blocking={instance.blocking},"
|
| 93 |
+
f" cannot be changed to timeout={timeout}, blocking={blocking}"
|
| 94 |
+
)
|
| 95 |
+
raise ValueError(msg)
|
| 96 |
+
return instance
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class ReadWriteLock(metaclass=_ReadWriteLockMeta):
|
| 100 |
+
"""
|
| 101 |
+
Cross-process read-write lock backed by SQLite.
|
| 102 |
+
|
| 103 |
+
Allows concurrent shared readers or a single exclusive writer. The lock is reentrant within the same mode (multiple
|
| 104 |
+
``acquire_read`` calls nest, as do multiple ``acquire_write`` calls from the same thread), but upgrading from read
|
| 105 |
+
to write or downgrading from write to read raises :class:`RuntimeError`. Write locks are pinned to the thread that
|
| 106 |
+
acquired them.
|
| 107 |
+
|
| 108 |
+
By default, ``is_singleton=True``: calling ``ReadWriteLock(path)`` with the same resolved path returns the same
|
| 109 |
+
instance. The lock file must use a ``.db`` extension (SQLite database).
|
| 110 |
+
|
| 111 |
+
:param lock_file: path to the SQLite database file used as the lock
|
| 112 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 113 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 114 |
+
:param is_singleton: if ``True``, reuse existing instances for the same resolved path
|
| 115 |
+
|
| 116 |
+
.. versionadded:: 3.21.0
|
| 117 |
+
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
_instances: WeakValueDictionary[pathlib.Path, ReadWriteLock] = WeakValueDictionary()
|
| 121 |
+
_instances_lock = threading.Lock()
|
| 122 |
+
|
| 123 |
+
@classmethod
|
| 124 |
+
def get_lock(
|
| 125 |
+
cls, lock_file: str | os.PathLike[str], timeout: float = -1, *, blocking: bool = True
|
| 126 |
+
) -> ReadWriteLock:
|
| 127 |
+
"""
|
| 128 |
+
Return the singleton :class:`ReadWriteLock` for *lock_file*.
|
| 129 |
+
|
| 130 |
+
:param lock_file: path to the SQLite database file used as the lock
|
| 131 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 132 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 133 |
+
|
| 134 |
+
:returns: the singleton lock instance
|
| 135 |
+
|
| 136 |
+
:raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values
|
| 137 |
+
|
| 138 |
+
"""
|
| 139 |
+
return cls(lock_file, timeout, blocking=blocking)
|
| 140 |
+
|
| 141 |
+
def __init__(
|
| 142 |
+
self,
|
| 143 |
+
lock_file: str | os.PathLike[str],
|
| 144 |
+
timeout: float = -1,
|
| 145 |
+
*,
|
| 146 |
+
blocking: bool = True,
|
| 147 |
+
is_singleton: bool = True, # noqa: ARG002 # consumed by _ReadWriteLockMeta.__call__
|
| 148 |
+
) -> None:
|
| 149 |
+
self.lock_file = os.fspath(lock_file)
|
| 150 |
+
self.timeout = timeout
|
| 151 |
+
self.blocking = blocking
|
| 152 |
+
self._transaction_lock = threading.Lock() # serializes the (possibly blocking) SQLite transaction work
|
| 153 |
+
self._internal_lock = threading.Lock() # protects _lock_level / _current_mode updates and rollback
|
| 154 |
+
self._lock_level = 0
|
| 155 |
+
self._current_mode: Literal["read", "write"] | None = None
|
| 156 |
+
self._write_thread_id: int | None = None
|
| 157 |
+
self._con = sqlite3.connect(self.lock_file, check_same_thread=False)
|
| 158 |
+
with _all_connections_lock:
|
| 159 |
+
_all_connections.add(self._con)
|
| 160 |
+
|
| 161 |
+
def _acquire_transaction_lock(self, *, blocking: bool, timeout: float) -> None:
|
| 162 |
+
if not blocking:
|
| 163 |
+
acquired = self._transaction_lock.acquire(blocking=False)
|
| 164 |
+
elif timeout == -1:
|
| 165 |
+
acquired = self._transaction_lock.acquire(blocking=True)
|
| 166 |
+
else:
|
| 167 |
+
acquired = self._transaction_lock.acquire(blocking=True, timeout=timeout)
|
| 168 |
+
if not acquired:
|
| 169 |
+
raise Timeout(self.lock_file) from None
|
| 170 |
+
|
| 171 |
+
def _validate_reentrant(self, mode: Literal["read", "write"], opposite: str, direction: str) -> AcquireReturnProxy:
|
| 172 |
+
if self._current_mode != mode:
|
| 173 |
+
msg = (
|
| 174 |
+
f"Cannot acquire {mode} lock on {self.lock_file} (lock id: {id(self)}): "
|
| 175 |
+
f"already holding a {opposite} lock ({direction} not allowed)"
|
| 176 |
+
)
|
| 177 |
+
raise RuntimeError(msg)
|
| 178 |
+
if mode == "write" and (cur := threading.get_ident()) != self._write_thread_id:
|
| 179 |
+
msg = (
|
| 180 |
+
f"Cannot acquire write lock on {self.lock_file} (lock id: {id(self)}) "
|
| 181 |
+
f"from thread {cur} while it is held by thread {self._write_thread_id}"
|
| 182 |
+
)
|
| 183 |
+
raise RuntimeError(msg)
|
| 184 |
+
self._lock_level += 1
|
| 185 |
+
return AcquireReturnProxy(lock=self)
|
| 186 |
+
|
| 187 |
+
def _configure_and_begin(
|
| 188 |
+
self, mode: Literal["read", "write"], timeout: float, *, blocking: bool, start_time: float
|
| 189 |
+
) -> None:
|
| 190 |
+
waited = time.perf_counter() - start_time
|
| 191 |
+
timeout_ms = timeout_for_sqlite(timeout, blocking=blocking, already_waited=waited)
|
| 192 |
+
self._con.execute(f"PRAGMA busy_timeout={timeout_ms};").close()
|
| 193 |
+
# Use legacy journal mode (not WAL) because WAL does not block readers when a concurrent EXCLUSIVE
|
| 194 |
+
# write transaction is active, making read-write locking impossible without modifying table data.
|
| 195 |
+
# MEMORY is safe here since no actual writes happen — crashes cannot corrupt the DB.
|
| 196 |
+
# See https://sqlite.org/lang_transaction.html#deferred_immediate_and_exclusive_transactions
|
| 197 |
+
#
|
| 198 |
+
# Set here (not in __init__) because this pragma itself may block on a locked database,
|
| 199 |
+
# so it must run after busy_timeout is configured above.
|
| 200 |
+
self._con.execute("PRAGMA journal_mode=MEMORY;").close()
|
| 201 |
+
# Recompute remaining timeout after the potentially blocking journal_mode pragma.
|
| 202 |
+
waited = time.perf_counter() - start_time
|
| 203 |
+
if (recomputed := timeout_for_sqlite(timeout, blocking=blocking, already_waited=waited)) != timeout_ms:
|
| 204 |
+
self._con.execute(f"PRAGMA busy_timeout={recomputed};").close()
|
| 205 |
+
stmt = "BEGIN EXCLUSIVE TRANSACTION;" if mode == "write" else "BEGIN TRANSACTION;"
|
| 206 |
+
self._con.execute(stmt).close()
|
| 207 |
+
if mode == "read":
|
| 208 |
+
# A SELECT is needed to force SQLite to actually acquire the SHARED lock on the database.
|
| 209 |
+
# https://www.sqlite.org/lockingv3.html#transaction_control
|
| 210 |
+
self._con.execute("SELECT name FROM sqlite_schema LIMIT 1;").close()
|
| 211 |
+
|
| 212 |
+
def _acquire(self, mode: Literal["read", "write"], timeout: float, *, blocking: bool) -> AcquireReturnProxy:
|
| 213 |
+
opposite = "write" if mode == "read" else "read"
|
| 214 |
+
direction = "downgrade" if mode == "read" else "upgrade"
|
| 215 |
+
|
| 216 |
+
with self._internal_lock:
|
| 217 |
+
if self._lock_level > 0:
|
| 218 |
+
return self._validate_reentrant(mode, opposite, direction)
|
| 219 |
+
|
| 220 |
+
start_time = time.perf_counter()
|
| 221 |
+
self._acquire_transaction_lock(blocking=blocking, timeout=timeout)
|
| 222 |
+
try:
|
| 223 |
+
# Double-check: another thread may have acquired the lock while we waited on _transaction_lock.
|
| 224 |
+
with self._internal_lock:
|
| 225 |
+
if self._lock_level > 0:
|
| 226 |
+
return self._validate_reentrant(mode, opposite, direction)
|
| 227 |
+
|
| 228 |
+
self._configure_and_begin(mode, timeout, blocking=blocking, start_time=start_time)
|
| 229 |
+
|
| 230 |
+
with self._internal_lock:
|
| 231 |
+
self._current_mode = mode
|
| 232 |
+
self._lock_level = 1
|
| 233 |
+
if mode == "write":
|
| 234 |
+
self._write_thread_id = threading.get_ident()
|
| 235 |
+
|
| 236 |
+
return AcquireReturnProxy(lock=self)
|
| 237 |
+
|
| 238 |
+
except sqlite3.OperationalError as exc:
|
| 239 |
+
if "database is locked" not in str(exc):
|
| 240 |
+
raise
|
| 241 |
+
raise Timeout(self.lock_file) from None
|
| 242 |
+
finally:
|
| 243 |
+
self._transaction_lock.release()
|
| 244 |
+
|
| 245 |
+
def acquire_read(self, timeout: float = -1, *, blocking: bool = True) -> AcquireReturnProxy:
|
| 246 |
+
"""
|
| 247 |
+
Acquire a shared read lock.
|
| 248 |
+
|
| 249 |
+
If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
|
| 250 |
+
read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed).
|
| 251 |
+
|
| 252 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 253 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 254 |
+
|
| 255 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 256 |
+
|
| 257 |
+
:raises RuntimeError: if a write lock is already held on this instance
|
| 258 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 259 |
+
|
| 260 |
+
"""
|
| 261 |
+
return self._acquire("read", timeout, blocking=blocking)
|
| 262 |
+
|
| 263 |
+
def acquire_write(self, timeout: float = -1, *, blocking: bool = True) -> AcquireReturnProxy:
|
| 264 |
+
"""
|
| 265 |
+
Acquire an exclusive write lock.
|
| 266 |
+
|
| 267 |
+
If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
|
| 268 |
+
Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not allowed).
|
| 269 |
+
Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
|
| 270 |
+
:class:`RuntimeError`.
|
| 271 |
+
|
| 272 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 273 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 274 |
+
|
| 275 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 276 |
+
|
| 277 |
+
:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
|
| 278 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 279 |
+
|
| 280 |
+
"""
|
| 281 |
+
return self._acquire("write", timeout, blocking=blocking)
|
| 282 |
+
|
| 283 |
+
def release(self, *, force: bool = False) -> None:
|
| 284 |
+
"""
|
| 285 |
+
Release one level of the current lock.
|
| 286 |
+
|
| 287 |
+
When the lock level reaches zero the underlying SQLite transaction is rolled back, releasing the database lock.
|
| 288 |
+
|
| 289 |
+
:param force: if ``True``, release the lock completely regardless of the current lock level
|
| 290 |
+
|
| 291 |
+
:raises RuntimeError: if no lock is currently held and *force* is ``False``
|
| 292 |
+
|
| 293 |
+
"""
|
| 294 |
+
should_rollback = False
|
| 295 |
+
with self._internal_lock:
|
| 296 |
+
if self._lock_level == 0:
|
| 297 |
+
if force:
|
| 298 |
+
return
|
| 299 |
+
msg = f"Cannot release a lock on {self.lock_file} (lock id: {id(self)}) that is not held"
|
| 300 |
+
raise RuntimeError(msg)
|
| 301 |
+
if force:
|
| 302 |
+
self._lock_level = 0
|
| 303 |
+
else:
|
| 304 |
+
self._lock_level -= 1
|
| 305 |
+
if self._lock_level == 0:
|
| 306 |
+
self._current_mode = None
|
| 307 |
+
self._write_thread_id = None
|
| 308 |
+
should_rollback = True
|
| 309 |
+
if should_rollback:
|
| 310 |
+
self._con.rollback()
|
| 311 |
+
|
| 312 |
+
@contextmanager
|
| 313 |
+
def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 314 |
+
"""
|
| 315 |
+
Context manager that acquires and releases a shared read lock.
|
| 316 |
+
|
| 317 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 318 |
+
|
| 319 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 320 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 321 |
+
|
| 322 |
+
"""
|
| 323 |
+
if timeout is None:
|
| 324 |
+
timeout = self.timeout
|
| 325 |
+
if blocking is None:
|
| 326 |
+
blocking = self.blocking
|
| 327 |
+
self.acquire_read(timeout, blocking=blocking)
|
| 328 |
+
try:
|
| 329 |
+
yield
|
| 330 |
+
finally:
|
| 331 |
+
self.release()
|
| 332 |
+
|
| 333 |
+
@contextmanager
|
| 334 |
+
def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 335 |
+
"""
|
| 336 |
+
Context manager that acquires and releases an exclusive write lock.
|
| 337 |
+
|
| 338 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 339 |
+
|
| 340 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 341 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 342 |
+
|
| 343 |
+
"""
|
| 344 |
+
if timeout is None:
|
| 345 |
+
timeout = self.timeout
|
| 346 |
+
if blocking is None:
|
| 347 |
+
blocking = self.blocking
|
| 348 |
+
self.acquire_write(timeout, blocking=blocking)
|
| 349 |
+
try:
|
| 350 |
+
yield
|
| 351 |
+
finally:
|
| 352 |
+
self.release()
|
| 353 |
+
|
| 354 |
+
def close(self) -> None:
|
| 355 |
+
"""
|
| 356 |
+
Release the lock (if held) and close the underlying SQLite connection.
|
| 357 |
+
|
| 358 |
+
After calling this method, the lock instance is no longer usable.
|
| 359 |
+
|
| 360 |
+
"""
|
| 361 |
+
self.release(force=True)
|
| 362 |
+
self._con.close()
|
| 363 |
+
with _all_connections_lock:
|
| 364 |
+
_all_connections.discard(self._con)
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_soft.py
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
+
import time
|
| 7 |
+
from contextlib import suppress
|
| 8 |
+
from errno import EACCES, EEXIST, EPERM, ESRCH
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
from ._api import BaseFileLock
|
| 12 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
| 13 |
+
|
| 14 |
+
_WIN_SYNCHRONIZE = 0x100000
|
| 15 |
+
_WIN_ERROR_INVALID_PARAMETER = 87
|
| 16 |
+
_WIN_PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
| 17 |
+
_MALFORMED_LOCK_AGE_THRESHOLD = 2.0
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class SoftFileLock(BaseFileLock):
|
| 21 |
+
"""
|
| 22 |
+
Portable file lock based on file existence.
|
| 23 |
+
|
| 24 |
+
Unlike :class:`UnixFileLock <filelock.UnixFileLock>` and :class:`WindowsFileLock <filelock.WindowsFileLock>`, this
|
| 25 |
+
lock does not use OS-level locking primitives. Instead, it creates the lock file with ``O_CREAT | O_EXCL`` and
|
| 26 |
+
treats its existence as the lock indicator. This makes it work on any filesystem but leaves stale lock files behind
|
| 27 |
+
if the process crashes without releasing the lock.
|
| 28 |
+
|
| 29 |
+
To mitigate stale locks, the lock file contains the PID and hostname of the holding process. On contention, if the
|
| 30 |
+
holder is on the same host and its PID no longer exists, the stale lock is broken automatically.
|
| 31 |
+
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def _acquire(self) -> None:
|
| 35 |
+
raise_on_not_writable_file(self.lock_file)
|
| 36 |
+
ensure_directory_exists(self.lock_file)
|
| 37 |
+
flags = (
|
| 38 |
+
os.O_WRONLY # open for writing only
|
| 39 |
+
| os.O_CREAT
|
| 40 |
+
| os.O_EXCL # together with above raise EEXIST if the file specified by filename exists
|
| 41 |
+
| os.O_TRUNC # truncate the file to zero byte
|
| 42 |
+
)
|
| 43 |
+
if (o_nofollow := getattr(os, "O_NOFOLLOW", None)) is not None:
|
| 44 |
+
flags |= o_nofollow
|
| 45 |
+
try:
|
| 46 |
+
file_handler = os.open(self.lock_file, flags, self._open_mode())
|
| 47 |
+
except OSError as exception:
|
| 48 |
+
if not (
|
| 49 |
+
exception.errno == EEXIST or (exception.errno == EACCES and sys.platform == "win32")
|
| 50 |
+
): # pragma: win32 no cover
|
| 51 |
+
raise
|
| 52 |
+
self._try_break_stale_lock()
|
| 53 |
+
else:
|
| 54 |
+
self._write_lock_info(file_handler)
|
| 55 |
+
self._context.lock_file_fd = file_handler
|
| 56 |
+
|
| 57 |
+
def _try_break_stale_lock(self) -> None:
|
| 58 |
+
with suppress(OSError, ValueError):
|
| 59 |
+
lock_path = Path(self.lock_file)
|
| 60 |
+
stat_result = lock_path.stat()
|
| 61 |
+
content = lock_path.read_text(encoding="utf-8")
|
| 62 |
+
lines = content.strip().splitlines()
|
| 63 |
+
|
| 64 |
+
if len(lines) not in {2, 3}:
|
| 65 |
+
if time.time() - stat_result.st_mtime >= _MALFORMED_LOCK_AGE_THRESHOLD:
|
| 66 |
+
self._evict_lock_file()
|
| 67 |
+
return
|
| 68 |
+
|
| 69 |
+
pid_str, hostname = lines[0], lines[1]
|
| 70 |
+
creation_time_str = lines[2] if len(lines) == 3 else None # noqa: PLR2004
|
| 71 |
+
|
| 72 |
+
if hostname != socket.gethostname():
|
| 73 |
+
return
|
| 74 |
+
|
| 75 |
+
pid = int(pid_str)
|
| 76 |
+
|
| 77 |
+
if self._is_process_alive(pid):
|
| 78 |
+
if sys.platform == "win32" and creation_time_str is not None: # pragma: win32 cover
|
| 79 |
+
stored = int(creation_time_str)
|
| 80 |
+
actual = self._get_process_creation_time(pid)
|
| 81 |
+
if actual is not None and actual != stored:
|
| 82 |
+
pass # PID recycled, fall through to evict
|
| 83 |
+
else:
|
| 84 |
+
return # same process or can't verify — don't evict
|
| 85 |
+
else:
|
| 86 |
+
return
|
| 87 |
+
|
| 88 |
+
self._evict_lock_file()
|
| 89 |
+
|
| 90 |
+
def _evict_lock_file(self) -> None:
|
| 91 |
+
break_path = f"{self.lock_file}.break.{os.getpid()}"
|
| 92 |
+
Path(self.lock_file).rename(break_path)
|
| 93 |
+
Path(break_path).unlink()
|
| 94 |
+
|
| 95 |
+
@staticmethod
|
| 96 |
+
def _is_process_alive(pid: int) -> bool:
|
| 97 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 98 |
+
import ctypes # noqa: PLC0415
|
| 99 |
+
|
| 100 |
+
kernel32 = ctypes.windll.kernel32
|
| 101 |
+
handle = kernel32.OpenProcess(_WIN_SYNCHRONIZE, 0, pid)
|
| 102 |
+
if handle:
|
| 103 |
+
kernel32.CloseHandle(handle)
|
| 104 |
+
return True
|
| 105 |
+
return kernel32.GetLastError() != _WIN_ERROR_INVALID_PARAMETER
|
| 106 |
+
try:
|
| 107 |
+
os.kill(pid, 0)
|
| 108 |
+
except OSError as exc:
|
| 109 |
+
if exc.errno == ESRCH:
|
| 110 |
+
return False
|
| 111 |
+
if exc.errno == EPERM:
|
| 112 |
+
return True
|
| 113 |
+
raise
|
| 114 |
+
return True
|
| 115 |
+
|
| 116 |
+
@staticmethod
|
| 117 |
+
def _get_process_creation_time(pid: int) -> int | None:
|
| 118 |
+
"""Return the process creation FILETIME as an integer on Windows, ``None`` otherwise."""
|
| 119 |
+
if sys.platform != "win32": # pragma: win32 no cover
|
| 120 |
+
return None
|
| 121 |
+
import ctypes # pragma: win32 cover # noqa: PLC0415
|
| 122 |
+
from ctypes import wintypes # noqa: PLC0415
|
| 123 |
+
|
| 124 |
+
kernel32 = ctypes.windll.kernel32
|
| 125 |
+
handle = kernel32.OpenProcess(_WIN_PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
|
| 126 |
+
if not handle:
|
| 127 |
+
return None
|
| 128 |
+
try:
|
| 129 |
+
creation = wintypes.FILETIME()
|
| 130 |
+
exit_time = wintypes.FILETIME()
|
| 131 |
+
kernel_time = wintypes.FILETIME()
|
| 132 |
+
user_time = wintypes.FILETIME()
|
| 133 |
+
if not kernel32.GetProcessTimes(
|
| 134 |
+
handle,
|
| 135 |
+
ctypes.byref(creation),
|
| 136 |
+
ctypes.byref(exit_time),
|
| 137 |
+
ctypes.byref(kernel_time),
|
| 138 |
+
ctypes.byref(user_time),
|
| 139 |
+
):
|
| 140 |
+
return None
|
| 141 |
+
finally:
|
| 142 |
+
kernel32.CloseHandle(handle)
|
| 143 |
+
return (creation.dwHighDateTime << 32) | creation.dwLowDateTime
|
| 144 |
+
|
| 145 |
+
@staticmethod
|
| 146 |
+
def _write_lock_info(fd: int) -> None:
|
| 147 |
+
with suppress(OSError):
|
| 148 |
+
info = f"{os.getpid()}\n{socket.gethostname()}\n"
|
| 149 |
+
if sys.platform == "win32" and (ct := SoftFileLock._get_process_creation_time(os.getpid())) is not None:
|
| 150 |
+
info += f"{ct}\n"
|
| 151 |
+
os.write(fd, info.encode())
|
| 152 |
+
|
| 153 |
+
@property
|
| 154 |
+
def pid(self) -> int | None:
|
| 155 |
+
"""
|
| 156 |
+
The PID of the process holding this lock, read from the lock file.
|
| 157 |
+
|
| 158 |
+
:returns: the PID as an integer, or ``None`` if the lock file does not exist or cannot be parsed
|
| 159 |
+
|
| 160 |
+
"""
|
| 161 |
+
try:
|
| 162 |
+
content = Path(self.lock_file).read_text(encoding="utf-8")
|
| 163 |
+
lines = content.strip().splitlines()
|
| 164 |
+
if lines:
|
| 165 |
+
return int(lines[0])
|
| 166 |
+
except (OSError, ValueError):
|
| 167 |
+
pass
|
| 168 |
+
return None
|
| 169 |
+
|
| 170 |
+
@property
|
| 171 |
+
def is_lock_held_by_us(self) -> bool:
|
| 172 |
+
"""
|
| 173 |
+
Whether this lock is held by the current process.
|
| 174 |
+
|
| 175 |
+
:returns: ``True`` if the lock file exists and contains the current process's PID
|
| 176 |
+
|
| 177 |
+
"""
|
| 178 |
+
return self.pid == os.getpid()
|
| 179 |
+
|
| 180 |
+
def break_lock(self) -> None:
|
| 181 |
+
"""Forcibly break the lock by removing the lock file, regardless of who holds it."""
|
| 182 |
+
with suppress(OSError):
|
| 183 |
+
Path(self.lock_file).unlink()
|
| 184 |
+
|
| 185 |
+
def _release(self) -> None:
|
| 186 |
+
assert self._context.lock_file_fd is not None # noqa: S101
|
| 187 |
+
os.close(self._context.lock_file_fd)
|
| 188 |
+
self._context.lock_file_fd = None
|
| 189 |
+
if sys.platform == "win32":
|
| 190 |
+
self._windows_unlink_with_retry()
|
| 191 |
+
else:
|
| 192 |
+
with suppress(OSError):
|
| 193 |
+
Path(self.lock_file).unlink()
|
| 194 |
+
|
| 195 |
+
def _windows_unlink_with_retry(self) -> None:
|
| 196 |
+
max_retries = 10
|
| 197 |
+
retry_delay = 0.001
|
| 198 |
+
for attempt in range(max_retries):
|
| 199 |
+
# Windows doesn't immediately release file handles after close, causing EACCES/EPERM on unlink
|
| 200 |
+
try:
|
| 201 |
+
Path(self.lock_file).unlink()
|
| 202 |
+
except OSError as exc: # noqa: PERF203
|
| 203 |
+
if exc.errno not in {EACCES, EPERM}:
|
| 204 |
+
return
|
| 205 |
+
if attempt < max_retries - 1:
|
| 206 |
+
time.sleep(retry_delay)
|
| 207 |
+
retry_delay *= 2
|
| 208 |
+
else:
|
| 209 |
+
return
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
__all__ = [
|
| 213 |
+
"SoftFileLock",
|
| 214 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_soft_rw/_async.py
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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SoftReadWriteLock` for use with ``asyncio``."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import functools
|
| 7 |
+
from contextlib import asynccontextmanager
|
| 8 |
+
from typing import TYPE_CHECKING
|
| 9 |
+
|
| 10 |
+
from ._sync import SoftReadWriteLock
|
| 11 |
+
|
| 12 |
+
if TYPE_CHECKING:
|
| 13 |
+
import os
|
| 14 |
+
from collections.abc import AsyncGenerator, Callable
|
| 15 |
+
from concurrent import futures
|
| 16 |
+
from types import TracebackType
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class AsyncAcquireSoftReadWriteReturnProxy:
|
| 20 |
+
"""Async context-aware object that releases an :class:`AsyncSoftReadWriteLock` on exit."""
|
| 21 |
+
|
| 22 |
+
def __init__(self, lock: AsyncSoftReadWriteLock) -> None:
|
| 23 |
+
self.lock = lock
|
| 24 |
+
|
| 25 |
+
async def __aenter__(self) -> AsyncSoftReadWriteLock:
|
| 26 |
+
return self.lock
|
| 27 |
+
|
| 28 |
+
async def __aexit__(
|
| 29 |
+
self,
|
| 30 |
+
exc_type: type[BaseException] | None,
|
| 31 |
+
exc_value: BaseException | None,
|
| 32 |
+
traceback: TracebackType | None,
|
| 33 |
+
) -> None:
|
| 34 |
+
await self.lock.release()
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class AsyncSoftReadWriteLock:
|
| 38 |
+
"""
|
| 39 |
+
Async wrapper around :class:`SoftReadWriteLock` for ``asyncio`` applications.
|
| 40 |
+
|
| 41 |
+
The sync class's blocking filesystem operations run on a thread pool via ``loop.run_in_executor()``.
|
| 42 |
+
Reentrancy, upgrade/downgrade rules, fork handling, heartbeat and TTL stale detection, and singleton
|
| 43 |
+
behavior are delegated to the underlying :class:`SoftReadWriteLock`.
|
| 44 |
+
|
| 45 |
+
:param lock_file: path to the lock file; sidecar state/write/readers live next to it
|
| 46 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 47 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
|
| 48 |
+
:param is_singleton: if ``True``, reuse existing :class:`SoftReadWriteLock` instances per resolved path
|
| 49 |
+
:param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
|
| 50 |
+
:param stale_threshold: seconds of mtime inactivity before a marker is stale; defaults to ``3 * heartbeat_interval``
|
| 51 |
+
:param poll_interval: seconds between acquire retries under contention; default 0.25 s
|
| 52 |
+
:param loop: event loop for ``run_in_executor``; ``None`` uses the running loop
|
| 53 |
+
:param executor: executor for ``run_in_executor``; ``None`` uses the default executor
|
| 54 |
+
|
| 55 |
+
.. versionadded:: 3.27.0
|
| 56 |
+
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def __init__( # noqa: PLR0913
|
| 60 |
+
self,
|
| 61 |
+
lock_file: str | os.PathLike[str],
|
| 62 |
+
timeout: float = -1,
|
| 63 |
+
*,
|
| 64 |
+
blocking: bool = True,
|
| 65 |
+
is_singleton: bool = True,
|
| 66 |
+
heartbeat_interval: float = 30.0,
|
| 67 |
+
stale_threshold: float | None = None,
|
| 68 |
+
poll_interval: float = 0.25,
|
| 69 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 70 |
+
executor: futures.Executor | None = None,
|
| 71 |
+
) -> None:
|
| 72 |
+
self._lock = SoftReadWriteLock(
|
| 73 |
+
lock_file,
|
| 74 |
+
timeout,
|
| 75 |
+
blocking=blocking,
|
| 76 |
+
is_singleton=is_singleton,
|
| 77 |
+
heartbeat_interval=heartbeat_interval,
|
| 78 |
+
stale_threshold=stale_threshold,
|
| 79 |
+
poll_interval=poll_interval,
|
| 80 |
+
)
|
| 81 |
+
self._loop = loop
|
| 82 |
+
self._executor = executor
|
| 83 |
+
|
| 84 |
+
@property
|
| 85 |
+
def lock_file(self) -> str:
|
| 86 |
+
""":returns: the path to the lock file passed to the constructor."""
|
| 87 |
+
return self._lock.lock_file
|
| 88 |
+
|
| 89 |
+
@property
|
| 90 |
+
def timeout(self) -> float:
|
| 91 |
+
""":returns: the default timeout applied when ``acquire_read`` / ``acquire_write`` is called without one."""
|
| 92 |
+
return self._lock.timeout
|
| 93 |
+
|
| 94 |
+
@property
|
| 95 |
+
def blocking(self) -> bool:
|
| 96 |
+
""":returns: whether ``acquire_*`` defaults to blocking; ``False`` makes contention raise immediately."""
|
| 97 |
+
return self._lock.blocking
|
| 98 |
+
|
| 99 |
+
@property
|
| 100 |
+
def loop(self) -> asyncio.AbstractEventLoop | None:
|
| 101 |
+
""":returns: the event loop used for ``run_in_executor``, or ``None`` for the running loop."""
|
| 102 |
+
return self._loop
|
| 103 |
+
|
| 104 |
+
@property
|
| 105 |
+
def executor(self) -> futures.Executor | None:
|
| 106 |
+
""":returns: the executor used for ``run_in_executor``, or ``None`` for the default executor."""
|
| 107 |
+
return self._executor
|
| 108 |
+
|
| 109 |
+
async def acquire_read(
|
| 110 |
+
self, timeout: float | None = None, *, blocking: bool | None = None
|
| 111 |
+
) -> AsyncAcquireSoftReadWriteReturnProxy:
|
| 112 |
+
"""
|
| 113 |
+
Acquire a shared read lock.
|
| 114 |
+
|
| 115 |
+
See :meth:`SoftReadWriteLock.acquire_read` for the full reentrancy / upgrade / fork semantics. The blocking
|
| 116 |
+
work runs inside ``run_in_executor`` so other coroutines on the same loop continue to progress while this
|
| 117 |
+
call waits.
|
| 118 |
+
|
| 119 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 120 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 121 |
+
|
| 122 |
+
:returns: a proxy usable as an async context manager to release the lock
|
| 123 |
+
|
| 124 |
+
:raises RuntimeError: if a write lock is already held, if this instance was invalidated by
|
| 125 |
+
:func:`os.fork`, or if :meth:`close` was called
|
| 126 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 127 |
+
|
| 128 |
+
"""
|
| 129 |
+
await self._run(self._lock.acquire_read, timeout, blocking=blocking)
|
| 130 |
+
return AsyncAcquireSoftReadWriteReturnProxy(lock=self)
|
| 131 |
+
|
| 132 |
+
async def acquire_write(
|
| 133 |
+
self, timeout: float | None = None, *, blocking: bool | None = None
|
| 134 |
+
) -> AsyncAcquireSoftReadWriteReturnProxy:
|
| 135 |
+
"""
|
| 136 |
+
Acquire an exclusive write lock.
|
| 137 |
+
|
| 138 |
+
See :meth:`SoftReadWriteLock.acquire_write` for the two-phase writer-preferring semantics. The blocking
|
| 139 |
+
work runs inside ``run_in_executor``.
|
| 140 |
+
|
| 141 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 142 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 143 |
+
|
| 144 |
+
:returns: a proxy usable as an async context manager to release the lock
|
| 145 |
+
|
| 146 |
+
:raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if
|
| 147 |
+
this instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
|
| 148 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 149 |
+
|
| 150 |
+
"""
|
| 151 |
+
await self._run(self._lock.acquire_write, timeout, blocking=blocking)
|
| 152 |
+
return AsyncAcquireSoftReadWriteReturnProxy(lock=self)
|
| 153 |
+
|
| 154 |
+
async def release(self, *, force: bool = False) -> None:
|
| 155 |
+
"""
|
| 156 |
+
Release one level of the current lock.
|
| 157 |
+
|
| 158 |
+
:param force: if ``True``, release the lock completely regardless of the current lock level
|
| 159 |
+
|
| 160 |
+
:raises RuntimeError: if no lock is currently held and *force* is ``False``
|
| 161 |
+
|
| 162 |
+
"""
|
| 163 |
+
await self._run(self._lock.release, force=force)
|
| 164 |
+
|
| 165 |
+
@asynccontextmanager
|
| 166 |
+
async def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:
|
| 167 |
+
"""
|
| 168 |
+
Async context manager that acquires and releases a shared read lock.
|
| 169 |
+
|
| 170 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 171 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 172 |
+
|
| 173 |
+
:raises RuntimeError: if a write lock is already held on this instance
|
| 174 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 175 |
+
|
| 176 |
+
"""
|
| 177 |
+
await self.acquire_read(timeout, blocking=blocking)
|
| 178 |
+
try:
|
| 179 |
+
yield
|
| 180 |
+
finally:
|
| 181 |
+
await self.release()
|
| 182 |
+
|
| 183 |
+
@asynccontextmanager
|
| 184 |
+
async def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> AsyncGenerator[None]:
|
| 185 |
+
"""
|
| 186 |
+
Async context manager that acquires and releases an exclusive write lock.
|
| 187 |
+
|
| 188 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 189 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 190 |
+
|
| 191 |
+
:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
|
| 192 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 193 |
+
|
| 194 |
+
"""
|
| 195 |
+
await self.acquire_write(timeout, blocking=blocking)
|
| 196 |
+
try:
|
| 197 |
+
yield
|
| 198 |
+
finally:
|
| 199 |
+
await self.release()
|
| 200 |
+
|
| 201 |
+
async def close(self) -> None:
|
| 202 |
+
"""Release any held lock and release the underlying filesystem resources. Idempotent."""
|
| 203 |
+
await self._run(self._lock.close)
|
| 204 |
+
|
| 205 |
+
async def _run(self, func: Callable[..., object], *args: object, **kwargs: object) -> object:
|
| 206 |
+
loop = self._loop or asyncio.get_running_loop()
|
| 207 |
+
return await loop.run_in_executor(self._executor, functools.partial(func, *args, **kwargs))
|
| 208 |
+
|
| 209 |
+
|
| 210 |
+
__all__ = [
|
| 211 |
+
"AsyncAcquireSoftReadWriteReturnProxy",
|
| 212 |
+
"AsyncSo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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Cross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import atexit
|
| 6 |
+
import hmac
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
import secrets
|
| 10 |
+
import socket
|
| 11 |
+
import stat
|
| 12 |
+
import sys
|
| 13 |
+
import threading
|
| 14 |
+
import time
|
| 15 |
+
import uuid
|
| 16 |
+
from contextlib import contextmanager, suppress
|
| 17 |
+
from dataclasses import dataclass
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
from typing import TYPE_CHECKING, Literal
|
| 20 |
+
from weakref import WeakValueDictionary
|
| 21 |
+
|
| 22 |
+
from filelock._api import AcquireReturnProxy
|
| 23 |
+
from filelock._error import Timeout
|
| 24 |
+
from filelock._soft import SoftFileLock
|
| 25 |
+
from filelock._util import ensure_directory_exists
|
| 26 |
+
|
| 27 |
+
if TYPE_CHECKING:
|
| 28 |
+
from collections.abc import Callable, Generator
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
_Mode = Literal["read", "write"]
|
| 32 |
+
_BREAK_SUFFIX = ".break"
|
| 33 |
+
_MAX_MARKER_SIZE = 1024
|
| 34 |
+
_O_NOFOLLOW = getattr(os, "O_NOFOLLOW", 0)
|
| 35 |
+
# dirfd-relative I/O is a Unix-only optimization; Windows cannot ``os.open()`` a directory at all, and
|
| 36 |
+
# its ``os`` module skips dir_fd support entirely. When disabled, callers fall back to full-path ops.
|
| 37 |
+
_SUPPORTS_DIR_FD = sys.platform != "win32" and os.open in os.supports_dir_fd
|
| 38 |
+
|
| 39 |
+
_all_instances: WeakValueDictionary[Path, SoftReadWriteLock] = WeakValueDictionary()
|
| 40 |
+
_all_instances_lock = threading.Lock()
|
| 41 |
+
_atexit_registered = False
|
| 42 |
+
_fork_registered = False
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@dataclass(frozen=True)
|
| 46 |
+
class _Paths:
|
| 47 |
+
state: str
|
| 48 |
+
write: str
|
| 49 |
+
readers: str
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@dataclass
|
| 53 |
+
class _Locks:
|
| 54 |
+
internal: threading.Lock
|
| 55 |
+
transaction: threading.Lock
|
| 56 |
+
state: SoftFileLock
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
@dataclass(frozen=True)
|
| 60 |
+
class _MarkerInfo:
|
| 61 |
+
token: str
|
| 62 |
+
pid: int
|
| 63 |
+
hostname: str
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@dataclass
|
| 67 |
+
class _Hold:
|
| 68 |
+
"""Everything that exists only while a lock is held; ``None`` when the instance has no lock."""
|
| 69 |
+
|
| 70 |
+
level: int
|
| 71 |
+
mode: _Mode
|
| 72 |
+
write_thread_id: int | None
|
| 73 |
+
marker_name: str
|
| 74 |
+
is_reader: bool
|
| 75 |
+
token: str
|
| 76 |
+
heartbeat_thread: _HeartbeatThread
|
| 77 |
+
heartbeat_stop: threading.Event
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
class _SoftRWMeta(type):
|
| 81 |
+
_instances: WeakValueDictionary[Path, SoftReadWriteLock]
|
| 82 |
+
_instances_lock: threading.Lock
|
| 83 |
+
|
| 84 |
+
def __call__( # noqa: PLR0913
|
| 85 |
+
cls,
|
| 86 |
+
lock_file: str | os.PathLike[str],
|
| 87 |
+
timeout: float = -1,
|
| 88 |
+
*,
|
| 89 |
+
blocking: bool = True,
|
| 90 |
+
is_singleton: bool = True,
|
| 91 |
+
heartbeat_interval: float = 30.0,
|
| 92 |
+
stale_threshold: float | None = None,
|
| 93 |
+
poll_interval: float = 0.25,
|
| 94 |
+
) -> SoftReadWriteLock:
|
| 95 |
+
if not is_singleton:
|
| 96 |
+
return super().__call__(
|
| 97 |
+
lock_file,
|
| 98 |
+
timeout,
|
| 99 |
+
blocking=blocking,
|
| 100 |
+
is_singleton=is_singleton,
|
| 101 |
+
heartbeat_interval=heartbeat_interval,
|
| 102 |
+
stale_threshold=stale_threshold,
|
| 103 |
+
poll_interval=poll_interval,
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
normalized = Path(lock_file).resolve()
|
| 107 |
+
with cls._instances_lock:
|
| 108 |
+
instance = cls._instances.get(normalized)
|
| 109 |
+
if instance is None:
|
| 110 |
+
instance = super().__call__(
|
| 111 |
+
lock_file,
|
| 112 |
+
timeout,
|
| 113 |
+
blocking=blocking,
|
| 114 |
+
is_singleton=is_singleton,
|
| 115 |
+
heartbeat_interval=heartbeat_interval,
|
| 116 |
+
stale_threshold=stale_threshold,
|
| 117 |
+
poll_interval=poll_interval,
|
| 118 |
+
)
|
| 119 |
+
cls._instances[normalized] = instance
|
| 120 |
+
elif instance.timeout != timeout or instance.blocking != blocking:
|
| 121 |
+
msg = (
|
| 122 |
+
f"Singleton lock created with timeout={instance.timeout}, blocking={instance.blocking},"
|
| 123 |
+
f" cannot be changed to timeout={timeout}, blocking={blocking}"
|
| 124 |
+
)
|
| 125 |
+
raise ValueError(msg)
|
| 126 |
+
return instance
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
class SoftReadWriteLock(metaclass=_SoftRWMeta):
|
| 130 |
+
"""
|
| 131 |
+
Cross-process and cross-host reader/writer lock built on :class:`SoftFileLock` primitives.
|
| 132 |
+
|
| 133 |
+
Use this class instead of :class:`~filelock.ReadWriteLock` when the lock file lives on a network
|
| 134 |
+
filesystem (NFS, Lustre with ``-o flock``, HPC cluster shared storage). ``ReadWriteLock`` is backed
|
| 135 |
+
by SQLite and cannot run on NFS because SQLite's ``fcntl`` locking is unreliable there.
|
| 136 |
+
|
| 137 |
+
Layout on disk for a lock at ``foo.lock``:
|
| 138 |
+
|
| 139 |
+
- ``foo.lock.state`` — a :class:`SoftFileLock` taken only during state transitions (microseconds).
|
| 140 |
+
- ``foo.lock.write`` — writer marker; its presence means a writer is claiming or holding the lock.
|
| 141 |
+
- ``foo.lock.readers/<host>.<pid>.<uuid>`` — one file per reader.
|
| 142 |
+
|
| 143 |
+
Each marker stores a random token (``secrets.token_hex(16)``), the holder's pid, and the holder's
|
| 144 |
+
hostname. A daemon heartbeat thread refreshes ``mtime`` on every held marker. A marker whose mtime
|
| 145 |
+
has not advanced in ``stale_threshold`` seconds may be evicted by any process on any host, giving
|
| 146 |
+
correct behavior when a compute node crashes with a lock held.
|
| 147 |
+
|
| 148 |
+
Writer acquire is two-phase and writer-preferring: phase 1 claims ``.write`` (blocking any new
|
| 149 |
+
reader), phase 2 waits for existing readers to drain. Writer starvation is impossible.
|
| 150 |
+
|
| 151 |
+
Reentrancy, upgrade/downgrade rules, thread pinning, and singleton caching by resolved path match
|
| 152 |
+
:class:`~filelock.ReadWriteLock`.
|
| 153 |
+
|
| 154 |
+
Forking while holding a lock invalidates the inherited instance in the child so the child cannot
|
| 155 |
+
double-own the lock with its parent; ``release()`` on a fork-invalidated instance is a no-op, and
|
| 156 |
+
the child must re-acquire if it needs a lock.
|
| 157 |
+
|
| 158 |
+
Trust boundary: protects against same-UID non-cooperating processes (one host or cross-host) and
|
| 159 |
+
same-host different-UID users via ``0o600`` / ``0o700`` permissions. Does not protect against root
|
| 160 |
+
compromise, NTP tampering on same-UID cross-host nodes, or multi-tenant mounts where hostile
|
| 161 |
+
co-tenants share the UID.
|
| 162 |
+
|
| 163 |
+
:param lock_file: path to the lock file; sidecar state/write/readers live next to it
|
| 164 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 165 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately on contention
|
| 166 |
+
:param is_singleton: if ``True``, reuse existing instances for the same resolved path
|
| 167 |
+
:param heartbeat_interval: seconds between heartbeat refreshes; default 30 s
|
| 168 |
+
:param stale_threshold: seconds of ``mtime`` inactivity before a marker is stale; defaults to
|
| 169 |
+
``3 * heartbeat_interval``, matching etcd's ``LeaseKeepAlive`` convention
|
| 170 |
+
:param poll_interval: seconds between acquire retries under contention; default 0.25 s
|
| 171 |
+
|
| 172 |
+
.. versionadded:: 3.27.0
|
| 173 |
+
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
_instances: WeakValueDictionary[Path, SoftReadWriteLock] = WeakValueDictionary()
|
| 177 |
+
_instances_lock = threading.Lock()
|
| 178 |
+
|
| 179 |
+
def __init__( # noqa: PLR0913
|
| 180 |
+
self,
|
| 181 |
+
lock_file: str | os.PathLike[str],
|
| 182 |
+
timeout: float = -1,
|
| 183 |
+
*,
|
| 184 |
+
blocking: bool = True,
|
| 185 |
+
is_singleton: bool = True, # noqa: ARG002
|
| 186 |
+
heartbeat_interval: float = 30.0,
|
| 187 |
+
stale_threshold: float | None = None,
|
| 188 |
+
poll_interval: float = 0.25,
|
| 189 |
+
) -> None:
|
| 190 |
+
if heartbeat_interval <= 0:
|
| 191 |
+
msg = f"heartbeat_interval must be positive, got {heartbeat_interval}"
|
| 192 |
+
raise ValueError(msg)
|
| 193 |
+
if stale_threshold is None:
|
| 194 |
+
stale_threshold = heartbeat_interval * 3
|
| 195 |
+
if stale_threshold <= heartbeat_interval:
|
| 196 |
+
msg = f"stale_threshold must exceed heartbeat_interval ({stale_threshold} <= {heartbeat_interval})"
|
| 197 |
+
raise ValueError(msg)
|
| 198 |
+
if poll_interval <= 0:
|
| 199 |
+
msg = f"poll_interval must be positive, got {poll_interval}"
|
| 200 |
+
raise ValueError(msg)
|
| 201 |
+
|
| 202 |
+
self.lock_file: str = os.fspath(lock_file)
|
| 203 |
+
self.timeout: float = timeout
|
| 204 |
+
self.blocking: bool = blocking
|
| 205 |
+
self.heartbeat_interval: float = heartbeat_interval
|
| 206 |
+
self.stale_threshold: float = stale_threshold
|
| 207 |
+
self.poll_interval: float = poll_interval
|
| 208 |
+
|
| 209 |
+
self._paths = _Paths(
|
| 210 |
+
state=f"{self.lock_file}.state",
|
| 211 |
+
write=f"{self.lock_file}.write",
|
| 212 |
+
readers=f"{self.lock_file}.readers",
|
| 213 |
+
)
|
| 214 |
+
ensure_directory_exists(self.lock_file)
|
| 215 |
+
self._locks = _Locks(
|
| 216 |
+
internal=threading.Lock(),
|
| 217 |
+
transaction=threading.Lock(),
|
| 218 |
+
state=SoftFileLock(self._paths.state, timeout=-1),
|
| 219 |
+
)
|
| 220 |
+
self._readers_dir_fd: int | None = None
|
| 221 |
+
self._hold: _Hold | None = None
|
| 222 |
+
self._fork_invalidated: bool = False
|
| 223 |
+
self._closed: bool = False
|
| 224 |
+
|
| 225 |
+
with _all_instances_lock:
|
| 226 |
+
_all_instances[Path(self.lock_file).resolve()] = self
|
| 227 |
+
_register_hooks()
|
| 228 |
+
|
| 229 |
+
@contextmanager
|
| 230 |
+
def read_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 231 |
+
"""
|
| 232 |
+
Context manager that acquires and releases a shared read lock.
|
| 233 |
+
|
| 234 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 235 |
+
|
| 236 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 237 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 238 |
+
|
| 239 |
+
:raises RuntimeError: if a write lock is already held on this instance
|
| 240 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 241 |
+
|
| 242 |
+
"""
|
| 243 |
+
self.acquire_read(timeout, blocking=blocking)
|
| 244 |
+
try:
|
| 245 |
+
yield
|
| 246 |
+
finally:
|
| 247 |
+
self.release()
|
| 248 |
+
|
| 249 |
+
@contextmanager
|
| 250 |
+
def write_lock(self, timeout: float | None = None, *, blocking: bool | None = None) -> Generator[None]:
|
| 251 |
+
"""
|
| 252 |
+
Context manager that acquires and releases an exclusive write lock.
|
| 253 |
+
|
| 254 |
+
Falls back to instance defaults for *timeout* and *blocking* when ``None``.
|
| 255 |
+
|
| 256 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default
|
| 257 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately; ``None`` uses the instance default
|
| 258 |
+
|
| 259 |
+
:raises RuntimeError: if a read lock is already held, or a write lock is held by a different thread
|
| 260 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 261 |
+
|
| 262 |
+
"""
|
| 263 |
+
self.acquire_write(timeout, blocking=blocking)
|
| 264 |
+
try:
|
| 265 |
+
yield
|
| 266 |
+
finally:
|
| 267 |
+
self.release()
|
| 268 |
+
|
| 269 |
+
def acquire_read(self, timeout: float | None = None, *, blocking: bool | None = None) -> AcquireReturnProxy:
|
| 270 |
+
"""
|
| 271 |
+
Acquire a shared read lock.
|
| 272 |
+
|
| 273 |
+
If this instance already holds a read lock, the lock level is incremented (reentrant). Attempting to acquire a
|
| 274 |
+
read lock while holding a write lock raises :class:`RuntimeError` (downgrade not allowed). On the 0→1
|
| 275 |
+
transition a daemon heartbeat thread is started that refreshes the reader marker's ``mtime`` every
|
| 276 |
+
``heartbeat_interval`` seconds so peers on other hosts do not evict the marker as stale.
|
| 277 |
+
|
| 278 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
|
| 279 |
+
indefinitely
|
| 280 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
|
| 281 |
+
``None`` uses the instance default
|
| 282 |
+
|
| 283 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 284 |
+
|
| 285 |
+
:raises RuntimeError: if a write lock is already held on this instance, if this instance was invalidated by
|
| 286 |
+
:func:`os.fork`, or if :meth:`close` was called
|
| 287 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 288 |
+
|
| 289 |
+
"""
|
| 290 |
+
return self._acquire("read", timeout, blocking=blocking)
|
| 291 |
+
|
| 292 |
+
def acquire_write(self, timeout: float | None = None, *, blocking: bool | None = None) -> AcquireReturnProxy:
|
| 293 |
+
"""
|
| 294 |
+
Acquire an exclusive write lock.
|
| 295 |
+
|
| 296 |
+
If this instance already holds a write lock from the same thread, the lock level is incremented (reentrant).
|
| 297 |
+
Attempting to acquire a write lock while holding a read lock raises :class:`RuntimeError` (upgrade not
|
| 298 |
+
allowed). Write locks are pinned to the acquiring thread: a different thread trying to re-enter also raises
|
| 299 |
+
:class:`RuntimeError`.
|
| 300 |
+
|
| 301 |
+
Writer acquisition runs in two phases. Phase 1 atomically claims ``<path>.write`` via ``O_CREAT | O_EXCL``,
|
| 302 |
+
which immediately blocks any new reader on any host. Phase 2 waits for existing readers to drain. Writer
|
| 303 |
+
starvation is impossible: new readers see ``<path>.write`` during phase 2 and wait behind the pending writer.
|
| 304 |
+
|
| 305 |
+
:param timeout: maximum wait time in seconds, or ``None`` to use the instance default; ``-1`` means block
|
| 306 |
+
indefinitely
|
| 307 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable;
|
| 308 |
+
``None`` uses the instance default
|
| 309 |
+
|
| 310 |
+
:returns: a proxy that can be used as a context manager to release the lock
|
| 311 |
+
|
| 312 |
+
:raises RuntimeError: if a read lock is already held, if a write lock is held by a different thread, if this
|
| 313 |
+
instance was invalidated by :func:`os.fork`, or if :meth:`close` was called
|
| 314 |
+
:raises Timeout: if the lock cannot be acquired within *timeout* seconds
|
| 315 |
+
|
| 316 |
+
"""
|
| 317 |
+
return self._acquire("write", timeout, blocking=blocking)
|
| 318 |
+
|
| 319 |
+
def close(self) -> None:
|
| 320 |
+
"""
|
| 321 |
+
Release any held lock and release internal filesystem resources.
|
| 322 |
+
|
| 323 |
+
Idempotent. After calling this method the instance can no longer acquire locks — subsequent acquires raise
|
| 324 |
+
:class:`RuntimeError`. A fork-invalidated instance is closed without raising.
|
| 325 |
+
"""
|
| 326 |
+
self.release(force=True)
|
| 327 |
+
with self._locks.internal:
|
| 328 |
+
if self._closed:
|
| 329 |
+
return
|
| 330 |
+
self._closed = True
|
| 331 |
+
if self._readers_dir_fd is not None:
|
| 332 |
+
with suppress(OSError):
|
| 333 |
+
os.close(self._readers_dir_fd)
|
| 334 |
+
self._readers_dir_fd = None
|
| 335 |
+
|
| 336 |
+
def release(self, *, force: bool = False) -> None:
|
| 337 |
+
"""
|
| 338 |
+
Release one level of the current lock.
|
| 339 |
+
|
| 340 |
+
When the lock level reaches zero the heartbeat thread is stopped and the held marker file is unlinked. On a
|
| 341 |
+
fork-invalidated instance (that is, the child of a :func:`os.fork` call made while the parent held a lock)
|
| 342 |
+
this method is a no-op so inherited ``with`` blocks can unwind cleanly in the child.
|
| 343 |
+
|
| 344 |
+
:param force: if ``True``, release the lock completely regardless of the current lock level
|
| 345 |
+
|
| 346 |
+
:raises RuntimeError: if no lock is currently held and *force* is ``False``
|
| 347 |
+
|
| 348 |
+
"""
|
| 349 |
+
with self._locks.internal:
|
| 350 |
+
if self._fork_invalidated:
|
| 351 |
+
# Inherited state from the parent is meaningless in the child; clear any counters and return.
|
| 352 |
+
self._hold = None
|
| 353 |
+
return
|
| 354 |
+
hold = self._hold
|
| 355 |
+
if hold is None:
|
| 356 |
+
if force:
|
| 357 |
+
return
|
| 358 |
+
msg = f"Cannot release a lock on {self.lock_file} (lock id: {id(self)}) that is not held"
|
| 359 |
+
raise RuntimeError(msg)
|
| 360 |
+
if force:
|
| 361 |
+
hold.level = 0
|
| 362 |
+
else:
|
| 363 |
+
hold.level -= 1
|
| 364 |
+
if hold.level > 0:
|
| 365 |
+
return
|
| 366 |
+
self._hold = None
|
| 367 |
+
|
| 368 |
+
# Order matters: signal → join → unlink. A late tick on a deleted marker is harmless, and the
|
| 369 |
+
# token check in the heartbeat callback would catch any re-acquisition race, but joining first
|
| 370 |
+
# removes even that theoretical race.
|
| 371 |
+
hold.heartbeat_stop.set()
|
| 372 |
+
hold.heartbeat_thread.join(timeout=self.heartbeat_interval + 1.0)
|
| 373 |
+
if hold.is_reader:
|
| 374 |
+
_unlink(hold.marker_name, dir_fd=self._readers_dir_fd)
|
| 375 |
+
else:
|
| 376 |
+
_unlink(hold.marker_name)
|
| 377 |
+
|
| 378 |
+
@classmethod
|
| 379 |
+
def get_lock(
|
| 380 |
+
cls,
|
| 381 |
+
lock_file: str | os.PathLike[str],
|
| 382 |
+
timeout: float = -1,
|
| 383 |
+
*,
|
| 384 |
+
blocking: bool = True,
|
| 385 |
+
) -> SoftReadWriteLock:
|
| 386 |
+
"""
|
| 387 |
+
Return the singleton :class:`SoftReadWriteLock` for *lock_file*.
|
| 388 |
+
|
| 389 |
+
:param lock_file: path to the lock file; sidecar state/write/readers live next to it
|
| 390 |
+
:param timeout: maximum wait time in seconds; ``-1`` means block indefinitely
|
| 391 |
+
:param blocking: if ``False``, raise :class:`~filelock.Timeout` immediately when the lock is unavailable
|
| 392 |
+
|
| 393 |
+
:returns: the singleton lock instance
|
| 394 |
+
|
| 395 |
+
:raises ValueError: if an instance already exists for this path with different *timeout* or *blocking* values
|
| 396 |
+
|
| 397 |
+
"""
|
| 398 |
+
return cls(lock_file, timeout, blocking=blocking)
|
| 399 |
+
|
| 400 |
+
def _acquire(
|
| 401 |
+
self,
|
| 402 |
+
mode: _Mode,
|
| 403 |
+
timeout: float | None,
|
| 404 |
+
*,
|
| 405 |
+
blocking: bool | None,
|
| 406 |
+
) -> AcquireReturnProxy:
|
| 407 |
+
effective_timeout = self.timeout if timeout is None else timeout
|
| 408 |
+
effective_blocking = self.blocking if blocking is None else blocking
|
| 409 |
+
|
| 410 |
+
with self._locks.internal:
|
| 411 |
+
if self._fork_invalidated:
|
| 412 |
+
msg = f"SoftReadWriteLock on {self.lock_file} was invalidated by fork(); construct a new instance"
|
| 413 |
+
raise RuntimeError(msg)
|
| 414 |
+
if self._closed:
|
| 415 |
+
msg = f"SoftReadWriteLock on {self.lock_file} has been closed"
|
| 416 |
+
raise RuntimeError(msg)
|
| 417 |
+
if self._hold is not None:
|
| 418 |
+
return self._validate_reentrant(mode)
|
| 419 |
+
|
| 420 |
+
start = time.perf_counter()
|
| 421 |
+
if not effective_blocking:
|
| 422 |
+
acquired = self._locks.transaction.acquire(blocking=False)
|
| 423 |
+
elif effective_timeout == -1:
|
| 424 |
+
acquired = self._locks.transaction.acquire(blocking=True)
|
| 425 |
+
else:
|
| 426 |
+
acquired = self._locks.transaction.acquire(blocking=True, timeout=effective_timeout)
|
| 427 |
+
if not acquired:
|
| 428 |
+
raise Timeout(self.lock_file) from None
|
| 429 |
+
try:
|
| 430 |
+
with self._locks.internal:
|
| 431 |
+
if self._hold is not None:
|
| 432 |
+
return self._validate_reentrant(mode)
|
| 433 |
+
|
| 434 |
+
deadline = None if effective_timeout == -1 else start + effective_timeout
|
| 435 |
+
token = secrets.token_hex(16)
|
| 436 |
+
if mode == "write":
|
| 437 |
+
marker_name, is_reader = self._acquire_writer_slot(
|
| 438 |
+
token, deadline=deadline, blocking=effective_blocking
|
| 439 |
+
)
|
| 440 |
+
else:
|
| 441 |
+
marker_name, is_reader = self._acquire_reader_slot(
|
| 442 |
+
token, deadline=deadline, blocking=effective_blocking
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
stop_event = threading.Event()
|
| 446 |
+
heartbeat = _HeartbeatThread(
|
| 447 |
+
refresh=self._refresh_marker,
|
| 448 |
+
interval=self.heartbeat_interval,
|
| 449 |
+
stop_event=stop_event,
|
| 450 |
+
name=f"filelock-heartbeat-{id(self):x}",
|
| 451 |
+
)
|
| 452 |
+
|
| 453 |
+
with self._locks.internal:
|
| 454 |
+
self._hold = _Hold(
|
| 455 |
+
level=1,
|
| 456 |
+
mode=mode,
|
| 457 |
+
write_thread_id=threading.get_ident() if mode == "write" else None,
|
| 458 |
+
marker_name=marker_name,
|
| 459 |
+
is_reader=is_reader,
|
| 460 |
+
token=token,
|
| 461 |
+
heartbeat_thread=heartbeat,
|
| 462 |
+
heartbeat_stop=stop_event,
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
heartbeat.start()
|
| 466 |
+
return AcquireReturnProxy(lock=self)
|
| 467 |
+
finally:
|
| 468 |
+
self._locks.transaction.release()
|
| 469 |
+
|
| 470 |
+
def _validate_reentrant(self, mode: _Mode) -> AcquireReturnProxy:
|
| 471 |
+
hold = self._hold
|
| 472 |
+
assert hold is not None # noqa: S101
|
| 473 |
+
if hold.mode != mode:
|
| 474 |
+
opposite = "write" if mode == "read" else "read"
|
| 475 |
+
direction = "downgrade" if mode == "read" else "upgrade"
|
| 476 |
+
msg = (
|
| 477 |
+
f"Cannot acquire {mode} lock on {self.lock_file} (lock id: {id(self)}): "
|
| 478 |
+
f"already holding a {opposite} lock ({direction} not allowed)"
|
| 479 |
+
)
|
| 480 |
+
raise RuntimeError(msg)
|
| 481 |
+
if mode == "write" and (cur := threading.get_ident()) != hold.write_thread_id:
|
| 482 |
+
msg = (
|
| 483 |
+
f"Cannot acquire write lock on {self.lock_file} (lock id: {id(self)}) "
|
| 484 |
+
f"from thread {cur} while it is held by thread {hold.write_thread_id}"
|
| 485 |
+
)
|
| 486 |
+
raise RuntimeError(msg)
|
| 487 |
+
hold.level += 1
|
| 488 |
+
return AcquireReturnProxy(lock=self)
|
| 489 |
+
|
| 490 |
+
def _acquire_writer_slot(
|
| 491 |
+
self,
|
| 492 |
+
token: str,
|
| 493 |
+
*,
|
| 494 |
+
deadline: float | None,
|
| 495 |
+
blocking: bool,
|
| 496 |
+
) -> tuple[str, bool]:
|
| 497 |
+
# Phase 2 scans readers/ via dirfd (where supported), so we need it open even though writers never
|
| 498 |
+
# create files inside.
|
| 499 |
+
self._open_readers_dir()
|
| 500 |
+
|
| 501 |
+
def try_claim_writer() -> bool:
|
| 502 |
+
with self._locks.state:
|
| 503 |
+
_break_stale_marker(self._paths.write, stale_threshold=self.stale_threshold, now=time.time())
|
| 504 |
+
if _file_exists(self._paths.write):
|
| 505 |
+
return False
|
| 506 |
+
try:
|
| 507 |
+
_atomic_create_marker(self._paths.write, token)
|
| 508 |
+
except FileExistsError:
|
| 509 |
+
return False
|
| 510 |
+
return True
|
| 511 |
+
|
| 512 |
+
def readers_drained_touching() -> bool:
|
| 513 |
+
with self._locks.state:
|
| 514 |
+
# Refresh our writer marker on every scan iteration. Otherwise phase 2 can exceed
|
| 515 |
+
# ``stale_threshold`` under contention and a peer would treat us as stale and evict us.
|
| 516 |
+
with suppress(OSError):
|
| 517 |
+
_touch(self._paths.write)
|
| 518 |
+
self._break_stale_readers(time.time())
|
| 519 |
+
return not self._any_readers()
|
| 520 |
+
|
| 521 |
+
self._wait_for(try_claim_writer, deadline=deadline, blocking=blocking)
|
| 522 |
+
try:
|
| 523 |
+
self._wait_for(readers_drained_touching, deadline=deadline, blocking=blocking)
|
| 524 |
+
except Timeout:
|
| 525 |
+
# Give up our writer claim so readers can make progress again.
|
| 526 |
+
_unlink(self._paths.write)
|
| 527 |
+
raise
|
| 528 |
+
return self._paths.write, False
|
| 529 |
+
|
| 530 |
+
def _acquire_reader_slot(
|
| 531 |
+
self,
|
| 532 |
+
token: str,
|
| 533 |
+
*,
|
| 534 |
+
deadline: float | None,
|
| 535 |
+
blocking: bool,
|
| 536 |
+
) -> tuple[str, bool]:
|
| 537 |
+
self._open_readers_dir()
|
| 538 |
+
reader_name = f"{uuid.uuid4().hex}.{os.getpid()}"
|
| 539 |
+
dir_fd = self._readers_dir_fd
|
| 540 |
+
full_reader_path = str(Path(self._paths.readers) / reader_name)
|
| 541 |
+
|
| 542 |
+
def try_claim_reader() -> bool:
|
| 543 |
+
with self._locks.state:
|
| 544 |
+
_break_stale_marker(self._paths.write, stale_threshold=self.stale_threshold, now=time.time())
|
| 545 |
+
if _file_exists(self._paths.write):
|
| 546 |
+
return False
|
| 547 |
+
if dir_fd is not None:
|
| 548 |
+
_atomic_create_marker(reader_name, token, dir_fd=dir_fd)
|
| 549 |
+
else: # pragma: win32 cover
|
| 550 |
+
_atomic_create_marker(full_reader_path, token)
|
| 551 |
+
return True
|
| 552 |
+
|
| 553 |
+
self._wait_for(try_claim_reader, deadline=deadline, blocking=blocking)
|
| 554 |
+
return (reader_name if dir_fd is not None else full_reader_path), True
|
| 555 |
+
|
| 556 |
+
def _wait_for(
|
| 557 |
+
self,
|
| 558 |
+
predicate: Callable[[], bool],
|
| 559 |
+
*,
|
| 560 |
+
deadline: float | None,
|
| 561 |
+
blocking: bool,
|
| 562 |
+
) -> None:
|
| 563 |
+
while True:
|
| 564 |
+
if predicate():
|
| 565 |
+
return
|
| 566 |
+
now = time.perf_counter()
|
| 567 |
+
if not blocking:
|
| 568 |
+
raise Timeout(self.lock_file)
|
| 569 |
+
if deadline is not None and now >= deadline:
|
| 570 |
+
raise Timeout(self.lock_file)
|
| 571 |
+
sleep_for = self.poll_interval
|
| 572 |
+
if deadline is not None:
|
| 573 |
+
sleep_for = min(sleep_for, max(deadline - now, 0.0))
|
| 574 |
+
time.sleep(sleep_for)
|
| 575 |
+
|
| 576 |
+
def _open_readers_dir(self) -> None:
|
| 577 |
+
readers_path = Path(self._paths.readers)
|
| 578 |
+
with suppress(FileExistsError):
|
| 579 |
+
readers_path.mkdir(mode=0o700)
|
| 580 |
+
# mkdir has no O_NOFOLLOW, so verify via lstat that we did not land on an attacker-placed symlink
|
| 581 |
+
# or a regular file before we open or scan inside.
|
| 582 |
+
st = os.lstat(self._paths.readers)
|
| 583 |
+
if stat.S_ISLNK(st.st_mode) or not stat.S_ISDIR(st.st_mode):
|
| 584 |
+
msg = f"{self._paths.readers} exists but is not a directory or is a symlink; refusing to use it"
|
| 585 |
+
raise RuntimeError(msg)
|
| 586 |
+
if self._readers_dir_fd is None and _SUPPORTS_DIR_FD:
|
| 587 |
+
flags = os.O_RDONLY | getattr(os, "O_DIRECTORY", 0) | _O_NOFOLLOW
|
| 588 |
+
self._readers_dir_fd = os.open(self._paths.readers, flags)
|
| 589 |
+
|
| 590 |
+
def _any_readers(self) -> bool:
|
| 591 |
+
for _ in self._iter_reader_entries():
|
| 592 |
+
return True
|
| 593 |
+
return False
|
| 594 |
+
|
| 595 |
+
def _iter_reader_entries(self) -> Generator[tuple[str, bool]]:
|
| 596 |
+
"""
|
| 597 |
+
Yield ``(name, dirfd_relative)`` pairs for every live reader marker.
|
| 598 |
+
|
| 599 |
+
``dirfd_relative`` is ``True`` when *name* should be passed to ``dir_fd=``-aware syscalls; ``False``
|
| 600 |
+
when *name* is a full path because dirfd-relative I/O is unavailable on this platform.
|
| 601 |
+
"""
|
| 602 |
+
if self._readers_dir_fd is not None:
|
| 603 |
+
with os.scandir(self._readers_dir_fd) as it:
|
| 604 |
+
for entry in it:
|
| 605 |
+
if not _is_housekeeping_name(entry.name):
|
| 606 |
+
yield entry.name, True
|
| 607 |
+
return
|
| 608 |
+
readers_path = Path(self._paths.readers) # pragma: win32 cover
|
| 609 |
+
with os.scandir(readers_path) as it: # pragma: win32 cover
|
| 610 |
+
for entry in it: # pragma: win32 cover
|
| 611 |
+
if not _is_housekeeping_name(entry.name): # pragma: win32 cover
|
| 612 |
+
yield str(readers_path / entry.name), False # pragma: win32 cover
|
| 613 |
+
|
| 614 |
+
def _break_stale_readers(self, now: float) -> None:
|
| 615 |
+
names: list[tuple[str, int | None]] = []
|
| 616 |
+
try:
|
| 617 |
+
for name, dirfd_relative in self._iter_reader_entries():
|
| 618 |
+
names.append((name, self._readers_dir_fd if dirfd_relative else None))
|
| 619 |
+
except OSError: # pragma: no cover - transient NFS scandir hiccup
|
| 620 |
+
return
|
| 621 |
+
for name, fd in names:
|
| 622 |
+
_break_stale_marker(name, stale_threshold=self.stale_threshold, now=now, dir_fd=fd)
|
| 623 |
+
|
| 624 |
+
def _refresh_marker(self) -> bool:
|
| 625 |
+
with self._locks.internal:
|
| 626 |
+
hold = self._hold
|
| 627 |
+
if hold is None: # pragma: no cover - race between stop_event.set and join
|
| 628 |
+
return False
|
| 629 |
+
marker_name = hold.marker_name
|
| 630 |
+
token = hold.token
|
| 631 |
+
dir_fd = self._readers_dir_fd if hold.is_reader else None
|
| 632 |
+
|
| 633 |
+
read_result = _read_marker(marker_name, dir_fd=dir_fd)
|
| 634 |
+
if read_result is None:
|
| 635 |
+
return False
|
| 636 |
+
info, _mtime = read_result
|
| 637 |
+
# Token mismatch means another process already evicted our marker and created its own; stop the
|
| 638 |
+
# thread so it does not touch a stranger's file.
|
| 639 |
+
if info is None or not hmac.compare_digest(info.token, token):
|
| 640 |
+
return False
|
| 641 |
+
try:
|
| 642 |
+
_touch(marker_name, dir_fd=dir_fd)
|
| 643 |
+
except FileNotFoundError: # pragma: no cover - race between successful read and touch
|
| 644 |
+
return False
|
| 645 |
+
return True
|
| 646 |
+
|
| 647 |
+
def _reset_after_fork_in_child(self) -> None: # pragma: no cover - fork child not tracked
|
| 648 |
+
# Replace every lock this instance owns with a fresh one; the inherited locks may still be held
|
| 649 |
+
# by threads that no longer exist in the child. The readers dirfd and the SoftFileLock state
|
| 650 |
+
# mutex both get dropped for the same reason — the child re-creates them on its next acquire.
|
| 651 |
+
self._locks = _Locks(
|
| 652 |
+
internal=threading.Lock(),
|
| 653 |
+
transaction=threading.Lock(),
|
| 654 |
+
state=SoftFileLock(self._paths.state, timeout=-1),
|
| 655 |
+
)
|
| 656 |
+
self._hold = None
|
| 657 |
+
self._readers_dir_fd = None
|
| 658 |
+
self._fork_invalidated = True
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
class _HeartbeatThread(threading.Thread):
|
| 662 |
+
def __init__(
|
| 663 |
+
self,
|
| 664 |
+
refresh: Callable[[], bool],
|
| 665 |
+
interval: float,
|
| 666 |
+
stop_event: threading.Event,
|
| 667 |
+
name: str,
|
| 668 |
+
) -> None:
|
| 669 |
+
super().__init__(name=name, daemon=True)
|
| 670 |
+
self._refresh = refresh
|
| 671 |
+
self._interval = interval
|
| 672 |
+
self._stop_event = stop_event
|
| 673 |
+
|
| 674 |
+
def run(self) -> None:
|
| 675 |
+
while not self._stop_event.wait(self._interval):
|
| 676 |
+
if not self._refresh():
|
| 677 |
+
self._stop_event.set()
|
| 678 |
+
return
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
def _atomic_create_marker(name: str, token: str, *, dir_fd: int | None = None) -> None:
|
| 682 |
+
# O_NOFOLLOW blocks the symlink-overwrite attack where an attacker pre-creates the marker path as a
|
| 683 |
+
# symlink pointing at a victim file. Mode 0o600 keeps the token unreadable to other users.
|
| 684 |
+
flags = os.O_CREAT | os.O_EXCL | os.O_WRONLY | _O_NOFOLLOW
|
| 685 |
+
if _SUPPORTS_DIR_FD and dir_fd is not None:
|
| 686 |
+
fd = os.open(name, flags, 0o600, dir_fd=dir_fd)
|
| 687 |
+
else:
|
| 688 |
+
fd = os.open(name, flags, 0o600)
|
| 689 |
+
try:
|
| 690 |
+
content = f"{token}\n{os.getpid()}\n{socket.gethostname()}\n".encode("ascii")
|
| 691 |
+
os.write(fd, content)
|
| 692 |
+
finally:
|
| 693 |
+
os.close(fd)
|
| 694 |
+
|
| 695 |
+
|
| 696 |
+
def _read_marker(name: str, *, dir_fd: int | None = None) -> tuple[_MarkerInfo | None, float] | None:
|
| 697 |
+
# O_NOFOLLOW is defense in depth: we already created this file, but a hostile replacement by symlink
|
| 698 |
+
# between create and read would be caught here.
|
| 699 |
+
flags = os.O_RDONLY | _O_NOFOLLOW
|
| 700 |
+
try:
|
| 701 |
+
fd = os.open(name, flags, dir_fd=dir_fd) if _SUPPORTS_DIR_FD and dir_fd is not None else os.open(name, flags)
|
| 702 |
+
except OSError:
|
| 703 |
+
return None
|
| 704 |
+
try:
|
| 705 |
+
try:
|
| 706 |
+
st = os.fstat(fd)
|
| 707 |
+
data = os.read(fd, _MAX_MARKER_SIZE + 1)
|
| 708 |
+
except OSError: # pragma: no cover - fstat/read after a successful open is hard to provoke
|
| 709 |
+
return None
|
| 710 |
+
finally:
|
| 711 |
+
os.close(fd)
|
| 712 |
+
return _parse_marker_bytes(data), st.st_mtime
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
def _parse_marker_bytes(data: bytes) -> _MarkerInfo | None:
|
| 716 |
+
# Trust nothing about attacker-controlled markers; any deviation returns None so callers fall through
|
| 717 |
+
# to stale cleanup. ``re.match`` caches compiled patterns internally, so the regex is built only once
|
| 718 |
+
# despite being defined inline.
|
| 719 |
+
if not data or len(data) > _MAX_MARKER_SIZE:
|
| 720 |
+
return None
|
| 721 |
+
try:
|
| 722 |
+
text = data.decode("ascii")
|
| 723 |
+
except UnicodeDecodeError:
|
| 724 |
+
return None
|
| 725 |
+
match = re.match(
|
| 726 |
+
r"""
|
| 727 |
+
\A # start of string
|
| 728 |
+
(?P<token> [0-9a-f]{32} ) \n # 128-bit hex token
|
| 729 |
+
(?P<pid> [1-9][0-9]{0,9} ) \n # decimal pid: no leading zero, ≤ 10 digits
|
| 730 |
+
(?P<hostname> [\x21-\x7e]{1,253}) # printable non-whitespace ASCII (RFC 1123 hostname limit)
|
| 731 |
+
\n* # tolerate sloppy writers that append extra newlines
|
| 732 |
+
\Z # end of string
|
| 733 |
+
""",
|
| 734 |
+
text,
|
| 735 |
+
re.VERBOSE,
|
| 736 |
+
)
|
| 737 |
+
if match is None:
|
| 738 |
+
return None
|
| 739 |
+
pid = int(match["pid"], 10)
|
| 740 |
+
if pid > 2**31 - 1:
|
| 741 |
+
return None
|
| 742 |
+
return _MarkerInfo(token=match["token"], pid=pid, hostname=match["hostname"])
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
def _break_stale_marker( # noqa: PLR0911
|
| 746 |
+
name: str,
|
| 747 |
+
*,
|
| 748 |
+
stale_threshold: float,
|
| 749 |
+
now: float,
|
| 750 |
+
dir_fd: int | None = None,
|
| 751 |
+
) -> bool:
|
| 752 |
+
# Atomic break pattern: read → rename to unique break-name → re-verify → unlink. The rename gives us a
|
| 753 |
+
# private name nobody else can touch; if the re-verify sees a newer mtime or a different token, the
|
| 754 |
+
# legitimate holder's heartbeat fired between read and rename and we must abort (leaving the .break.*
|
| 755 |
+
# file behind rather than rollback-renaming, because rollback is itself racy).
|
| 756 |
+
read_result = _read_marker(name, dir_fd=dir_fd)
|
| 757 |
+
if read_result is None:
|
| 758 |
+
return False
|
| 759 |
+
info_before, mtime_before = read_result
|
| 760 |
+
if now - mtime_before <= stale_threshold:
|
| 761 |
+
return False
|
| 762 |
+
if info_before is None:
|
| 763 |
+
_unlink(name, dir_fd=dir_fd)
|
| 764 |
+
return True
|
| 765 |
+
|
| 766 |
+
break_name = f"{name}{_BREAK_SUFFIX}.{os.getpid()}.{secrets.token_hex(16)}"
|
| 767 |
+
try:
|
| 768 |
+
if _SUPPORTS_DIR_FD and dir_fd is not None:
|
| 769 |
+
os.rename(name, break_name, src_dir_fd=dir_fd, dst_dir_fd=dir_fd)
|
| 770 |
+
else:
|
| 771 |
+
Path(name).rename(break_name)
|
| 772 |
+
except OSError: # pragma: no cover - race where the marker vanishes between read and rename
|
| 773 |
+
return False
|
| 774 |
+
|
| 775 |
+
read_after = _read_marker(break_name, dir_fd=dir_fd)
|
| 776 |
+
if read_after is None: # pragma: no cover - race where a peer unlinks the break-name file
|
| 777 |
+
return False
|
| 778 |
+
info_after, mtime_after = read_after
|
| 779 |
+
if info_after is None: # pragma: no cover - content replaced post-rename by a racing peer
|
| 780 |
+
_unlink(break_name, dir_fd=dir_fd)
|
| 781 |
+
return True
|
| 782 |
+
if not hmac.compare_digest(info_before.token, info_after.token): # pragma: no cover - race only
|
| 783 |
+
return False
|
| 784 |
+
if mtime_after > mtime_before: # pragma: no cover - heartbeat raced our rename
|
| 785 |
+
return False
|
| 786 |
+
_unlink(break_name, dir_fd=dir_fd)
|
| 787 |
+
return True
|
| 788 |
+
|
| 789 |
+
|
| 790 |
+
def _unlink(name: str, *, dir_fd: int | None = None) -> None:
|
| 791 |
+
with suppress(FileNotFoundError):
|
| 792 |
+
if _SUPPORTS_DIR_FD and dir_fd is not None:
|
| 793 |
+
# Path.unlink has no dir_fd support, so we stay on os.unlink for the dirfd path.
|
| 794 |
+
os.unlink(name, dir_fd=dir_fd)
|
| 795 |
+
else:
|
| 796 |
+
Path(name).unlink()
|
| 797 |
+
|
| 798 |
+
|
| 799 |
+
def _touch(name: str, *, dir_fd: int | None = None) -> None:
|
| 800 |
+
if _SUPPORTS_DIR_FD and dir_fd is not None:
|
| 801 |
+
os.utime(name, None, dir_fd=dir_fd)
|
| 802 |
+
else:
|
| 803 |
+
os.utime(name, None)
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
def _file_exists(path: str) -> bool:
|
| 807 |
+
try:
|
| 808 |
+
st = os.lstat(path)
|
| 809 |
+
except FileNotFoundError:
|
| 810 |
+
return False
|
| 811 |
+
return stat.S_ISREG(st.st_mode)
|
| 812 |
+
|
| 813 |
+
|
| 814 |
+
def _is_housekeeping_name(name: str) -> bool:
|
| 815 |
+
return name.startswith(".") or _BREAK_SUFFIX in name
|
| 816 |
+
|
| 817 |
+
|
| 818 |
+
def _reset_all_after_fork() -> None: # pragma: no cover - fork child, not tracked by coverage
|
| 819 |
+
global _all_instances_lock # noqa: PLW0603
|
| 820 |
+
# User-created threading locks do not auto-reset across fork: any lock held by a parent thread stays
|
| 821 |
+
# locked in the child with no owner to release it. Replace the module-level lock and every instance's
|
| 822 |
+
# locks with fresh ones; the child is single-threaded at this point so no synchronization is needed.
|
| 823 |
+
_all_instances_lock = threading.Lock()
|
| 824 |
+
for instance in list(_all_instances.values()):
|
| 825 |
+
instance._reset_after_fork_in_child() # noqa: SLF001
|
| 826 |
+
|
| 827 |
+
|
| 828 |
+
def _cleanup_all_instances() -> None: # pragma: no cover - runs from atexit at interpreter shutdown
|
| 829 |
+
for instance in list(_all_instances.values()):
|
| 830 |
+
with suppress(Exception):
|
| 831 |
+
instance.release(force=True)
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
def _register_hooks() -> None:
|
| 835 |
+
global _atexit_registered, _fork_registered # noqa: PLW0603
|
| 836 |
+
if not _atexit_registered:
|
| 837 |
+
atexit.register(_cleanup_all_instances)
|
| 838 |
+
_atexit_registered = True
|
| 839 |
+
# after_in_child replaces inherited state so the child cannot double-own any lock the parent held.
|
| 840 |
+
if not _fork_registered and hasattr(os, "register_at_fork"):
|
| 841 |
+
os.register_at_fork(after_in_child=_reset_all_after_fork)
|
| 842 |
+
_fork_registered = True
|
| 843 |
+
|
| 844 |
+
|
| 845 |
+
__all__ = [
|
| 846 |
+
"SoftReadWriteLock",
|
| 847 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_unix.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import warnings
|
| 6 |
+
from contextlib import suppress
|
| 7 |
+
from errno import EAGAIN, ENOSYS, EWOULDBLOCK
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
from typing import cast
|
| 10 |
+
|
| 11 |
+
from ._api import BaseFileLock
|
| 12 |
+
from ._util import ensure_directory_exists
|
| 13 |
+
|
| 14 |
+
#: a flag to indicate if the fcntl API is available
|
| 15 |
+
has_fcntl = False
|
| 16 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 17 |
+
|
| 18 |
+
class UnixFileLock(BaseFileLock):
|
| 19 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
| 20 |
+
|
| 21 |
+
def _acquire(self) -> None:
|
| 22 |
+
raise NotImplementedError
|
| 23 |
+
|
| 24 |
+
def _release(self) -> None:
|
| 25 |
+
raise NotImplementedError
|
| 26 |
+
|
| 27 |
+
else: # pragma: win32 no cover
|
| 28 |
+
try:
|
| 29 |
+
import fcntl
|
| 30 |
+
|
| 31 |
+
_ = (fcntl.flock, fcntl.LOCK_EX, fcntl.LOCK_NB, fcntl.LOCK_UN)
|
| 32 |
+
except (ImportError, AttributeError):
|
| 33 |
+
pass
|
| 34 |
+
else:
|
| 35 |
+
has_fcntl = True
|
| 36 |
+
|
| 37 |
+
class UnixFileLock(BaseFileLock):
|
| 38 |
+
"""
|
| 39 |
+
Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems.
|
| 40 |
+
|
| 41 |
+
Lock file cleanup: Unix and macOS delete the lock file reliably after release, even in
|
| 42 |
+
multi-threaded scenarios. Unlike Windows, Unix allows unlinking files that other processes
|
| 43 |
+
have open.
|
| 44 |
+
"""
|
| 45 |
+
|
| 46 |
+
def _acquire(self) -> None: # noqa: C901, PLR0912
|
| 47 |
+
ensure_directory_exists(self.lock_file)
|
| 48 |
+
open_flags = os.O_RDWR | os.O_TRUNC
|
| 49 |
+
o_nofollow = getattr(os, "O_NOFOLLOW", None)
|
| 50 |
+
if o_nofollow is not None:
|
| 51 |
+
open_flags |= o_nofollow
|
| 52 |
+
open_flags |= os.O_CREAT
|
| 53 |
+
open_mode = self._open_mode()
|
| 54 |
+
try:
|
| 55 |
+
fd = os.open(self.lock_file, open_flags, open_mode)
|
| 56 |
+
except FileNotFoundError:
|
| 57 |
+
# On FUSE/NFS, os.open(O_CREAT) is not atomic: LOOKUP + CREATE can be split, allowing a concurrent
|
| 58 |
+
# unlink() to delete the file between them. For valid paths, treat ENOENT as transient contention.
|
| 59 |
+
# For invalid paths (e.g., empty string), re-raise to avoid infinite retry loops.
|
| 60 |
+
if self.lock_file and Path(self.lock_file).parent.exists():
|
| 61 |
+
return
|
| 62 |
+
raise
|
| 63 |
+
except PermissionError:
|
| 64 |
+
# Sticky-bit dirs (e.g. /tmp): O_CREAT fails if the file is owned by another user (#317).
|
| 65 |
+
# Fall back to opening the existing file without O_CREAT.
|
| 66 |
+
if not Path(self.lock_file).exists():
|
| 67 |
+
raise
|
| 68 |
+
try:
|
| 69 |
+
fd = os.open(self.lock_file, open_flags & ~os.O_CREAT, open_mode)
|
| 70 |
+
except FileNotFoundError:
|
| 71 |
+
return
|
| 72 |
+
if self.has_explicit_mode:
|
| 73 |
+
with suppress(PermissionError):
|
| 74 |
+
os.fchmod(fd, self._context.mode)
|
| 75 |
+
try:
|
| 76 |
+
fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
| 77 |
+
except OSError as exception:
|
| 78 |
+
os.close(fd)
|
| 79 |
+
if exception.errno == ENOSYS:
|
| 80 |
+
with suppress(OSError):
|
| 81 |
+
Path(self.lock_file).unlink()
|
| 82 |
+
self._fallback_to_soft_lock()
|
| 83 |
+
self._acquire()
|
| 84 |
+
return
|
| 85 |
+
if exception.errno not in {EAGAIN, EWOULDBLOCK}:
|
| 86 |
+
raise
|
| 87 |
+
else:
|
| 88 |
+
# The file may have been unlinked by a concurrent _release() between our open() and flock().
|
| 89 |
+
# A lock on an unlinked inode is useless — discard and let the retry loop start fresh.
|
| 90 |
+
if os.fstat(fd).st_nlink == 0:
|
| 91 |
+
os.close(fd)
|
| 92 |
+
else:
|
| 93 |
+
self._context.lock_file_fd = fd
|
| 94 |
+
|
| 95 |
+
def _fallback_to_soft_lock(self) -> None:
|
| 96 |
+
from ._soft import SoftFileLock # noqa: PLC0415
|
| 97 |
+
|
| 98 |
+
warnings.warn("flock not supported on this filesystem, falling back to SoftFileLock", stacklevel=2)
|
| 99 |
+
from .asyncio import AsyncSoftFileLock, BaseAsyncFileLock # noqa: PLC0415
|
| 100 |
+
|
| 101 |
+
self.__class__ = AsyncSoftFileLock if isinstance(self, BaseAsyncFileLock) else SoftFileLock
|
| 102 |
+
|
| 103 |
+
def _release(self) -> None:
|
| 104 |
+
fd = cast("int", self._context.lock_file_fd)
|
| 105 |
+
self._context.lock_file_fd = None
|
| 106 |
+
with suppress(OSError):
|
| 107 |
+
Path(self.lock_file).unlink()
|
| 108 |
+
fcntl.flock(fd, fcntl.LOCK_UN)
|
| 109 |
+
with suppress(OSError): # close can raise EIO on FUSE/Docker bind-mount filesystems after unlink
|
| 110 |
+
os.close(fd)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
__all__ = [
|
| 114 |
+
"UnixFileLock",
|
| 115 |
+
"has_fcntl",
|
| 116 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_util.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import stat
|
| 5 |
+
import sys
|
| 6 |
+
from errno import EACCES, EISDIR
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def raise_on_not_writable_file(filename: str) -> None:
|
| 11 |
+
"""
|
| 12 |
+
Raise an exception if attempting to open the file for writing would fail.
|
| 13 |
+
|
| 14 |
+
This is done so files that will never be writable can be separated from files that are writable but currently
|
| 15 |
+
locked.
|
| 16 |
+
|
| 17 |
+
:param filename: file to check
|
| 18 |
+
|
| 19 |
+
:raises OSError: as if the file was opened for writing.
|
| 20 |
+
|
| 21 |
+
"""
|
| 22 |
+
try: # use stat to do exists + can write to check without race condition
|
| 23 |
+
file_stat = os.stat(filename) # noqa: PTH116
|
| 24 |
+
except OSError:
|
| 25 |
+
return # swallow does not exist or other errors
|
| 26 |
+
|
| 27 |
+
if file_stat.st_mtime != 0: # if os.stat returns but modification is zero that's an invalid os.stat - ignore it
|
| 28 |
+
if not (file_stat.st_mode & stat.S_IWUSR):
|
| 29 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
| 30 |
+
|
| 31 |
+
if stat.S_ISDIR(file_stat.st_mode):
|
| 32 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 33 |
+
# On Windows, this is PermissionError
|
| 34 |
+
raise PermissionError(EACCES, "Permission denied", filename)
|
| 35 |
+
else: # pragma: win32 no cover # noqa: RET506
|
| 36 |
+
# On linux / macOS, this is IsADirectoryError
|
| 37 |
+
raise IsADirectoryError(EISDIR, "Is a directory", filename)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def ensure_directory_exists(filename: Path | str) -> None:
|
| 41 |
+
"""
|
| 42 |
+
Ensure the directory containing the file exists (create it if necessary).
|
| 43 |
+
|
| 44 |
+
:param filename: file.
|
| 45 |
+
|
| 46 |
+
"""
|
| 47 |
+
Path(filename).parent.mkdir(parents=True, exist_ok=True)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
__all__ = [
|
| 51 |
+
"ensure_directory_exists",
|
| 52 |
+
"raise_on_not_writable_file",
|
| 53 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/_windows.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
from contextlib import suppress
|
| 6 |
+
from errno import EACCES
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import cast
|
| 9 |
+
|
| 10 |
+
from ._api import BaseFileLock
|
| 11 |
+
from ._util import ensure_directory_exists, raise_on_not_writable_file
|
| 12 |
+
|
| 13 |
+
if sys.platform == "win32": # pragma: win32 cover
|
| 14 |
+
import ctypes
|
| 15 |
+
import msvcrt
|
| 16 |
+
from ctypes import wintypes
|
| 17 |
+
|
| 18 |
+
# Windows API constants for reparse point detection
|
| 19 |
+
FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
|
| 20 |
+
INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF
|
| 21 |
+
|
| 22 |
+
# Load kernel32.dll
|
| 23 |
+
_kernel32 = ctypes.WinDLL("kernel32", use_last_error=True)
|
| 24 |
+
_kernel32.GetFileAttributesW.argtypes = [wintypes.LPCWSTR]
|
| 25 |
+
_kernel32.GetFileAttributesW.restype = wintypes.DWORD
|
| 26 |
+
|
| 27 |
+
def _is_reparse_point(path: str) -> bool:
|
| 28 |
+
"""
|
| 29 |
+
Check if a path is a reparse point (symlink, junction, etc.) on Windows.
|
| 30 |
+
|
| 31 |
+
:param path: Path to check
|
| 32 |
+
|
| 33 |
+
:returns: True if path is a reparse point, False otherwise
|
| 34 |
+
|
| 35 |
+
:raises OSError: If GetFileAttributesW fails for reasons other than file-not-found
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
attrs = _kernel32.GetFileAttributesW(path)
|
| 39 |
+
if attrs == INVALID_FILE_ATTRIBUTES:
|
| 40 |
+
# File doesn't exist yet - that's fine, we'll create it
|
| 41 |
+
err = ctypes.get_last_error()
|
| 42 |
+
if err == 2: # noqa: PLR2004 # ERROR_FILE_NOT_FOUND
|
| 43 |
+
return False
|
| 44 |
+
if err == 3: # noqa: PLR2004 # ERROR_PATH_NOT_FOUND
|
| 45 |
+
return False
|
| 46 |
+
# Some other error - let caller handle it
|
| 47 |
+
return False
|
| 48 |
+
return bool(attrs & FILE_ATTRIBUTE_REPARSE_POINT)
|
| 49 |
+
|
| 50 |
+
class WindowsFileLock(BaseFileLock):
|
| 51 |
+
"""
|
| 52 |
+
Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems.
|
| 53 |
+
|
| 54 |
+
Lock file cleanup: Windows attempts to delete the lock file after release, but deletion is
|
| 55 |
+
not guaranteed in multi-threaded scenarios where another thread holds an open handle. The lock
|
| 56 |
+
file may persist on disk, which does not affect lock correctness.
|
| 57 |
+
"""
|
| 58 |
+
|
| 59 |
+
def _acquire(self) -> None:
|
| 60 |
+
raise_on_not_writable_file(self.lock_file)
|
| 61 |
+
ensure_directory_exists(self.lock_file)
|
| 62 |
+
|
| 63 |
+
# Security check: Refuse to open reparse points (symlinks, junctions)
|
| 64 |
+
# This prevents TOCTOU symlink attacks (CVE-TBD)
|
| 65 |
+
if _is_reparse_point(self.lock_file):
|
| 66 |
+
msg = f"Lock file is a reparse point (symlink/junction): {self.lock_file}"
|
| 67 |
+
raise OSError(msg)
|
| 68 |
+
|
| 69 |
+
flags = (
|
| 70 |
+
os.O_RDWR # open for read and write
|
| 71 |
+
| os.O_CREAT # create file if not exists
|
| 72 |
+
)
|
| 73 |
+
try:
|
| 74 |
+
fd = os.open(self.lock_file, flags, self._open_mode())
|
| 75 |
+
except OSError as exception:
|
| 76 |
+
if exception.errno != EACCES: # has no access to this lock
|
| 77 |
+
raise
|
| 78 |
+
else:
|
| 79 |
+
try:
|
| 80 |
+
msvcrt.locking(fd, msvcrt.LK_NBLCK, 1)
|
| 81 |
+
except OSError as exception:
|
| 82 |
+
os.close(fd) # close file first
|
| 83 |
+
if exception.errno != EACCES: # file is already locked
|
| 84 |
+
raise
|
| 85 |
+
else:
|
| 86 |
+
self._context.lock_file_fd = fd
|
| 87 |
+
|
| 88 |
+
def _release(self) -> None:
|
| 89 |
+
fd = cast("int", self._context.lock_file_fd)
|
| 90 |
+
self._context.lock_file_fd = None
|
| 91 |
+
msvcrt.locking(fd, msvcrt.LK_UNLCK, 1)
|
| 92 |
+
os.close(fd)
|
| 93 |
+
|
| 94 |
+
with suppress(OSError):
|
| 95 |
+
Path(self.lock_file).unlink()
|
| 96 |
+
|
| 97 |
+
else: # pragma: win32 no cover
|
| 98 |
+
|
| 99 |
+
class WindowsFileLock(BaseFileLock):
|
| 100 |
+
"""Uses the :func:`msvcrt.locking` function to hard lock the lock file on Windows systems."""
|
| 101 |
+
|
| 102 |
+
def _acquire(self) -> None:
|
| 103 |
+
raise NotImplementedError
|
| 104 |
+
|
| 105 |
+
def _release(self) -> None:
|
| 106 |
+
raise NotImplementedError
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
__all__ = [
|
| 110 |
+
"WindowsFileLock",
|
| 111 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/asyncio.py
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""An asyncio-based implementation of the file lock."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import asyncio
|
| 6 |
+
import contextlib
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import time
|
| 10 |
+
from dataclasses import dataclass
|
| 11 |
+
from inspect import iscoroutinefunction
|
| 12 |
+
from threading import local
|
| 13 |
+
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar
|
| 14 |
+
|
| 15 |
+
from ._api import _UNSET_FILE_MODE, BaseFileLock, FileLockContext, FileLockMeta
|
| 16 |
+
from ._error import Timeout
|
| 17 |
+
from ._soft import SoftFileLock
|
| 18 |
+
from ._unix import UnixFileLock
|
| 19 |
+
from ._windows import WindowsFileLock
|
| 20 |
+
|
| 21 |
+
if TYPE_CHECKING:
|
| 22 |
+
import sys
|
| 23 |
+
from collections.abc import Callable
|
| 24 |
+
from concurrent import futures
|
| 25 |
+
from types import TracebackType
|
| 26 |
+
|
| 27 |
+
if sys.version_info >= (3, 11): # pragma: no cover (py311+)
|
| 28 |
+
from typing import Self
|
| 29 |
+
else: # pragma: no cover (<py311)
|
| 30 |
+
from typing_extensions import Self
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
_LOGGER = logging.getLogger("filelock")
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@dataclass
|
| 37 |
+
class AsyncFileLockContext(FileLockContext):
|
| 38 |
+
"""A dataclass which holds the context for a ``BaseAsyncFileLock`` object."""
|
| 39 |
+
|
| 40 |
+
#: Whether run in executor
|
| 41 |
+
run_in_executor: bool = True
|
| 42 |
+
|
| 43 |
+
#: The executor
|
| 44 |
+
executor: futures.Executor | None = None
|
| 45 |
+
|
| 46 |
+
#: The loop
|
| 47 |
+
loop: asyncio.AbstractEventLoop | None = None
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
class AsyncThreadLocalFileContext(AsyncFileLockContext, local):
|
| 51 |
+
"""A thread local version of the ``FileLockContext`` class."""
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
class AsyncAcquireReturnProxy:
|
| 55 |
+
"""A context-aware object that will release the lock file when exiting."""
|
| 56 |
+
|
| 57 |
+
def __init__(self, lock: BaseAsyncFileLock) -> None: # noqa: D107
|
| 58 |
+
self.lock = lock
|
| 59 |
+
|
| 60 |
+
async def __aenter__(self) -> BaseAsyncFileLock: # noqa: D105
|
| 61 |
+
return self.lock
|
| 62 |
+
|
| 63 |
+
async def __aexit__( # noqa: D105
|
| 64 |
+
self,
|
| 65 |
+
exc_type: type[BaseException] | None,
|
| 66 |
+
exc_value: BaseException | None,
|
| 67 |
+
traceback: TracebackType | None,
|
| 68 |
+
) -> None:
|
| 69 |
+
await self.lock.release()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
_AT = TypeVar("_AT", bound="BaseAsyncFileLock")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
class AsyncFileLockMeta(FileLockMeta):
|
| 76 |
+
def __call__( # ty: ignore[invalid-method-override] # noqa: PLR0913
|
| 77 |
+
cls: type[_AT], # noqa: N805
|
| 78 |
+
lock_file: str | os.PathLike[str],
|
| 79 |
+
timeout: float = -1,
|
| 80 |
+
mode: int = _UNSET_FILE_MODE,
|
| 81 |
+
thread_local: bool = False, # noqa: FBT001, FBT002
|
| 82 |
+
*,
|
| 83 |
+
blocking: bool = True,
|
| 84 |
+
is_singleton: bool = False,
|
| 85 |
+
poll_interval: float = 0.05,
|
| 86 |
+
lifetime: float | None = None,
|
| 87 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 88 |
+
run_in_executor: bool = True,
|
| 89 |
+
executor: futures.Executor | None = None,
|
| 90 |
+
) -> _AT:
|
| 91 |
+
if thread_local and run_in_executor:
|
| 92 |
+
msg = "run_in_executor is not supported when thread_local is True"
|
| 93 |
+
raise ValueError(msg)
|
| 94 |
+
return super().__call__(
|
| 95 |
+
lock_file=lock_file,
|
| 96 |
+
timeout=timeout,
|
| 97 |
+
mode=mode,
|
| 98 |
+
thread_local=thread_local,
|
| 99 |
+
blocking=blocking,
|
| 100 |
+
is_singleton=is_singleton,
|
| 101 |
+
poll_interval=poll_interval,
|
| 102 |
+
lifetime=lifetime,
|
| 103 |
+
loop=loop,
|
| 104 |
+
run_in_executor=run_in_executor,
|
| 105 |
+
executor=executor,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
class BaseAsyncFileLock(BaseFileLock, metaclass=AsyncFileLockMeta):
|
| 110 |
+
"""
|
| 111 |
+
Base class for asynchronous file locks.
|
| 112 |
+
|
| 113 |
+
.. versionadded:: 3.15.0
|
| 114 |
+
|
| 115 |
+
"""
|
| 116 |
+
|
| 117 |
+
def __init__( # noqa: PLR0913
|
| 118 |
+
self,
|
| 119 |
+
lock_file: str | os.PathLike[str],
|
| 120 |
+
timeout: float = -1,
|
| 121 |
+
mode: int = _UNSET_FILE_MODE,
|
| 122 |
+
thread_local: bool = False, # noqa: FBT001, FBT002
|
| 123 |
+
*,
|
| 124 |
+
blocking: bool = True,
|
| 125 |
+
is_singleton: bool = False,
|
| 126 |
+
poll_interval: float = 0.05,
|
| 127 |
+
lifetime: float | None = None,
|
| 128 |
+
loop: asyncio.AbstractEventLoop | None = None,
|
| 129 |
+
run_in_executor: bool = True,
|
| 130 |
+
executor: futures.Executor | None = None,
|
| 131 |
+
) -> None:
|
| 132 |
+
"""
|
| 133 |
+
Create a new lock object.
|
| 134 |
+
|
| 135 |
+
:param lock_file: path to the file
|
| 136 |
+
:param timeout: default timeout when acquiring the lock, in seconds. It will be used as fallback value in the
|
| 137 |
+
acquire method, if no timeout value (``None``) is given. If you want to disable the timeout, set it to a
|
| 138 |
+
negative value. A timeout of 0 means that there is exactly one attempt to acquire the file lock.
|
| 139 |
+
:param mode: file permissions for the lockfile. When not specified, the OS controls permissions via umask and
|
| 140 |
+
default ACLs, preserving POSIX default ACL inheritance in shared directories.
|
| 141 |
+
:param thread_local: Whether this object's internal context should be thread local or not. If this is set to
|
| 142 |
+
``False`` then the lock will be reentrant across threads.
|
| 143 |
+
:param blocking: whether the lock should be blocking or not
|
| 144 |
+
:param is_singleton: If this is set to ``True`` then only one instance of this class will be created per lock
|
| 145 |
+
file. This is useful if you want to use the lock object for reentrant locking without needing to pass the
|
| 146 |
+
same object around.
|
| 147 |
+
:param poll_interval: default interval for polling the lock file, in seconds. It will be used as fallback value
|
| 148 |
+
in the acquire method, if no poll_interval value (``None``) is given.
|
| 149 |
+
:param lifetime: maximum time in seconds a lock can be held before it is considered expired. When set, a waiting
|
| 150 |
+
process will break a lock whose file modification time is older than ``lifetime`` seconds. ``None`` (the
|
| 151 |
+
default) means locks never expire.
|
| 152 |
+
:param loop: The event loop to use. If not specified, the running event loop will be used.
|
| 153 |
+
:param run_in_executor: If this is set to ``True`` then the lock will be acquired in an executor.
|
| 154 |
+
:param executor: The executor to use. If not specified, the default executor will be used.
|
| 155 |
+
|
| 156 |
+
"""
|
| 157 |
+
self._is_thread_local = thread_local
|
| 158 |
+
self._is_singleton = is_singleton
|
| 159 |
+
|
| 160 |
+
# Create the context. Note that external code should not work with the context directly and should instead use
|
| 161 |
+
# properties of this class.
|
| 162 |
+
kwargs: dict[str, Any] = {
|
| 163 |
+
"lock_file": os.fspath(lock_file),
|
| 164 |
+
"timeout": timeout,
|
| 165 |
+
"mode": mode,
|
| 166 |
+
"blocking": blocking,
|
| 167 |
+
"poll_interval": poll_interval,
|
| 168 |
+
"lifetime": lifetime,
|
| 169 |
+
"loop": loop,
|
| 170 |
+
"run_in_executor": run_in_executor,
|
| 171 |
+
"executor": executor,
|
| 172 |
+
}
|
| 173 |
+
self._context: AsyncFileLockContext = (AsyncThreadLocalFileContext if thread_local else AsyncFileLockContext)(
|
| 174 |
+
**kwargs
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
@property
|
| 178 |
+
def run_in_executor(self) -> bool:
|
| 179 |
+
""":returns: whether run in executor."""
|
| 180 |
+
return self._context.run_in_executor
|
| 181 |
+
|
| 182 |
+
@property
|
| 183 |
+
def executor(self) -> futures.Executor | None:
|
| 184 |
+
""":returns: the executor."""
|
| 185 |
+
return self._context.executor
|
| 186 |
+
|
| 187 |
+
@executor.setter
|
| 188 |
+
def executor(self, value: futures.Executor | None) -> None: # pragma: no cover
|
| 189 |
+
"""
|
| 190 |
+
Change the executor.
|
| 191 |
+
|
| 192 |
+
:param futures.Executor | None value: the new executor or ``None``
|
| 193 |
+
|
| 194 |
+
"""
|
| 195 |
+
self._context.executor = value
|
| 196 |
+
|
| 197 |
+
@property
|
| 198 |
+
def loop(self) -> asyncio.AbstractEventLoop | None:
|
| 199 |
+
""":returns: the event loop."""
|
| 200 |
+
return self._context.loop
|
| 201 |
+
|
| 202 |
+
async def acquire( # ty: ignore[invalid-method-override]
|
| 203 |
+
self,
|
| 204 |
+
timeout: float | None = None,
|
| 205 |
+
poll_interval: float | None = None,
|
| 206 |
+
*,
|
| 207 |
+
blocking: bool | None = None,
|
| 208 |
+
cancel_check: Callable[[], bool] | None = None,
|
| 209 |
+
) -> AsyncAcquireReturnProxy:
|
| 210 |
+
"""
|
| 211 |
+
Try to acquire the file lock.
|
| 212 |
+
|
| 213 |
+
:param timeout: maximum wait time for acquiring the lock, ``None`` means use the default
|
| 214 |
+
:attr:`~BaseFileLock.timeout` is and if ``timeout < 0``, there is no timeout and this method will block
|
| 215 |
+
until the lock could be acquired
|
| 216 |
+
:param poll_interval: interval of trying to acquire the lock file, ``None`` means use the default
|
| 217 |
+
:attr:`~BaseFileLock.poll_interval`
|
| 218 |
+
:param blocking: defaults to True. If False, function will return immediately if it cannot obtain a lock on the
|
| 219 |
+
first attempt. Otherwise, this method will block until the timeout expires or the lock is acquired.
|
| 220 |
+
:param cancel_check: a callable returning ``True`` when the acquisition should be canceled. Checked on each poll
|
| 221 |
+
iteration. When triggered, raises :class:`~Timeout` just like an expired timeout.
|
| 222 |
+
|
| 223 |
+
:returns: a context object that will unlock the file when the context is exited
|
| 224 |
+
|
| 225 |
+
:raises Timeout: if fails to acquire lock within the timeout period
|
| 226 |
+
|
| 227 |
+
.. code-block:: python
|
| 228 |
+
|
| 229 |
+
# You can use this method in the context manager (recommended)
|
| 230 |
+
with lock.acquire():
|
| 231 |
+
pass
|
| 232 |
+
|
| 233 |
+
# Or use an equivalent try-finally construct:
|
| 234 |
+
lock.acquire()
|
| 235 |
+
try:
|
| 236 |
+
pass
|
| 237 |
+
finally:
|
| 238 |
+
lock.release()
|
| 239 |
+
|
| 240 |
+
"""
|
| 241 |
+
# Use the default timeout, if no timeout is provided.
|
| 242 |
+
if timeout is None:
|
| 243 |
+
timeout = self._context.timeout
|
| 244 |
+
|
| 245 |
+
if blocking is None:
|
| 246 |
+
blocking = self._context.blocking
|
| 247 |
+
|
| 248 |
+
if poll_interval is None:
|
| 249 |
+
poll_interval = self._context.poll_interval
|
| 250 |
+
|
| 251 |
+
# Increment the number right at the beginning. We can still undo it, if something fails.
|
| 252 |
+
self._context.lock_counter += 1
|
| 253 |
+
|
| 254 |
+
lock_id = id(self)
|
| 255 |
+
lock_filename = self.lock_file
|
| 256 |
+
start_time = time.perf_counter()
|
| 257 |
+
try:
|
| 258 |
+
while True:
|
| 259 |
+
if not self.is_locked:
|
| 260 |
+
self._try_break_expired_lock()
|
| 261 |
+
_LOGGER.debug("Attempting to acquire lock %s on %s", lock_id, lock_filename)
|
| 262 |
+
await self._run_internal_method(self._acquire)
|
| 263 |
+
if self.is_locked:
|
| 264 |
+
_LOGGER.debug("Lock %s acquired on %s", lock_id, lock_filename)
|
| 265 |
+
break
|
| 266 |
+
if self._check_give_up(
|
| 267 |
+
lock_id,
|
| 268 |
+
lock_filename,
|
| 269 |
+
blocking=blocking,
|
| 270 |
+
cancel_check=cancel_check,
|
| 271 |
+
timeout=timeout,
|
| 272 |
+
start_time=start_time,
|
| 273 |
+
):
|
| 274 |
+
raise Timeout(lock_filename) # noqa: TRY301
|
| 275 |
+
msg = "Lock %s not acquired on %s, waiting %s seconds ..."
|
| 276 |
+
_LOGGER.debug(msg, lock_id, lock_filename, poll_interval)
|
| 277 |
+
await asyncio.sleep(poll_interval)
|
| 278 |
+
except BaseException: # Something did go wrong, so decrement the counter.
|
| 279 |
+
self._context.lock_counter = max(0, self._context.lock_counter - 1)
|
| 280 |
+
raise
|
| 281 |
+
return AsyncAcquireReturnProxy(lock=self)
|
| 282 |
+
|
| 283 |
+
async def release(self, force: bool = False) -> None: # ty: ignore[invalid-method-override] # noqa: FBT001, FBT002
|
| 284 |
+
"""
|
| 285 |
+
Release the file lock. The lock is only completely released when the lock counter reaches 0. The lock file
|
| 286 |
+
itself is not automatically deleted.
|
| 287 |
+
|
| 288 |
+
:param force: If true, the lock counter is ignored and the lock is released in every case.
|
| 289 |
+
|
| 290 |
+
"""
|
| 291 |
+
if self.is_locked:
|
| 292 |
+
self._context.lock_counter -= 1
|
| 293 |
+
|
| 294 |
+
if self._context.lock_counter == 0 or force:
|
| 295 |
+
lock_id, lock_filename = id(self), self.lock_file
|
| 296 |
+
|
| 297 |
+
_LOGGER.debug("Attempting to release lock %s on %s", lock_id, lock_filename)
|
| 298 |
+
await self._run_internal_method(self._release)
|
| 299 |
+
self._context.lock_counter = 0
|
| 300 |
+
_LOGGER.debug("Lock %s released on %s", lock_id, lock_filename)
|
| 301 |
+
|
| 302 |
+
async def _run_internal_method(self, method: Callable[[], Any]) -> None:
|
| 303 |
+
if iscoroutinefunction(method):
|
| 304 |
+
await method()
|
| 305 |
+
elif self.run_in_executor:
|
| 306 |
+
await asyncio.get_running_loop().run_in_executor(self.executor, method)
|
| 307 |
+
else:
|
| 308 |
+
method()
|
| 309 |
+
|
| 310 |
+
def __enter__(self) -> NoReturn:
|
| 311 |
+
"""Sync context manager entry is not supported because lock acquisition is a coroutine."""
|
| 312 |
+
msg = "Use `async with` — acquire/release are coroutines and cannot be awaited in a sync context manager."
|
| 313 |
+
raise NotImplementedError(msg)
|
| 314 |
+
|
| 315 |
+
def __exit__(
|
| 316 |
+
self,
|
| 317 |
+
exc_type: type[BaseException] | None,
|
| 318 |
+
exc_value: BaseException | None,
|
| 319 |
+
traceback: object,
|
| 320 |
+
) -> None:
|
| 321 |
+
"""Sync context manager exit is not supported because lock release is a coroutine."""
|
| 322 |
+
msg = "Use `async with` — acquire/release are coroutines and cannot be awaited in a sync context manager."
|
| 323 |
+
raise NotImplementedError(msg)
|
| 324 |
+
|
| 325 |
+
async def __aenter__(self) -> Self:
|
| 326 |
+
"""
|
| 327 |
+
Acquire the lock.
|
| 328 |
+
|
| 329 |
+
:returns: the lock object
|
| 330 |
+
|
| 331 |
+
"""
|
| 332 |
+
await self.acquire()
|
| 333 |
+
return self
|
| 334 |
+
|
| 335 |
+
async def __aexit__(
|
| 336 |
+
self,
|
| 337 |
+
exc_type: type[BaseException] | None,
|
| 338 |
+
exc_value: BaseException | None,
|
| 339 |
+
traceback: TracebackType | None,
|
| 340 |
+
) -> None:
|
| 341 |
+
"""
|
| 342 |
+
Release the lock.
|
| 343 |
+
|
| 344 |
+
:param exc_type: the exception type if raised
|
| 345 |
+
:param exc_value: the exception value if raised
|
| 346 |
+
:param traceback: the exception traceback if raised
|
| 347 |
+
|
| 348 |
+
"""
|
| 349 |
+
await self.release()
|
| 350 |
+
|
| 351 |
+
def __del__(self) -> None:
|
| 352 |
+
"""Release on deletion — safe to call during GC even when no event loop is running."""
|
| 353 |
+
with contextlib.suppress(Exception):
|
| 354 |
+
try:
|
| 355 |
+
loop = asyncio.get_running_loop()
|
| 356 |
+
except RuntimeError:
|
| 357 |
+
# No running loop — try stored loop or create one
|
| 358 |
+
loop = self._context.loop if self._context.loop and not self._context.loop.is_closed() else None
|
| 359 |
+
if loop is None:
|
| 360 |
+
return
|
| 361 |
+
if not loop.is_running(): # pragma: no cover
|
| 362 |
+
loop.run_until_complete(self.release(force=True))
|
| 363 |
+
else:
|
| 364 |
+
loop.create_task(self.release(force=True))
|
| 365 |
+
|
| 366 |
+
|
| 367 |
+
class AsyncSoftFileLock(SoftFileLock, BaseAsyncFileLock):
|
| 368 |
+
"""Simply watches the existence of the lock file."""
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
class AsyncUnixFileLock(UnixFileLock, BaseAsyncFileLock):
|
| 372 |
+
"""Uses the :func:`fcntl.flock` to hard lock the lock file on unix systems."""
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
class AsyncWindowsFileLock(WindowsFileLock, BaseAsyncFileLock):
|
| 376 |
+
"""Uses the :func:`msvcrt.locking` to hard lock the lock file on windows systems."""
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
__all__ = [
|
| 380 |
+
"AsyncAcquireReturnProxy",
|
| 381 |
+
"AsyncSoftFileLock",
|
| 382 |
+
"AsyncUnixFileLock",
|
| 383 |
+
"AsyncWindowsFileLock",
|
| 384 |
+
"BaseAsyncFileLock",
|
| 385 |
+
]
|
.cache/uv/archive-v0/-y3nSpGgh2lg0PkmpCImR/filelock/py.typed
ADDED
|
File without changes
|