tuandunghcmut commited on
Commit
90ecf37
·
verified ·
1 Parent(s): c4cc7f9

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. opencompass/.eggs/click-8.1.7-py3.10.egg/EGG-INFO/LICENSE.rst +28 -0
  2. opencompass/.eggs/click-8.1.7-py3.10.egg/EGG-INFO/PKG-INFO +103 -0
  3. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/LICENSE.txt +208 -0
  4. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/PKG-INFO +1060 -0
  5. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/RECORD +10 -0
  6. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/WHEEL +6 -0
  7. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/top_level.txt +1 -0
  8. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/__init__.py +3 -0
  9. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/_regex_core.py +0 -0
  10. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/regex.py +746 -0
  11. opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/test_regex.py +0 -0
  12. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/LICENCE +49 -0
  13. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/PKG-INFO +1594 -0
  14. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/RECORD +40 -0
  15. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/WHEEL +5 -0
  16. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/entry_points.txt +2 -0
  17. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/requires.txt +19 -0
  18. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/top_level.txt +1 -0
  19. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/__init__.py +38 -0
  20. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/__main__.py +3 -0
  21. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_dist_ver.py +1 -0
  22. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_main.py +9 -0
  23. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_monitor.py +95 -0
  24. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm.py +9 -0
  25. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_gui.py +9 -0
  26. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_notebook.py +9 -0
  27. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_pandas.py +24 -0
  28. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_utils.py +11 -0
  29. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/asyncio.py +93 -0
  30. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/auto.py +40 -0
  31. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/autonotebook.py +29 -0
  32. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/cli.py +324 -0
  33. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/completion.sh +19 -0
  34. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/__init__.py +92 -0
  35. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/bells.py +26 -0
  36. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/concurrent.py +105 -0
  37. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/discord.py +156 -0
  38. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/itertools.py +35 -0
  39. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/logging.py +126 -0
  40. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/slack.py +120 -0
  41. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/telegram.py +153 -0
  42. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/utils_worker.py +38 -0
  43. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/dask.py +44 -0
  44. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/gui.py +179 -0
  45. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/keras.py +122 -0
  46. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/notebook.py +317 -0
  47. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/rich.py +151 -0
  48. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/std.py +1524 -0
  49. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/tk.py +196 -0
  50. opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/tqdm.1 +314 -0
opencompass/.eggs/click-8.1.7-py3.10.egg/EGG-INFO/LICENSE.rst ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright 2014 Pallets
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are
5
+ met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ 3. Neither the name of the copyright holder nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21
+ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
24
+ TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
opencompass/.eggs/click-8.1.7-py3.10.egg/EGG-INFO/PKG-INFO ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: click
3
+ Version: 8.1.7
4
+ Summary: Composable command line interface toolkit
5
+ Home-page: https://palletsprojects.com/p/click/
6
+ Maintainer: Pallets
7
+ Maintainer-email: contact@palletsprojects.com
8
+ License: BSD-3-Clause
9
+ Project-URL: Donate, https://palletsprojects.com/donate
10
+ Project-URL: Documentation, https://click.palletsprojects.com/
11
+ Project-URL: Changes, https://click.palletsprojects.com/changes/
12
+ Project-URL: Source Code, https://github.com/pallets/click/
13
+ Project-URL: Issue Tracker, https://github.com/pallets/click/issues/
14
+ Project-URL: Chat, https://discord.gg/pallets
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: BSD License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python
20
+ Requires-Python: >=3.7
21
+ Description-Content-Type: text/x-rst
22
+ License-File: LICENSE.rst
23
+ Requires-Dist: colorama ; platform_system == "Windows"
24
+ Requires-Dist: importlib-metadata ; python_version < "3.8"
25
+
26
+ \$ click\_
27
+ ==========
28
+
29
+ Click is a Python package for creating beautiful command line interfaces
30
+ in a composable way with as little code as necessary. It's the "Command
31
+ Line Interface Creation Kit". It's highly configurable but comes with
32
+ sensible defaults out of the box.
33
+
34
+ It aims to make the process of writing command line tools quick and fun
35
+ while also preventing any frustration caused by the inability to
36
+ implement an intended CLI API.
37
+
38
+ Click in three points:
39
+
40
+ - Arbitrary nesting of commands
41
+ - Automatic help page generation
42
+ - Supports lazy loading of subcommands at runtime
43
+
44
+
45
+ Installing
46
+ ----------
47
+
48
+ Install and update using `pip`_:
49
+
50
+ .. code-block:: text
51
+
52
+ $ pip install -U click
53
+
54
+ .. _pip: https://pip.pypa.io/en/stable/getting-started/
55
+
56
+
57
+ A Simple Example
58
+ ----------------
59
+
60
+ .. code-block:: python
61
+
62
+ import click
63
+
64
+ @click.command()
65
+ @click.option("--count", default=1, help="Number of greetings.")
66
+ @click.option("--name", prompt="Your name", help="The person to greet.")
67
+ def hello(count, name):
68
+ """Simple program that greets NAME for a total of COUNT times."""
69
+ for _ in range(count):
70
+ click.echo(f"Hello, {name}!")
71
+
72
+ if __name__ == '__main__':
73
+ hello()
74
+
75
+ .. code-block:: text
76
+
77
+ $ python hello.py --count=3
78
+ Your name: Click
79
+ Hello, Click!
80
+ Hello, Click!
81
+ Hello, Click!
82
+
83
+
84
+ Donate
85
+ ------
86
+
87
+ The Pallets organization develops and supports Click and other popular
88
+ packages. In order to grow the community of contributors and users, and
89
+ allow the maintainers to devote more time to the projects, `please
90
+ donate today`_.
91
+
92
+ .. _please donate today: https://palletsprojects.com/donate
93
+
94
+
95
+ Links
96
+ -----
97
+
98
+ - Documentation: https://click.palletsprojects.com/
99
+ - Changes: https://click.palletsprojects.com/changes/
100
+ - PyPI Releases: https://pypi.org/project/click/
101
+ - Source Code: https://github.com/pallets/click
102
+ - Issue Tracker: https://github.com/pallets/click/issues
103
+ - Chat: https://discord.gg/pallets
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/LICENSE.txt ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ This work was derived from the 're' module of CPython 2.6 and CPython 3.1,
2
+ copyright (c) 1998-2001 by Secret Labs AB and licensed under CNRI's Python 1.6
3
+ license.
4
+
5
+ All additions and alterations are licensed under the Apache 2.0 License.
6
+
7
+
8
+ Apache License
9
+ Version 2.0, January 2004
10
+ http://www.apache.org/licenses/
11
+
12
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+
14
+ 1. Definitions.
15
+
16
+ "License" shall mean the terms and conditions for use, reproduction,
17
+ and distribution as defined by Sections 1 through 9 of this document.
18
+
19
+ "Licensor" shall mean the copyright owner or entity authorized by
20
+ the copyright owner that is granting the License.
21
+
22
+ "Legal Entity" shall mean the union of the acting entity and all
23
+ other entities that control, are controlled by, or are under common
24
+ control with that entity. For the purposes of this definition,
25
+ "control" means (i) the power, direct or indirect, to cause the
26
+ direction or management of such entity, whether by contract or
27
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
+ outstanding shares, or (iii) beneficial ownership of such entity.
29
+
30
+ "You" (or "Your") shall mean an individual or Legal Entity
31
+ exercising permissions granted by this License.
32
+
33
+ "Source" form shall mean the preferred form for making modifications,
34
+ including but not limited to software source code, documentation
35
+ source, and configuration files.
36
+
37
+ "Object" form shall mean any form resulting from mechanical
38
+ transformation or translation of a Source form, including but
39
+ not limited to compiled object code, generated documentation,
40
+ and conversions to other media types.
41
+
42
+ "Work" shall mean the work of authorship, whether in Source or
43
+ Object form, made available under the License, as indicated by a
44
+ copyright notice that is included in or attached to the work
45
+ (an example is provided in the Appendix below).
46
+
47
+ "Derivative Works" shall mean any work, whether in Source or Object
48
+ form, that is based on (or derived from) the Work and for which the
49
+ editorial revisions, annotations, elaborations, or other modifications
50
+ represent, as a whole, an original work of authorship. For the purposes
51
+ of this License, Derivative Works shall not include works that remain
52
+ separable from, or merely link (or bind by name) to the interfaces of,
53
+ the Work and Derivative Works thereof.
54
+
55
+ "Contribution" shall mean any work of authorship, including
56
+ the original version of the Work and any modifications or additions
57
+ to that Work or Derivative Works thereof, that is intentionally
58
+ submitted to Licensor for inclusion in the Work by the copyright owner
59
+ or by an individual or Legal Entity authorized to submit on behalf of
60
+ the copyright owner. For the purposes of this definition, "submitted"
61
+ means any form of electronic, verbal, or written communication sent
62
+ to the Licensor or its representatives, including but not limited to
63
+ communication on electronic mailing lists, source code control systems,
64
+ and issue tracking systems that are managed by, or on behalf of, the
65
+ Licensor for the purpose of discussing and improving the Work, but
66
+ excluding communication that is conspicuously marked or otherwise
67
+ designated in writing by the copyright owner as "Not a Contribution."
68
+
69
+ "Contributor" shall mean Licensor and any individual or Legal Entity
70
+ on behalf of whom a Contribution has been received by Licensor and
71
+ subsequently incorporated within the Work.
72
+
73
+ 2. Grant of Copyright License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ copyright license to reproduce, prepare Derivative Works of,
77
+ publicly display, publicly perform, sublicense, and distribute the
78
+ Work and such Derivative Works in Source or Object form.
79
+
80
+ 3. Grant of Patent License. Subject to the terms and conditions of
81
+ this License, each Contributor hereby grants to You a perpetual,
82
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
+ (except as stated in this section) patent license to make, have made,
84
+ use, offer to sell, sell, import, and otherwise transfer the Work,
85
+ where such license applies only to those patent claims licensable
86
+ by such Contributor that are necessarily infringed by their
87
+ Contribution(s) alone or by combination of their Contribution(s)
88
+ with the Work to which such Contribution(s) was submitted. If You
89
+ institute patent litigation against any entity (including a
90
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
91
+ or a Contribution incorporated within the Work constitutes direct
92
+ or contributory patent infringement, then any patent licenses
93
+ granted to You under this License for that Work shall terminate
94
+ as of the date such litigation is filed.
95
+
96
+ 4. Redistribution. You may reproduce and distribute copies of the
97
+ Work or Derivative Works thereof in any medium, with or without
98
+ modifications, and in Source or Object form, provided that You
99
+ meet the following conditions:
100
+
101
+ (a) You must give any other recipients of the Work or
102
+ Derivative Works a copy of this License; and
103
+
104
+ (b) You must cause any modified files to carry prominent notices
105
+ stating that You changed the files; and
106
+
107
+ (c) You must retain, in the Source form of any Derivative Works
108
+ that You distribute, all copyright, patent, trademark, and
109
+ attribution notices from the Source form of the Work,
110
+ excluding those notices that do not pertain to any part of
111
+ the Derivative Works; and
112
+
113
+ (d) If the Work includes a "NOTICE" text file as part of its
114
+ distribution, then any Derivative Works that You distribute must
115
+ include a readable copy of the attribution notices contained
116
+ within such NOTICE file, excluding those notices that do not
117
+ pertain to any part of the Derivative Works, in at least one
118
+ of the following places: within a NOTICE text file distributed
119
+ as part of the Derivative Works; within the Source form or
120
+ documentation, if provided along with the Derivative Works; or,
121
+ within a display generated by the Derivative Works, if and
122
+ wherever such third-party notices normally appear. The contents
123
+ of the NOTICE file are for informational purposes only and
124
+ do not modify the License. You may add Your own attribution
125
+ notices within Derivative Works that You distribute, alongside
126
+ or as an addendum to the NOTICE text from the Work, provided
127
+ that such additional attribution notices cannot be construed
128
+ as modifying the License.
129
+
130
+ You may add Your own copyright statement to Your modifications and
131
+ may provide additional or different license terms and conditions
132
+ for use, reproduction, or distribution of Your modifications, or
133
+ for any such Derivative Works as a whole, provided Your use,
134
+ reproduction, and distribution of the Work otherwise complies with
135
+ the conditions stated in this License.
136
+
137
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
138
+ any Contribution intentionally submitted for inclusion in the Work
139
+ by You to the Licensor shall be under the terms and conditions of
140
+ this License, without any additional terms or conditions.
141
+ Notwithstanding the above, nothing herein shall supersede or modify
142
+ the terms of any separate license agreement you may have executed
143
+ with Licensor regarding such Contributions.
144
+
145
+ 6. Trademarks. This License does not grant permission to use the trade
146
+ names, trademarks, service marks, or product names of the Licensor,
147
+ except as required for reasonable and customary use in describing the
148
+ origin of the Work and reproducing the content of the NOTICE file.
149
+
150
+ 7. Disclaimer of Warranty. Unless required by applicable law or
151
+ agreed to in writing, Licensor provides the Work (and each
152
+ Contributor provides its Contributions) on an "AS IS" BASIS,
153
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
+ implied, including, without limitation, any warranties or conditions
155
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
+ PARTICULAR PURPOSE. You are solely responsible for determining the
157
+ appropriateness of using or redistributing the Work and assume any
158
+ risks associated with Your exercise of permissions under this License.
159
+
160
+ 8. Limitation of Liability. In no event and under no legal theory,
161
+ whether in tort (including negligence), contract, or otherwise,
162
+ unless required by applicable law (such as deliberate and grossly
163
+ negligent acts) or agreed to in writing, shall any Contributor be
164
+ liable to You for damages, including any direct, indirect, special,
165
+ incidental, or consequential damages of any character arising as a
166
+ result of this License or out of the use or inability to use the
167
+ Work (including but not limited to damages for loss of goodwill,
168
+ work stoppage, computer failure or malfunction, or any and all
169
+ other commercial damages or losses), even if such Contributor
170
+ has been advised of the possibility of such damages.
171
+
172
+ 9. Accepting Warranty or Additional Liability. While redistributing
173
+ the Work or Derivative Works thereof, You may choose to offer,
174
+ and charge a fee for, acceptance of support, warranty, indemnity,
175
+ or other liability obligations and/or rights consistent with this
176
+ License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf
178
+ of any other Contributor, and only if You agree to indemnify,
179
+ defend, and hold each Contributor harmless for any liability
180
+ incurred by, or claims asserted against, such Contributor by reason
181
+ of your accepting any such warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work.
186
+
187
+ To apply the Apache License to your work, attach the following
188
+ boilerplate notice, with the fields enclosed by brackets "[]"
189
+ replaced with your own identifying information. (Don't include
190
+ the brackets!) The text should be enclosed in the appropriate
191
+ comment syntax for the file format. We also recommend that a
192
+ file or class name and description of purpose be included on the
193
+ same "printed page" as the copyright notice for easier
194
+ identification within third-party archives.
195
+
196
+ Copyright 2020 Matthew Barnett
197
+
198
+ Licensed under the Apache License, Version 2.0 (the "License");
199
+ you may not use this file except in compliance with the License.
200
+ You may obtain a copy of the License at
201
+
202
+ http://www.apache.org/licenses/LICENSE-2.0
203
+
204
+ Unless required by applicable law or agreed to in writing, software
205
+ distributed under the License is distributed on an "AS IS" BASIS,
206
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
+ See the License for the specific language governing permissions and
208
+ limitations under the License.
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/PKG-INFO ADDED
@@ -0,0 +1,1060 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: regex
3
+ Version: 2024.11.6
4
+ Summary: Alternative regular expression module, to replace re.
5
+ Home-page: https://github.com/mrabarnett/mrab-regex
6
+ Author: Matthew Barnett
7
+ Author-email: regex@mrabarnett.plus.com
8
+ License: Apache Software License
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Topic :: Text Processing
22
+ Classifier: Topic :: Text Processing :: General
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/x-rst
25
+ License-File: LICENSE.txt
26
+
27
+ Introduction
28
+ ------------
29
+
30
+ This regex implementation is backwards-compatible with the standard 're' module, but offers additional functionality.
31
+
32
+ Python 2
33
+ --------
34
+
35
+ Python 2 is no longer supported. The last release that supported Python 2 was 2021.11.10.
36
+
37
+ PyPy
38
+ ----
39
+
40
+ This module is targeted at CPython. It expects that all codepoints are the same width, so it won't behave properly with PyPy outside U+0000..U+007F because PyPy stores strings as UTF-8.
41
+
42
+ Multithreading
43
+ --------------
44
+
45
+ The regex module releases the GIL during matching on instances of the built-in (immutable) string classes, enabling other Python threads to run concurrently. It is also possible to force the regex module to release the GIL during matching by calling the matching methods with the keyword argument ``concurrent=True``. The behaviour is undefined if the string changes during matching, so use it *only* when it is guaranteed that that won't happen.
46
+
47
+ Unicode
48
+ -------
49
+
50
+ This module supports Unicode 16.0.0. Full Unicode case-folding is supported.
51
+
52
+ Flags
53
+ -----
54
+
55
+ There are 2 kinds of flag: scoped and global. Scoped flags can apply to only part of a pattern and can be turned on or off; global flags apply to the entire pattern and can only be turned on.
56
+
57
+ The scoped flags are: ``ASCII (?a)``, ``FULLCASE (?f)``, ``IGNORECASE (?i)``, ``LOCALE (?L)``, ``MULTILINE (?m)``, ``DOTALL (?s)``, ``UNICODE (?u)``, ``VERBOSE (?x)``, ``WORD (?w)``.
58
+
59
+ The global flags are: ``BESTMATCH (?b)``, ``ENHANCEMATCH (?e)``, ``POSIX (?p)``, ``REVERSE (?r)``, ``VERSION0 (?V0)``, ``VERSION1 (?V1)``.
60
+
61
+ If neither the ``ASCII``, ``LOCALE`` nor ``UNICODE`` flag is specified, it will default to ``UNICODE`` if the regex pattern is a Unicode string and ``ASCII`` if it's a bytestring.
62
+
63
+ The ``ENHANCEMATCH`` flag makes fuzzy matching attempt to improve the fit of the next match that it finds.
64
+
65
+ The ``BESTMATCH`` flag makes fuzzy matching search for the best match instead of the next match.
66
+
67
+ Old vs new behaviour
68
+ --------------------
69
+
70
+ In order to be compatible with the re module, this module has 2 behaviours:
71
+
72
+ * **Version 0** behaviour (old behaviour, compatible with the re module):
73
+
74
+ Please note that the re module's behaviour may change over time, and I'll endeavour to match that behaviour in version 0.
75
+
76
+ * Indicated by the ``VERSION0`` flag.
77
+
78
+ * Zero-width matches are not handled correctly in the re module before Python 3.7. The behaviour in those earlier versions is:
79
+
80
+ * ``.split`` won't split a string at a zero-width match.
81
+
82
+ * ``.sub`` will advance by one character after a zero-width match.
83
+
84
+ * Inline flags apply to the entire pattern, and they can't be turned off.
85
+
86
+ * Only simple sets are supported.
87
+
88
+ * Case-insensitive matches in Unicode use simple case-folding by default.
89
+
90
+ * **Version 1** behaviour (new behaviour, possibly different from the re module):
91
+
92
+ * Indicated by the ``VERSION1`` flag.
93
+
94
+ * Zero-width matches are handled correctly.
95
+
96
+ * Inline flags apply to the end of the group or pattern, and they can be turned off.
97
+
98
+ * Nested sets and set operations are supported.
99
+
100
+ * Case-insensitive matches in Unicode use full case-folding by default.
101
+
102
+ If no version is specified, the regex module will default to ``regex.DEFAULT_VERSION``.
103
+
104
+ Case-insensitive matches in Unicode
105
+ -----------------------------------
106
+
107
+ The regex module supports both simple and full case-folding for case-insensitive matches in Unicode. Use of full case-folding can be turned on using the ``FULLCASE`` flag. Please note that this flag affects how the ``IGNORECASE`` flag works; the ``FULLCASE`` flag itself does not turn on case-insensitive matching.
108
+
109
+ Version 0 behaviour: the flag is off by default.
110
+
111
+ Version 1 behaviour: the flag is on by default.
112
+
113
+ Nested sets and set operations
114
+ ------------------------------
115
+
116
+ It's not possible to support both simple sets, as used in the re module, and nested sets at the same time because of a difference in the meaning of an unescaped ``"["`` in a set.
117
+
118
+ For example, the pattern ``[[a-z]--[aeiou]]`` is treated in the version 0 behaviour (simple sets, compatible with the re module) as:
119
+
120
+ * Set containing "[" and the letters "a" to "z"
121
+
122
+ * Literal "--"
123
+
124
+ * Set containing letters "a", "e", "i", "o", "u"
125
+
126
+ * Literal "]"
127
+
128
+ but in the version 1 behaviour (nested sets, enhanced behaviour) as:
129
+
130
+ * Set which is:
131
+
132
+ * Set containing the letters "a" to "z"
133
+
134
+ * but excluding:
135
+
136
+ * Set containing the letters "a", "e", "i", "o", "u"
137
+
138
+ Version 0 behaviour: only simple sets are supported.
139
+
140
+ Version 1 behaviour: nested sets and set operations are supported.
141
+
142
+ Notes on named groups
143
+ ---------------------
144
+
145
+ All groups have a group number, starting from 1.
146
+
147
+ Groups with the same group name will have the same group number, and groups with a different group name will have a different group number.
148
+
149
+ The same name can be used by more than one group, with later captures 'overwriting' earlier captures. All the captures of the group will be available from the ``captures`` method of the match object.
150
+
151
+ Group numbers will be reused across different branches of a branch reset, eg. ``(?|(first)|(second))`` has only group 1. If groups have different group names then they will, of course, have different group numbers, eg. ``(?|(?P<foo>first)|(?P<bar>second))`` has group 1 ("foo") and group 2 ("bar").
152
+
153
+ In the regex ``(\s+)(?|(?P<foo>[A-Z]+)|(\w+) (?P<foo>[0-9]+)`` there are 2 groups:
154
+
155
+ * ``(\s+)`` is group 1.
156
+
157
+ * ``(?P<foo>[A-Z]+)`` is group 2, also called "foo".
158
+
159
+ * ``(\w+)`` is group 2 because of the branch reset.
160
+
161
+ * ``(?P<foo>[0-9]+)`` is group 2 because it's called "foo".
162
+
163
+ If you want to prevent ``(\w+)`` from being group 2, you need to name it (different name, different group number).
164
+
165
+ Additional features
166
+ -------------------
167
+
168
+ The issue numbers relate to the Python bug tracker, except where listed otherwise.
169
+
170
+ Added ``\p{Horiz_Space}`` and ``\p{Vert_Space}`` (`GitHub issue 477 <https://github.com/mrabarnett/mrab-regex/issues/477#issuecomment-1216779547>`_)
171
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
172
+
173
+ ``\p{Horiz_Space}`` or ``\p{H}`` matches horizontal whitespace and ``\p{Vert_Space}`` or ``\p{V}`` matches vertical whitespace.
174
+
175
+ Added support for lookaround in conditional pattern (`Hg issue 163 <https://github.com/mrabarnett/mrab-regex/issues/163>`_)
176
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
177
+
178
+ The test of a conditional pattern can be a lookaround.
179
+
180
+ .. sourcecode:: python
181
+
182
+ >>> regex.match(r'(?(?=\d)\d+|\w+)', '123abc')
183
+ <regex.Match object; span=(0, 3), match='123'>
184
+ >>> regex.match(r'(?(?=\d)\d+|\w+)', 'abc123')
185
+ <regex.Match object; span=(0, 6), match='abc123'>
186
+
187
+ This is not quite the same as putting a lookaround in the first branch of a pair of alternatives.
188
+
189
+ .. sourcecode:: python
190
+
191
+ >>> print(regex.match(r'(?:(?=\d)\d+\b|\w+)', '123abc'))
192
+ <regex.Match object; span=(0, 6), match='123abc'>
193
+ >>> print(regex.match(r'(?(?=\d)\d+\b|\w+)', '123abc'))
194
+ None
195
+
196
+ In the first example, the lookaround matched, but the remainder of the first branch failed to match, and so the second branch was attempted, whereas in the second example, the lookaround matched, and the first branch failed to match, but the second branch was **not** attempted.
197
+
198
+ Added POSIX matching (leftmost longest) (`Hg issue 150 <https://github.com/mrabarnett/mrab-regex/issues/150>`_)
199
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
200
+
201
+ The POSIX standard for regex is to return the leftmost longest match. This can be turned on using the ``POSIX`` flag.
202
+
203
+ .. sourcecode:: python
204
+
205
+ >>> # Normal matching.
206
+ >>> regex.search(r'Mr|Mrs', 'Mrs')
207
+ <regex.Match object; span=(0, 2), match='Mr'>
208
+ >>> regex.search(r'one(self)?(selfsufficient)?', 'oneselfsufficient')
209
+ <regex.Match object; span=(0, 7), match='oneself'>
210
+ >>> # POSIX matching.
211
+ >>> regex.search(r'(?p)Mr|Mrs', 'Mrs')
212
+ <regex.Match object; span=(0, 3), match='Mrs'>
213
+ >>> regex.search(r'(?p)one(self)?(selfsufficient)?', 'oneselfsufficient')
214
+ <regex.Match object; span=(0, 17), match='oneselfsufficient'>
215
+
216
+ Note that it will take longer to find matches because when it finds a match at a certain position, it won't return that immediately, but will keep looking to see if there's another longer match there.
217
+
218
+ Added ``(?(DEFINE)...)`` (`Hg issue 152 <https://github.com/mrabarnett/mrab-regex/issues/152>`_)
219
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220
+
221
+ If there's no group called "DEFINE", then ... will be ignored except that any groups defined within it can be called and that the normal rules for numbering groups still apply.
222
+
223
+ .. sourcecode:: python
224
+
225
+ >>> regex.search(r'(?(DEFINE)(?P<quant>\d+)(?P<item>\w+))(?&quant) (?&item)', '5 elephants')
226
+ <regex.Match object; span=(0, 11), match='5 elephants'>
227
+
228
+ Added ``(*PRUNE)``, ``(*SKIP)`` and ``(*FAIL)`` (`Hg issue 153 <https://github.com/mrabarnett/mrab-regex/issues/153>`_)
229
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
230
+
231
+ ``(*PRUNE)`` discards the backtracking info up to that point. When used in an atomic group or a lookaround, it won't affect the enclosing pattern.
232
+
233
+ ``(*SKIP)`` is similar to ``(*PRUNE)``, except that it also sets where in the text the next attempt to match will start. When used in an atomic group or a lookaround, it won't affect the enclosing pattern.
234
+
235
+ ``(*FAIL)`` causes immediate backtracking. ``(*F)`` is a permitted abbreviation.
236
+
237
+ Added ``\K`` (`Hg issue 151 <https://github.com/mrabarnett/mrab-regex/issues/151>`_)
238
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
239
+
240
+ Keeps the part of the entire match after the position where ``\K`` occurred; the part before it is discarded.
241
+
242
+ It does not affect what groups return.
243
+
244
+ .. sourcecode:: python
245
+
246
+ >>> m = regex.search(r'(\w\w\K\w\w\w)', 'abcdef')
247
+ >>> m[0]
248
+ 'cde'
249
+ >>> m[1]
250
+ 'abcde'
251
+ >>>
252
+ >>> m = regex.search(r'(?r)(\w\w\K\w\w\w)', 'abcdef')
253
+ >>> m[0]
254
+ 'bc'
255
+ >>> m[1]
256
+ 'bcdef'
257
+
258
+ Added capture subscripting for ``expandf`` and ``subf``/``subfn`` (`Hg issue 133 <https://github.com/mrabarnett/mrab-regex/issues/133>`_)
259
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260
+
261
+ You can use subscripting to get the captures of a repeated group.
262
+
263
+ .. sourcecode:: python
264
+
265
+ >>> m = regex.match(r"(\w)+", "abc")
266
+ >>> m.expandf("{1}")
267
+ 'c'
268
+ >>> m.expandf("{1[0]} {1[1]} {1[2]}")
269
+ 'a b c'
270
+ >>> m.expandf("{1[-1]} {1[-2]} {1[-3]}")
271
+ 'c b a'
272
+ >>>
273
+ >>> m = regex.match(r"(?P<letter>\w)+", "abc")
274
+ >>> m.expandf("{letter}")
275
+ 'c'
276
+ >>> m.expandf("{letter[0]} {letter[1]} {letter[2]}")
277
+ 'a b c'
278
+ >>> m.expandf("{letter[-1]} {letter[-2]} {letter[-3]}")
279
+ 'c b a'
280
+
281
+ Added support for referring to a group by number using ``(?P=...)``
282
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283
+
284
+ This is in addition to the existing ``\g<...>``.
285
+
286
+ Fixed the handling of locale-sensitive regexes
287
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
288
+
289
+ The ``LOCALE`` flag is intended for legacy code and has limited support. You're still recommended to use Unicode instead.
290
+
291
+ Added partial matches (`Hg issue 102 <https://github.com/mrabarnett/mrab-regex/issues/102>`_)
292
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
293
+
294
+ A partial match is one that matches up to the end of string, but that string has been truncated and you want to know whether a complete match could be possible if the string had not been truncated.
295
+
296
+ Partial matches are supported by ``match``, ``search``, ``fullmatch`` and ``finditer`` with the ``partial`` keyword argument.
297
+
298
+ Match objects have a ``partial`` attribute, which is ``True`` if it's a partial match.
299
+
300
+ For example, if you wanted a user to enter a 4-digit number and check it character by character as it was being entered:
301
+
302
+ .. sourcecode:: python
303
+
304
+ >>> pattern = regex.compile(r'\d{4}')
305
+
306
+ >>> # Initially, nothing has been entered:
307
+ >>> print(pattern.fullmatch('', partial=True))
308
+ <regex.Match object; span=(0, 0), match='', partial=True>
309
+
310
+ >>> # An empty string is OK, but it's only a partial match.
311
+ >>> # The user enters a letter:
312
+ >>> print(pattern.fullmatch('a', partial=True))
313
+ None
314
+ >>> # It'll never match.
315
+
316
+ >>> # The user deletes that and enters a digit:
317
+ >>> print(pattern.fullmatch('1', partial=True))
318
+ <regex.Match object; span=(0, 1), match='1', partial=True>
319
+ >>> # It matches this far, but it's only a partial match.
320
+
321
+ >>> # The user enters 2 more digits:
322
+ >>> print(pattern.fullmatch('123', partial=True))
323
+ <regex.Match object; span=(0, 3), match='123', partial=True>
324
+ >>> # It matches this far, but it's only a partial match.
325
+
326
+ >>> # The user enters another digit:
327
+ >>> print(pattern.fullmatch('1234', partial=True))
328
+ <regex.Match object; span=(0, 4), match='1234'>
329
+ >>> # It's a complete match.
330
+
331
+ >>> # If the user enters another digit:
332
+ >>> print(pattern.fullmatch('12345', partial=True))
333
+ None
334
+ >>> # It's no longer a match.
335
+
336
+ >>> # This is a partial match:
337
+ >>> pattern.match('123', partial=True).partial
338
+ True
339
+
340
+ >>> # This is a complete match:
341
+ >>> pattern.match('1233', partial=True).partial
342
+ False
343
+
344
+ ``*`` operator not working correctly with sub() (`Hg issue 106 <https://github.com/mrabarnett/mrab-regex/issues/106>`_)
345
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
346
+
347
+ Sometimes it's not clear how zero-width matches should be handled. For example, should ``.*`` match 0 characters directly after matching >0 characters?
348
+
349
+ .. sourcecode:: python
350
+
351
+ >>> regex.sub('.*', 'x', 'test')
352
+ 'xx'
353
+ >>> regex.sub('.*?', '|', 'test')
354
+ '|||||||||'
355
+
356
+ Added ``capturesdict`` (`Hg issue 86 <https://github.com/mrabarnett/mrab-regex/issues/86>`_)
357
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
358
+
359
+ ``capturesdict`` is a combination of ``groupdict`` and ``captures``:
360
+
361
+ ``groupdict`` returns a dict of the named groups and the last capture of those groups.
362
+
363
+ ``captures`` returns a list of all the captures of a group
364
+
365
+ ``capturesdict`` returns a dict of the named groups and lists of all the captures of those groups.
366
+
367
+ .. sourcecode:: python
368
+
369
+ >>> m = regex.match(r"(?:(?P<word>\w+) (?P<digits>\d+)\n)+", "one 1\ntwo 2\nthree 3\n")
370
+ >>> m.groupdict()
371
+ {'word': 'three', 'digits': '3'}
372
+ >>> m.captures("word")
373
+ ['one', 'two', 'three']
374
+ >>> m.captures("digits")
375
+ ['1', '2', '3']
376
+ >>> m.capturesdict()
377
+ {'word': ['one', 'two', 'three'], 'digits': ['1', '2', '3']}
378
+
379
+ Added ``allcaptures`` and ``allspans`` (`Git issue 474 <https://github.com/mrabarnett/mrab-regex/issues/474>`_)
380
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
381
+
382
+ ``allcaptures`` returns a list of all the captures of all the groups.
383
+
384
+ ``allspans`` returns a list of all the spans of the all captures of all the groups.
385
+
386
+ .. sourcecode:: python
387
+
388
+ >>> m = regex.match(r"(?:(?P<word>\w+) (?P<digits>\d+)\n)+", "one 1\ntwo 2\nthree 3\n")
389
+ >>> m.allcaptures()
390
+ (['one 1\ntwo 2\nthree 3\n'], ['one', 'two', 'three'], ['1', '2', '3'])
391
+ >>> m.allspans()
392
+ ([(0, 20)], [(0, 3), (6, 9), (12, 17)], [(4, 5), (10, 11), (18, 19)])
393
+
394
+ Allow duplicate names of groups (`Hg issue 87 <https://github.com/mrabarnett/mrab-regex/issues/87>`_)
395
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
396
+
397
+ Group names can be duplicated.
398
+
399
+ .. sourcecode:: python
400
+
401
+ >>> # With optional groups:
402
+ >>>
403
+ >>> # Both groups capture, the second capture 'overwriting' the first.
404
+ >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or second")
405
+ >>> m.group("item")
406
+ 'second'
407
+ >>> m.captures("item")
408
+ ['first', 'second']
409
+ >>> # Only the second group captures.
410
+ >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", " or second")
411
+ >>> m.group("item")
412
+ 'second'
413
+ >>> m.captures("item")
414
+ ['second']
415
+ >>> # Only the first group captures.
416
+ >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or ")
417
+ >>> m.group("item")
418
+ 'first'
419
+ >>> m.captures("item")
420
+ ['first']
421
+ >>>
422
+ >>> # With mandatory groups:
423
+ >>>
424
+ >>> # Both groups capture, the second capture 'overwriting' the first.
425
+ >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)?", "first or second")
426
+ >>> m.group("item")
427
+ 'second'
428
+ >>> m.captures("item")
429
+ ['first', 'second']
430
+ >>> # Again, both groups capture, the second capture 'overwriting' the first.
431
+ >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", " or second")
432
+ >>> m.group("item")
433
+ 'second'
434
+ >>> m.captures("item")
435
+ ['', 'second']
436
+ >>> # And yet again, both groups capture, the second capture 'overwriting' the first.
437
+ >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", "first or ")
438
+ >>> m.group("item")
439
+ ''
440
+ >>> m.captures("item")
441
+ ['first', '']
442
+
443
+ Added ``fullmatch`` (`issue #16203 <https://bugs.python.org/issue16203>`_)
444
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
445
+
446
+ ``fullmatch`` behaves like ``match``, except that it must match all of the string.
447
+
448
+ .. sourcecode:: python
449
+
450
+ >>> print(regex.fullmatch(r"abc", "abc").span())
451
+ (0, 3)
452
+ >>> print(regex.fullmatch(r"abc", "abcx"))
453
+ None
454
+ >>> print(regex.fullmatch(r"abc", "abcx", endpos=3).span())
455
+ (0, 3)
456
+ >>> print(regex.fullmatch(r"abc", "xabcy", pos=1, endpos=4).span())
457
+ (1, 4)
458
+ >>>
459
+ >>> regex.match(r"a.*?", "abcd").group(0)
460
+ 'a'
461
+ >>> regex.fullmatch(r"a.*?", "abcd").group(0)
462
+ 'abcd'
463
+
464
+ Added ``subf`` and ``subfn``
465
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
466
+
467
+ ``subf`` and ``subfn`` are alternatives to ``sub`` and ``subn`` respectively. When passed a replacement string, they treat it as a format string.
468
+
469
+ .. sourcecode:: python
470
+
471
+ >>> regex.subf(r"(\w+) (\w+)", "{0} => {2} {1}", "foo bar")
472
+ 'foo bar => bar foo'
473
+ >>> regex.subf(r"(?P<word1>\w+) (?P<word2>\w+)", "{word2} {word1}", "foo bar")
474
+ 'bar foo'
475
+
476
+ Added ``expandf`` to match object
477
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
478
+
479
+ ``expandf`` is an alternative to ``expand``. When passed a replacement string, it treats it as a format string.
480
+
481
+ .. sourcecode:: python
482
+
483
+ >>> m = regex.match(r"(\w+) (\w+)", "foo bar")
484
+ >>> m.expandf("{0} => {2} {1}")
485
+ 'foo bar => bar foo'
486
+ >>>
487
+ >>> m = regex.match(r"(?P<word1>\w+) (?P<word2>\w+)", "foo bar")
488
+ >>> m.expandf("{word2} {word1}")
489
+ 'bar foo'
490
+
491
+ Detach searched string
492
+ ^^^^^^^^^^^^^^^^^^^^^^
493
+
494
+ A match object contains a reference to the string that was searched, via its ``string`` attribute. The ``detach_string`` method will 'detach' that string, making it available for garbage collection, which might save valuable memory if that string is very large.
495
+
496
+ .. sourcecode:: python
497
+
498
+ >>> m = regex.search(r"\w+", "Hello world")
499
+ >>> print(m.group())
500
+ Hello
501
+ >>> print(m.string)
502
+ Hello world
503
+ >>> m.detach_string()
504
+ >>> print(m.group())
505
+ Hello
506
+ >>> print(m.string)
507
+ None
508
+
509
+ Recursive patterns (`Hg issue 27 <https://github.com/mrabarnett/mrab-regex/issues/27>`_)
510
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
511
+
512
+ Recursive and repeated patterns are supported.
513
+
514
+ ``(?R)`` or ``(?0)`` tries to match the entire regex recursively. ``(?1)``, ``(?2)``, etc, try to match the relevant group.
515
+
516
+ ``(?&name)`` tries to match the named group.
517
+
518
+ .. sourcecode:: python
519
+
520
+ >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Tarzan loves Jane").groups()
521
+ ('Tarzan',)
522
+ >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Jane loves Tarzan").groups()
523
+ ('Jane',)
524
+
525
+ >>> m = regex.search(r"(\w)(?:(?R)|(\w?))\1", "kayak")
526
+ >>> m.group(0, 1, 2)
527
+ ('kayak', 'k', None)
528
+
529
+ The first two examples show how the subpattern within the group is reused, but is _not_ itself a group. In other words, ``"(Tarzan|Jane) loves (?1)"`` is equivalent to ``"(Tarzan|Jane) loves (?:Tarzan|Jane)"``.
530
+
531
+ It's possible to backtrack into a recursed or repeated group.
532
+
533
+ You can't call a group if there is more than one group with that group name or group number (``"ambiguous group reference"``).
534
+
535
+ The alternative forms ``(?P>name)`` and ``(?P&name)`` are also supported.
536
+
537
+ Full Unicode case-folding is supported
538
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
539
+
540
+ In version 1 behaviour, the regex module uses full case-folding when performing case-insensitive matches in Unicode.
541
+
542
+ .. sourcecode:: python
543
+
544
+ >>> regex.match(r"(?iV1)strasse", "stra\N{LATIN SMALL LETTER SHARP S}e").span()
545
+ (0, 6)
546
+ >>> regex.match(r"(?iV1)stra\N{LATIN SMALL LETTER SHARP S}e", "STRASSE").span()
547
+ (0, 7)
548
+
549
+ In version 0 behaviour, it uses simple case-folding for backward compatibility with the re module.
550
+
551
+ Approximate "fuzzy" matching (`Hg issue 12 <https://github.com/mrabarnett/mrab-regex/issues/12>`_, `Hg issue 41 <https://github.com/mrabarnett/mrab-regex/issues/41>`_, `Hg issue 109 <https://github.com/mrabarnett/mrab-regex/issues/109>`_)
552
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
553
+
554
+ Regex usually attempts an exact match, but sometimes an approximate, or "fuzzy", match is needed, for those cases where the text being searched may contain errors in the form of inserted, deleted or substituted characters.
555
+
556
+ A fuzzy regex specifies which types of errors are permitted, and, optionally, either the minimum and maximum or only the maximum permitted number of each type. (You cannot specify only a minimum.)
557
+
558
+ The 3 types of error are:
559
+
560
+ * Insertion, indicated by "i"
561
+
562
+ * Deletion, indicated by "d"
563
+
564
+ * Substitution, indicated by "s"
565
+
566
+ In addition, "e" indicates any type of error.
567
+
568
+ The fuzziness of a regex item is specified between "{" and "}" after the item.
569
+
570
+ Examples:
571
+
572
+ * ``foo`` match "foo" exactly
573
+
574
+ * ``(?:foo){i}`` match "foo", permitting insertions
575
+
576
+ * ``(?:foo){d}`` match "foo", permitting deletions
577
+
578
+ * ``(?:foo){s}`` match "foo", permitting substitutions
579
+
580
+ * ``(?:foo){i,s}`` match "foo", permitting insertions and substitutions
581
+
582
+ * ``(?:foo){e}`` match "foo", permitting errors
583
+
584
+ If a certain type of error is specified, then any type not specified will **not** be permitted.
585
+
586
+ In the following examples I'll omit the item and write only the fuzziness:
587
+
588
+ * ``{d<=3}`` permit at most 3 deletions, but no other types
589
+
590
+ * ``{i<=1,s<=2}`` permit at most 1 insertion and at most 2 substitutions, but no deletions
591
+
592
+ * ``{1<=e<=3}`` permit at least 1 and at most 3 errors
593
+
594
+ * ``{i<=2,d<=2,e<=3}`` permit at most 2 insertions, at most 2 deletions, at most 3 errors in total, but no substitutions
595
+
596
+ It's also possible to state the costs of each type of error and the maximum permitted total cost.
597
+
598
+ Examples:
599
+
600
+ * ``{2i+2d+1s<=4}`` each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
601
+
602
+ * ``{i<=1,d<=1,s<=1,2i+2d+1s<=4}`` at most 1 insertion, at most 1 deletion, at most 1 substitution; each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
603
+
604
+ You can also use "<" instead of "<=" if you want an exclusive minimum or maximum.
605
+
606
+ You can add a test to perform on a character that's substituted or inserted.
607
+
608
+ Examples:
609
+
610
+ * ``{s<=2:[a-z]}`` at most 2 substitutions, which must be in the character set ``[a-z]``.
611
+
612
+ * ``{s<=2,i<=3:\d}`` at most 2 substitutions, at most 3 insertions, which must be digits.
613
+
614
+ By default, fuzzy matching searches for the first match that meets the given constraints. The ``ENHANCEMATCH`` flag will cause it to attempt to improve the fit (i.e. reduce the number of errors) of the match that it has found.
615
+
616
+ The ``BESTMATCH`` flag will make it search for the best match instead.
617
+
618
+ Further examples to note:
619
+
620
+ * ``regex.search("(dog){e}", "cat and dog")[1]`` returns ``"cat"`` because that matches ``"dog"`` with 3 errors (an unlimited number of errors is permitted).
621
+
622
+ * ``regex.search("(dog){e<=1}", "cat and dog")[1]`` returns ``" dog"`` (with a leading space) because that matches ``"dog"`` with 1 error, which is within the limit.
623
+
624
+ * ``regex.search("(?e)(dog){e<=1}", "cat and dog")[1]`` returns ``"dog"`` (without a leading space) because the fuzzy search matches ``" dog"`` with 1 error, which is within the limit, and the ``(?e)`` then it attempts a better fit.
625
+
626
+ In the first two examples there are perfect matches later in the string, but in neither case is it the first possible match.
627
+
628
+ The match object has an attribute ``fuzzy_counts`` which gives the total number of substitutions, insertions and deletions.
629
+
630
+ .. sourcecode:: python
631
+
632
+ >>> # A 'raw' fuzzy match:
633
+ >>> regex.fullmatch(r"(?:cats|cat){e<=1}", "cat").fuzzy_counts
634
+ (0, 0, 1)
635
+ >>> # 0 substitutions, 0 insertions, 1 deletion.
636
+
637
+ >>> # A better match might be possible if the ENHANCEMATCH flag used:
638
+ >>> regex.fullmatch(r"(?e)(?:cats|cat){e<=1}", "cat").fuzzy_counts
639
+ (0, 0, 0)
640
+ >>> # 0 substitutions, 0 insertions, 0 deletions.
641
+
642
+ The match object also has an attribute ``fuzzy_changes`` which gives a tuple of the positions of the substitutions, insertions and deletions.
643
+
644
+ .. sourcecode:: python
645
+
646
+ >>> m = regex.search('(fuu){i<=2,d<=2,e<=5}', 'anaconda foo bar')
647
+ >>> m
648
+ <regex.Match object; span=(7, 10), match='a f', fuzzy_counts=(0, 2, 2)>
649
+ >>> m.fuzzy_changes
650
+ ([], [7, 8], [10, 11])
651
+
652
+ What this means is that if the matched part of the string had been:
653
+
654
+ .. sourcecode:: python
655
+
656
+ 'anacondfuuoo bar'
657
+
658
+ it would've been an exact match.
659
+
660
+ However, there were insertions at positions 7 and 8:
661
+
662
+ .. sourcecode:: python
663
+
664
+ 'anaconda fuuoo bar'
665
+ ^^
666
+
667
+ and deletions at positions 10 and 11:
668
+
669
+ .. sourcecode:: python
670
+
671
+ 'anaconda f~~oo bar'
672
+ ^^
673
+
674
+ So the actual string was:
675
+
676
+ .. sourcecode:: python
677
+
678
+ 'anaconda foo bar'
679
+
680
+ Named lists ``\L<name>`` (`Hg issue 11 <https://github.com/mrabarnett/mrab-regex/issues/11>`_)
681
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
682
+
683
+ There are occasions where you may want to include a list (actually, a set) of options in a regex.
684
+
685
+ One way is to build the pattern like this:
686
+
687
+ .. sourcecode:: python
688
+
689
+ >>> p = regex.compile(r"first|second|third|fourth|fifth")
690
+
691
+ but if the list is large, parsing the resulting regex can take considerable time, and care must also be taken that the strings are properly escaped and properly ordered, for example, "cats" before "cat".
692
+
693
+ The new alternative is to use a named list:
694
+
695
+ .. sourcecode:: python
696
+
697
+ >>> option_set = ["first", "second", "third", "fourth", "fifth"]
698
+ >>> p = regex.compile(r"\L<options>", options=option_set)
699
+
700
+ The order of the items is irrelevant, they are treated as a set. The named lists are available as the ``.named_lists`` attribute of the pattern object :
701
+
702
+ .. sourcecode:: python
703
+
704
+ >>> print(p.named_lists)
705
+ {'options': frozenset({'third', 'first', 'fifth', 'fourth', 'second'})}
706
+
707
+ If there are any unused keyword arguments, ``ValueError`` will be raised unless you tell it otherwise:
708
+
709
+ .. sourcecode:: python
710
+
711
+ >>> option_set = ["first", "second", "third", "fourth", "fifth"]
712
+ >>> p = regex.compile(r"\L<options>", options=option_set, other_options=[])
713
+ Traceback (most recent call last):
714
+ File "<stdin>", line 1, in <module>
715
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 353, in compile
716
+ return _compile(pattern, flags, ignore_unused, kwargs, cache_pattern)
717
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 500, in _compile
718
+ complain_unused_args()
719
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 483, in complain_unused_args
720
+ raise ValueError('unused keyword argument {!a}'.format(any_one))
721
+ ValueError: unused keyword argument 'other_options'
722
+ >>> p = regex.compile(r"\L<options>", options=option_set, other_options=[], ignore_unused=True)
723
+ >>> p = regex.compile(r"\L<options>", options=option_set, other_options=[], ignore_unused=False)
724
+ Traceback (most recent call last):
725
+ File "<stdin>", line 1, in <module>
726
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 353, in compile
727
+ return _compile(pattern, flags, ignore_unused, kwargs, cache_pattern)
728
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 500, in _compile
729
+ complain_unused_args()
730
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 483, in complain_unused_args
731
+ raise ValueError('unused keyword argument {!a}'.format(any_one))
732
+ ValueError: unused keyword argument 'other_options'
733
+ >>>
734
+
735
+ Start and end of word
736
+ ^^^^^^^^^^^^^^^^^^^^^
737
+
738
+ ``\m`` matches at the start of a word.
739
+
740
+ ``\M`` matches at the end of a word.
741
+
742
+ Compare with ``\b``, which matches at the start or end of a word.
743
+
744
+ Unicode line separators
745
+ ^^^^^^^^^^^^^^^^^^^^^^^
746
+
747
+ Normally the only line separator is ``\n`` (``\x0A``), but if the ``WORD`` flag is turned on then the line separators are ``\x0D\x0A``, ``\x0A``, ``\x0B``, ``\x0C`` and ``\x0D``, plus ``\x85``, ``\u2028`` and ``\u2029`` when working with Unicode.
748
+
749
+ This affects the regex dot ``"."``, which, with the ``DOTALL`` flag turned off, matches any character except a line separator. It also affects the line anchors ``^`` and ``$`` (in multiline mode).
750
+
751
+ Set operators
752
+ ^^^^^^^^^^^^^
753
+
754
+ **Version 1 behaviour only**
755
+
756
+ Set operators have been added, and a set ``[...]`` can include nested sets.
757
+
758
+ The operators, in order of increasing precedence, are:
759
+
760
+ * ``||`` for union ("x||y" means "x or y")
761
+
762
+ * ``~~`` (double tilde) for symmetric difference ("x~~y" means "x or y, but not both")
763
+
764
+ * ``&&`` for intersection ("x&&y" means "x and y")
765
+
766
+ * ``--`` (double dash) for difference ("x--y" means "x but not y")
767
+
768
+ Implicit union, ie, simple juxtaposition like in ``[ab]``, has the highest precedence. Thus, ``[ab&&cd]`` is the same as ``[[a||b]&&[c||d]]``.
769
+
770
+ Examples:
771
+
772
+ * ``[ab]`` # Set containing 'a' and 'b'
773
+
774
+ * ``[a-z]`` # Set containing 'a' .. 'z'
775
+
776
+ * ``[[a-z]--[qw]]`` # Set containing 'a' .. 'z', but not 'q' or 'w'
777
+
778
+ * ``[a-z--qw]`` # Same as above
779
+
780
+ * ``[\p{L}--QW]`` # Set containing all letters except 'Q' and 'W'
781
+
782
+ * ``[\p{N}--[0-9]]`` # Set containing all numbers except '0' .. '9'
783
+
784
+ * ``[\p{ASCII}&&\p{Letter}]`` # Set containing all characters which are ASCII and letter
785
+
786
+ regex.escape (`issue #2650 <https://bugs.python.org/issue2650>`_)
787
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
788
+
789
+ regex.escape has an additional keyword parameter ``special_only``. When True, only 'special' regex characters, such as '?', are escaped.
790
+
791
+ .. sourcecode:: python
792
+
793
+ >>> regex.escape("foo!?", special_only=False)
794
+ 'foo\\!\\?'
795
+ >>> regex.escape("foo!?", special_only=True)
796
+ 'foo!\\?'
797
+
798
+ regex.escape (`Hg issue 249 <https://github.com/mrabarnett/mrab-regex/issues/249>`_)
799
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
800
+
801
+ regex.escape has an additional keyword parameter ``literal_spaces``. When True, spaces are not escaped.
802
+
803
+ .. sourcecode:: python
804
+
805
+ >>> regex.escape("foo bar!?", literal_spaces=False)
806
+ 'foo\\ bar!\\?'
807
+ >>> regex.escape("foo bar!?", literal_spaces=True)
808
+ 'foo bar!\\?'
809
+
810
+ Repeated captures (`issue #7132 <https://bugs.python.org/issue7132>`_)
811
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
812
+
813
+ A match object has additional methods which return information on all the successful matches of a repeated group. These methods are:
814
+
815
+ * ``matchobject.captures([group1, ...])``
816
+
817
+ * Returns a list of the strings matched in a group or groups. Compare with ``matchobject.group([group1, ...])``.
818
+
819
+ * ``matchobject.starts([group])``
820
+
821
+ * Returns a list of the start positions. Compare with ``matchobject.start([group])``.
822
+
823
+ * ``matchobject.ends([group])``
824
+
825
+ * Returns a list of the end positions. Compare with ``matchobject.end([group])``.
826
+
827
+ * ``matchobject.spans([group])``
828
+
829
+ * Returns a list of the spans. Compare with ``matchobject.span([group])``.
830
+
831
+ .. sourcecode:: python
832
+
833
+ >>> m = regex.search(r"(\w{3})+", "123456789")
834
+ >>> m.group(1)
835
+ '789'
836
+ >>> m.captures(1)
837
+ ['123', '456', '789']
838
+ >>> m.start(1)
839
+ 6
840
+ >>> m.starts(1)
841
+ [0, 3, 6]
842
+ >>> m.end(1)
843
+ 9
844
+ >>> m.ends(1)
845
+ [3, 6, 9]
846
+ >>> m.span(1)
847
+ (6, 9)
848
+ >>> m.spans(1)
849
+ [(0, 3), (3, 6), (6, 9)]
850
+
851
+ Atomic grouping ``(?>...)`` (`issue #433030 <https://bugs.python.org/issue433030>`_)
852
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
853
+
854
+ If the following pattern subsequently fails, then the subpattern as a whole will fail.
855
+
856
+ Possessive quantifiers
857
+ ^^^^^^^^^^^^^^^^^^^^^^
858
+
859
+ ``(?:...)?+`` ; ``(?:...)*+`` ; ``(?:...)++`` ; ``(?:...){min,max}+``
860
+
861
+ The subpattern is matched up to 'max' times. If the following pattern subsequently fails, then all the repeated subpatterns will fail as a whole. For example, ``(?:...)++`` is equivalent to ``(?>(?:...)+)``.
862
+
863
+ Scoped flags (`issue #433028 <https://bugs.python.org/issue433028>`_)
864
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
865
+
866
+ ``(?flags-flags:...)``
867
+
868
+ The flags will apply only to the subpattern. Flags can be turned on or off.
869
+
870
+ Definition of 'word' character (`issue #1693050 <https://bugs.python.org/issue1693050>`_)
871
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
872
+
873
+ The definition of a 'word' character has been expanded for Unicode. It conforms to the Unicode specification at ``http://www.unicode.org/reports/tr29/``.
874
+
875
+ Variable-length lookbehind
876
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
877
+
878
+ A lookbehind can match a variable-length string.
879
+
880
+ Flags argument for regex.split, regex.sub and regex.subn (`issue #3482 <https://bugs.python.org/issue3482>`_)
881
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
882
+
883
+ ``regex.split``, ``regex.sub`` and ``regex.subn`` support a 'flags' argument.
884
+
885
+ Pos and endpos arguments for regex.sub and regex.subn
886
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
887
+
888
+ ``regex.sub`` and ``regex.subn`` support 'pos' and 'endpos' arguments.
889
+
890
+ 'Overlapped' argument for regex.findall and regex.finditer
891
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
892
+
893
+ ``regex.findall`` and ``regex.finditer`` support an 'overlapped' flag which permits overlapped matches.
894
+
895
+ Splititer
896
+ ^^^^^^^^^
897
+
898
+ ``regex.splititer`` has been added. It's a generator equivalent of ``regex.split``.
899
+
900
+ Subscripting match objects for groups
901
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
902
+
903
+ A match object accepts access to the groups via subscripting and slicing:
904
+
905
+ .. sourcecode:: python
906
+
907
+ >>> m = regex.search(r"(?P<before>.*?)(?P<num>\d+)(?P<after>.*)", "pqr123stu")
908
+ >>> print(m["before"])
909
+ pqr
910
+ >>> print(len(m))
911
+ 4
912
+ >>> print(m[:])
913
+ ('pqr123stu', 'pqr', '123', 'stu')
914
+
915
+ Named groups
916
+ ^^^^^^^^^^^^
917
+
918
+ Groups can be named with ``(?<name>...)`` as well as the existing ``(?P<name>...)``.
919
+
920
+ Group references
921
+ ^^^^^^^^^^^^^^^^
922
+
923
+ Groups can be referenced within a pattern with ``\g<name>``. This also allows there to be more than 99 groups.
924
+
925
+ Named characters ``\N{name}``
926
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
927
+
928
+ Named characters are supported. Note that only those known by Python's Unicode database will be recognised.
929
+
930
+ Unicode codepoint properties, including scripts and blocks
931
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
932
+
933
+ ``\p{property=value}``; ``\P{property=value}``; ``\p{value}`` ; ``\P{value}``
934
+
935
+ Many Unicode properties are supported, including blocks and scripts. ``\p{property=value}`` or ``\p{property:value}`` matches a character whose property ``property`` has value ``value``. The inverse of ``\p{property=value}`` is ``\P{property=value}`` or ``\p{^property=value}``.
936
+
937
+ If the short form ``\p{value}`` is used, the properties are checked in the order: ``General_Category``, ``Script``, ``Block``, binary property:
938
+
939
+ * ``Latin``, the 'Latin' script (``Script=Latin``).
940
+
941
+ * ``BasicLatin``, the 'BasicLatin' block (``Block=BasicLatin``).
942
+
943
+ * ``Alphabetic``, the 'Alphabetic' binary property (``Alphabetic=Yes``).
944
+
945
+ A short form starting with ``Is`` indicates a script or binary property:
946
+
947
+ * ``IsLatin``, the 'Latin' script (``Script=Latin``).
948
+
949
+ * ``IsAlphabetic``, the 'Alphabetic' binary property (``Alphabetic=Yes``).
950
+
951
+ A short form starting with ``In`` indicates a block property:
952
+
953
+ * ``InBasicLatin``, the 'BasicLatin' block (``Block=BasicLatin``).
954
+
955
+ POSIX character classes
956
+ ^^^^^^^^^^^^^^^^^^^^^^^
957
+
958
+ ``[[:alpha:]]``; ``[[:^alpha:]]``
959
+
960
+ POSIX character classes are supported. These are normally treated as an alternative form of ``\p{...}``.
961
+
962
+ The exceptions are ``alnum``, ``digit``, ``punct`` and ``xdigit``, whose definitions are different from those of Unicode.
963
+
964
+ ``[[:alnum:]]`` is equivalent to ``\p{posix_alnum}``.
965
+
966
+ ``[[:digit:]]`` is equivalent to ``\p{posix_digit}``.
967
+
968
+ ``[[:punct:]]`` is equivalent to ``\p{posix_punct}``.
969
+
970
+ ``[[:xdigit:]]`` is equivalent to ``\p{posix_xdigit}``.
971
+
972
+ Search anchor ``\G``
973
+ ^^^^^^^^^^^^^^^^^^^^
974
+
975
+ A search anchor has been added. It matches at the position where each search started/continued and can be used for contiguous matches or in negative variable-length lookbehinds to limit how far back the lookbehind goes:
976
+
977
+ .. sourcecode:: python
978
+
979
+ >>> regex.findall(r"\w{2}", "abcd ef")
980
+ ['ab', 'cd', 'ef']
981
+ >>> regex.findall(r"\G\w{2}", "abcd ef")
982
+ ['ab', 'cd']
983
+
984
+ * The search starts at position 0 and matches 'ab'.
985
+
986
+ * The search continues at position 2 and matches 'cd'.
987
+
988
+ * The search continues at position 4 and fails to match any letters.
989
+
990
+ * The anchor stops the search start position from being advanced, so there are no more results.
991
+
992
+ Reverse searching
993
+ ^^^^^^^^^^^^^^^^^
994
+
995
+ Searches can also work backwards:
996
+
997
+ .. sourcecode:: python
998
+
999
+ >>> regex.findall(r".", "abc")
1000
+ ['a', 'b', 'c']
1001
+ >>> regex.findall(r"(?r).", "abc")
1002
+ ['c', 'b', 'a']
1003
+
1004
+ Note that the result of a reverse search is not necessarily the reverse of a forward search:
1005
+
1006
+ .. sourcecode:: python
1007
+
1008
+ >>> regex.findall(r"..", "abcde")
1009
+ ['ab', 'cd']
1010
+ >>> regex.findall(r"(?r)..", "abcde")
1011
+ ['de', 'bc']
1012
+
1013
+ Matching a single grapheme ``\X``
1014
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1015
+
1016
+ The grapheme matcher is supported. It conforms to the Unicode specification at ``http://www.unicode.org/reports/tr29/``.
1017
+
1018
+ Branch reset ``(?|...|...)``
1019
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1020
+
1021
+ Group numbers will be reused across the alternatives, but groups with different names will have different group numbers.
1022
+
1023
+ .. sourcecode:: python
1024
+
1025
+ >>> regex.match(r"(?|(first)|(second))", "first").groups()
1026
+ ('first',)
1027
+ >>> regex.match(r"(?|(first)|(second))", "second").groups()
1028
+ ('second',)
1029
+
1030
+ Note that there is only one group.
1031
+
1032
+ Default Unicode word boundary
1033
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1034
+
1035
+ The ``WORD`` flag changes the definition of a 'word boundary' to that of a default Unicode word boundary. This applies to ``\b`` and ``\B``.
1036
+
1037
+ Timeout
1038
+ ^^^^^^^
1039
+
1040
+ The matching methods and functions support timeouts. The timeout (in seconds) applies to the entire operation:
1041
+
1042
+ .. sourcecode:: python
1043
+
1044
+ >>> from time import sleep
1045
+ >>>
1046
+ >>> def fast_replace(m):
1047
+ ... return 'X'
1048
+ ...
1049
+ >>> def slow_replace(m):
1050
+ ... sleep(0.5)
1051
+ ... return 'X'
1052
+ ...
1053
+ >>> regex.sub(r'[a-z]', fast_replace, 'abcde', timeout=2)
1054
+ 'XXXXX'
1055
+ >>> regex.sub(r'[a-z]', slow_replace, 'abcde', timeout=2)
1056
+ Traceback (most recent call last):
1057
+ File "<stdin>", line 1, in <module>
1058
+ File "C:\Python310\lib\site-packages\regex\regex.py", line 278, in sub
1059
+ return pat.sub(repl, string, count, pos, endpos, concurrent, timeout)
1060
+ TimeoutError: regex timed out
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/RECORD ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ regex-2024.11.6.dist-info/top_level.txt,sha256=aQmiDMhNTF26cCK4_7D-qaVvhbxClG0wyCTnEhkzYBs,6
2
+ regex-2024.11.6.dist-info/RECORD,,
3
+ regex-2024.11.6.dist-info/LICENSE.txt,sha256=v_Ve9M3MjBTOJZ-OirYOJkQYRA1jNfTcE4Jz-9UGFE0,11584
4
+ regex-2024.11.6.dist-info/METADATA,sha256=g01OaInJKSZgaE-sd6S4Bawc-xS2fg0yHRbrU1OXzpg,40487
5
+ regex-2024.11.6.dist-info/WHEEL,sha256=-ffw4ErOrld3H5FyGb0-yfKd91A4S1balHz5KyTz-4c,151
6
+ regex/_regex.cpython-310-x86_64-linux-gnu.so,sha256=Kd11XBKvKuuw55a0vdOHjd7PUR7NCW8qDlNMataGDyw,2549016
7
+ regex/regex.py,sha256=gzxSPPegvGU13Hl64L5aviFexrkXVvu390FTG5aEEWs,32683
8
+ regex/_regex_core.py,sha256=MI8nzE7gBEUTDDrao8aOHg7_QhhDzE07VoKFl_WSxCM,141028
9
+ regex/__init__.py,sha256=9slNQEb4SCZ9LncNzcQvqmkyxXlcOAF7QwAwigxWjsw,65
10
+ regex/test_regex.py,sha256=x_FfGHpd7hT0BFQ_jCetdxv7GxdziBZHgsT8X0FVTOM,222040
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/WHEEL ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.3.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp310-cp310-manylinux_2_17_x86_64
5
+ Tag: cp310-cp310-manylinux2014_x86_64
6
+
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/EGG-INFO/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ regex
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/__init__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from .regex import *
2
+ from . import regex
3
+ __all__ = regex.__all__
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/_regex_core.py ADDED
The diff for this file is too large to render. See raw diff
 
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/regex.py ADDED
@@ -0,0 +1,746 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #
2
+ # Secret Labs' Regular Expression Engine
3
+ #
4
+ # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
5
+ #
6
+ # This version of the SRE library can be redistributed under CNRI's
7
+ # Python 1.6 license. For any other use, please contact Secret Labs
8
+ # AB (info@pythonware.com).
9
+ #
10
+ # Portions of this engine have been developed in cooperation with
11
+ # CNRI. Hewlett-Packard provided funding for 1.6 integration and
12
+ # other compatibility work.
13
+ #
14
+ # 2010-01-16 mrab Python front-end re-written and extended
15
+
16
+ r"""Support for regular expressions (RE).
17
+
18
+ This module provides regular expression matching operations similar to those
19
+ found in Perl. It supports both 8-bit and Unicode strings; both the pattern and
20
+ the strings being processed can contain null bytes and characters outside the
21
+ US ASCII range.
22
+
23
+ Regular expressions can contain both special and ordinary characters. Most
24
+ ordinary characters, like "A", "a", or "0", are the simplest regular
25
+ expressions; they simply match themselves. You can concatenate ordinary
26
+ characters, so last matches the string 'last'.
27
+
28
+ There are a few differences between the old (legacy) behaviour and the new
29
+ (enhanced) behaviour, which are indicated by VERSION0 or VERSION1.
30
+
31
+ The special characters are:
32
+ "." Matches any character except a newline.
33
+ "^" Matches the start of the string.
34
+ "$" Matches the end of the string or just before the
35
+ newline at the end of the string.
36
+ "*" Matches 0 or more (greedy) repetitions of the preceding
37
+ RE. Greedy means that it will match as many repetitions
38
+ as possible.
39
+ "+" Matches 1 or more (greedy) repetitions of the preceding
40
+ RE.
41
+ "?" Matches 0 or 1 (greedy) of the preceding RE.
42
+ *?,+?,?? Non-greedy versions of the previous three special
43
+ characters.
44
+ *+,++,?+ Possessive versions of the previous three special
45
+ characters.
46
+ {m,n} Matches from m to n repetitions of the preceding RE.
47
+ {m,n}? Non-greedy version of the above.
48
+ {m,n}+ Possessive version of the above.
49
+ {...} Fuzzy matching constraints.
50
+ "\\" Either escapes special characters or signals a special
51
+ sequence.
52
+ [...] Indicates a set of characters. A "^" as the first
53
+ character indicates a complementing set.
54
+ "|" A|B, creates an RE that will match either A or B.
55
+ (...) Matches the RE inside the parentheses. The contents are
56
+ captured and can be retrieved or matched later in the
57
+ string.
58
+ (?flags-flags) VERSION1: Sets/clears the flags for the remainder of
59
+ the group or pattern; VERSION0: Sets the flags for the
60
+ entire pattern.
61
+ (?:...) Non-capturing version of regular parentheses.
62
+ (?>...) Atomic non-capturing version of regular parentheses.
63
+ (?flags-flags:...) Non-capturing version of regular parentheses with local
64
+ flags.
65
+ (?P<name>...) The substring matched by the group is accessible by
66
+ name.
67
+ (?<name>...) The substring matched by the group is accessible by
68
+ name.
69
+ (?P=name) Matches the text matched earlier by the group named
70
+ name.
71
+ (?#...) A comment; ignored.
72
+ (?=...) Matches if ... matches next, but doesn't consume the
73
+ string.
74
+ (?!...) Matches if ... doesn't match next.
75
+ (?<=...) Matches if preceded by ....
76
+ (?<!...) Matches if not preceded by ....
77
+ (?(id)yes|no) Matches yes pattern if group id matched, the (optional)
78
+ no pattern otherwise.
79
+ (?(DEFINE)...) If there's no group called "DEFINE", then ... will be
80
+ ignored, but any group definitions will be available.
81
+ (?|...|...) (?|A|B), creates an RE that will match either A or B,
82
+ but reuses capture group numbers across the
83
+ alternatives.
84
+ (*FAIL) Forces matching to fail, which means immediate
85
+ backtracking.
86
+ (*F) Abbreviation for (*FAIL).
87
+ (*PRUNE) Discards the current backtracking information. Its
88
+ effect doesn't extend outside an atomic group or a
89
+ lookaround.
90
+ (*SKIP) Similar to (*PRUNE), except that it also sets where in
91
+ the text the next attempt at matching the entire
92
+ pattern will start. Its effect doesn't extend outside
93
+ an atomic group or a lookaround.
94
+
95
+ The fuzzy matching constraints are: "i" to permit insertions, "d" to permit
96
+ deletions, "s" to permit substitutions, "e" to permit any of these. Limits are
97
+ optional with "<=" and "<". If any type of error is provided then any type not
98
+ provided is not permitted.
99
+
100
+ A cost equation may be provided.
101
+
102
+ Examples:
103
+ (?:fuzzy){i<=2}
104
+ (?:fuzzy){i<=1,s<=2,d<=1,1i+1s+1d<3}
105
+
106
+ VERSION1: Set operators are supported, and a set can include nested sets. The
107
+ set operators, in order of increasing precedence, are:
108
+ || Set union ("x||y" means "x or y").
109
+ ~~ (double tilde) Symmetric set difference ("x~~y" means "x or y, but not
110
+ both").
111
+ && Set intersection ("x&&y" means "x and y").
112
+ -- (double dash) Set difference ("x--y" means "x but not y").
113
+
114
+ Implicit union, ie, simple juxtaposition like in [ab], has the highest
115
+ precedence.
116
+
117
+ VERSION0 and VERSION1:
118
+ The special sequences consist of "\\" and a character from the list below. If
119
+ the ordinary character is not on the list, then the resulting RE will match the
120
+ second character.
121
+ \number Matches the contents of the group of the same number if
122
+ number is no more than 2 digits, otherwise the character
123
+ with the 3-digit octal code.
124
+ \a Matches the bell character.
125
+ \A Matches only at the start of the string.
126
+ \b Matches the empty string, but only at the start or end of a
127
+ word.
128
+ \B Matches the empty string, but not at the start or end of a
129
+ word.
130
+ \d Matches any decimal digit; equivalent to the set [0-9] when
131
+ matching a bytestring or a Unicode string with the ASCII
132
+ flag, or the whole range of Unicode digits when matching a
133
+ Unicode string.
134
+ \D Matches any non-digit character; equivalent to [^\d].
135
+ \f Matches the formfeed character.
136
+ \g<name> Matches the text matched by the group named name.
137
+ \G Matches the empty string, but only at the position where
138
+ the search started.
139
+ \h Matches horizontal whitespace.
140
+ \K Keeps only what follows for the entire match.
141
+ \L<name> Named list. The list is provided as a keyword argument.
142
+ \m Matches the empty string, but only at the start of a word.
143
+ \M Matches the empty string, but only at the end of a word.
144
+ \n Matches the newline character.
145
+ \N{name} Matches the named character.
146
+ \p{name=value} Matches the character if its property has the specified
147
+ value.
148
+ \P{name=value} Matches the character if its property hasn't the specified
149
+ value.
150
+ \r Matches the carriage-return character.
151
+ \s Matches any whitespace character; equivalent to
152
+ [ \t\n\r\f\v].
153
+ \S Matches any non-whitespace character; equivalent to [^\s].
154
+ \t Matches the tab character.
155
+ \uXXXX Matches the Unicode codepoint with 4-digit hex code XXXX.
156
+ \UXXXXXXXX Matches the Unicode codepoint with 8-digit hex code
157
+ XXXXXXXX.
158
+ \v Matches the vertical tab character.
159
+ \w Matches any alphanumeric character; equivalent to
160
+ [a-zA-Z0-9_] when matching a bytestring or a Unicode string
161
+ with the ASCII flag, or the whole range of Unicode
162
+ alphanumeric characters (letters plus digits plus
163
+ underscore) when matching a Unicode string. With LOCALE, it
164
+ will match the set [0-9_] plus characters defined as
165
+ letters for the current locale.
166
+ \W Matches the complement of \w; equivalent to [^\w].
167
+ \xXX Matches the character with 2-digit hex code XX.
168
+ \X Matches a grapheme.
169
+ \Z Matches only at the end of the string.
170
+ \\ Matches a literal backslash.
171
+
172
+ This module exports the following functions:
173
+ match Match a regular expression pattern at the beginning of a string.
174
+ fullmatch Match a regular expression pattern against all of a string.
175
+ search Search a string for the presence of a pattern.
176
+ sub Substitute occurrences of a pattern found in a string using a
177
+ template string.
178
+ subf Substitute occurrences of a pattern found in a string using a
179
+ format string.
180
+ subn Same as sub, but also return the number of substitutions made.
181
+ subfn Same as subf, but also return the number of substitutions made.
182
+ split Split a string by the occurrences of a pattern. VERSION1: will
183
+ split at zero-width match; VERSION0: won't split at zero-width
184
+ match.
185
+ splititer Return an iterator yielding the parts of a split string.
186
+ findall Find all occurrences of a pattern in a string.
187
+ finditer Return an iterator yielding a match object for each match.
188
+ compile Compile a pattern into a Pattern object.
189
+ purge Clear the regular expression cache.
190
+ escape Backslash all non-alphanumerics or special characters in a
191
+ string.
192
+
193
+ Most of the functions support a concurrent parameter: if True, the GIL will be
194
+ released during matching, allowing other Python threads to run concurrently. If
195
+ the string changes during matching, the behaviour is undefined. This parameter
196
+ is not needed when working on the builtin (immutable) string classes.
197
+
198
+ Some of the functions in this module take flags as optional parameters. Most of
199
+ these flags can also be set within an RE:
200
+ A a ASCII Make \w, \W, \b, \B, \d, and \D match the
201
+ corresponding ASCII character categories. Default
202
+ when matching a bytestring.
203
+ B b BESTMATCH Find the best fuzzy match (default is first).
204
+ D DEBUG Print the parsed pattern.
205
+ E e ENHANCEMATCH Attempt to improve the fit after finding the first
206
+ fuzzy match.
207
+ F f FULLCASE Use full case-folding when performing
208
+ case-insensitive matching in Unicode.
209
+ I i IGNORECASE Perform case-insensitive matching.
210
+ L L LOCALE Make \w, \W, \b, \B, \d, and \D dependent on the
211
+ current locale. (One byte per character only.)
212
+ M m MULTILINE "^" matches the beginning of lines (after a newline)
213
+ as well as the string. "$" matches the end of lines
214
+ (before a newline) as well as the end of the string.
215
+ P p POSIX Perform POSIX-standard matching (leftmost longest).
216
+ R r REVERSE Searches backwards.
217
+ S s DOTALL "." matches any character at all, including the
218
+ newline.
219
+ U u UNICODE Make \w, \W, \b, \B, \d, and \D dependent on the
220
+ Unicode locale. Default when matching a Unicode
221
+ string.
222
+ V0 V0 VERSION0 Turn on the old legacy behaviour.
223
+ V1 V1 VERSION1 Turn on the new enhanced behaviour. This flag
224
+ includes the FULLCASE flag.
225
+ W w WORD Make \b and \B work with default Unicode word breaks
226
+ and make ".", "^" and "$" work with Unicode line
227
+ breaks.
228
+ X x VERBOSE Ignore whitespace and comments for nicer looking REs.
229
+
230
+ This module also defines an exception 'error'.
231
+
232
+ """
233
+
234
+ # Public symbols.
235
+ __all__ = ["cache_all", "compile", "DEFAULT_VERSION", "escape", "findall",
236
+ "finditer", "fullmatch", "match", "purge", "search", "split", "splititer",
237
+ "sub", "subf", "subfn", "subn", "template", "Scanner", "A", "ASCII", "B",
238
+ "BESTMATCH", "D", "DEBUG", "E", "ENHANCEMATCH", "S", "DOTALL", "F",
239
+ "FULLCASE", "I", "IGNORECASE", "L", "LOCALE", "M", "MULTILINE", "P", "POSIX",
240
+ "R", "REVERSE", "T", "TEMPLATE", "U", "UNICODE", "V0", "VERSION0", "V1",
241
+ "VERSION1", "X", "VERBOSE", "W", "WORD", "error", "Regex", "__version__",
242
+ "__doc__", "RegexFlag"]
243
+
244
+ __version__ = "2.5.148"
245
+
246
+ # --------------------------------------------------------------------
247
+ # Public interface.
248
+
249
+ def match(pattern, string, flags=0, pos=None, endpos=None, partial=False,
250
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
251
+ """Try to apply the pattern at the start of the string, returning a match
252
+ object, or None if no match was found."""
253
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
254
+ return pat.match(string, pos, endpos, concurrent, partial, timeout)
255
+
256
+ def fullmatch(pattern, string, flags=0, pos=None, endpos=None, partial=False,
257
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
258
+ """Try to apply the pattern against all of the string, returning a match
259
+ object, or None if no match was found."""
260
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
261
+ return pat.fullmatch(string, pos, endpos, concurrent, partial, timeout)
262
+
263
+ def search(pattern, string, flags=0, pos=None, endpos=None, partial=False,
264
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
265
+ """Search through string looking for a match to the pattern, returning a
266
+ match object, or None if no match was found."""
267
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
268
+ return pat.search(string, pos, endpos, concurrent, partial, timeout)
269
+
270
+ def sub(pattern, repl, string, count=0, flags=0, pos=None, endpos=None,
271
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
272
+ """Return the string obtained by replacing the leftmost (or rightmost with a
273
+ reverse pattern) non-overlapping occurrences of the pattern in string by the
274
+ replacement repl. repl can be either a string or a callable; if a string,
275
+ backslash escapes in it are processed; if a callable, it's passed the match
276
+ object and must return a replacement string to be used."""
277
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
278
+ return pat.sub(repl, string, count, pos, endpos, concurrent, timeout)
279
+
280
+ def subf(pattern, format, string, count=0, flags=0, pos=None, endpos=None,
281
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
282
+ """Return the string obtained by replacing the leftmost (or rightmost with a
283
+ reverse pattern) non-overlapping occurrences of the pattern in string by the
284
+ replacement format. format can be either a string or a callable; if a string,
285
+ it's treated as a format string; if a callable, it's passed the match object
286
+ and must return a replacement string to be used."""
287
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
288
+ return pat.subf(format, string, count, pos, endpos, concurrent, timeout)
289
+
290
+ def subn(pattern, repl, string, count=0, flags=0, pos=None, endpos=None,
291
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
292
+ """Return a 2-tuple containing (new_string, number). new_string is the string
293
+ obtained by replacing the leftmost (or rightmost with a reverse pattern)
294
+ non-overlapping occurrences of the pattern in the source string by the
295
+ replacement repl. number is the number of substitutions that were made. repl
296
+ can be either a string or a callable; if a string, backslash escapes in it
297
+ are processed; if a callable, it's passed the match object and must return a
298
+ replacement string to be used."""
299
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
300
+ return pat.subn(repl, string, count, pos, endpos, concurrent, timeout)
301
+
302
+ def subfn(pattern, format, string, count=0, flags=0, pos=None, endpos=None,
303
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
304
+ """Return a 2-tuple containing (new_string, number). new_string is the string
305
+ obtained by replacing the leftmost (or rightmost with a reverse pattern)
306
+ non-overlapping occurrences of the pattern in the source string by the
307
+ replacement format. number is the number of substitutions that were made. format
308
+ can be either a string or a callable; if a string, it's treated as a format
309
+ string; if a callable, it's passed the match object and must return a
310
+ replacement string to be used."""
311
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
312
+ return pat.subfn(format, string, count, pos, endpos, concurrent, timeout)
313
+
314
+ def split(pattern, string, maxsplit=0, flags=0, concurrent=None, timeout=None,
315
+ ignore_unused=False, **kwargs):
316
+ """Split the source string by the occurrences of the pattern, returning a
317
+ list containing the resulting substrings. If capturing parentheses are used
318
+ in pattern, then the text of all groups in the pattern are also returned as
319
+ part of the resulting list. If maxsplit is nonzero, at most maxsplit splits
320
+ occur, and the remainder of the string is returned as the final element of
321
+ the list."""
322
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
323
+ return pat.split(string, maxsplit, concurrent, timeout)
324
+
325
+ def splititer(pattern, string, maxsplit=0, flags=0, concurrent=None,
326
+ timeout=None, ignore_unused=False, **kwargs):
327
+ "Return an iterator yielding the parts of a split string."
328
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
329
+ return pat.splititer(string, maxsplit, concurrent, timeout)
330
+
331
+ def findall(pattern, string, flags=0, pos=None, endpos=None, overlapped=False,
332
+ concurrent=None, timeout=None, ignore_unused=False, **kwargs):
333
+ """Return a list of all matches in the string. The matches may be overlapped
334
+ if overlapped is True. If one or more groups are present in the pattern,
335
+ return a list of groups; this will be a list of tuples if the pattern has
336
+ more than one group. Empty matches are included in the result."""
337
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
338
+ return pat.findall(string, pos, endpos, overlapped, concurrent, timeout)
339
+
340
+ def finditer(pattern, string, flags=0, pos=None, endpos=None, overlapped=False,
341
+ partial=False, concurrent=None, timeout=None, ignore_unused=False, **kwargs):
342
+ """Return an iterator over all matches in the string. The matches may be
343
+ overlapped if overlapped is True. For each match, the iterator returns a
344
+ match object. Empty matches are included in the result."""
345
+ pat = _compile(pattern, flags, ignore_unused, kwargs, True)
346
+ return pat.finditer(string, pos, endpos, overlapped, concurrent, partial,
347
+ timeout)
348
+
349
+ def compile(pattern, flags=0, ignore_unused=False, cache_pattern=None, **kwargs):
350
+ "Compile a regular expression pattern, returning a pattern object."
351
+ if cache_pattern is None:
352
+ cache_pattern = _cache_all
353
+ return _compile(pattern, flags, ignore_unused, kwargs, cache_pattern)
354
+
355
+ def purge():
356
+ "Clear the regular expression cache"
357
+ _cache.clear()
358
+ _locale_sensitive.clear()
359
+
360
+ # Whether to cache all patterns.
361
+ _cache_all = True
362
+
363
+ def cache_all(value=True):
364
+ """Sets whether to cache all patterns, even those are compiled explicitly.
365
+ Passing None has no effect, but returns the current setting."""
366
+ global _cache_all
367
+
368
+ if value is None:
369
+ return _cache_all
370
+
371
+ _cache_all = value
372
+
373
+ def template(pattern, flags=0):
374
+ "Compile a template pattern, returning a pattern object."
375
+ return _compile(pattern, flags | TEMPLATE, False, {}, False)
376
+
377
+ def escape(pattern, special_only=True, literal_spaces=False):
378
+ """Escape a string for use as a literal in a pattern. If special_only is
379
+ True, escape only special characters, else escape all non-alphanumeric
380
+ characters. If literal_spaces is True, don't escape spaces."""
381
+ # Convert it to Unicode.
382
+ if isinstance(pattern, bytes):
383
+ p = pattern.decode("latin-1")
384
+ else:
385
+ p = pattern
386
+
387
+ s = []
388
+ if special_only:
389
+ for c in p:
390
+ if c == " " and literal_spaces:
391
+ s.append(c)
392
+ elif c in _METACHARS or c.isspace():
393
+ s.append("\\")
394
+ s.append(c)
395
+ else:
396
+ s.append(c)
397
+ else:
398
+ for c in p:
399
+ if c == " " and literal_spaces:
400
+ s.append(c)
401
+ elif c in _ALNUM:
402
+ s.append(c)
403
+ else:
404
+ s.append("\\")
405
+ s.append(c)
406
+
407
+ r = "".join(s)
408
+ # Convert it back to bytes if necessary.
409
+ if isinstance(pattern, bytes):
410
+ r = r.encode("latin-1")
411
+
412
+ return r
413
+
414
+ # --------------------------------------------------------------------
415
+ # Internals.
416
+
417
+ import regex._regex_core as _regex_core
418
+ import regex._regex as _regex
419
+ from threading import RLock as _RLock
420
+ from locale import getpreferredencoding as _getpreferredencoding
421
+ from regex._regex_core import *
422
+ from regex._regex_core import (_ALL_VERSIONS, _ALL_ENCODINGS, _FirstSetError,
423
+ _UnscopedFlagSet, _check_group_features, _compile_firstset,
424
+ _compile_replacement, _flatten_code, _fold_case, _get_required_string,
425
+ _parse_pattern, _shrink_cache)
426
+ from regex._regex_core import (ALNUM as _ALNUM, Info as _Info, OP as _OP, Source
427
+ as _Source, Fuzzy as _Fuzzy)
428
+
429
+ # Version 0 is the old behaviour, compatible with the original 're' module.
430
+ # Version 1 is the new behaviour, which differs slightly.
431
+
432
+ DEFAULT_VERSION = VERSION0
433
+
434
+ _METACHARS = frozenset("()[]{}?*+|^$\\.-#&~")
435
+
436
+ _regex_core.DEFAULT_VERSION = DEFAULT_VERSION
437
+
438
+ # Caches for the patterns and replacements.
439
+ _cache = {}
440
+ _cache_lock = _RLock()
441
+ _named_args = {}
442
+ _replacement_cache = {}
443
+ _locale_sensitive = {}
444
+
445
+ # Maximum size of the cache.
446
+ _MAXCACHE = 500
447
+ _MAXREPCACHE = 500
448
+
449
+ def _compile(pattern, flags, ignore_unused, kwargs, cache_it):
450
+ "Compiles a regular expression to a PatternObject."
451
+
452
+ global DEFAULT_VERSION
453
+ try:
454
+ from regex import DEFAULT_VERSION
455
+ except ImportError:
456
+ pass
457
+
458
+ # We won't bother to cache the pattern if we're debugging.
459
+ if (flags & DEBUG) != 0:
460
+ cache_it = False
461
+
462
+ # What locale is this pattern using?
463
+ locale_key = (type(pattern), pattern)
464
+ if _locale_sensitive.get(locale_key, True) or (flags & LOCALE) != 0:
465
+ # This pattern is, or might be, locale-sensitive.
466
+ pattern_locale = _getpreferredencoding()
467
+ else:
468
+ # This pattern is definitely not locale-sensitive.
469
+ pattern_locale = None
470
+
471
+ def complain_unused_args():
472
+ if ignore_unused:
473
+ return
474
+
475
+ # Complain about any unused keyword arguments, possibly resulting from a typo.
476
+ unused_kwargs = set(kwargs) - {k for k, v in args_needed}
477
+ if unused_kwargs:
478
+ any_one = next(iter(unused_kwargs))
479
+ raise ValueError('unused keyword argument {!a}'.format(any_one))
480
+
481
+ if cache_it:
482
+ try:
483
+ # Do we know what keyword arguments are needed?
484
+ args_key = pattern, type(pattern), flags
485
+ args_needed = _named_args[args_key]
486
+
487
+ # Are we being provided with its required keyword arguments?
488
+ args_supplied = set()
489
+ if args_needed:
490
+ for k, v in args_needed:
491
+ try:
492
+ args_supplied.add((k, frozenset(kwargs[k])))
493
+ except KeyError:
494
+ raise error("missing named list: {!r}".format(k))
495
+
496
+ complain_unused_args()
497
+
498
+ args_supplied = frozenset(args_supplied)
499
+
500
+ # Have we already seen this regular expression and named list?
501
+ pattern_key = (pattern, type(pattern), flags, args_supplied,
502
+ DEFAULT_VERSION, pattern_locale)
503
+ return _cache[pattern_key]
504
+ except KeyError:
505
+ # It's a new pattern, or new named list for a known pattern.
506
+ pass
507
+
508
+ # Guess the encoding from the class of the pattern string.
509
+ if isinstance(pattern, str):
510
+ guess_encoding = UNICODE
511
+ elif isinstance(pattern, bytes):
512
+ guess_encoding = ASCII
513
+ elif isinstance(pattern, Pattern):
514
+ if flags:
515
+ raise ValueError("cannot process flags argument with a compiled pattern")
516
+
517
+ return pattern
518
+ else:
519
+ raise TypeError("first argument must be a string or compiled pattern")
520
+
521
+ # Set the default version in the core code in case it has been changed.
522
+ _regex_core.DEFAULT_VERSION = DEFAULT_VERSION
523
+
524
+ global_flags = flags
525
+
526
+ while True:
527
+ caught_exception = None
528
+ try:
529
+ source = _Source(pattern)
530
+ info = _Info(global_flags, source.char_type, kwargs)
531
+ info.guess_encoding = guess_encoding
532
+ source.ignore_space = bool(info.flags & VERBOSE)
533
+ parsed = _parse_pattern(source, info)
534
+ break
535
+ except _UnscopedFlagSet:
536
+ # Remember the global flags for the next attempt.
537
+ global_flags = info.global_flags
538
+ except error as e:
539
+ caught_exception = e
540
+
541
+ if caught_exception:
542
+ raise error(caught_exception.msg, caught_exception.pattern,
543
+ caught_exception.pos)
544
+
545
+ if not source.at_end():
546
+ raise error("unbalanced parenthesis", pattern, source.pos)
547
+
548
+ # Check the global flags for conflicts.
549
+ version = (info.flags & _ALL_VERSIONS) or DEFAULT_VERSION
550
+ if version not in (0, VERSION0, VERSION1):
551
+ raise ValueError("VERSION0 and VERSION1 flags are mutually incompatible")
552
+
553
+ if (info.flags & _ALL_ENCODINGS) not in (0, ASCII, LOCALE, UNICODE):
554
+ raise ValueError("ASCII, LOCALE and UNICODE flags are mutually incompatible")
555
+
556
+ if isinstance(pattern, bytes) and (info.flags & UNICODE):
557
+ raise ValueError("cannot use UNICODE flag with a bytes pattern")
558
+
559
+ if not (info.flags & _ALL_ENCODINGS):
560
+ if isinstance(pattern, str):
561
+ info.flags |= UNICODE
562
+ else:
563
+ info.flags |= ASCII
564
+
565
+ reverse = bool(info.flags & REVERSE)
566
+ fuzzy = isinstance(parsed, _Fuzzy)
567
+
568
+ # Remember whether this pattern as an inline locale flag.
569
+ _locale_sensitive[locale_key] = info.inline_locale
570
+
571
+ # Fix the group references.
572
+ caught_exception = None
573
+ try:
574
+ parsed.fix_groups(pattern, reverse, False)
575
+ except error as e:
576
+ caught_exception = e
577
+
578
+ if caught_exception:
579
+ raise error(caught_exception.msg, caught_exception.pattern,
580
+ caught_exception.pos)
581
+
582
+ # Should we print the parsed pattern?
583
+ if flags & DEBUG:
584
+ parsed.dump(indent=0, reverse=reverse)
585
+
586
+ # Optimise the parsed pattern.
587
+ parsed = parsed.optimise(info, reverse)
588
+ parsed = parsed.pack_characters(info)
589
+
590
+ # Get the required string.
591
+ req_offset, req_chars, req_flags = _get_required_string(parsed, info.flags)
592
+
593
+ # Build the named lists.
594
+ named_lists = {}
595
+ named_list_indexes = [None] * len(info.named_lists_used)
596
+ args_needed = set()
597
+ for key, index in info.named_lists_used.items():
598
+ name, case_flags = key
599
+ values = frozenset(kwargs[name])
600
+ if case_flags:
601
+ items = frozenset(_fold_case(info, v) for v in values)
602
+ else:
603
+ items = values
604
+ named_lists[name] = values
605
+ named_list_indexes[index] = items
606
+ args_needed.add((name, values))
607
+
608
+ complain_unused_args()
609
+
610
+ # Check the features of the groups.
611
+ _check_group_features(info, parsed)
612
+
613
+ # Compile the parsed pattern. The result is a list of tuples.
614
+ code = parsed.compile(reverse)
615
+
616
+ # Is there a group call to the pattern as a whole?
617
+ key = (0, reverse, fuzzy)
618
+ ref = info.call_refs.get(key)
619
+ if ref is not None:
620
+ code = [(_OP.CALL_REF, ref)] + code + [(_OP.END, )]
621
+
622
+ # Add the final 'success' opcode.
623
+ code += [(_OP.SUCCESS, )]
624
+
625
+ # Compile the additional copies of the groups that we need.
626
+ for group, rev, fuz in info.additional_groups:
627
+ code += group.compile(rev, fuz)
628
+
629
+ # Flatten the code into a list of ints.
630
+ code = _flatten_code(code)
631
+
632
+ if not parsed.has_simple_start():
633
+ # Get the first set, if possible.
634
+ try:
635
+ fs_code = _compile_firstset(info, parsed.get_firstset(reverse))
636
+ fs_code = _flatten_code(fs_code)
637
+ code = fs_code + code
638
+ except _FirstSetError:
639
+ pass
640
+
641
+ # The named capture groups.
642
+ index_group = dict((v, n) for n, v in info.group_index.items())
643
+
644
+ # Create the PatternObject.
645
+ #
646
+ # Local flags like IGNORECASE affect the code generation, but aren't needed
647
+ # by the PatternObject itself. Conversely, global flags like LOCALE _don't_
648
+ # affect the code generation but _are_ needed by the PatternObject.
649
+ compiled_pattern = _regex.compile(pattern, info.flags | version, code,
650
+ info.group_index, index_group, named_lists, named_list_indexes,
651
+ req_offset, req_chars, req_flags, info.group_count)
652
+
653
+ # Do we need to reduce the size of the cache?
654
+ if len(_cache) >= _MAXCACHE:
655
+ with _cache_lock:
656
+ _shrink_cache(_cache, _named_args, _locale_sensitive, _MAXCACHE)
657
+
658
+ if cache_it:
659
+ if (info.flags & LOCALE) == 0:
660
+ pattern_locale = None
661
+
662
+ args_needed = frozenset(args_needed)
663
+
664
+ # Store this regular expression and named list.
665
+ pattern_key = (pattern, type(pattern), flags, args_needed,
666
+ DEFAULT_VERSION, pattern_locale)
667
+ _cache[pattern_key] = compiled_pattern
668
+
669
+ # Store what keyword arguments are needed.
670
+ _named_args[args_key] = args_needed
671
+
672
+ return compiled_pattern
673
+
674
+ def _compile_replacement_helper(pattern, template):
675
+ "Compiles a replacement template."
676
+ # This function is called by the _regex module.
677
+
678
+ # Have we seen this before?
679
+ key = pattern.pattern, pattern.flags, template
680
+ compiled = _replacement_cache.get(key)
681
+ if compiled is not None:
682
+ return compiled
683
+
684
+ if len(_replacement_cache) >= _MAXREPCACHE:
685
+ _replacement_cache.clear()
686
+
687
+ is_unicode = isinstance(template, str)
688
+ source = _Source(template)
689
+ if is_unicode:
690
+ def make_string(char_codes):
691
+ return "".join(chr(c) for c in char_codes)
692
+ else:
693
+ def make_string(char_codes):
694
+ return bytes(char_codes)
695
+
696
+ compiled = []
697
+ literal = []
698
+ while True:
699
+ ch = source.get()
700
+ if not ch:
701
+ break
702
+ if ch == "\\":
703
+ # '_compile_replacement' will return either an int group reference
704
+ # or a string literal. It returns items (plural) in order to handle
705
+ # a 2-character literal (an invalid escape sequence).
706
+ is_group, items = _compile_replacement(source, pattern, is_unicode)
707
+ if is_group:
708
+ # It's a group, so first flush the literal.
709
+ if literal:
710
+ compiled.append(make_string(literal))
711
+ literal = []
712
+ compiled.extend(items)
713
+ else:
714
+ literal.extend(items)
715
+ else:
716
+ literal.append(ord(ch))
717
+
718
+ # Flush the literal.
719
+ if literal:
720
+ compiled.append(make_string(literal))
721
+
722
+ _replacement_cache[key] = compiled
723
+
724
+ return compiled
725
+
726
+ # We define Pattern here after all the support objects have been defined.
727
+ _pat = _compile('', 0, False, {}, False)
728
+ Pattern = type(_pat)
729
+ Match = type(_pat.match(''))
730
+ del _pat
731
+
732
+ # Make Pattern public for typing annotations.
733
+ __all__.append("Pattern")
734
+ __all__.append("Match")
735
+
736
+ # We'll define an alias for the 'compile' function so that the repr of a
737
+ # pattern object is eval-able.
738
+ Regex = compile
739
+
740
+ # Register myself for pickling.
741
+ import copyreg as _copy_reg
742
+
743
+ def _pickle(pattern):
744
+ return _regex.compile, pattern._pickled_data
745
+
746
+ _copy_reg.pickle(Pattern, _pickle)
opencompass/.eggs/regex-2024.11.6-py3.10-linux-x86_64.egg/regex/test_regex.py ADDED
The diff for this file is too large to render. See raw diff
 
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/LICENCE ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `tqdm` is a product of collaborative work.
2
+ Unless otherwise stated, all authors (see commit logs) retain copyright
3
+ for their respective work, and release the work under the MIT licence
4
+ (text below).
5
+
6
+ Exceptions or notable authors are listed below
7
+ in reverse chronological order:
8
+
9
+ * files: *
10
+ MPL-2.0 2015-2024 (c) Casper da Costa-Luis
11
+ [casperdcl](https://github.com/casperdcl).
12
+ * files: tqdm/_tqdm.py
13
+ MIT 2016 (c) [PR #96] on behalf of Google Inc.
14
+ * files: tqdm/_tqdm.py README.rst .gitignore
15
+ MIT 2013 (c) Noam Yorav-Raphael, original author.
16
+
17
+ [PR #96]: https://github.com/tqdm/tqdm/pull/96
18
+
19
+
20
+ Mozilla Public Licence (MPL) v. 2.0 - Exhibit A
21
+ -----------------------------------------------
22
+
23
+ This Source Code Form is subject to the terms of the
24
+ Mozilla Public License, v. 2.0.
25
+ If a copy of the MPL was not distributed with this project,
26
+ You can obtain one at https://mozilla.org/MPL/2.0/.
27
+
28
+
29
+ MIT License (MIT)
30
+ -----------------
31
+
32
+ Copyright (c) 2013 noamraph
33
+
34
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
35
+ this software and associated documentation files (the "Software"), to deal in
36
+ the Software without restriction, including without limitation the rights to
37
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
38
+ the Software, and to permit persons to whom the Software is furnished to do so,
39
+ subject to the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be included in all
42
+ copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
46
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
47
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
48
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
49
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/PKG-INFO ADDED
@@ -0,0 +1,1594 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Metadata-Version: 2.1
2
+ Name: tqdm
3
+ Version: 4.67.1
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: License :: OSI Approved :: MIT License
26
+ Classifier: License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)
27
+ Classifier: Operating System :: MacOS
28
+ Classifier: Operating System :: MacOS :: MacOS X
29
+ Classifier: Operating System :: Microsoft
30
+ Classifier: Operating System :: Microsoft :: MS-DOS
31
+ Classifier: Operating System :: Microsoft :: Windows
32
+ Classifier: Operating System :: POSIX
33
+ Classifier: Operating System :: POSIX :: BSD
34
+ Classifier: Operating System :: POSIX :: BSD :: FreeBSD
35
+ Classifier: Operating System :: POSIX :: Linux
36
+ Classifier: Operating System :: POSIX :: SunOS/Solaris
37
+ Classifier: Operating System :: Unix
38
+ Classifier: Programming Language :: Python
39
+ Classifier: Programming Language :: Python :: 3
40
+ Classifier: Programming Language :: Python :: 3.7
41
+ Classifier: Programming Language :: Python :: 3.8
42
+ Classifier: Programming Language :: Python :: 3.9
43
+ Classifier: Programming Language :: Python :: 3.10
44
+ Classifier: Programming Language :: Python :: 3.11
45
+ Classifier: Programming Language :: Python :: 3.12
46
+ Classifier: Programming Language :: Python :: 3 :: Only
47
+ Classifier: Programming Language :: Python :: Implementation
48
+ Classifier: Programming Language :: Python :: Implementation :: IronPython
49
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
50
+ Classifier: Programming Language :: Unix Shell
51
+ Classifier: Topic :: Desktop Environment
52
+ Classifier: Topic :: Education :: Computer Aided Instruction (CAI)
53
+ Classifier: Topic :: Education :: Testing
54
+ Classifier: Topic :: Office/Business
55
+ Classifier: Topic :: Other/Nonlisted Topic
56
+ Classifier: Topic :: Software Development :: Build Tools
57
+ Classifier: Topic :: Software Development :: Libraries
58
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
59
+ Classifier: Topic :: Software Development :: Pre-processors
60
+ Classifier: Topic :: Software Development :: User Interfaces
61
+ Classifier: Topic :: System :: Installation/Setup
62
+ Classifier: Topic :: System :: Logging
63
+ Classifier: Topic :: System :: Monitoring
64
+ Classifier: Topic :: System :: Shells
65
+ Classifier: Topic :: Terminals
66
+ Classifier: Topic :: Utilities
67
+ Requires-Python: >=3.7
68
+ Description-Content-Type: text/x-rst
69
+ License-File: LICENCE
70
+ Requires-Dist: colorama; platform_system == "Windows"
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
+
86
+ |Logo|
87
+
88
+ tqdm
89
+ ====
90
+
91
+ |Py-Versions| |Versions| |Conda-Forge-Status| |Docker| |Snapcraft|
92
+
93
+ |Build-Status| |Coverage-Status| |Branch-Coverage-Status| |Codacy-Grade| |Libraries-Rank| |PyPI-Downloads|
94
+
95
+ |LICENCE| |OpenHub-Status| |binder-demo| |awesome-python|
96
+
97
+ ``tqdm`` derives from the Arabic word *taqaddum* (تقدّم) which can mean "progress,"
98
+ and is an abbreviation for "I love you so much" in Spanish (*te quiero demasiado*).
99
+
100
+ Instantly make your loops show a smart progress meter - just wrap any
101
+ iterable with ``tqdm(iterable)``, and you're done!
102
+
103
+ .. code:: python
104
+
105
+ from tqdm import tqdm
106
+ for i in tqdm(range(10000)):
107
+ ...
108
+
109
+ ``76%|████████████████████████        | 7568/10000 [00:33<00:10, 229.00it/s]``
110
+
111
+ ``trange(N)`` can be also used as a convenient shortcut for
112
+ ``tqdm(range(N))``.
113
+
114
+ |Screenshot|
115
+ |Video| |Slides| |Merch|
116
+
117
+ It can also be executed as a module with pipes:
118
+
119
+ .. code:: sh
120
+
121
+ $ seq 9999999 | tqdm --bytes | wc -l
122
+ 75.2MB [00:00, 217MB/s]
123
+ 9999999
124
+
125
+ $ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
126
+ > backup.tgz
127
+ 32%|██████████▍ | 8.89G/27.9G [00:42<01:31, 223MB/s]
128
+
129
+ Overhead is low -- about 60ns per iteration (80ns with ``tqdm.gui``), and is
130
+ unit tested against performance regression.
131
+ By comparison, the well-established
132
+ `ProgressBar <https://github.com/niltonvolpato/python-progressbar>`__ has
133
+ an 800ns/iter overhead.
134
+
135
+ In addition to its low overhead, ``tqdm`` uses smart algorithms to predict
136
+ the remaining time and to skip unnecessary iteration displays, which allows
137
+ for a negligible overhead in most cases.
138
+
139
+ ``tqdm`` works on any platform
140
+ (Linux, Windows, Mac, FreeBSD, NetBSD, Solaris/SunOS),
141
+ in any console or in a GUI, and is also friendly with IPython/Jupyter notebooks.
142
+
143
+ ``tqdm`` does not require any dependencies (not even ``curses``!), just
144
+ Python and an environment supporting ``carriage return \r`` and
145
+ ``line feed \n`` control characters.
146
+
147
+ ------------------------------------------
148
+
149
+ .. contents:: Table of contents
150
+ :backlinks: top
151
+ :local:
152
+
153
+
154
+ Installation
155
+ ------------
156
+
157
+ Latest PyPI stable release
158
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
159
+
160
+ |Versions| |PyPI-Downloads| |Libraries-Dependents|
161
+
162
+ .. code:: sh
163
+
164
+ pip install tqdm
165
+
166
+ Latest development release on GitHub
167
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
168
+
169
+ |GitHub-Status| |GitHub-Stars| |GitHub-Commits| |GitHub-Forks| |GitHub-Updated|
170
+
171
+ Pull and install pre-release ``devel`` branch:
172
+
173
+ .. code:: sh
174
+
175
+ pip install "git+https://github.com/tqdm/tqdm.git@devel#egg=tqdm"
176
+
177
+ Latest Conda release
178
+ ~~~~~~~~~~~~~~~~~~~~
179
+
180
+ |Conda-Forge-Status|
181
+
182
+ .. code:: sh
183
+
184
+ conda install -c conda-forge tqdm
185
+
186
+ Latest Snapcraft release
187
+ ~~~~~~~~~~~~~~~~~~~~~~~~
188
+
189
+ |Snapcraft|
190
+
191
+ There are 3 channels to choose from:
192
+
193
+ .. code:: sh
194
+
195
+ snap install tqdm # implies --stable, i.e. latest tagged release
196
+ snap install tqdm --candidate # master branch
197
+ snap install tqdm --edge # devel branch
198
+
199
+ Note that ``snap`` binaries are purely for CLI use (not ``import``-able), and
200
+ automatically set up ``bash`` tab-completion.
201
+
202
+ Latest Docker release
203
+ ~~~~~~~~~~~~~~~~~~~~~
204
+
205
+ |Docker|
206
+
207
+ .. code:: sh
208
+
209
+ docker pull tqdm/tqdm
210
+ docker run -i --rm tqdm/tqdm --help
211
+
212
+ Other
213
+ ~~~~~
214
+
215
+ There are other (unofficial) places where ``tqdm`` may be downloaded, particularly for CLI use:
216
+
217
+ |Repology|
218
+
219
+ .. |Repology| image:: https://repology.org/badge/tiny-repos/python:tqdm.svg
220
+ :target: https://repology.org/project/python:tqdm/versions
221
+
222
+ Changelog
223
+ ---------
224
+
225
+ The list of all changes is available either on GitHub's Releases:
226
+ |GitHub-Status|, on the
227
+ `wiki <https://github.com/tqdm/tqdm/wiki/Releases>`__, or on the
228
+ `website <https://tqdm.github.io/releases>`__.
229
+
230
+
231
+ Usage
232
+ -----
233
+
234
+ ``tqdm`` is very versatile and can be used in a number of ways.
235
+ The three main ones are given below.
236
+
237
+ Iterable-based
238
+ ~~~~~~~~~~~~~~
239
+
240
+ Wrap ``tqdm()`` around any iterable:
241
+
242
+ .. code:: python
243
+
244
+ from tqdm import tqdm
245
+ from time import sleep
246
+
247
+ text = ""
248
+ for char in tqdm(["a", "b", "c", "d"]):
249
+ sleep(0.25)
250
+ text = text + char
251
+
252
+ ``trange(i)`` is a special optimised instance of ``tqdm(range(i))``:
253
+
254
+ .. code:: python
255
+
256
+ from tqdm import trange
257
+
258
+ for i in trange(100):
259
+ sleep(0.01)
260
+
261
+ Instantiation outside of the loop allows for manual control over ``tqdm()``:
262
+
263
+ .. code:: python
264
+
265
+ pbar = tqdm(["a", "b", "c", "d"])
266
+ for char in pbar:
267
+ sleep(0.25)
268
+ pbar.set_description("Processing %s" % char)
269
+
270
+ Manual
271
+ ~~~~~~
272
+
273
+ Manual control of ``tqdm()`` updates using a ``with`` statement:
274
+
275
+ .. code:: python
276
+
277
+ with tqdm(total=100) as pbar:
278
+ for i in range(10):
279
+ sleep(0.1)
280
+ pbar.update(10)
281
+
282
+ If the optional variable ``total`` (or an iterable with ``len()``) is
283
+ provided, predictive stats are displayed.
284
+
285
+ ``with`` is also optional (you can just assign ``tqdm()`` to a variable,
286
+ but in this case don't forget to ``del`` or ``close()`` at the end:
287
+
288
+ .. code:: python
289
+
290
+ pbar = tqdm(total=100)
291
+ for i in range(10):
292
+ sleep(0.1)
293
+ pbar.update(10)
294
+ pbar.close()
295
+
296
+ Module
297
+ ~~~~~~
298
+
299
+ Perhaps the most wonderful use of ``tqdm`` is in a script or on the command
300
+ line. Simply inserting ``tqdm`` (or ``python -m tqdm``) between pipes will pass
301
+ through all ``stdin`` to ``stdout`` while printing progress to ``stderr``.
302
+
303
+ The example below demonstrate counting the number of lines in all Python files
304
+ in the current directory, with timing information included.
305
+
306
+ .. code:: sh
307
+
308
+ $ time find . -name '*.py' -type f -exec cat \{} \; | wc -l
309
+ 857365
310
+
311
+ real 0m3.458s
312
+ user 0m0.274s
313
+ sys 0m3.325s
314
+
315
+ $ time find . -name '*.py' -type f -exec cat \{} \; | tqdm | wc -l
316
+ 857366it [00:03, 246471.31it/s]
317
+ 857365
318
+
319
+ real 0m3.585s
320
+ user 0m0.862s
321
+ sys 0m3.358s
322
+
323
+ Note that the usual arguments for ``tqdm`` can also be specified.
324
+
325
+ .. code:: sh
326
+
327
+ $ find . -name '*.py' -type f -exec cat \{} \; |
328
+ tqdm --unit loc --unit_scale --total 857366 >> /dev/null
329
+ 100%|███████████████████████��█████████| 857K/857K [00:04<00:00, 246Kloc/s]
330
+
331
+ Backing up a large directory?
332
+
333
+ .. code:: sh
334
+
335
+ $ tar -zcf - docs/ | tqdm --bytes --total `du -sb docs/ | cut -f1` \
336
+ > backup.tgz
337
+ 44%|██████████████▊ | 153M/352M [00:14<00:18, 11.0MB/s]
338
+
339
+ This can be beautified further:
340
+
341
+ .. code:: sh
342
+
343
+ $ BYTES=$(du -sb docs/ | cut -f1)
344
+ $ tar -cf - docs/ \
345
+ | tqdm --bytes --total "$BYTES" --desc Processing | gzip \
346
+ | tqdm --bytes --total "$BYTES" --desc Compressed --position 1 \
347
+ > ~/backup.tgz
348
+ Processing: 100%|██████████████████████| 352M/352M [00:14<00:00, 30.2MB/s]
349
+ Compressed: 42%|█████████▎ | 148M/352M [00:14<00:19, 10.9MB/s]
350
+
351
+ Or done on a file level using 7-zip:
352
+
353
+ .. code:: sh
354
+
355
+ $ 7z a -bd -r backup.7z docs/ | grep Compressing \
356
+ | tqdm --total $(find docs/ -type f | wc -l) --unit files \
357
+ | grep -v Compressing
358
+ 100%|██████████████████████████▉| 15327/15327 [01:00<00:00, 712.96files/s]
359
+
360
+ Pre-existing CLI programs already outputting basic progress information will
361
+ benefit from ``tqdm``'s ``--update`` and ``--update_to`` flags:
362
+
363
+ .. code:: sh
364
+
365
+ $ seq 3 0.1 5 | tqdm --total 5 --update_to --null
366
+ 100%|████████████████████████████████████| 5.0/5 [00:00<00:00, 9673.21it/s]
367
+ $ seq 10 | tqdm --update --null # 1 + 2 + ... + 10 = 55 iterations
368
+ 55it [00:00, 90006.52it/s]
369
+
370
+ FAQ and Known Issues
371
+ --------------------
372
+
373
+ |GitHub-Issues|
374
+
375
+ The most common issues relate to excessive output on multiple lines, instead
376
+ of a neat one-line progress bar.
377
+
378
+ - Consoles in general: require support for carriage return (``CR``, ``\r``).
379
+
380
+ * Some cloud logging consoles which don't support ``\r`` properly
381
+ (`cloudwatch <https://github.com/tqdm/tqdm/issues/966>`__,
382
+ `K8s <https://github.com/tqdm/tqdm/issues/1319>`__) may benefit from
383
+ ``export TQDM_POSITION=-1``.
384
+
385
+ - Nested progress bars:
386
+
387
+ * Consoles in general: require support for moving cursors up to the
388
+ previous line. For example,
389
+ `IDLE <https://github.com/tqdm/tqdm/issues/191#issuecomment-230168030>`__,
390
+ `ConEmu <https://github.com/tqdm/tqdm/issues/254>`__ and
391
+ `PyCharm <https://github.com/tqdm/tqdm/issues/203>`__ (also
392
+ `here <https://github.com/tqdm/tqdm/issues/208>`__,
393
+ `here <https://github.com/tqdm/tqdm/issues/307>`__, and
394
+ `here <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__)
395
+ lack full support.
396
+ * Windows: additionally may require the Python module ``colorama``
397
+ to ensure nested bars stay within their respective lines.
398
+
399
+ - Unicode:
400
+
401
+ * Environments which report that they support unicode will have solid smooth
402
+ progressbars. The fallback is an ``ascii``-only bar.
403
+ * Windows consoles often only partially support unicode and thus
404
+ `often require explicit ascii=True <https://github.com/tqdm/tqdm/issues/454#issuecomment-335416815>`__
405
+ (also `here <https://github.com/tqdm/tqdm/issues/499>`__). This is due to
406
+ either normal-width unicode characters being incorrectly displayed as
407
+ "wide", or some unicode characters not rendering.
408
+
409
+ - Wrapping generators:
410
+
411
+ * Generator wrapper functions tend to hide the length of iterables.
412
+ ``tqdm`` does not.
413
+ * Replace ``tqdm(enumerate(...))`` with ``enumerate(tqdm(...))`` or
414
+ ``tqdm(enumerate(x), total=len(x), ...)``.
415
+ The same applies to ``numpy.ndenumerate``.
416
+ * Replace ``tqdm(zip(a, b))`` with ``zip(tqdm(a), b)`` or even
417
+ ``zip(tqdm(a), tqdm(b))``.
418
+ * The same applies to ``itertools``.
419
+ * Some useful convenience functions can be found under ``tqdm.contrib``.
420
+
421
+ - `No intermediate output in docker-compose <https://github.com/tqdm/tqdm/issues/771>`__:
422
+ use ``docker-compose run`` instead of ``docker-compose up`` and ``tty: true``.
423
+
424
+ - Overriding defaults via environment variables:
425
+ e.g. in CI/cloud jobs, ``export TQDM_MININTERVAL=5`` to avoid log spam.
426
+ This override logic is handled by the ``tqdm.utils.envwrap`` decorator
427
+ (useful independent of ``tqdm``).
428
+
429
+ If you come across any other difficulties, browse and file |GitHub-Issues|.
430
+
431
+ Documentation
432
+ -------------
433
+
434
+ |Py-Versions| |README-Hits| (Since 19 May 2016)
435
+
436
+ .. code:: python
437
+
438
+ class tqdm():
439
+ """
440
+ Decorate an iterable object, returning an iterator which acts exactly
441
+ like the original iterable, but prints a dynamically updating
442
+ progressbar every time a value is requested.
443
+ """
444
+
445
+ @envwrap("TQDM_") # override defaults via env vars
446
+ def __init__(self, iterable=None, desc=None, total=None, leave=True,
447
+ file=None, ncols=None, mininterval=0.1,
448
+ maxinterval=10.0, miniters=None, ascii=None, disable=False,
449
+ unit='it', unit_scale=False, dynamic_ncols=False,
450
+ smoothing=0.3, bar_format=None, initial=0, position=None,
451
+ postfix=None, unit_divisor=1000, write_bytes=False,
452
+ lock_args=None, nrows=None, colour=None, delay=0):
453
+
454
+ Parameters
455
+ ~~~~~~~~~~
456
+
457
+ * iterable : iterable, optional
458
+ Iterable to decorate with a progressbar.
459
+ Leave blank to manually manage the updates.
460
+ * desc : str, optional
461
+ Prefix for the progressbar.
462
+ * total : int or float, optional
463
+ The number of expected iterations. If unspecified,
464
+ len(iterable) is used if possible. If float("inf") or as a last
465
+ resort, only basic progress statistics are displayed
466
+ (no ETA, no progressbar).
467
+ If ``gui`` is True and this parameter needs subsequent updating,
468
+ specify an initial arbitrary large positive number,
469
+ e.g. 9e9.
470
+ * leave : bool, optional
471
+ If [default: True], keeps all traces of the progressbar
472
+ upon termination of iteration.
473
+ If ``None``, will leave only if ``position`` is ``0``.
474
+ * file : ``io.TextIOWrapper`` or ``io.StringIO``, optional
475
+ Specifies where to output the progress messages
476
+ (default: sys.stderr). Uses ``file.write(str)`` and ``file.flush()``
477
+ methods. For encoding, see ``write_bytes``.
478
+ * ncols : int, optional
479
+ The width of the entire output message. If specified,
480
+ dynamically resizes the progressbar to stay within this bound.
481
+ If unspecified, attempts to use environment width. The
482
+ fallback is a meter width of 10 and no limit for the counter and
483
+ statistics. If 0, will not print any meter (only stats).
484
+ * mininterval : float, optional
485
+ Minimum progress display update interval [default: 0.1] seconds.
486
+ * maxinterval : float, optional
487
+ Maximum progress display update interval [default: 10] seconds.
488
+ Automatically adjusts ``miniters`` to correspond to ``mininterval``
489
+ after long display update lag. Only works if ``dynamic_miniters``
490
+ or monitor thread is enabled.
491
+ * miniters : int or float, optional
492
+ Minimum progress display update interval, in iterations.
493
+ If 0 and ``dynamic_miniters``, will automatically adjust to equal
494
+ ``mininterval`` (more CPU efficient, good for tight loops).
495
+ If > 0, will skip display of specified number of iterations.
496
+ Tweak this and ``mininterval`` to get very efficient loops.
497
+ If your progress is erratic with both fast and slow iterations
498
+ (network, skipping items, etc) you should set miniters=1.
499
+ * ascii : bool or str, optional
500
+ If unspecified or False, use unicode (smooth blocks) to fill
501
+ the meter. The fallback is to use ASCII characters " 123456789#".
502
+ * disable : bool, optional
503
+ Whether to disable the entire progressbar wrapper
504
+ [default: False]. If set to None, disable on non-TTY.
505
+ * unit : str, optional
506
+ String that will be used to define the unit of each iteration
507
+ [default: it].
508
+ * unit_scale : bool or int or float, optional
509
+ If 1 or True, the number of iterations will be reduced/scaled
510
+ automatically and a metric prefix following the
511
+ International System of Units standard will be added
512
+ (kilo, mega, etc.) [default: False]. If any other non-zero
513
+ number, will scale ``total`` and ``n``.
514
+ * dynamic_ncols : bool, optional
515
+ If set, constantly alters ``ncols`` and ``nrows`` to the
516
+ environment (allowing for window resizes) [default: False].
517
+ * smoothing : float, optional
518
+ Exponential moving average smoothing factor for speed estimates
519
+ (ignored in GUI mode). Ranges from 0 (average speed) to 1
520
+ (current/instantaneous speed) [default: 0.3].
521
+ * bar_format : str, optional
522
+ Specify a custom bar string formatting. May impact performance.
523
+ [default: '{l_bar}{bar}{r_bar}'], where
524
+ l_bar='{desc}: {percentage:3.0f}%|' and
525
+ r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
526
+ '{rate_fmt}{postfix}]'
527
+ Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
528
+ percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
529
+ rate, rate_fmt, rate_noinv, rate_noinv_fmt,
530
+ rate_inv, rate_inv_fmt, postfix, unit_divisor,
531
+ remaining, remaining_s, eta.
532
+ Note that a trailing ": " is automatically removed after {desc}
533
+ if the latter is empty.
534
+ * initial : int or float, optional
535
+ The initial counter value. Useful when restarting a progress
536
+ bar [default: 0]. If using float, consider specifying ``{n:.3f}``
537
+ or similar in ``bar_format``, or specifying ``unit_scale``.
538
+ * position : int, optional
539
+ Specify the line offset to print this bar (starting from 0)
540
+ Automatic if unspecified.
541
+ Useful to manage multiple bars at once (eg, from threads).
542
+ * postfix : dict or ``*``, optional
543
+ Specify additional stats to display at the end of the bar.
544
+ Calls ``set_postfix(**postfix)`` if possible (dict).
545
+ * unit_divisor : float, optional
546
+ [default: 1000], ignored unless ``unit_scale`` is True.
547
+ * write_bytes : bool, optional
548
+ Whether to write bytes. If (default: False) will write unicode.
549
+ * lock_args : tuple, optional
550
+ Passed to ``refresh`` for intermediate output
551
+ (initialisation, iterating, and updating).
552
+ * nrows : int, optional
553
+ The screen height. If specified, hides nested bars outside this
554
+ bound. If unspecified, attempts to use environment height.
555
+ The fallback is 20.
556
+ * colour : str, optional
557
+ Bar colour (e.g. 'green', '#00ff00').
558
+ * delay : float, optional
559
+ Don't display until [default: 0] seconds have elapsed.
560
+
561
+ Extra CLI Options
562
+ ~~~~~~~~~~~~~~~~~
563
+
564
+ * delim : chr, optional
565
+ Delimiting character [default: '\n']. Use '\0' for null.
566
+ N.B.: on Windows systems, Python converts '\n' to '\r\n'.
567
+ * buf_size : int, optional
568
+ String buffer size in bytes [default: 256]
569
+ used when ``delim`` is specified.
570
+ * bytes : bool, optional
571
+ If true, will count bytes, ignore ``delim``, and default
572
+ ``unit_scale`` to True, ``unit_divisor`` to 1024, and ``unit`` to 'B'.
573
+ * tee : bool, optional
574
+ If true, passes ``stdin`` to both ``stderr`` and ``stdout``.
575
+ * update : bool, optional
576
+ If true, will treat input as newly elapsed iterations,
577
+ i.e. numbers to pass to ``update()``. Note that this is slow
578
+ (~2e5 it/s) since every input must be decoded as a number.
579
+ * update_to : bool, optional
580
+ If true, will treat input as total elapsed iterations,
581
+ i.e. numbers to assign to ``self.n``. Note that this is slow
582
+ (~2e5 it/s) since every input must be decoded as a number.
583
+ * null : bool, optional
584
+ If true, will discard input (no stdout).
585
+ * manpath : str, optional
586
+ Directory in which to install tqdm man pages.
587
+ * comppath : str, optional
588
+ Directory in which to place tqdm completion.
589
+ * log : str, optional
590
+ CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
591
+
592
+ Returns
593
+ ~~~~~~~
594
+
595
+ * out : decorated iterator.
596
+
597
+ .. code:: python
598
+
599
+ class tqdm():
600
+ def update(self, n=1):
601
+ """
602
+ Manually update the progress bar, useful for streams
603
+ such as reading files.
604
+ E.g.:
605
+ >>> t = tqdm(total=filesize) # Initialise
606
+ >>> for current_buffer in stream:
607
+ ... ...
608
+ ... t.update(len(current_buffer))
609
+ >>> t.close()
610
+ The last line is highly recommended, but possibly not necessary if
611
+ ``t.update()`` will be called in such a way that ``filesize`` will be
612
+ exactly reached and printed.
613
+
614
+ Parameters
615
+ ----------
616
+ n : int or float, optional
617
+ Increment to add to the internal counter of iterations
618
+ [default: 1]. If using float, consider specifying ``{n:.3f}``
619
+ or similar in ``bar_format``, or specifying ``unit_scale``.
620
+
621
+ Returns
622
+ -------
623
+ out : bool or None
624
+ True if a ``display()`` was triggered.
625
+ """
626
+
627
+ def close(self):
628
+ """Cleanup and (if leave=False) close the progressbar."""
629
+
630
+ def clear(self, nomove=False):
631
+ """Clear current bar display."""
632
+
633
+ def refresh(self):
634
+ """
635
+ Force refresh the display of this bar.
636
+
637
+ Parameters
638
+ ----------
639
+ nolock : bool, optional
640
+ If ``True``, does not lock.
641
+ If [default: ``False``]: calls ``acquire()`` on internal lock.
642
+ lock_args : tuple, optional
643
+ Passed to internal lock's ``acquire()``.
644
+ If specified, will only ``display()`` if ``acquire()`` returns ``True``.
645
+ """
646
+
647
+ def unpause(self):
648
+ """Restart tqdm timer from last print time."""
649
+
650
+ def reset(self, total=None):
651
+ """
652
+ Resets to 0 iterations for repeated use.
653
+
654
+ Consider combining with ``leave=True``.
655
+
656
+ Parameters
657
+ ----------
658
+ total : int or float, optional. Total to use for the new bar.
659
+ """
660
+
661
+ def set_description(self, desc=None, refresh=True):
662
+ """
663
+ Set/modify description of the progress bar.
664
+
665
+ Parameters
666
+ ----------
667
+ desc : str, optional
668
+ refresh : bool, optional
669
+ Forces refresh [default: True].
670
+ """
671
+
672
+ def set_postfix(self, ordered_dict=None, refresh=True, **tqdm_kwargs):
673
+ """
674
+ Set/modify postfix (additional stats)
675
+ with automatic formatting based on datatype.
676
+
677
+ Parameters
678
+ ----------
679
+ ordered_dict : dict or OrderedDict, optional
680
+ refresh : bool, optional
681
+ Forces refresh [default: True].
682
+ kwargs : dict, optional
683
+ """
684
+
685
+ @classmethod
686
+ def write(cls, s, file=sys.stdout, end="\n"):
687
+ """Print a message via tqdm (without overlap with bars)."""
688
+
689
+ @property
690
+ def format_dict(self):
691
+ """Public API for read-only member access."""
692
+
693
+ def display(self, msg=None, pos=None):
694
+ """
695
+ Use ``self.sp`` to display ``msg`` in the specified ``pos``.
696
+
697
+ Consider overloading this function when inheriting to use e.g.:
698
+ ``self.some_frontend(**self.format_dict)`` instead of ``self.sp``.
699
+
700
+ Parameters
701
+ ----------
702
+ msg : str, optional. What to display (default: ``repr(self)``).
703
+ pos : int, optional. Position to ``moveto``
704
+ (default: ``abs(self.pos)``).
705
+ """
706
+
707
+ @classmethod
708
+ @contextmanager
709
+ def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
710
+ """
711
+ stream : file-like object.
712
+ method : str, "read" or "write". The result of ``read()`` and
713
+ the first argument of ``write()`` should have a ``len()``.
714
+
715
+ >>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
716
+ ... while True:
717
+ ... chunk = fobj.read(chunk_size)
718
+ ... if not chunk:
719
+ ... break
720
+ """
721
+
722
+ @classmethod
723
+ def pandas(cls, *targs, **tqdm_kwargs):
724
+ """Registers the current `tqdm` class with `pandas`."""
725
+
726
+ def trange(*args, **tqdm_kwargs):
727
+ """Shortcut for `tqdm(range(*args), **tqdm_kwargs)`."""
728
+
729
+ Convenience Functions
730
+ ~~~~~~~~~~~~~~~~~~~~~
731
+
732
+ .. code:: python
733
+
734
+ def tqdm.contrib.tenumerate(iterable, start=0, total=None,
735
+ tqdm_class=tqdm.auto.tqdm, **tqdm_kwargs):
736
+ """Equivalent of `numpy.ndenumerate` or builtin `enumerate`."""
737
+
738
+ def tqdm.contrib.tzip(iter1, *iter2plus, **tqdm_kwargs):
739
+ """Equivalent of builtin `zip`."""
740
+
741
+ def tqdm.contrib.tmap(function, *sequences, **tqdm_kwargs):
742
+ """Equivalent of builtin `map`."""
743
+
744
+ Submodules
745
+ ~~~~~~~~~~
746
+
747
+ .. code:: python
748
+
749
+ class tqdm.notebook.tqdm(tqdm.tqdm):
750
+ """IPython/Jupyter Notebook widget."""
751
+
752
+ class tqdm.auto.tqdm(tqdm.tqdm):
753
+ """Automatically chooses beween `tqdm.notebook` and `tqdm.tqdm`."""
754
+
755
+ class tqdm.asyncio.tqdm(tqdm.tqdm):
756
+ """Asynchronous version."""
757
+ @classmethod
758
+ def as_completed(cls, fs, *, loop=None, timeout=None, total=None,
759
+ **tqdm_kwargs):
760
+ """Wrapper for `asyncio.as_completed`."""
761
+
762
+ class tqdm.gui.tqdm(tqdm.tqdm):
763
+ """Matplotlib GUI version."""
764
+
765
+ class tqdm.tk.tqdm(tqdm.tqdm):
766
+ """Tkinter GUI version."""
767
+
768
+ class tqdm.rich.tqdm(tqdm.tqdm):
769
+ """`rich.progress` version."""
770
+
771
+ class tqdm.keras.TqdmCallback(keras.callbacks.Callback):
772
+ """Keras callback for epoch and batch progress."""
773
+
774
+ class tqdm.dask.TqdmCallback(dask.callbacks.Callback):
775
+ """Dask callback for task progress."""
776
+
777
+
778
+ ``contrib``
779
+ +++++++++++
780
+
781
+ The ``tqdm.contrib`` package also contains experimental modules:
782
+
783
+ - ``tqdm.contrib.itertools``: Thin wrappers around ``itertools``
784
+ - ``tqdm.contrib.concurrent``: Thin wrappers around ``concurrent.futures``
785
+ - ``tqdm.contrib.slack``: Posts to `Slack <https://slack.com>`__ bots
786
+ - ``tqdm.contrib.discord``: Posts to `Discord <https://discord.com>`__ bots
787
+ - ``tqdm.contrib.telegram``: Posts to `Telegram <https://telegram.org>`__ bots
788
+ - ``tqdm.contrib.bells``: Automagically enables all optional features
789
+
790
+ * ``auto``, ``pandas``, ``slack``, ``discord``, ``telegram``
791
+
792
+ Examples and Advanced Usage
793
+ ---------------------------
794
+
795
+ - See the `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
796
+ folder;
797
+ - import the module and run ``help()``;
798
+ - consult the `wiki <https://github.com/tqdm/tqdm/wiki>`__;
799
+
800
+ * this has an
801
+ `excellent article <https://github.com/tqdm/tqdm/wiki/How-to-make-a-great-Progress-Bar>`__
802
+ on how to make a **great** progressbar;
803
+
804
+ - check out the `slides from PyData London <https://tqdm.github.io/PyData2019/slides.html>`__, or
805
+ - run the |binder-demo|.
806
+
807
+ Description and additional stats
808
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
809
+
810
+ Custom information can be displayed and updated dynamically on ``tqdm`` bars
811
+ with the ``desc`` and ``postfix`` arguments:
812
+
813
+ .. code:: python
814
+
815
+ from tqdm import tqdm, trange
816
+ from random import random, randint
817
+ from time import sleep
818
+
819
+ with trange(10) as t:
820
+ for i in t:
821
+ # Description will be displayed on the left
822
+ t.set_description('GEN %i' % i)
823
+ # Postfix will be displayed on the right,
824
+ # formatted automatically based on argument's datatype
825
+ t.set_postfix(loss=random(), gen=randint(1,999), str='h',
826
+ lst=[1, 2])
827
+ sleep(0.1)
828
+
829
+ with tqdm(total=10, bar_format="{postfix[0]} {postfix[1][value]:>8.2g}",
830
+ postfix=["Batch", {"value": 0}]) as t:
831
+ for i in range(10):
832
+ sleep(0.1)
833
+ t.postfix[1]["value"] = i / 2
834
+ t.update()
835
+
836
+ Points to remember when using ``{postfix[...]}`` in the ``bar_format`` string:
837
+
838
+ - ``postfix`` also needs to be passed as an initial argument in a compatible
839
+ format, and
840
+ - ``postfix`` will be auto-converted to a string if it is a ``dict``-like
841
+ object. To prevent this behaviour, insert an extra item into the dictionary
842
+ where the key is not a string.
843
+
844
+ Additional ``bar_format`` parameters may also be defined by overriding
845
+ ``format_dict``, and the bar itself may be modified using ``ascii``:
846
+
847
+ .. code:: python
848
+
849
+ from tqdm import tqdm
850
+ class TqdmExtraFormat(tqdm):
851
+ """Provides a `total_time` format parameter"""
852
+ @property
853
+ def format_dict(self):
854
+ d = super().format_dict
855
+ total_time = d["elapsed"] * (d["total"] or 0) / max(d["n"], 1)
856
+ d.update(total_time=self.format_interval(total_time) + " in total")
857
+ return d
858
+
859
+ for i in TqdmExtraFormat(
860
+ range(9), ascii=" .oO0",
861
+ bar_format="{total_time}: {percentage:.0f}%|{bar}{r_bar}"):
862
+ if i == 4:
863
+ break
864
+
865
+ .. code::
866
+
867
+ 00:00 in total: 44%|0000. | 4/9 [00:00<00:00, 962.93it/s]
868
+
869
+ Note that ``{bar}`` also supports a format specifier ``[width][type]``.
870
+
871
+ - ``width``
872
+
873
+ * unspecified (default): automatic to fill ``ncols``
874
+ * ``int >= 0``: fixed width overriding ``ncols`` logic
875
+ * ``int < 0``: subtract from the automatic default
876
+
877
+ - ``type``
878
+
879
+ * ``a``: ascii (``ascii=True`` override)
880
+ * ``u``: unicode (``ascii=False`` override)
881
+ * ``b``: blank (``ascii=" "`` override)
882
+
883
+ This means a fixed bar with right-justified text may be created by using:
884
+ ``bar_format="{l_bar}{bar:10}|{bar:-10b}right-justified"``
885
+
886
+ Nested progress bars
887
+ ~~~~~~~~~~~~~~~~~~~~
888
+
889
+ ``tqdm`` supports nested progress bars. Here's an example:
890
+
891
+ .. code:: python
892
+
893
+ from tqdm.auto import trange
894
+ from time import sleep
895
+
896
+ for i in trange(4, desc='1st loop'):
897
+ for j in trange(5, desc='2nd loop'):
898
+ for k in trange(50, desc='3rd loop', leave=False):
899
+ sleep(0.01)
900
+
901
+ For manual control over positioning (e.g. for multi-processing use),
902
+ you may specify ``position=n`` where ``n=0`` for the outermost bar,
903
+ ``n=1`` for the next, and so on.
904
+ However, it's best to check if ``tqdm`` can work without manual ``position``
905
+ first.
906
+
907
+ .. code:: python
908
+
909
+ from time import sleep
910
+ from tqdm import trange, tqdm
911
+ from multiprocessing import Pool, RLock, freeze_support
912
+
913
+ L = list(range(9))
914
+
915
+ def progresser(n):
916
+ interval = 0.001 / (n + 2)
917
+ total = 5000
918
+ text = f"#{n}, est. {interval * total:<04.2}s"
919
+ for _ in trange(total, desc=text, position=n):
920
+ sleep(interval)
921
+
922
+ if __name__ == '__main__':
923
+ freeze_support() # for Windows support
924
+ tqdm.set_lock(RLock()) # for managing output contention
925
+ p = Pool(initializer=tqdm.set_lock, initargs=(tqdm.get_lock(),))
926
+ p.map(progresser, L)
927
+
928
+ Note that in Python 3, ``tqdm.write`` is thread-safe:
929
+
930
+ .. code:: python
931
+
932
+ from time import sleep
933
+ from tqdm import tqdm, trange
934
+ from concurrent.futures import ThreadPoolExecutor
935
+
936
+ L = list(range(9))
937
+
938
+ def progresser(n):
939
+ interval = 0.001 / (n + 2)
940
+ total = 5000
941
+ text = f"#{n}, est. {interval * total:<04.2}s"
942
+ for _ in trange(total, desc=text):
943
+ sleep(interval)
944
+ if n == 6:
945
+ tqdm.write("n == 6 completed.")
946
+ tqdm.write("`tqdm.write()` is thread-safe in py3!")
947
+
948
+ if __name__ == '__main__':
949
+ with ThreadPoolExecutor() as p:
950
+ p.map(progresser, L)
951
+
952
+ Hooks and callbacks
953
+ ~~~~~~~~~~~~~~~~~~~
954
+
955
+ ``tqdm`` can easily support callbacks/hooks and manual updates.
956
+ Here's an example with ``urllib``:
957
+
958
+ **``urllib.urlretrieve`` documentation**
959
+
960
+ | [...]
961
+ | If present, the hook function will be called once
962
+ | on establishment of the network connection and once after each block read
963
+ | thereafter. The hook will be passed three arguments; a count of blocks
964
+ | transferred so far, a block size in bytes, and the total size of the file.
965
+ | [...]
966
+
967
+ .. code:: python
968
+
969
+ import urllib, os
970
+ from tqdm import tqdm
971
+ urllib = getattr(urllib, 'request', urllib)
972
+
973
+ class TqdmUpTo(tqdm):
974
+ """Provides `update_to(n)` which uses `tqdm.update(delta_n)`."""
975
+ def update_to(self, b=1, bsize=1, tsize=None):
976
+ """
977
+ b : int, optional
978
+ Number of blocks transferred so far [default: 1].
979
+ bsize : int, optional
980
+ Size of each block (in tqdm units) [default: 1].
981
+ tsize : int, optional
982
+ Total size (in tqdm units). If [default: None] remains unchanged.
983
+ """
984
+ if tsize is not None:
985
+ self.total = tsize
986
+ return self.update(b * bsize - self.n) # also sets self.n = b * bsize
987
+
988
+ eg_link = "https://caspersci.uk.to/matryoshka.zip"
989
+ with TqdmUpTo(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
990
+ desc=eg_link.split('/')[-1]) as t: # all optional kwargs
991
+ urllib.urlretrieve(eg_link, filename=os.devnull,
992
+ reporthook=t.update_to, data=None)
993
+ t.total = t.n
994
+
995
+ Inspired by `twine#242 <https://github.com/pypa/twine/pull/242>`__.
996
+ Functional alternative in
997
+ `examples/tqdm_wget.py <https://github.com/tqdm/tqdm/blob/master/examples/tqdm_wget.py>`__.
998
+
999
+ It is recommend to use ``miniters=1`` whenever there is potentially
1000
+ large differences in iteration speed (e.g. downloading a file over
1001
+ a patchy connection).
1002
+
1003
+ **Wrapping read/write methods**
1004
+
1005
+ To measure throughput through a file-like object's ``read`` or ``write``
1006
+ methods, use ``CallbackIOWrapper``:
1007
+
1008
+ .. code:: python
1009
+
1010
+ from tqdm.auto import tqdm
1011
+ from tqdm.utils import CallbackIOWrapper
1012
+
1013
+ with tqdm(total=file_obj.size,
1014
+ unit='B', unit_scale=True, unit_divisor=1024) as t:
1015
+ fobj = CallbackIOWrapper(t.update, file_obj, "read")
1016
+ while True:
1017
+ chunk = fobj.read(chunk_size)
1018
+ if not chunk:
1019
+ break
1020
+ t.reset()
1021
+ # ... continue to use `t` for something else
1022
+
1023
+ Alternatively, use the even simpler ``wrapattr`` convenience function,
1024
+ which would condense both the ``urllib`` and ``CallbackIOWrapper`` examples
1025
+ down to:
1026
+
1027
+ .. code:: python
1028
+
1029
+ import urllib, os
1030
+ from tqdm import tqdm
1031
+
1032
+ eg_link = "https://caspersci.uk.to/matryoshka.zip"
1033
+ response = getattr(urllib, 'request', urllib).urlopen(eg_link)
1034
+ with tqdm.wrapattr(open(os.devnull, "wb"), "write",
1035
+ miniters=1, desc=eg_link.split('/')[-1],
1036
+ total=getattr(response, 'length', None)) as fout:
1037
+ for chunk in response:
1038
+ fout.write(chunk)
1039
+
1040
+ The ``requests`` equivalent is nearly identical:
1041
+
1042
+ .. code:: python
1043
+
1044
+ import requests, os
1045
+ from tqdm import tqdm
1046
+
1047
+ eg_link = "https://caspersci.uk.to/matryoshka.zip"
1048
+ response = requests.get(eg_link, stream=True)
1049
+ with tqdm.wrapattr(open(os.devnull, "wb"), "write",
1050
+ miniters=1, desc=eg_link.split('/')[-1],
1051
+ total=int(response.headers.get('content-length', 0))) as fout:
1052
+ for chunk in response.iter_content(chunk_size=4096):
1053
+ fout.write(chunk)
1054
+
1055
+ **Custom callback**
1056
+
1057
+ ``tqdm`` is known for intelligently skipping unnecessary displays. To make a
1058
+ custom callback take advantage of this, simply use the return value of
1059
+ ``update()``. This is set to ``True`` if a ``display()`` was triggered.
1060
+
1061
+ .. code:: python
1062
+
1063
+ from tqdm.auto import tqdm as std_tqdm
1064
+
1065
+ def external_callback(*args, **kwargs):
1066
+ ...
1067
+
1068
+ class TqdmExt(std_tqdm):
1069
+ def update(self, n=1):
1070
+ displayed = super().update(n)
1071
+ if displayed:
1072
+ external_callback(**self.format_dict)
1073
+ return displayed
1074
+
1075
+ ``asyncio``
1076
+ ~~~~~~~~~~~
1077
+
1078
+ Note that ``break`` isn't currently caught by asynchronous iterators.
1079
+ This means that ``tqdm`` cannot clean up after itself in this case:
1080
+
1081
+ .. code:: python
1082
+
1083
+ from tqdm.asyncio import tqdm
1084
+
1085
+ async for i in tqdm(range(9)):
1086
+ if i == 2:
1087
+ break
1088
+
1089
+ Instead, either call ``pbar.close()`` manually or use the context manager syntax:
1090
+
1091
+ .. code:: python
1092
+
1093
+ from tqdm.asyncio import tqdm
1094
+
1095
+ with tqdm(range(9)) as pbar:
1096
+ async for i in pbar:
1097
+ if i == 2:
1098
+ break
1099
+
1100
+ Pandas Integration
1101
+ ~~~~~~~~~~~~~~~~~~
1102
+
1103
+ Due to popular demand we've added support for ``pandas`` -- here's an example
1104
+ for ``DataFrame.progress_apply`` and ``DataFrameGroupBy.progress_apply``:
1105
+
1106
+ .. code:: python
1107
+
1108
+ import pandas as pd
1109
+ import numpy as np
1110
+ from tqdm import tqdm
1111
+
1112
+ df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
1113
+
1114
+ # Register `pandas.progress_apply` and `pandas.Series.map_apply` with `tqdm`
1115
+ # (can use `tqdm.gui.tqdm`, `tqdm.notebook.tqdm`, optional kwargs, etc.)
1116
+ tqdm.pandas(desc="my bar!")
1117
+
1118
+ # Now you can use `progress_apply` instead of `apply`
1119
+ # and `progress_map` instead of `map`
1120
+ df.progress_apply(lambda x: x**2)
1121
+ # can also groupby:
1122
+ # df.groupby(0).progress_apply(lambda x: x**2)
1123
+
1124
+ In case you're interested in how this works (and how to modify it for your
1125
+ own callbacks), see the
1126
+ `examples <https://github.com/tqdm/tqdm/tree/master/examples>`__
1127
+ folder or import the module and run ``help()``.
1128
+
1129
+ Keras Integration
1130
+ ~~~~~~~~~~~~~~~~~
1131
+
1132
+ A ``keras`` callback is also available:
1133
+
1134
+ .. code:: python
1135
+
1136
+ from tqdm.keras import TqdmCallback
1137
+
1138
+ ...
1139
+
1140
+ model.fit(..., verbose=0, callbacks=[TqdmCallback()])
1141
+
1142
+ Dask Integration
1143
+ ~~~~~~~~~~~~~~~~
1144
+
1145
+ A ``dask`` callback is also available:
1146
+
1147
+ .. code:: python
1148
+
1149
+ from tqdm.dask import TqdmCallback
1150
+
1151
+ with TqdmCallback(desc="compute"):
1152
+ ...
1153
+ arr.compute()
1154
+
1155
+ # or use callback globally
1156
+ cb = TqdmCallback(desc="global")
1157
+ cb.register()
1158
+ arr.compute()
1159
+
1160
+ IPython/Jupyter Integration
1161
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1162
+
1163
+ IPython/Jupyter is supported via the ``tqdm.notebook`` submodule:
1164
+
1165
+ .. code:: python
1166
+
1167
+ from tqdm.notebook import trange, tqdm
1168
+ from time import sleep
1169
+
1170
+ for i in trange(3, desc='1st loop'):
1171
+ for j in tqdm(range(100), desc='2nd loop'):
1172
+ sleep(0.01)
1173
+
1174
+ In addition to ``tqdm`` features, the submodule provides a native Jupyter
1175
+ widget (compatible with IPython v1-v4 and Jupyter), fully working nested bars
1176
+ and colour hints (blue: normal, green: completed, red: error/interrupt,
1177
+ light blue: no ETA); as demonstrated below.
1178
+
1179
+ |Screenshot-Jupyter1|
1180
+ |Screenshot-Jupyter2|
1181
+ |Screenshot-Jupyter3|
1182
+
1183
+ The ``notebook`` version supports percentage or pixels for overall width
1184
+ (e.g.: ``ncols='100%'`` or ``ncols='480px'``).
1185
+
1186
+ It is also possible to let ``tqdm`` automatically choose between
1187
+ console or notebook versions by using the ``autonotebook`` submodule:
1188
+
1189
+ .. code:: python
1190
+
1191
+ from tqdm.autonotebook import tqdm
1192
+ tqdm.pandas()
1193
+
1194
+ Note that this will issue a ``TqdmExperimentalWarning`` if run in a notebook
1195
+ since it is not meant to be possible to distinguish between ``jupyter notebook``
1196
+ and ``jupyter console``. Use ``auto`` instead of ``autonotebook`` to suppress
1197
+ this warning.
1198
+
1199
+ Note that notebooks will display the bar in the cell where it was created.
1200
+ This may be a different cell from the one where it is used.
1201
+ If this is not desired, either
1202
+
1203
+ - delay the creation of the bar to the cell where it must be displayed, or
1204
+ - create the bar with ``display=False``, and in a later cell call
1205
+ ``display(bar.container)``:
1206
+
1207
+ .. code:: python
1208
+
1209
+ from tqdm.notebook import tqdm
1210
+ pbar = tqdm(..., display=False)
1211
+
1212
+ .. code:: python
1213
+
1214
+ # different cell
1215
+ display(pbar.container)
1216
+
1217
+ The ``keras`` callback has a ``display()`` method which can be used likewise:
1218
+
1219
+ .. code:: python
1220
+
1221
+ from tqdm.keras import TqdmCallback
1222
+ cbk = TqdmCallback(display=False)
1223
+
1224
+ .. code:: python
1225
+
1226
+ # different cell
1227
+ cbk.display()
1228
+ model.fit(..., verbose=0, callbacks=[cbk])
1229
+
1230
+ Another possibility is to have a single bar (near the top of the notebook)
1231
+ which is constantly re-used (using ``reset()`` rather than ``close()``).
1232
+ For this reason, the notebook version (unlike the CLI version) does not
1233
+ automatically call ``close()`` upon ``Exception``.
1234
+
1235
+ .. code:: python
1236
+
1237
+ from tqdm.notebook import tqdm
1238
+ pbar = tqdm()
1239
+
1240
+ .. code:: python
1241
+
1242
+ # different cell
1243
+ iterable = range(100)
1244
+ pbar.reset(total=len(iterable)) # initialise with new `total`
1245
+ for i in iterable:
1246
+ pbar.update()
1247
+ pbar.refresh() # force print final status but don't `close()`
1248
+
1249
+ Custom Integration
1250
+ ~~~~~~~~~~~~~~~~~~
1251
+
1252
+ To change the default arguments (such as making ``dynamic_ncols=True``),
1253
+ simply use built-in Python magic:
1254
+
1255
+ .. code:: python
1256
+
1257
+ from functools import partial
1258
+ from tqdm import tqdm as std_tqdm
1259
+ tqdm = partial(std_tqdm, dynamic_ncols=True)
1260
+
1261
+ For further customisation,
1262
+ ``tqdm`` may be inherited from to create custom callbacks (as with the
1263
+ ``TqdmUpTo`` example `above <#hooks-and-callbacks>`__) or for custom frontends
1264
+ (e.g. GUIs such as notebook or plotting packages). In the latter case:
1265
+
1266
+ 1. ``def __init__()`` to call ``super().__init__(..., gui=True)`` to disable
1267
+ terminal ``status_printer`` creation.
1268
+ 2. Redefine: ``close()``, ``clear()``, ``display()``.
1269
+
1270
+ Consider overloading ``display()`` to use e.g.
1271
+ ``self.frontend(**self.format_dict)`` instead of ``self.sp(repr(self))``.
1272
+
1273
+ Some submodule examples of inheritance:
1274
+
1275
+ - `tqdm/notebook.py <https://github.com/tqdm/tqdm/blob/master/tqdm/notebook.py>`__
1276
+ - `tqdm/gui.py <https://github.com/tqdm/tqdm/blob/master/tqdm/gui.py>`__
1277
+ - `tqdm/tk.py <https://github.com/tqdm/tqdm/blob/master/tqdm/tk.py>`__
1278
+ - `tqdm/contrib/slack.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/slack.py>`__
1279
+ - `tqdm/contrib/discord.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/discord.py>`__
1280
+ - `tqdm/contrib/telegram.py <https://github.com/tqdm/tqdm/blob/master/tqdm/contrib/telegram.py>`__
1281
+
1282
+ Dynamic Monitor/Meter
1283
+ ~~~~~~~~~~~~~~~~~~~~~
1284
+
1285
+ You can use a ``tqdm`` as a meter which is not monotonically increasing.
1286
+ This could be because ``n`` decreases (e.g. a CPU usage monitor) or ``total``
1287
+ changes.
1288
+
1289
+ One example would be recursively searching for files. The ``total`` is the
1290
+ number of objects found so far, while ``n`` is the number of those objects which
1291
+ are files (rather than folders):
1292
+
1293
+ .. code:: python
1294
+
1295
+ from tqdm import tqdm
1296
+ import os.path
1297
+
1298
+ def find_files_recursively(path, show_progress=True):
1299
+ files = []
1300
+ # total=1 assumes `path` is a file
1301
+ t = tqdm(total=1, unit="file", disable=not show_progress)
1302
+ if not os.path.exists(path):
1303
+ raise IOError("Cannot find:" + path)
1304
+
1305
+ def append_found_file(f):
1306
+ files.append(f)
1307
+ t.update()
1308
+
1309
+ def list_found_dir(path):
1310
+ """returns os.listdir(path) assuming os.path.isdir(path)"""
1311
+ listing = os.listdir(path)
1312
+ # subtract 1 since a "file" we found was actually this directory
1313
+ t.total += len(listing) - 1
1314
+ # fancy way to give info without forcing a refresh
1315
+ t.set_postfix(dir=path[-10:], refresh=False)
1316
+ t.update(0) # may trigger a refresh
1317
+ return listing
1318
+
1319
+ def recursively_search(path):
1320
+ if os.path.isdir(path):
1321
+ for f in list_found_dir(path):
1322
+ recursively_search(os.path.join(path, f))
1323
+ else:
1324
+ append_found_file(path)
1325
+
1326
+ recursively_search(path)
1327
+ t.set_postfix(dir=path)
1328
+ t.close()
1329
+ return files
1330
+
1331
+ Using ``update(0)`` is a handy way to let ``tqdm`` decide when to trigger a
1332
+ display refresh to avoid console spamming.
1333
+
1334
+ Writing messages
1335
+ ~~~~~~~~~~~~~~~~
1336
+
1337
+ This is a work in progress (see
1338
+ `#737 <https://github.com/tqdm/tqdm/issues/737>`__).
1339
+
1340
+ Since ``tqdm`` uses a simple printing mechanism to display progress bars,
1341
+ you should not write any message in the terminal using ``print()`` while
1342
+ a progressbar is open.
1343
+
1344
+ To write messages in the terminal without any collision with ``tqdm`` bar
1345
+ display, a ``.write()`` method is provided:
1346
+
1347
+ .. code:: python
1348
+
1349
+ from tqdm.auto import tqdm, trange
1350
+ from time import sleep
1351
+
1352
+ bar = trange(10)
1353
+ for i in bar:
1354
+ # Print using tqdm class method .write()
1355
+ sleep(0.1)
1356
+ if not (i % 3):
1357
+ tqdm.write("Done task %i" % i)
1358
+ # Can also use bar.write()
1359
+
1360
+ By default, this will print to standard output ``sys.stdout``. but you can
1361
+ specify any file-like object using the ``file`` argument. For example, this
1362
+ can be used to redirect the messages writing to a log file or class.
1363
+
1364
+ Redirecting writing
1365
+ ~~~~~~~~~~~~~~~~~~~
1366
+
1367
+ If using a library that can print messages to the console, editing the library
1368
+ by replacing ``print()`` with ``tqdm.write()`` may not be desirable.
1369
+ In that case, redirecting ``sys.stdout`` to ``tqdm.write()`` is an option.
1370
+
1371
+ To redirect ``sys.stdout``, create a file-like class that will write
1372
+ any input string to ``tqdm.write()``, and supply the arguments
1373
+ ``file=sys.stdout, dynamic_ncols=True``.
1374
+
1375
+ A reusable canonical example is given below:
1376
+
1377
+ .. code:: python
1378
+
1379
+ from time import sleep
1380
+ import contextlib
1381
+ import sys
1382
+ from tqdm import tqdm
1383
+ from tqdm.contrib import DummyTqdmFile
1384
+
1385
+
1386
+ @contextlib.contextmanager
1387
+ def std_out_err_redirect_tqdm():
1388
+ orig_out_err = sys.stdout, sys.stderr
1389
+ try:
1390
+ sys.stdout, sys.stderr = map(DummyTqdmFile, orig_out_err)
1391
+ yield orig_out_err[0]
1392
+ # Relay exceptions
1393
+ except Exception as exc:
1394
+ raise exc
1395
+ # Always restore sys.stdout/err if necessary
1396
+ finally:
1397
+ sys.stdout, sys.stderr = orig_out_err
1398
+
1399
+ def some_fun(i):
1400
+ print("Fee, fi, fo,".split()[i])
1401
+
1402
+ # Redirect stdout to tqdm.write() (don't forget the `as save_stdout`)
1403
+ with std_out_err_redirect_tqdm() as orig_stdout:
1404
+ # tqdm needs the original stdout
1405
+ # and dynamic_ncols=True to autodetect console width
1406
+ for i in tqdm(range(3), file=orig_stdout, dynamic_ncols=True):
1407
+ sleep(.5)
1408
+ some_fun(i)
1409
+
1410
+ # After the `with`, printing is restored
1411
+ print("Done!")
1412
+
1413
+ Redirecting ``logging``
1414
+ ~~~~~~~~~~~~~~~~~~~~~~~
1415
+
1416
+ Similar to ``sys.stdout``/``sys.stderr`` as detailed above, console ``logging``
1417
+ may also be redirected to ``tqdm.write()``.
1418
+
1419
+ Warning: if also redirecting ``sys.stdout``/``sys.stderr``, make sure to
1420
+ redirect ``logging`` first if needed.
1421
+
1422
+ Helper methods are available in ``tqdm.contrib.logging``. For example:
1423
+
1424
+ .. code:: python
1425
+
1426
+ import logging
1427
+ from tqdm import trange
1428
+ from tqdm.contrib.logging import logging_redirect_tqdm
1429
+
1430
+ LOG = logging.getLogger(__name__)
1431
+
1432
+ if __name__ == '__main__':
1433
+ logging.basicConfig(level=logging.INFO)
1434
+ with logging_redirect_tqdm():
1435
+ for i in trange(9):
1436
+ if i == 4:
1437
+ LOG.info("console logging redirected to `tqdm.write()`")
1438
+ # logging restored
1439
+
1440
+ Monitoring thread, intervals and miniters
1441
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1442
+
1443
+ ``tqdm`` implements a few tricks to increase efficiency and reduce overhead.
1444
+
1445
+ - Avoid unnecessary frequent bar refreshing: ``mininterval`` defines how long
1446
+ to wait between each refresh. ``tqdm`` always gets updated in the background,
1447
+ but it will display only every ``mininterval``.
1448
+ - Reduce number of calls to check system clock/time.
1449
+ - ``mininterval`` is more intuitive to configure than ``miniters``.
1450
+ A clever adjustment system ``dynamic_miniters`` will automatically adjust
1451
+ ``miniters`` to the amount of iterations that fit into time ``mininterval``.
1452
+ Essentially, ``tqdm`` will check if it's time to print without actually
1453
+ checking time. This behaviour can be still be bypassed by manually setting
1454
+ ``miniters``.
1455
+
1456
+ However, consider a case with a combination of fast and slow iterations.
1457
+ After a few fast iterations, ``dynamic_miniters`` will set ``miniters`` to a
1458
+ large number. When iteration rate subsequently slows, ``miniters`` will
1459
+ remain large and thus reduce display update frequency. To address this:
1460
+
1461
+ - ``maxinterval`` defines the maximum time between display refreshes.
1462
+ A concurrent monitoring thread checks for overdue updates and forces one
1463
+ where necessary.
1464
+
1465
+ The monitoring thread should not have a noticeable overhead, and guarantees
1466
+ updates at least every 10 seconds by default.
1467
+ This value can be directly changed by setting the ``monitor_interval`` of
1468
+ any ``tqdm`` instance (i.e. ``t = tqdm.tqdm(...); t.monitor_interval = 2``).
1469
+ The monitor thread may be disabled application-wide by setting
1470
+ ``tqdm.tqdm.monitor_interval = 0`` before instantiation of any ``tqdm`` bar.
1471
+
1472
+
1473
+ Merch
1474
+ -----
1475
+
1476
+ You can buy `tqdm branded merch <https://tqdm.github.io/merch>`__ now!
1477
+
1478
+ Contributions
1479
+ -------------
1480
+
1481
+ |GitHub-Commits| |GitHub-Issues| |GitHub-PRs| |OpenHub-Status| |GitHub-Contributions| |CII Best Practices|
1482
+
1483
+ All source code is hosted on `GitHub <https://github.com/tqdm/tqdm>`__.
1484
+ Contributions are welcome.
1485
+
1486
+ See the
1487
+ `CONTRIBUTING <https://github.com/tqdm/tqdm/blob/master/CONTRIBUTING.md>`__
1488
+ file for more information.
1489
+
1490
+ Developers who have made significant contributions, ranked by *SLoC*
1491
+ (surviving lines of code,
1492
+ `git fame <https://github.com/casperdcl/git-fame>`__ ``-wMC --excl '\.(png|gif|jpg)$'``),
1493
+ are:
1494
+
1495
+ ==================== ======================================================== ==== ================================
1496
+ Name ID SLoC Notes
1497
+ ==================== ======================================================== ==== ================================
1498
+ Casper da Costa-Luis `casperdcl <https://github.com/casperdcl>`__ ~80% primary maintainer |Gift-Casper|
1499
+ Stephen Larroque `lrq3000 <https://github.com/lrq3000>`__ ~9% team member
1500
+ Martin Zugnoni `martinzugnoni <https://github.com/martinzugnoni>`__ ~3%
1501
+ Daniel Ecer `de-code <https://github.com/de-code>`__ ~2%
1502
+ Richard Sheridan `richardsheridan <https://github.com/richardsheridan>`__ ~1%
1503
+ Guangshuo Chen `chengs <https://github.com/chengs>`__ ~1%
1504
+ Helio Machado `0x2b3bfa0 <https://github.com/0x2b3bfa0>`__ ~1%
1505
+ Kyle Altendorf `altendky <https://github.com/altendky>`__ <1%
1506
+ Noam Yorav-Raphael `noamraph <https://github.com/noamraph>`__ <1% original author
1507
+ Matthew Stevens `mjstevens777 <https://github.com/mjstevens777>`__ <1%
1508
+ Hadrien Mary `hadim <https://github.com/hadim>`__ <1% team member
1509
+ Mikhail Korobov `kmike <https://github.com/kmike>`__ <1% team member
1510
+ ==================== ======================================================== ==== ================================
1511
+
1512
+ Ports to Other Languages
1513
+ ~~~~~~~~~~~~~~~~~~~~~~~~
1514
+
1515
+ A list is available on
1516
+ `this wiki page <https://github.com/tqdm/tqdm/wiki/tqdm-ports>`__.
1517
+
1518
+
1519
+ LICENCE
1520
+ -------
1521
+
1522
+ Open Source (OSI approved): |LICENCE|
1523
+
1524
+ Citation information: |DOI|
1525
+
1526
+ |README-Hits| (Since 19 May 2016)
1527
+
1528
+ .. |Logo| image:: https://tqdm.github.io/img/logo.gif
1529
+ .. |Screenshot| image:: https://tqdm.github.io/img/tqdm.gif
1530
+ .. |Video| image:: https://tqdm.github.io/img/video.jpg
1531
+ :target: https://tqdm.github.io/video
1532
+ .. |Slides| image:: https://tqdm.github.io/img/slides.jpg
1533
+ :target: https://tqdm.github.io/PyData2019/slides.html
1534
+ .. |Merch| image:: https://tqdm.github.io/img/merch.jpg
1535
+ :target: https://tqdm.github.io/merch
1536
+ .. |Build-Status| image:: https://img.shields.io/github/actions/workflow/status/tqdm/tqdm/test.yml?branch=master&label=tqdm&logo=GitHub
1537
+ :target: https://github.com/tqdm/tqdm/actions/workflows/test.yml
1538
+ .. |Coverage-Status| image:: https://img.shields.io/coveralls/github/tqdm/tqdm/master?logo=coveralls
1539
+ :target: https://coveralls.io/github/tqdm/tqdm
1540
+ .. |Branch-Coverage-Status| image:: https://codecov.io/gh/tqdm/tqdm/branch/master/graph/badge.svg
1541
+ :target: https://codecov.io/gh/tqdm/tqdm
1542
+ .. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/3f965571598f44549c7818f29cdcf177
1543
+ :target: https://www.codacy.com/gh/tqdm/tqdm/dashboard
1544
+ .. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge
1545
+ :target: https://bestpractices.coreinfrastructure.org/projects/3264
1546
+ .. |GitHub-Status| image:: https://img.shields.io/github/tag/tqdm/tqdm.svg?maxAge=86400&logo=github&logoColor=white
1547
+ :target: https://github.com/tqdm/tqdm/releases
1548
+ .. |GitHub-Forks| image:: https://img.shields.io/github/forks/tqdm/tqdm.svg?logo=github&logoColor=white
1549
+ :target: https://github.com/tqdm/tqdm/network
1550
+ .. |GitHub-Stars| image:: https://img.shields.io/github/stars/tqdm/tqdm.svg?logo=github&logoColor=white
1551
+ :target: https://github.com/tqdm/tqdm/stargazers
1552
+ .. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/tqdm/tqdm.svg?logo=git&logoColor=white
1553
+ :target: https://github.com/tqdm/tqdm/graphs/commit-activity
1554
+ .. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/tqdm/tqdm.svg?logo=github&logoColor=white
1555
+ :target: https://github.com/tqdm/tqdm/issues?q=
1556
+ .. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/tqdm/tqdm.svg?logo=github&logoColor=white
1557
+ :target: https://github.com/tqdm/tqdm/pulls
1558
+ .. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/tqdm/tqdm.svg?logo=github&logoColor=white
1559
+ :target: https://github.com/tqdm/tqdm/graphs/contributors
1560
+ .. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/tqdm/tqdm/master.svg?logo=github&logoColor=white&label=pushed
1561
+ :target: https://github.com/tqdm/tqdm/pulse
1562
+ .. |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
1563
+ :target: https://cdcl.ml/sponsor
1564
+ .. |Versions| image:: https://img.shields.io/pypi/v/tqdm.svg
1565
+ :target: https://tqdm.github.io/releases
1566
+ .. |PyPI-Downloads| image:: https://img.shields.io/pypi/dm/tqdm.svg?label=pypi%20downloads&logo=PyPI&logoColor=white
1567
+ :target: https://pepy.tech/project/tqdm
1568
+ .. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/tqdm.svg?logo=python&logoColor=white
1569
+ :target: https://pypi.org/project/tqdm
1570
+ .. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/tqdm.svg?label=conda-forge&logo=conda-forge
1571
+ :target: https://anaconda.org/conda-forge/tqdm
1572
+ .. |Snapcraft| image:: https://img.shields.io/badge/snap-install-82BEA0.svg?logo=snapcraft
1573
+ :target: https://snapcraft.io/tqdm
1574
+ .. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white
1575
+ :target: https://hub.docker.com/r/tqdm/tqdm
1576
+ .. |Libraries-Rank| image:: https://img.shields.io/librariesio/sourcerank/pypi/tqdm.svg?logo=koding&logoColor=white
1577
+ :target: https://libraries.io/pypi/tqdm
1578
+ .. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/tqdm.svg?logo=koding&logoColor=white
1579
+ :target: https://github.com/tqdm/tqdm/network/dependents
1580
+ .. |OpenHub-Status| image:: https://www.openhub.net/p/tqdm/widgets/project_thin_badge?format=gif
1581
+ :target: https://www.openhub.net/p/tqdm?ref=Thin+badge
1582
+ .. |awesome-python| image:: https://awesome.re/mentioned-badge.svg
1583
+ :target: https://github.com/vinta/awesome-python
1584
+ .. |LICENCE| image:: https://img.shields.io/pypi/l/tqdm.svg
1585
+ :target: https://raw.githubusercontent.com/tqdm/tqdm/master/LICENCE
1586
+ .. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg
1587
+ :target: https://doi.org/10.5281/zenodo.595120
1588
+ .. |binder-demo| image:: https://mybinder.org/badge_logo.svg
1589
+ :target: https://mybinder.org/v2/gh/tqdm/tqdm/master?filepath=DEMO.ipynb
1590
+ .. |Screenshot-Jupyter1| image:: https://tqdm.github.io/img/jupyter-1.gif
1591
+ .. |Screenshot-Jupyter2| image:: https://tqdm.github.io/img/jupyter-2.gif
1592
+ .. |Screenshot-Jupyter3| image:: https://tqdm.github.io/img/jupyter-3.gif
1593
+ .. |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
1594
+ :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
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/RECORD ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ tqdm/__init__.py,sha256=9mQNYSSqP99JasubEC1POJLMmhkkBH6cJZxPIR5G2pQ,1572
2
+ tqdm/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
+ tqdm/_dist_ver.py,sha256=m5AdYI-jB-v6P0VJ_70isH_p24EzSOGSwVvuAZmkmKY,23
4
+ tqdm/_main.py,sha256=9ySvgmi_2Sw4CAo5UDW0Q2dxfTryboEWGHohfCJz0sA,283
5
+ tqdm/_monitor.py,sha256=Uku-DPWgzJ7dO5CK08xKJK-E_F6qQ-JB3ksuXczSYR0,3699
6
+ tqdm/_tqdm.py,sha256=LfLCuJ6bpsVo9xilmtBXyEm1vGnUCFrliW85j3J-nD4,283
7
+ tqdm/_tqdm_gui.py,sha256=03Hc8KayxJveieI5-0-2NGiDpLvw9jZekofJUV7CCwk,287
8
+ tqdm/_tqdm_notebook.py,sha256=BuHiLuxu6uEfZFaPJW3RPpPaxaVctEQA3kdSJSDL1hw,307
9
+ tqdm/_tqdm_pandas.py,sha256=c9jptUgigN6axRDhRd4Rif98Tmxeopc1nFNFhIpbFUE,888
10
+ tqdm/_utils.py,sha256=_4E73bfDj4f1s3sM42NLHNrZDOkijZoWq-n6xWLkdZ8,553
11
+ tqdm/asyncio.py,sha256=Kp2rSkNRf9KRqa3d9YpgeZQ7L7EZf2Ki4bSc7UPIyoo,2757
12
+ tqdm/auto.py,sha256=nDZflj6p2zKkjBCNBourrhS81zYfZy1_dQvbckrdW8o,871
13
+ tqdm/autonotebook.py,sha256=Yb9F5uaiBPhfbDDFpbtoG8I2YUw3uQJ89rUDLbfR6ws,956
14
+ tqdm/cli.py,sha256=SbKlN8QyZ2ogenqt-wT_p6_sx2OOdCjCyhoZBFnlmyI,11010
15
+ tqdm/completion.sh,sha256=j79KbSmpIj_E11jfTfBXrGnUTzKXVpQ1vGVQvsyDRl4,946
16
+ tqdm/dask.py,sha256=9Ei58eVqTossRLhAfWyUFCduXYKjmLmwkaXIy-CHYfs,1319
17
+ tqdm/gui.py,sha256=STIB3K8iDzDgkNUqWIpvcI_u0OGtbGNy5NwpALXhfWs,5479
18
+ tqdm/keras.py,sha256=op9sBkb6q6c6dw2wJ0SD2ZwpPK7yM1Vbg4l1Qiy3MIo,4373
19
+ tqdm/notebook.py,sha256=GtZ3IapLL1v8WNDaTSvPw0bJGTyfp71Vfz5HDnAzx1M,10895
20
+ tqdm/rich.py,sha256=YyMPkEHVyYUVUR3adJKbVX26iTmNKpNMf3DEqmm-m60,5021
21
+ tqdm/std.py,sha256=tWjz6-QCa92aqYjz7PIdkLUCAfiy-lJZheBtZyIIyO0,57461
22
+ tqdm/tk.py,sha256=Gu0uwXwLCGPRGHORdi3WvBLGiseUp_xxX_h_gp9VpK0,6701
23
+ tqdm/tqdm.1,sha256=aILyUPk2S4OPe_uWy2P4AMjUf0oQ6PUW0nLYXB-BWwI,7889
24
+ tqdm/utils.py,sha256=6E0BQw3Sg7uGWKBM_cDn3P42tXswRhzkggbhBgLDjl8,11821
25
+ tqdm/version.py,sha256=-1yWjfu3P0eghVsysHH07fbzdiADNRdzRtYPqOaqR2A,333
26
+ tqdm/contrib/__init__.py,sha256=OgSwVXm-vlDJ-2imtoQ9z8qdom4snMSRztH72KMA82A,2494
27
+ tqdm/contrib/bells.py,sha256=Yx1HqGCmHrESCAO700j5wE__JCleNODJxedh1ijPLD0,837
28
+ tqdm/contrib/concurrent.py,sha256=K1yjloKS5WRNFyjLRth0DmU5PAnDbF0A-GD27N-J4a8,3986
29
+ tqdm/contrib/discord.py,sha256=MtVIL1s_dxH21G4sL8FBgQ4Wei23ho9Ek5T-AommvNc,5243
30
+ tqdm/contrib/itertools.py,sha256=WdKKQU5eSzsqHu29SN_oH12huYZo0Jihqoi9-nVhwz4,774
31
+ tqdm/contrib/logging.py,sha256=NsYtnKttj2mMrGm58mEdo5a9DP_2vv8pZyrimSuWulA,3760
32
+ tqdm/contrib/slack.py,sha256=eP_Mr5sQonYniHxxQNGue3jk2JkIPmPWFZqIYxnOui0,4007
33
+ tqdm/contrib/telegram.py,sha256=vn_9SATMbbwn2PAbzSDyOX6av3eBB01QBug11P4H-Og,5008
34
+ tqdm/contrib/utils_worker.py,sha256=HJP5Mz1S1xyzEke2JaqJ2sYLHXADYoo2epT5AzQ38eA,1207
35
+ tqdm-4.67.1.dist-info/LICENCE,sha256=3DMlLoKQFeOxUAhvubOkD2rW-zLC9GEM6BL6Z301mGo,1985
36
+ tqdm-4.67.1.dist-info/METADATA,sha256=aIoWMt9SWhmP7FLc_vsSRtMerO6cA1qsrC1-r42P9mk,57675
37
+ tqdm-4.67.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
38
+ tqdm-4.67.1.dist-info/entry_points.txt,sha256=ReJCH7Ui3Zyh6M16E4OhsZ1oU7WtMXCfbtoyBhGO29Y,39
39
+ tqdm-4.67.1.dist-info/top_level.txt,sha256=NLiUJNfmc9At15s7JURiwvqMEjUi9G5PMGRrmMYzNSM,5
40
+ tqdm-4.67.1.dist-info/RECORD,,
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/WHEEL ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.6.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/entry_points.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ [console_scripts]
2
+ tqdm = tqdm.cli:main
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/requires.txt ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ [dev]
3
+ pytest>=6
4
+ pytest-cov
5
+ pytest-timeout
6
+ pytest-asyncio>=0.24
7
+ nbval
8
+
9
+ [discord]
10
+ requests
11
+
12
+ [notebook]
13
+ ipywidgets>=6
14
+
15
+ [slack]
16
+ slack-sdk
17
+
18
+ [telegram]
19
+ requests
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/EGG-INFO/top_level.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ tqdm
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/__init__.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from ._monitor import TMonitor, TqdmSynchronisationWarning
2
+ from ._tqdm_pandas import tqdm_pandas
3
+ from .cli import main # TODO: remove in v5.0.0
4
+ from .gui import tqdm as tqdm_gui # TODO: remove in v5.0.0
5
+ from .gui import trange as tgrange # TODO: remove in v5.0.0
6
+ from .std import (
7
+ TqdmDeprecationWarning, TqdmExperimentalWarning, TqdmKeyError, TqdmMonitorWarning,
8
+ TqdmTypeError, TqdmWarning, tqdm, trange)
9
+ from .version import __version__
10
+
11
+ __all__ = ['tqdm', 'tqdm_gui', 'trange', 'tgrange', 'tqdm_pandas',
12
+ 'tqdm_notebook', 'tnrange', 'main', 'TMonitor',
13
+ 'TqdmTypeError', 'TqdmKeyError',
14
+ 'TqdmWarning', 'TqdmDeprecationWarning',
15
+ 'TqdmExperimentalWarning',
16
+ 'TqdmMonitorWarning', 'TqdmSynchronisationWarning',
17
+ '__version__']
18
+
19
+
20
+ def tqdm_notebook(*args, **kwargs): # pragma: no cover
21
+ """See tqdm.notebook.tqdm for full documentation"""
22
+ from warnings import warn
23
+
24
+ from .notebook import tqdm as _tqdm_notebook
25
+ warn("This function will be removed in tqdm==5.0.0\n"
26
+ "Please use `tqdm.notebook.tqdm` instead of `tqdm.tqdm_notebook`",
27
+ TqdmDeprecationWarning, stacklevel=2)
28
+ return _tqdm_notebook(*args, **kwargs)
29
+
30
+
31
+ def tnrange(*args, **kwargs): # pragma: no cover
32
+ """Shortcut for `tqdm.notebook.tqdm(range(*args), **kwargs)`."""
33
+ from warnings import warn
34
+
35
+ from .notebook import trange as _tnrange
36
+ warn("Please use `tqdm.notebook.trange` instead of `tqdm.tnrange`",
37
+ TqdmDeprecationWarning, stacklevel=2)
38
+ return _tnrange(*args, **kwargs)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/__main__.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from .cli import main
2
+
3
+ main()
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_dist_ver.py ADDED
@@ -0,0 +1 @@
 
 
1
+ __version__ = '4.67.1'
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_main.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from warnings import warn
2
+
3
+ from .cli import * # NOQA
4
+ from .cli import __all__ # NOQA
5
+ from .std import TqdmDeprecationWarning
6
+
7
+ warn("This function will be removed in tqdm==5.0.0\n"
8
+ "Please use `tqdm.cli.*` instead of `tqdm._main.*`",
9
+ TqdmDeprecationWarning, stacklevel=2)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_monitor.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import atexit
2
+ from threading import Event, Thread, current_thread
3
+ from time import time
4
+ from warnings import warn
5
+
6
+ __all__ = ["TMonitor", "TqdmSynchronisationWarning"]
7
+
8
+
9
+ class TqdmSynchronisationWarning(RuntimeWarning):
10
+ """tqdm multi-thread/-process errors which may cause incorrect nesting
11
+ but otherwise no adverse effects"""
12
+ pass
13
+
14
+
15
+ class TMonitor(Thread):
16
+ """
17
+ Monitoring thread for tqdm bars.
18
+ Monitors if tqdm bars are taking too much time to display
19
+ and readjusts miniters automatically if necessary.
20
+
21
+ Parameters
22
+ ----------
23
+ tqdm_cls : class
24
+ tqdm class to use (can be core tqdm or a submodule).
25
+ sleep_interval : float
26
+ Time to sleep between monitoring checks.
27
+ """
28
+ _test = {} # internal vars for unit testing
29
+
30
+ def __init__(self, tqdm_cls, sleep_interval):
31
+ Thread.__init__(self)
32
+ self.daemon = True # kill thread when main killed (KeyboardInterrupt)
33
+ self.woken = 0 # last time woken up, to sync with monitor
34
+ self.tqdm_cls = tqdm_cls
35
+ self.sleep_interval = sleep_interval
36
+ self._time = self._test.get("time", time)
37
+ self.was_killed = self._test.get("Event", Event)()
38
+ atexit.register(self.exit)
39
+ self.start()
40
+
41
+ def exit(self):
42
+ self.was_killed.set()
43
+ if self is not current_thread():
44
+ self.join()
45
+ return self.report()
46
+
47
+ def get_instances(self):
48
+ # returns a copy of started `tqdm_cls` instances
49
+ return [i for i in self.tqdm_cls._instances.copy()
50
+ # Avoid race by checking that the instance started
51
+ if hasattr(i, 'start_t')]
52
+
53
+ def run(self):
54
+ cur_t = self._time()
55
+ while True:
56
+ # After processing and before sleeping, notify that we woke
57
+ # Need to be done just before sleeping
58
+ self.woken = cur_t
59
+ # Sleep some time...
60
+ self.was_killed.wait(self.sleep_interval)
61
+ # Quit if killed
62
+ if self.was_killed.is_set():
63
+ return
64
+ # Then monitor!
65
+ # Acquire lock (to access _instances)
66
+ with self.tqdm_cls.get_lock():
67
+ cur_t = self._time()
68
+ # Check tqdm instances are waiting too long to print
69
+ instances = self.get_instances()
70
+ for instance in instances:
71
+ # Check event in loop to reduce blocking time on exit
72
+ if self.was_killed.is_set():
73
+ return
74
+ # Only if mininterval > 1 (else iterations are just slow)
75
+ # and last refresh exceeded maxinterval
76
+ if (
77
+ instance.miniters > 1
78
+ and (cur_t - instance.last_print_t) >= instance.maxinterval
79
+ ):
80
+ # force bypassing miniters on next iteration
81
+ # (dynamic_miniters adjusts mininterval automatically)
82
+ instance.miniters = 1
83
+ # Refresh now! (works only for manual tqdm)
84
+ instance.refresh(nolock=True)
85
+ # Remove accidental long-lived strong reference
86
+ del instance
87
+ if instances != self.get_instances(): # pragma: nocover
88
+ warn("Set changed size during iteration" +
89
+ " (see https://github.com/tqdm/tqdm/issues/481)",
90
+ TqdmSynchronisationWarning, stacklevel=2)
91
+ # Remove accidental long-lived strong references
92
+ del instances
93
+
94
+ def report(self):
95
+ return not self.was_killed.is_set()
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from warnings import warn
2
+
3
+ from .std import * # NOQA
4
+ from .std import __all__ # NOQA
5
+ from .std import TqdmDeprecationWarning
6
+
7
+ warn("This function will be removed in tqdm==5.0.0\n"
8
+ "Please use `tqdm.std.*` instead of `tqdm._tqdm.*`",
9
+ TqdmDeprecationWarning, stacklevel=2)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_gui.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from warnings import warn
2
+
3
+ from .gui import * # NOQA
4
+ from .gui import __all__ # NOQA
5
+ from .std import TqdmDeprecationWarning
6
+
7
+ warn("This function will be removed in tqdm==5.0.0\n"
8
+ "Please use `tqdm.gui.*` instead of `tqdm._tqdm_gui.*`",
9
+ TqdmDeprecationWarning, stacklevel=2)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_notebook.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from warnings import warn
2
+
3
+ from .notebook import * # NOQA
4
+ from .notebook import __all__ # NOQA
5
+ from .std import TqdmDeprecationWarning
6
+
7
+ warn("This function will be removed in tqdm==5.0.0\n"
8
+ "Please use `tqdm.notebook.*` instead of `tqdm._tqdm_notebook.*`",
9
+ TqdmDeprecationWarning, stacklevel=2)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_tqdm_pandas.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+
3
+ __author__ = "github.com/casperdcl"
4
+ __all__ = ['tqdm_pandas']
5
+
6
+
7
+ def tqdm_pandas(tclass, **tqdm_kwargs):
8
+ """
9
+ Registers the given `tqdm` instance with
10
+ `pandas.core.groupby.DataFrameGroupBy.progress_apply`.
11
+ """
12
+ from tqdm import TqdmDeprecationWarning
13
+
14
+ if isinstance(tclass, type) or (getattr(tclass, '__name__', '').startswith(
15
+ 'tqdm_')): # delayed adapter case
16
+ TqdmDeprecationWarning(
17
+ "Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm, ...)`.",
18
+ fp_write=getattr(tqdm_kwargs.get('file', None), 'write', sys.stderr.write))
19
+ tclass.pandas(**tqdm_kwargs)
20
+ else:
21
+ TqdmDeprecationWarning(
22
+ "Please use `tqdm.pandas(...)` instead of `tqdm_pandas(tqdm(...))`.",
23
+ fp_write=getattr(tclass.fp, 'write', sys.stderr.write))
24
+ type(tclass).pandas(deprecated_t=tclass)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/_utils.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from warnings import warn
2
+
3
+ from .std import TqdmDeprecationWarning
4
+ from .utils import ( # NOQA, pylint: disable=unused-import
5
+ CUR_OS, IS_NIX, IS_WIN, RE_ANSI, Comparable, FormatReplace, SimpleTextIOWrapper,
6
+ _environ_cols_wrapper, _is_ascii, _is_utf, _screen_shape_linux, _screen_shape_tput,
7
+ _screen_shape_windows, _screen_shape_wrapper, _supports_unicode, _term_move_up, colorama)
8
+
9
+ warn("This function will be removed in tqdm==5.0.0\n"
10
+ "Please use `tqdm.utils.*` instead of `tqdm._utils.*`",
11
+ TqdmDeprecationWarning, stacklevel=2)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/asyncio.py ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Asynchronous progressbar decorator for iterators.
3
+ Includes a default `range` iterator printing to `stderr`.
4
+
5
+ Usage:
6
+ >>> from tqdm.asyncio import trange, tqdm
7
+ >>> async for i in trange(10):
8
+ ... ...
9
+ """
10
+ import asyncio
11
+ from sys import version_info
12
+
13
+ from .std import tqdm as std_tqdm
14
+
15
+ __author__ = {"github.com/": ["casperdcl"]}
16
+ __all__ = ['tqdm_asyncio', 'tarange', 'tqdm', 'trange']
17
+
18
+
19
+ class tqdm_asyncio(std_tqdm):
20
+ """
21
+ Asynchronous-friendly version of tqdm.
22
+ """
23
+ def __init__(self, iterable=None, *args, **kwargs):
24
+ super().__init__(iterable, *args, **kwargs)
25
+ self.iterable_awaitable = False
26
+ if iterable is not None:
27
+ if hasattr(iterable, "__anext__"):
28
+ self.iterable_next = iterable.__anext__
29
+ self.iterable_awaitable = True
30
+ elif hasattr(iterable, "__next__"):
31
+ self.iterable_next = iterable.__next__
32
+ else:
33
+ self.iterable_iterator = iter(iterable)
34
+ self.iterable_next = self.iterable_iterator.__next__
35
+
36
+ def __aiter__(self):
37
+ return self
38
+
39
+ async def __anext__(self):
40
+ try:
41
+ if self.iterable_awaitable:
42
+ res = await self.iterable_next()
43
+ else:
44
+ res = self.iterable_next()
45
+ self.update()
46
+ return res
47
+ except StopIteration:
48
+ self.close()
49
+ raise StopAsyncIteration
50
+ except BaseException:
51
+ self.close()
52
+ raise
53
+
54
+ def send(self, *args, **kwargs):
55
+ return self.iterable.send(*args, **kwargs)
56
+
57
+ @classmethod
58
+ def as_completed(cls, fs, *, loop=None, timeout=None, total=None, **tqdm_kwargs):
59
+ """
60
+ Wrapper for `asyncio.as_completed`.
61
+ """
62
+ if total is None:
63
+ total = len(fs)
64
+ kwargs = {}
65
+ if version_info[:2] < (3, 10):
66
+ kwargs['loop'] = loop
67
+ yield from cls(asyncio.as_completed(fs, timeout=timeout, **kwargs),
68
+ total=total, **tqdm_kwargs)
69
+
70
+ @classmethod
71
+ async def gather(cls, *fs, loop=None, timeout=None, total=None, **tqdm_kwargs):
72
+ """
73
+ Wrapper for `asyncio.gather`.
74
+ """
75
+ async def wrap_awaitable(i, f):
76
+ return i, await f
77
+
78
+ ifs = [wrap_awaitable(i, f) for i, f in enumerate(fs)]
79
+ res = [await f for f in cls.as_completed(ifs, loop=loop, timeout=timeout,
80
+ total=total, **tqdm_kwargs)]
81
+ return [i for _, i in sorted(res)]
82
+
83
+
84
+ def tarange(*args, **kwargs):
85
+ """
86
+ A shortcut for `tqdm.asyncio.tqdm(range(*args), **kwargs)`.
87
+ """
88
+ return tqdm_asyncio(range(*args), **kwargs)
89
+
90
+
91
+ # Aliases
92
+ tqdm = tqdm_asyncio
93
+ trange = tarange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/auto.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Enables multiple commonly used features.
3
+
4
+ Method resolution order:
5
+
6
+ - `tqdm.autonotebook` without import warnings
7
+ - `tqdm.asyncio`
8
+ - `tqdm.std` base class
9
+
10
+ Usage:
11
+ >>> from tqdm.auto import trange, tqdm
12
+ >>> for i in trange(10):
13
+ ... ...
14
+ """
15
+ import warnings
16
+
17
+ from .std import TqdmExperimentalWarning
18
+
19
+ with warnings.catch_warnings():
20
+ warnings.simplefilter("ignore", category=TqdmExperimentalWarning)
21
+ from .autonotebook import tqdm as notebook_tqdm
22
+
23
+ from .asyncio import tqdm as asyncio_tqdm
24
+ from .std import tqdm as std_tqdm
25
+
26
+ if notebook_tqdm != std_tqdm:
27
+ class tqdm(notebook_tqdm, asyncio_tqdm): # pylint: disable=inconsistent-mro
28
+ pass
29
+ else:
30
+ tqdm = asyncio_tqdm
31
+
32
+
33
+ def trange(*args, **kwargs):
34
+ """
35
+ A shortcut for `tqdm.auto.tqdm(range(*args), **kwargs)`.
36
+ """
37
+ return tqdm(range(*args), **kwargs)
38
+
39
+
40
+ __all__ = ["tqdm", "trange"]
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/autonotebook.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Automatically choose between `tqdm.notebook` and `tqdm.std`.
3
+
4
+ Usage:
5
+ >>> from tqdm.autonotebook import trange, tqdm
6
+ >>> for i in trange(10):
7
+ ... ...
8
+ """
9
+ import sys
10
+ from warnings import warn
11
+
12
+ try:
13
+ get_ipython = sys.modules['IPython'].get_ipython
14
+ if 'IPKernelApp' not in get_ipython().config: # pragma: no cover
15
+ raise ImportError("console")
16
+ from .notebook import WARN_NOIPYW, IProgress
17
+ if IProgress is None:
18
+ from .std import TqdmWarning
19
+ warn(WARN_NOIPYW, TqdmWarning, stacklevel=2)
20
+ raise ImportError('ipywidgets')
21
+ except Exception:
22
+ from .std import tqdm, trange
23
+ else: # pragma: no cover
24
+ from .notebook import tqdm, trange
25
+ from .std import TqdmExperimentalWarning
26
+ warn("Using `tqdm.autonotebook.tqdm` in notebook mode."
27
+ " Use `tqdm.tqdm` instead to force console mode"
28
+ " (e.g. in jupyter console)", TqdmExperimentalWarning, stacklevel=2)
29
+ __all__ = ["tqdm", "trange"]
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/cli.py ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Module version for monitoring CLI pipes (`... | python -m tqdm | ...`).
3
+ """
4
+ import logging
5
+ import re
6
+ import sys
7
+ from ast import literal_eval as numeric
8
+ from textwrap import indent
9
+
10
+ from .std import TqdmKeyError, TqdmTypeError, tqdm
11
+ from .version import __version__
12
+
13
+ __all__ = ["main"]
14
+ log = logging.getLogger(__name__)
15
+
16
+
17
+ def cast(val, typ):
18
+ log.debug((val, typ))
19
+ if " or " in typ:
20
+ for t in typ.split(" or "):
21
+ try:
22
+ return cast(val, t)
23
+ except TqdmTypeError:
24
+ pass
25
+ raise TqdmTypeError(f"{val} : {typ}")
26
+
27
+ # sys.stderr.write('\ndebug | `val:type`: `' + val + ':' + typ + '`.\n')
28
+ if typ == 'bool':
29
+ if (val == 'True') or (val == ''):
30
+ return True
31
+ if val == 'False':
32
+ return False
33
+ raise TqdmTypeError(val + ' : ' + typ)
34
+ if typ == 'chr':
35
+ if len(val) == 1:
36
+ return val.encode()
37
+ if re.match(r"^\\\w+$", val):
38
+ return eval(f'"{val}"').encode()
39
+ raise TqdmTypeError(f"{val} : {typ}")
40
+ if typ == 'str':
41
+ return val
42
+ if typ == 'int':
43
+ try:
44
+ return int(val)
45
+ except ValueError as exc:
46
+ raise TqdmTypeError(f"{val} : {typ}") from exc
47
+ if typ == 'float':
48
+ try:
49
+ return float(val)
50
+ except ValueError as exc:
51
+ raise TqdmTypeError(f"{val} : {typ}") from exc
52
+ raise TqdmTypeError(f"{val} : {typ}")
53
+
54
+
55
+ def posix_pipe(fin, fout, delim=b'\\n', buf_size=256,
56
+ callback=lambda float: None, callback_len=True):
57
+ """
58
+ Params
59
+ ------
60
+ fin : binary file with `read(buf_size : int)` method
61
+ fout : binary file with `write` (and optionally `flush`) methods.
62
+ callback : function(float), e.g.: `tqdm.update`
63
+ callback_len : If (default: True) do `callback(len(buffer))`.
64
+ Otherwise, do `callback(data) for data in buffer.split(delim)`.
65
+ """
66
+ fp_write = fout.write
67
+
68
+ if not delim:
69
+ while True:
70
+ tmp = fin.read(buf_size)
71
+
72
+ # flush at EOF
73
+ if not tmp:
74
+ getattr(fout, 'flush', lambda: None)()
75
+ return
76
+
77
+ fp_write(tmp)
78
+ callback(len(tmp))
79
+ # return
80
+
81
+ buf = b''
82
+ len_delim = len(delim)
83
+ # n = 0
84
+ while True:
85
+ tmp = fin.read(buf_size)
86
+
87
+ # flush at EOF
88
+ if not tmp:
89
+ if buf:
90
+ fp_write(buf)
91
+ if callback_len:
92
+ # n += 1 + buf.count(delim)
93
+ callback(1 + buf.count(delim))
94
+ else:
95
+ for i in buf.split(delim):
96
+ callback(i)
97
+ getattr(fout, 'flush', lambda: None)()
98
+ return # n
99
+
100
+ while True:
101
+ i = tmp.find(delim)
102
+ if i < 0:
103
+ buf += tmp
104
+ break
105
+ fp_write(buf + tmp[:i + len(delim)])
106
+ # n += 1
107
+ callback(1 if callback_len else (buf + tmp[:i]))
108
+ buf = b''
109
+ tmp = tmp[i + len_delim:]
110
+
111
+
112
+ # ((opt, type), ... )
113
+ RE_OPTS = re.compile(r'\n {4}(\S+)\s{2,}:\s*([^,]+)')
114
+ # better split method assuming no positional args
115
+ RE_SHLEX = re.compile(r'\s*(?<!\S)--?([^\s=]+)(\s+|=|$)')
116
+
117
+ # TODO: add custom support for some of the following?
118
+ UNSUPPORTED_OPTS = ('iterable', 'gui', 'out', 'file')
119
+
120
+ # The 8 leading spaces are required for consistency
121
+ CLI_EXTRA_DOC = r"""
122
+ Extra CLI Options
123
+ -----------------
124
+ name : type, optional
125
+ TODO: find out why this is needed.
126
+ delim : chr, optional
127
+ Delimiting character [default: '\n']. Use '\0' for null.
128
+ N.B.: on Windows systems, Python converts '\n' to '\r\n'.
129
+ buf_size : int, optional
130
+ String buffer size in bytes [default: 256]
131
+ used when `delim` is specified.
132
+ bytes : bool, optional
133
+ If true, will count bytes, ignore `delim`, and default
134
+ `unit_scale` to True, `unit_divisor` to 1024, and `unit` to 'B'.
135
+ tee : bool, optional
136
+ If true, passes `stdin` to both `stderr` and `stdout`.
137
+ update : bool, optional
138
+ If true, will treat input as newly elapsed iterations,
139
+ i.e. numbers to pass to `update()`. Note that this is slow
140
+ (~2e5 it/s) since every input must be decoded as a number.
141
+ update_to : bool, optional
142
+ If true, will treat input as total elapsed iterations,
143
+ i.e. numbers to assign to `self.n`. Note that this is slow
144
+ (~2e5 it/s) since every input must be decoded as a number.
145
+ null : bool, optional
146
+ If true, will discard input (no stdout).
147
+ manpath : str, optional
148
+ Directory in which to install tqdm man pages.
149
+ comppath : str, optional
150
+ Directory in which to place tqdm completion.
151
+ log : str, optional
152
+ CRITICAL|FATAL|ERROR|WARN(ING)|[default: 'INFO']|DEBUG|NOTSET.
153
+ """
154
+
155
+
156
+ def main(fp=sys.stderr, argv=None):
157
+ """
158
+ Parameters (internal use only)
159
+ ---------
160
+ fp : file-like object for tqdm
161
+ argv : list (default: sys.argv[1:])
162
+ """
163
+ if argv is None:
164
+ argv = sys.argv[1:]
165
+ try:
166
+ log_idx = argv.index('--log')
167
+ except ValueError:
168
+ for i in argv:
169
+ if i.startswith('--log='):
170
+ logLevel = i[len('--log='):]
171
+ break
172
+ else:
173
+ logLevel = 'INFO'
174
+ else:
175
+ # argv.pop(log_idx)
176
+ # logLevel = argv.pop(log_idx)
177
+ logLevel = argv[log_idx + 1]
178
+ logging.basicConfig(level=getattr(logging, logLevel),
179
+ format="%(levelname)s:%(module)s:%(lineno)d:%(message)s")
180
+
181
+ # py<3.13 doesn't dedent docstrings
182
+ d = (tqdm.__doc__ if sys.version_info < (3, 13)
183
+ else indent(tqdm.__doc__, " ")) + CLI_EXTRA_DOC
184
+
185
+ opt_types = dict(RE_OPTS.findall(d))
186
+ # opt_types['delim'] = 'chr'
187
+
188
+ for o in UNSUPPORTED_OPTS:
189
+ opt_types.pop(o)
190
+
191
+ log.debug(sorted(opt_types.items()))
192
+
193
+ # d = RE_OPTS.sub(r' --\1=<\1> : \2', d)
194
+ split = RE_OPTS.split(d)
195
+ opt_types_desc = zip(split[1::3], split[2::3], split[3::3])
196
+ d = ''.join(('\n --{0} : {2}{3}' if otd[1] == 'bool' else
197
+ '\n --{0}=<{1}> : {2}{3}').format(
198
+ otd[0].replace('_', '-'), otd[0], *otd[1:])
199
+ for otd in opt_types_desc if otd[0] not in UNSUPPORTED_OPTS)
200
+
201
+ help_short = "Usage:\n tqdm [--help | options]\n"
202
+ d = help_short + """
203
+ Options:
204
+ -h, --help Print this help and exit.
205
+ -v, --version Print version and exit.
206
+ """ + d.strip('\n') + '\n'
207
+
208
+ # opts = docopt(d, version=__version__)
209
+ if any(v in argv for v in ('-v', '--version')):
210
+ sys.stdout.write(__version__ + '\n')
211
+ sys.exit(0)
212
+ elif any(v in argv for v in ('-h', '--help')):
213
+ sys.stdout.write(d + '\n')
214
+ sys.exit(0)
215
+ elif argv and argv[0][:2] != '--':
216
+ sys.stderr.write(f"Error:Unknown argument:{argv[0]}\n{help_short}")
217
+
218
+ argv = RE_SHLEX.split(' '.join(["tqdm"] + argv))
219
+ opts = dict(zip(argv[1::3], argv[3::3]))
220
+
221
+ log.debug(opts)
222
+ opts.pop('log', True)
223
+
224
+ tqdm_args = {'file': fp}
225
+ try:
226
+ for (o, v) in opts.items():
227
+ o = o.replace('-', '_')
228
+ try:
229
+ tqdm_args[o] = cast(v, opt_types[o])
230
+ except KeyError as e:
231
+ raise TqdmKeyError(str(e))
232
+ log.debug('args:' + str(tqdm_args))
233
+
234
+ delim_per_char = tqdm_args.pop('bytes', False)
235
+ update = tqdm_args.pop('update', False)
236
+ update_to = tqdm_args.pop('update_to', False)
237
+ if sum((delim_per_char, update, update_to)) > 1:
238
+ raise TqdmKeyError("Can only have one of --bytes --update --update_to")
239
+ except Exception:
240
+ fp.write("\nError:\n" + help_short)
241
+ stdin, stdout_write = sys.stdin, sys.stdout.write
242
+ for i in stdin:
243
+ stdout_write(i)
244
+ raise
245
+ else:
246
+ buf_size = tqdm_args.pop('buf_size', 256)
247
+ delim = tqdm_args.pop('delim', b'\\n')
248
+ tee = tqdm_args.pop('tee', False)
249
+ manpath = tqdm_args.pop('manpath', None)
250
+ comppath = tqdm_args.pop('comppath', None)
251
+ if tqdm_args.pop('null', False):
252
+ class stdout(object):
253
+ @staticmethod
254
+ def write(_):
255
+ pass
256
+ else:
257
+ stdout = sys.stdout
258
+ stdout = getattr(stdout, 'buffer', stdout)
259
+ stdin = getattr(sys.stdin, 'buffer', sys.stdin)
260
+ if manpath or comppath:
261
+ try: # py<3.9
262
+ import importlib_resources as resources
263
+ except ImportError:
264
+ from importlib import resources
265
+ from pathlib import Path
266
+
267
+ def cp(name, dst):
268
+ """copy resource `name` to `dst`"""
269
+ fi = resources.files('tqdm') / name
270
+ dst.write_bytes(fi.read_bytes())
271
+ log.info("written:%s", dst)
272
+ if manpath is not None:
273
+ cp('tqdm.1', Path(manpath) / 'tqdm.1')
274
+ if comppath is not None:
275
+ cp('completion.sh', Path(comppath) / 'tqdm_completion.sh')
276
+ sys.exit(0)
277
+ if tee:
278
+ stdout_write = stdout.write
279
+ fp_write = getattr(fp, 'buffer', fp).write
280
+
281
+ class stdout(object): # pylint: disable=function-redefined
282
+ @staticmethod
283
+ def write(x):
284
+ with tqdm.external_write_mode(file=fp):
285
+ fp_write(x)
286
+ stdout_write(x)
287
+ if delim_per_char:
288
+ tqdm_args.setdefault('unit', 'B')
289
+ tqdm_args.setdefault('unit_scale', True)
290
+ tqdm_args.setdefault('unit_divisor', 1024)
291
+ log.debug(tqdm_args)
292
+ with tqdm(**tqdm_args) as t:
293
+ posix_pipe(stdin, stdout, '', buf_size, t.update)
294
+ elif delim == b'\\n':
295
+ log.debug(tqdm_args)
296
+ write = stdout.write
297
+ if update or update_to:
298
+ with tqdm(**tqdm_args) as t:
299
+ if update:
300
+ def callback(i):
301
+ t.update(numeric(i.decode()))
302
+ else: # update_to
303
+ def callback(i):
304
+ t.update(numeric(i.decode()) - t.n)
305
+ for i in stdin:
306
+ write(i)
307
+ callback(i)
308
+ else:
309
+ for i in tqdm(stdin, **tqdm_args):
310
+ write(i)
311
+ else:
312
+ log.debug(tqdm_args)
313
+ with tqdm(**tqdm_args) as t:
314
+ callback_len = False
315
+ if update:
316
+ def callback(i):
317
+ t.update(numeric(i.decode()))
318
+ elif update_to:
319
+ def callback(i):
320
+ t.update(numeric(i.decode()) - t.n)
321
+ else:
322
+ callback = t.update
323
+ callback_len = True
324
+ posix_pipe(stdin, stdout, delim, buf_size, callback, callback_len)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/completion.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ _tqdm(){
3
+ local cur prv
4
+ cur="${COMP_WORDS[COMP_CWORD]}"
5
+ prv="${COMP_WORDS[COMP_CWORD - 1]}"
6
+
7
+ case ${prv} in
8
+ --bar_format|--buf_size|--colour|--comppath|--delay|--delim|--desc|--initial|--lock_args|--manpath|--maxinterval|--mininterval|--miniters|--ncols|--nrows|--position|--postfix|--smoothing|--total|--unit|--unit_divisor)
9
+ # await user input
10
+ ;;
11
+ "--log")
12
+ COMPREPLY=($(compgen -W 'CRITICAL FATAL ERROR WARN WARNING INFO DEBUG NOTSET' -- ${cur}))
13
+ ;;
14
+ *)
15
+ COMPREPLY=($(compgen -W '--ascii --bar_format --buf_size --bytes --colour --comppath --delay --delim --desc --disable --dynamic_ncols --help --initial --leave --lock_args --log --manpath --maxinterval --mininterval --miniters --ncols --nrows --null --position --postfix --smoothing --tee --total --unit --unit_divisor --unit_scale --update --update_to --version --write_bytes -h -v' -- ${cur}))
16
+ ;;
17
+ esac
18
+ }
19
+ complete -F _tqdm tqdm
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/__init__.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Thin wrappers around common functions.
3
+
4
+ Subpackages contain potentially unstable extensions.
5
+ """
6
+ from warnings import warn
7
+
8
+ from ..auto import tqdm as tqdm_auto
9
+ from ..std import TqdmDeprecationWarning, tqdm
10
+ from ..utils import ObjectWrapper
11
+
12
+ __author__ = {"github.com/": ["casperdcl"]}
13
+ __all__ = ['tenumerate', 'tzip', 'tmap']
14
+
15
+
16
+ class DummyTqdmFile(ObjectWrapper):
17
+ """Dummy file-like that will write to tqdm"""
18
+
19
+ def __init__(self, wrapped):
20
+ super().__init__(wrapped)
21
+ self._buf = []
22
+
23
+ def write(self, x, nolock=False):
24
+ nl = b"\n" if isinstance(x, bytes) else "\n"
25
+ pre, sep, post = x.rpartition(nl)
26
+ if sep:
27
+ blank = type(nl)()
28
+ tqdm.write(blank.join(self._buf + [pre, sep]),
29
+ end=blank, file=self._wrapped, nolock=nolock)
30
+ self._buf = [post]
31
+ else:
32
+ self._buf.append(x)
33
+
34
+ def __del__(self):
35
+ if self._buf:
36
+ blank = type(self._buf[0])()
37
+ try:
38
+ tqdm.write(blank.join(self._buf), end=blank, file=self._wrapped)
39
+ except (OSError, ValueError):
40
+ pass
41
+
42
+
43
+ def builtin_iterable(func):
44
+ """Returns `func`"""
45
+ warn("This function has no effect, and will be removed in tqdm==5.0.0",
46
+ TqdmDeprecationWarning, stacklevel=2)
47
+ return func
48
+
49
+
50
+ def tenumerate(iterable, start=0, total=None, tqdm_class=tqdm_auto, **tqdm_kwargs):
51
+ """
52
+ Equivalent of `numpy.ndenumerate` or builtin `enumerate`.
53
+
54
+ Parameters
55
+ ----------
56
+ tqdm_class : [default: tqdm.auto.tqdm].
57
+ """
58
+ try:
59
+ import numpy as np
60
+ except ImportError:
61
+ pass
62
+ else:
63
+ if isinstance(iterable, np.ndarray):
64
+ return tqdm_class(np.ndenumerate(iterable), total=total or iterable.size,
65
+ **tqdm_kwargs)
66
+ return enumerate(tqdm_class(iterable, total=total, **tqdm_kwargs), start)
67
+
68
+
69
+ def tzip(iter1, *iter2plus, **tqdm_kwargs):
70
+ """
71
+ Equivalent of builtin `zip`.
72
+
73
+ Parameters
74
+ ----------
75
+ tqdm_class : [default: tqdm.auto.tqdm].
76
+ """
77
+ kwargs = tqdm_kwargs.copy()
78
+ tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
79
+ for i in zip(tqdm_class(iter1, **kwargs), *iter2plus):
80
+ yield i
81
+
82
+
83
+ def tmap(function, *sequences, **tqdm_kwargs):
84
+ """
85
+ Equivalent of builtin `map`.
86
+
87
+ Parameters
88
+ ----------
89
+ tqdm_class : [default: tqdm.auto.tqdm].
90
+ """
91
+ for i in tzip(*sequences, **tqdm_kwargs):
92
+ yield function(*i)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/bells.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Even more features than `tqdm.auto` (all the bells & whistles):
3
+
4
+ - `tqdm.auto`
5
+ - `tqdm.tqdm.pandas`
6
+ - `tqdm.contrib.telegram`
7
+ + uses `${TQDM_TELEGRAM_TOKEN}` and `${TQDM_TELEGRAM_CHAT_ID}`
8
+ - `tqdm.contrib.discord`
9
+ + uses `${TQDM_DISCORD_TOKEN}` and `${TQDM_DISCORD_CHANNEL_ID}`
10
+ """
11
+ __all__ = ['tqdm', 'trange']
12
+ import warnings
13
+ from os import getenv
14
+
15
+ if getenv("TQDM_SLACK_TOKEN") and getenv("TQDM_SLACK_CHANNEL"):
16
+ from .slack import tqdm, trange
17
+ elif getenv("TQDM_TELEGRAM_TOKEN") and getenv("TQDM_TELEGRAM_CHAT_ID"):
18
+ from .telegram import tqdm, trange
19
+ elif getenv("TQDM_DISCORD_TOKEN") and getenv("TQDM_DISCORD_CHANNEL_ID"):
20
+ from .discord import tqdm, trange
21
+ else:
22
+ from ..auto import tqdm, trange
23
+
24
+ with warnings.catch_warnings():
25
+ warnings.simplefilter("ignore", category=FutureWarning)
26
+ tqdm.pandas()
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/concurrent.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Thin wrappers around `concurrent.futures`.
3
+ """
4
+ from contextlib import contextmanager
5
+ from operator import length_hint
6
+ from os import cpu_count
7
+
8
+ from ..auto import tqdm as tqdm_auto
9
+ from ..std import TqdmWarning
10
+
11
+ __author__ = {"github.com/": ["casperdcl"]}
12
+ __all__ = ['thread_map', 'process_map']
13
+
14
+
15
+ @contextmanager
16
+ def ensure_lock(tqdm_class, lock_name=""):
17
+ """get (create if necessary) and then restore `tqdm_class`'s lock"""
18
+ old_lock = getattr(tqdm_class, '_lock', None) # don't create a new lock
19
+ lock = old_lock or tqdm_class.get_lock() # maybe create a new lock
20
+ lock = getattr(lock, lock_name, lock) # maybe subtype
21
+ tqdm_class.set_lock(lock)
22
+ yield lock
23
+ if old_lock is None:
24
+ del tqdm_class._lock
25
+ else:
26
+ tqdm_class.set_lock(old_lock)
27
+
28
+
29
+ def _executor_map(PoolExecutor, fn, *iterables, **tqdm_kwargs):
30
+ """
31
+ Implementation of `thread_map` and `process_map`.
32
+
33
+ Parameters
34
+ ----------
35
+ tqdm_class : [default: tqdm.auto.tqdm].
36
+ max_workers : [default: min(32, cpu_count() + 4)].
37
+ chunksize : [default: 1].
38
+ lock_name : [default: "":str].
39
+ """
40
+ kwargs = tqdm_kwargs.copy()
41
+ if "total" not in kwargs:
42
+ kwargs["total"] = length_hint(iterables[0])
43
+ tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
44
+ max_workers = kwargs.pop("max_workers", min(32, cpu_count() + 4))
45
+ chunksize = kwargs.pop("chunksize", 1)
46
+ lock_name = kwargs.pop("lock_name", "")
47
+ with ensure_lock(tqdm_class, lock_name=lock_name) as lk:
48
+ # share lock in case workers are already using `tqdm`
49
+ with PoolExecutor(max_workers=max_workers, initializer=tqdm_class.set_lock,
50
+ initargs=(lk,)) as ex:
51
+ return list(tqdm_class(ex.map(fn, *iterables, chunksize=chunksize), **kwargs))
52
+
53
+
54
+ def thread_map(fn, *iterables, **tqdm_kwargs):
55
+ """
56
+ Equivalent of `list(map(fn, *iterables))`
57
+ driven by `concurrent.futures.ThreadPoolExecutor`.
58
+
59
+ Parameters
60
+ ----------
61
+ tqdm_class : optional
62
+ `tqdm` class to use for bars [default: tqdm.auto.tqdm].
63
+ max_workers : int, optional
64
+ Maximum number of workers to spawn; passed to
65
+ `concurrent.futures.ThreadPoolExecutor.__init__`.
66
+ [default: max(32, cpu_count() + 4)].
67
+ """
68
+ from concurrent.futures import ThreadPoolExecutor
69
+ return _executor_map(ThreadPoolExecutor, fn, *iterables, **tqdm_kwargs)
70
+
71
+
72
+ def process_map(fn, *iterables, **tqdm_kwargs):
73
+ """
74
+ Equivalent of `list(map(fn, *iterables))`
75
+ driven by `concurrent.futures.ProcessPoolExecutor`.
76
+
77
+ Parameters
78
+ ----------
79
+ tqdm_class : optional
80
+ `tqdm` class to use for bars [default: tqdm.auto.tqdm].
81
+ max_workers : int, optional
82
+ Maximum number of workers to spawn; passed to
83
+ `concurrent.futures.ProcessPoolExecutor.__init__`.
84
+ [default: min(32, cpu_count() + 4)].
85
+ chunksize : int, optional
86
+ Size of chunks sent to worker processes; passed to
87
+ `concurrent.futures.ProcessPoolExecutor.map`. [default: 1].
88
+ lock_name : str, optional
89
+ Member of `tqdm_class.get_lock()` to use [default: mp_lock].
90
+ """
91
+ from concurrent.futures import ProcessPoolExecutor
92
+ if iterables and "chunksize" not in tqdm_kwargs:
93
+ # default `chunksize=1` has poor performance for large iterables
94
+ # (most time spent dispatching items to workers).
95
+ longest_iterable_len = max(map(length_hint, iterables))
96
+ if longest_iterable_len > 1000:
97
+ from warnings import warn
98
+ warn("Iterable length %d > 1000 but `chunksize` is not set."
99
+ " This may seriously degrade multiprocess performance."
100
+ " Set `chunksize=1` or more." % longest_iterable_len,
101
+ TqdmWarning, stacklevel=2)
102
+ if "lock_name" not in tqdm_kwargs:
103
+ tqdm_kwargs = tqdm_kwargs.copy()
104
+ tqdm_kwargs["lock_name"] = "mp_lock"
105
+ return _executor_map(ProcessPoolExecutor, fn, *iterables, **tqdm_kwargs)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/discord.py ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Sends updates to a Discord bot.
3
+
4
+ Usage:
5
+ >>> from tqdm.contrib.discord import tqdm, trange
6
+ >>> for i in trange(10, token='{token}', channel_id='{channel_id}'):
7
+ ... ...
8
+
9
+ ![screenshot](https://tqdm.github.io/img/screenshot-discord.png)
10
+ """
11
+ from os import getenv
12
+ from warnings import warn
13
+
14
+ from requests import Session
15
+ from requests.utils import default_user_agent
16
+
17
+ from ..auto import tqdm as tqdm_auto
18
+ from ..std import TqdmWarning
19
+ from ..version import __version__
20
+ from .utils_worker import MonoWorker
21
+
22
+ __author__ = {"github.com/": ["casperdcl", "guigoruiz1"]}
23
+ __all__ = ['DiscordIO', 'tqdm_discord', 'tdrange', 'tqdm', 'trange']
24
+
25
+
26
+ class DiscordIO(MonoWorker):
27
+ """Non-blocking file-like IO using a Discord Bot."""
28
+ API = "https://discord.com/api/v10"
29
+ UA = f"tqdm (https://tqdm.github.io, {__version__}) {default_user_agent()}"
30
+
31
+ def __init__(self, token, channel_id):
32
+ """Creates a new message in the given `channel_id`."""
33
+ super().__init__()
34
+ self.token = token
35
+ self.channel_id = channel_id
36
+ self.session = Session()
37
+ self.text = self.__class__.__name__
38
+ self.message_id
39
+
40
+ @property
41
+ def message_id(self):
42
+ if hasattr(self, '_message_id'):
43
+ return self._message_id
44
+ try:
45
+ res = self.session.post(
46
+ f'{self.API}/channels/{self.channel_id}/messages',
47
+ headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA},
48
+ json={'content': f"`{self.text}`"}).json()
49
+ except Exception as e:
50
+ tqdm_auto.write(str(e))
51
+ else:
52
+ if res.get('error_code') == 429:
53
+ warn("Creation rate limit: try increasing `mininterval`.",
54
+ TqdmWarning, stacklevel=2)
55
+ else:
56
+ self._message_id = res['id']
57
+ return self._message_id
58
+
59
+ def write(self, s):
60
+ """Replaces internal `message_id`'s text with `s`."""
61
+ if not s:
62
+ s = "..."
63
+ s = s.replace('\r', '').strip()
64
+ if s == self.text:
65
+ return # avoid duplicate message Bot error
66
+ message_id = self.message_id
67
+ if message_id is None:
68
+ return
69
+ self.text = s
70
+ try:
71
+ future = self.submit(
72
+ self.session.patch,
73
+ f'{self.API}/channels/{self.channel_id}/messages/{message_id}',
74
+ headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA},
75
+ json={'content': f"`{self.text}`"})
76
+ except Exception as e:
77
+ tqdm_auto.write(str(e))
78
+ else:
79
+ return future
80
+
81
+ def delete(self):
82
+ """Deletes internal `message_id`."""
83
+ try:
84
+ future = self.submit(
85
+ self.session.delete,
86
+ f'{self.API}/channels/{self.channel_id}/messages/{self.message_id}',
87
+ headers={'Authorization': f'Bot {self.token}', 'User-Agent': self.UA})
88
+ except Exception as e:
89
+ tqdm_auto.write(str(e))
90
+ else:
91
+ return future
92
+
93
+
94
+ class tqdm_discord(tqdm_auto):
95
+ """
96
+ Standard `tqdm.auto.tqdm` but also sends updates to a Discord Bot.
97
+ May take a few seconds to create (`__init__`).
98
+
99
+ - create a discord bot (not public, no requirement of OAuth2 code
100
+ grant, only send message permissions) & invite it to a channel:
101
+ <https://discordpy.readthedocs.io/en/latest/discord.html>
102
+ - copy the bot `{token}` & `{channel_id}` and paste below
103
+
104
+ >>> from tqdm.contrib.discord import tqdm, trange
105
+ >>> for i in tqdm(iterable, token='{token}', channel_id='{channel_id}'):
106
+ ... ...
107
+ """
108
+ def __init__(self, *args, **kwargs):
109
+ """
110
+ Parameters
111
+ ----------
112
+ token : str, required. Discord bot token
113
+ [default: ${TQDM_DISCORD_TOKEN}].
114
+ channel_id : int, required. Discord channel ID
115
+ [default: ${TQDM_DISCORD_CHANNEL_ID}].
116
+
117
+ See `tqdm.auto.tqdm.__init__` for other parameters.
118
+ """
119
+ if not kwargs.get('disable'):
120
+ kwargs = kwargs.copy()
121
+ self.dio = DiscordIO(
122
+ kwargs.pop('token', getenv('TQDM_DISCORD_TOKEN')),
123
+ kwargs.pop('channel_id', getenv('TQDM_DISCORD_CHANNEL_ID')))
124
+ super().__init__(*args, **kwargs)
125
+
126
+ def display(self, **kwargs):
127
+ super().display(**kwargs)
128
+ fmt = self.format_dict
129
+ if fmt.get('bar_format', None):
130
+ fmt['bar_format'] = fmt['bar_format'].replace(
131
+ '<bar/>', '{bar:10u}').replace('{bar}', '{bar:10u}')
132
+ else:
133
+ fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
134
+ self.dio.write(self.format_meter(**fmt))
135
+
136
+ def clear(self, *args, **kwargs):
137
+ super().clear(*args, **kwargs)
138
+ if not self.disable:
139
+ self.dio.write("")
140
+
141
+ def close(self):
142
+ if self.disable:
143
+ return
144
+ super().close()
145
+ if not (self.leave or (self.leave is None and self.pos == 0)):
146
+ self.dio.delete()
147
+
148
+
149
+ def tdrange(*args, **kwargs):
150
+ """Shortcut for `tqdm.contrib.discord.tqdm(range(*args), **kwargs)`."""
151
+ return tqdm_discord(range(*args), **kwargs)
152
+
153
+
154
+ # Aliases
155
+ tqdm = tqdm_discord
156
+ trange = tdrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/itertools.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Thin wrappers around `itertools`.
3
+ """
4
+ import itertools
5
+
6
+ from ..auto import tqdm as tqdm_auto
7
+
8
+ __author__ = {"github.com/": ["casperdcl"]}
9
+ __all__ = ['product']
10
+
11
+
12
+ def product(*iterables, **tqdm_kwargs):
13
+ """
14
+ Equivalent of `itertools.product`.
15
+
16
+ Parameters
17
+ ----------
18
+ tqdm_class : [default: tqdm.auto.tqdm].
19
+ """
20
+ kwargs = tqdm_kwargs.copy()
21
+ tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
22
+ try:
23
+ lens = list(map(len, iterables))
24
+ except TypeError:
25
+ total = None
26
+ else:
27
+ total = 1
28
+ for i in lens:
29
+ total *= i
30
+ kwargs.setdefault("total", total)
31
+ with tqdm_class(**kwargs) as t:
32
+ it = itertools.product(*iterables)
33
+ for i in it:
34
+ yield i
35
+ t.update()
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/logging.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Helper functionality for interoperability with stdlib `logging`.
3
+ """
4
+ import logging
5
+ import sys
6
+ from contextlib import contextmanager
7
+
8
+ try:
9
+ from typing import Iterator, List, Optional, Type # noqa: F401
10
+ except ImportError:
11
+ pass
12
+
13
+ from ..std import tqdm as std_tqdm
14
+
15
+
16
+ class _TqdmLoggingHandler(logging.StreamHandler):
17
+ def __init__(
18
+ self,
19
+ tqdm_class=std_tqdm # type: Type[std_tqdm]
20
+ ):
21
+ super().__init__()
22
+ self.tqdm_class = tqdm_class
23
+
24
+ def emit(self, record):
25
+ try:
26
+ msg = self.format(record)
27
+ self.tqdm_class.write(msg, file=self.stream)
28
+ self.flush()
29
+ except (KeyboardInterrupt, SystemExit):
30
+ raise
31
+ except: # noqa pylint: disable=bare-except
32
+ self.handleError(record)
33
+
34
+
35
+ def _is_console_logging_handler(handler):
36
+ return (isinstance(handler, logging.StreamHandler)
37
+ and handler.stream in {sys.stdout, sys.stderr})
38
+
39
+
40
+ def _get_first_found_console_logging_handler(handlers):
41
+ for handler in handlers:
42
+ if _is_console_logging_handler(handler):
43
+ return handler
44
+
45
+
46
+ @contextmanager
47
+ def logging_redirect_tqdm(
48
+ loggers=None, # type: Optional[List[logging.Logger]],
49
+ tqdm_class=std_tqdm # type: Type[std_tqdm]
50
+ ):
51
+ # type: (...) -> Iterator[None]
52
+ """
53
+ Context manager redirecting console logging to `tqdm.write()`, leaving
54
+ other logging handlers (e.g. log files) unaffected.
55
+
56
+ Parameters
57
+ ----------
58
+ loggers : list, optional
59
+ Which handlers to redirect (default: [logging.root]).
60
+ tqdm_class : optional
61
+
62
+ Example
63
+ -------
64
+ ```python
65
+ import logging
66
+ from tqdm import trange
67
+ from tqdm.contrib.logging import logging_redirect_tqdm
68
+
69
+ LOG = logging.getLogger(__name__)
70
+
71
+ if __name__ == '__main__':
72
+ logging.basicConfig(level=logging.INFO)
73
+ with logging_redirect_tqdm():
74
+ for i in trange(9):
75
+ if i == 4:
76
+ LOG.info("console logging redirected to `tqdm.write()`")
77
+ # logging restored
78
+ ```
79
+ """
80
+ if loggers is None:
81
+ loggers = [logging.root]
82
+ original_handlers_list = [logger.handlers for logger in loggers]
83
+ try:
84
+ for logger in loggers:
85
+ tqdm_handler = _TqdmLoggingHandler(tqdm_class)
86
+ orig_handler = _get_first_found_console_logging_handler(logger.handlers)
87
+ if orig_handler is not None:
88
+ tqdm_handler.setFormatter(orig_handler.formatter)
89
+ tqdm_handler.stream = orig_handler.stream
90
+ logger.handlers = [
91
+ handler for handler in logger.handlers
92
+ if not _is_console_logging_handler(handler)] + [tqdm_handler]
93
+ yield
94
+ finally:
95
+ for logger, original_handlers in zip(loggers, original_handlers_list):
96
+ logger.handlers = original_handlers
97
+
98
+
99
+ @contextmanager
100
+ def tqdm_logging_redirect(
101
+ *args,
102
+ # loggers=None, # type: Optional[List[logging.Logger]]
103
+ # tqdm=None, # type: Optional[Type[tqdm.tqdm]]
104
+ **kwargs
105
+ ):
106
+ # type: (...) -> Iterator[None]
107
+ """
108
+ Convenience shortcut for:
109
+ ```python
110
+ with tqdm_class(*args, **tqdm_kwargs) as pbar:
111
+ with logging_redirect_tqdm(loggers=loggers, tqdm_class=tqdm_class):
112
+ yield pbar
113
+ ```
114
+
115
+ Parameters
116
+ ----------
117
+ tqdm_class : optional, (default: tqdm.std.tqdm).
118
+ loggers : optional, list.
119
+ **tqdm_kwargs : passed to `tqdm_class`.
120
+ """
121
+ tqdm_kwargs = kwargs.copy()
122
+ loggers = tqdm_kwargs.pop('loggers', None)
123
+ tqdm_class = tqdm_kwargs.pop('tqdm_class', std_tqdm)
124
+ with tqdm_class(*args, **tqdm_kwargs) as pbar:
125
+ with logging_redirect_tqdm(loggers=loggers, tqdm_class=tqdm_class):
126
+ yield pbar
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/slack.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Sends updates to a Slack app.
3
+
4
+ Usage:
5
+ >>> from tqdm.contrib.slack import tqdm, trange
6
+ >>> for i in trange(10, token='{token}', channel='{channel}'):
7
+ ... ...
8
+
9
+ ![screenshot](https://tqdm.github.io/img/screenshot-slack.png)
10
+ """
11
+ import logging
12
+ from os import getenv
13
+
14
+ try:
15
+ from slack_sdk import WebClient
16
+ except ImportError:
17
+ raise ImportError("Please `pip install slack-sdk`")
18
+
19
+ from ..auto import tqdm as tqdm_auto
20
+ from .utils_worker import MonoWorker
21
+
22
+ __author__ = {"github.com/": ["0x2b3bfa0", "casperdcl"]}
23
+ __all__ = ['SlackIO', 'tqdm_slack', 'tsrange', 'tqdm', 'trange']
24
+
25
+
26
+ class SlackIO(MonoWorker):
27
+ """Non-blocking file-like IO using a Slack app."""
28
+ def __init__(self, token, channel):
29
+ """Creates a new message in the given `channel`."""
30
+ super().__init__()
31
+ self.client = WebClient(token=token)
32
+ self.text = self.__class__.__name__
33
+ try:
34
+ self.message = self.client.chat_postMessage(channel=channel, text=self.text)
35
+ except Exception as e:
36
+ tqdm_auto.write(str(e))
37
+ self.message = None
38
+
39
+ def write(self, s):
40
+ """Replaces internal `message`'s text with `s`."""
41
+ if not s:
42
+ s = "..."
43
+ s = s.replace('\r', '').strip()
44
+ if s == self.text:
45
+ return # skip duplicate message
46
+ message = self.message
47
+ if message is None:
48
+ return
49
+ self.text = s
50
+ try:
51
+ future = self.submit(self.client.chat_update, channel=message['channel'],
52
+ ts=message['ts'], text='`' + s + '`')
53
+ except Exception as e:
54
+ tqdm_auto.write(str(e))
55
+ else:
56
+ return future
57
+
58
+
59
+ class tqdm_slack(tqdm_auto):
60
+ """
61
+ Standard `tqdm.auto.tqdm` but also sends updates to a Slack app.
62
+ May take a few seconds to create (`__init__`).
63
+
64
+ - create a Slack app with the `chat:write` scope & invite it to a
65
+ channel: <https://api.slack.com/authentication/basics>
66
+ - copy the bot `{token}` & `{channel}` and paste below
67
+ >>> from tqdm.contrib.slack import tqdm, trange
68
+ >>> for i in tqdm(iterable, token='{token}', channel='{channel}'):
69
+ ... ...
70
+ """
71
+ def __init__(self, *args, **kwargs):
72
+ """
73
+ Parameters
74
+ ----------
75
+ token : str, required. Slack token
76
+ [default: ${TQDM_SLACK_TOKEN}].
77
+ channel : int, required. Slack channel
78
+ [default: ${TQDM_SLACK_CHANNEL}].
79
+ mininterval : float, optional.
80
+ Minimum of [default: 1.5] to avoid rate limit.
81
+
82
+ See `tqdm.auto.tqdm.__init__` for other parameters.
83
+ """
84
+ if not kwargs.get('disable'):
85
+ kwargs = kwargs.copy()
86
+ logging.getLogger("HTTPClient").setLevel(logging.WARNING)
87
+ self.sio = SlackIO(
88
+ kwargs.pop('token', getenv("TQDM_SLACK_TOKEN")),
89
+ kwargs.pop('channel', getenv("TQDM_SLACK_CHANNEL")))
90
+ kwargs['mininterval'] = max(1.5, kwargs.get('mininterval', 1.5))
91
+ super().__init__(*args, **kwargs)
92
+
93
+ def display(self, **kwargs):
94
+ super().display(**kwargs)
95
+ fmt = self.format_dict
96
+ if fmt.get('bar_format', None):
97
+ fmt['bar_format'] = fmt['bar_format'].replace(
98
+ '<bar/>', '`{bar:10}`').replace('{bar}', '`{bar:10u}`')
99
+ else:
100
+ fmt['bar_format'] = '{l_bar}`{bar:10}`{r_bar}'
101
+ if fmt['ascii'] is False:
102
+ fmt['ascii'] = [":black_square:", ":small_blue_diamond:", ":large_blue_diamond:",
103
+ ":large_blue_square:"]
104
+ fmt['ncols'] = 336
105
+ self.sio.write(self.format_meter(**fmt))
106
+
107
+ def clear(self, *args, **kwargs):
108
+ super().clear(*args, **kwargs)
109
+ if not self.disable:
110
+ self.sio.write("")
111
+
112
+
113
+ def tsrange(*args, **kwargs):
114
+ """Shortcut for `tqdm.contrib.slack.tqdm(range(*args), **kwargs)`."""
115
+ return tqdm_slack(range(*args), **kwargs)
116
+
117
+
118
+ # Aliases
119
+ tqdm = tqdm_slack
120
+ trange = tsrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/telegram.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Sends updates to a Telegram bot.
3
+
4
+ Usage:
5
+ >>> from tqdm.contrib.telegram import tqdm, trange
6
+ >>> for i in trange(10, token='{token}', chat_id='{chat_id}'):
7
+ ... ...
8
+
9
+ ![screenshot](https://tqdm.github.io/img/screenshot-telegram.gif)
10
+ """
11
+ from os import getenv
12
+ from warnings import warn
13
+
14
+ from requests import Session
15
+
16
+ from ..auto import tqdm as tqdm_auto
17
+ from ..std import TqdmWarning
18
+ from .utils_worker import MonoWorker
19
+
20
+ __author__ = {"github.com/": ["casperdcl"]}
21
+ __all__ = ['TelegramIO', 'tqdm_telegram', 'ttgrange', 'tqdm', 'trange']
22
+
23
+
24
+ class TelegramIO(MonoWorker):
25
+ """Non-blocking file-like IO using a Telegram Bot."""
26
+ API = 'https://api.telegram.org/bot'
27
+
28
+ def __init__(self, token, chat_id):
29
+ """Creates a new message in the given `chat_id`."""
30
+ super().__init__()
31
+ self.token = token
32
+ self.chat_id = chat_id
33
+ self.session = Session()
34
+ self.text = self.__class__.__name__
35
+ self.message_id
36
+
37
+ @property
38
+ def message_id(self):
39
+ if hasattr(self, '_message_id'):
40
+ return self._message_id
41
+ try:
42
+ res = self.session.post(
43
+ self.API + '%s/sendMessage' % self.token,
44
+ data={'text': '`' + self.text + '`', 'chat_id': self.chat_id,
45
+ 'parse_mode': 'MarkdownV2'}).json()
46
+ except Exception as e:
47
+ tqdm_auto.write(str(e))
48
+ else:
49
+ if res.get('error_code') == 429:
50
+ warn("Creation rate limit: try increasing `mininterval`.",
51
+ TqdmWarning, stacklevel=2)
52
+ else:
53
+ self._message_id = res['result']['message_id']
54
+ return self._message_id
55
+
56
+ def write(self, s):
57
+ """Replaces internal `message_id`'s text with `s`."""
58
+ if not s:
59
+ s = "..."
60
+ s = s.replace('\r', '').strip()
61
+ if s == self.text:
62
+ return # avoid duplicate message Bot error
63
+ message_id = self.message_id
64
+ if message_id is None:
65
+ return
66
+ self.text = s
67
+ try:
68
+ future = self.submit(
69
+ self.session.post, self.API + '%s/editMessageText' % self.token,
70
+ data={'text': '`' + s + '`', 'chat_id': self.chat_id,
71
+ 'message_id': message_id, 'parse_mode': 'MarkdownV2'})
72
+ except Exception as e:
73
+ tqdm_auto.write(str(e))
74
+ else:
75
+ return future
76
+
77
+ def delete(self):
78
+ """Deletes internal `message_id`."""
79
+ try:
80
+ future = self.submit(
81
+ self.session.post, self.API + '%s/deleteMessage' % self.token,
82
+ data={'chat_id': self.chat_id, 'message_id': self.message_id})
83
+ except Exception as e:
84
+ tqdm_auto.write(str(e))
85
+ else:
86
+ return future
87
+
88
+
89
+ class tqdm_telegram(tqdm_auto):
90
+ """
91
+ Standard `tqdm.auto.tqdm` but also sends updates to a Telegram Bot.
92
+ May take a few seconds to create (`__init__`).
93
+
94
+ - create a bot <https://core.telegram.org/bots#6-botfather>
95
+ - copy its `{token}`
96
+ - add the bot to a chat and send it a message such as `/start`
97
+ - go to <https://api.telegram.org/bot`{token}`/getUpdates> to find out
98
+ the `{chat_id}`
99
+ - paste the `{token}` & `{chat_id}` below
100
+
101
+ >>> from tqdm.contrib.telegram import tqdm, trange
102
+ >>> for i in tqdm(iterable, token='{token}', chat_id='{chat_id}'):
103
+ ... ...
104
+ """
105
+ def __init__(self, *args, **kwargs):
106
+ """
107
+ Parameters
108
+ ----------
109
+ token : str, required. Telegram token
110
+ [default: ${TQDM_TELEGRAM_TOKEN}].
111
+ chat_id : str, required. Telegram chat ID
112
+ [default: ${TQDM_TELEGRAM_CHAT_ID}].
113
+
114
+ See `tqdm.auto.tqdm.__init__` for other parameters.
115
+ """
116
+ if not kwargs.get('disable'):
117
+ kwargs = kwargs.copy()
118
+ self.tgio = TelegramIO(
119
+ kwargs.pop('token', getenv('TQDM_TELEGRAM_TOKEN')),
120
+ kwargs.pop('chat_id', getenv('TQDM_TELEGRAM_CHAT_ID')))
121
+ super().__init__(*args, **kwargs)
122
+
123
+ def display(self, **kwargs):
124
+ super().display(**kwargs)
125
+ fmt = self.format_dict
126
+ if fmt.get('bar_format', None):
127
+ fmt['bar_format'] = fmt['bar_format'].replace(
128
+ '<bar/>', '{bar:10u}').replace('{bar}', '{bar:10u}')
129
+ else:
130
+ fmt['bar_format'] = '{l_bar}{bar:10u}{r_bar}'
131
+ self.tgio.write(self.format_meter(**fmt))
132
+
133
+ def clear(self, *args, **kwargs):
134
+ super().clear(*args, **kwargs)
135
+ if not self.disable:
136
+ self.tgio.write("")
137
+
138
+ def close(self):
139
+ if self.disable:
140
+ return
141
+ super().close()
142
+ if not (self.leave or (self.leave is None and self.pos == 0)):
143
+ self.tgio.delete()
144
+
145
+
146
+ def ttgrange(*args, **kwargs):
147
+ """Shortcut for `tqdm.contrib.telegram.tqdm(range(*args), **kwargs)`."""
148
+ return tqdm_telegram(range(*args), **kwargs)
149
+
150
+
151
+ # Aliases
152
+ tqdm = tqdm_telegram
153
+ trange = ttgrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/contrib/utils_worker.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ IO/concurrency helpers for `tqdm.contrib`.
3
+ """
4
+ from collections import deque
5
+ from concurrent.futures import ThreadPoolExecutor
6
+
7
+ from ..auto import tqdm as tqdm_auto
8
+
9
+ __author__ = {"github.com/": ["casperdcl"]}
10
+ __all__ = ['MonoWorker']
11
+
12
+
13
+ class MonoWorker(object):
14
+ """
15
+ Supports one running task and one waiting task.
16
+ The waiting task is the most recent submitted (others are discarded).
17
+ """
18
+ def __init__(self):
19
+ self.pool = ThreadPoolExecutor(max_workers=1)
20
+ self.futures = deque([], 2)
21
+
22
+ def submit(self, func, *args, **kwargs):
23
+ """`func(*args, **kwargs)` may replace currently waiting task."""
24
+ futures = self.futures
25
+ if len(futures) == futures.maxlen:
26
+ running = futures.popleft()
27
+ if not running.done():
28
+ if len(futures): # clear waiting
29
+ waiting = futures.pop()
30
+ waiting.cancel()
31
+ futures.appendleft(running) # re-insert running
32
+ try:
33
+ waiting = self.pool.submit(func, *args, **kwargs)
34
+ except Exception as e:
35
+ tqdm_auto.write(str(e))
36
+ else:
37
+ futures.append(waiting)
38
+ return waiting
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/dask.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from functools import partial
2
+
3
+ from dask.callbacks import Callback
4
+
5
+ from .auto import tqdm as tqdm_auto
6
+
7
+ __author__ = {"github.com/": ["casperdcl"]}
8
+ __all__ = ['TqdmCallback']
9
+
10
+
11
+ class TqdmCallback(Callback):
12
+ """Dask callback for task progress."""
13
+ def __init__(self, start=None, pretask=None, tqdm_class=tqdm_auto,
14
+ **tqdm_kwargs):
15
+ """
16
+ Parameters
17
+ ----------
18
+ tqdm_class : optional
19
+ `tqdm` class to use for bars [default: `tqdm.auto.tqdm`].
20
+ tqdm_kwargs : optional
21
+ Any other arguments used for all bars.
22
+ """
23
+ super().__init__(start=start, pretask=pretask)
24
+ if tqdm_kwargs:
25
+ tqdm_class = partial(tqdm_class, **tqdm_kwargs)
26
+ self.tqdm_class = tqdm_class
27
+
28
+ def _start_state(self, _, state):
29
+ self.pbar = self.tqdm_class(total=sum(
30
+ len(state[k]) for k in ['ready', 'waiting', 'running', 'finished']))
31
+
32
+ def _posttask(self, *_, **__):
33
+ self.pbar.update()
34
+
35
+ def _finish(self, *_, **__):
36
+ self.pbar.close()
37
+
38
+ def display(self):
39
+ """Displays in the current cell in Notebooks."""
40
+ container = getattr(self.bar, 'container', None)
41
+ if container is None:
42
+ return
43
+ from .notebook import display
44
+ display(container)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/gui.py ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Matplotlib GUI progressbar decorator for iterators.
3
+
4
+ Usage:
5
+ >>> from tqdm.gui import trange, tqdm
6
+ >>> for i in trange(10):
7
+ ... ...
8
+ """
9
+ # future division is important to divide integers and get as
10
+ # a result precise floating numbers (instead of truncated int)
11
+ import re
12
+ from warnings import warn
13
+
14
+ # to inherit from the tqdm class
15
+ from .std import TqdmExperimentalWarning
16
+ from .std import tqdm as std_tqdm
17
+
18
+ # import compatibility functions and utilities
19
+
20
+ __author__ = {"github.com/": ["casperdcl", "lrq3000"]}
21
+ __all__ = ['tqdm_gui', 'tgrange', 'tqdm', 'trange']
22
+
23
+
24
+ class tqdm_gui(std_tqdm): # pragma: no cover
25
+ """Experimental Matplotlib GUI version of tqdm!"""
26
+ # TODO: @classmethod: write() on GUI?
27
+ def __init__(self, *args, **kwargs):
28
+ from collections import deque
29
+
30
+ import matplotlib as mpl
31
+ import matplotlib.pyplot as plt
32
+ kwargs = kwargs.copy()
33
+ kwargs['gui'] = True
34
+ colour = kwargs.pop('colour', 'g')
35
+ super().__init__(*args, **kwargs)
36
+
37
+ if self.disable:
38
+ return
39
+
40
+ warn("GUI is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
41
+ self.mpl = mpl
42
+ self.plt = plt
43
+
44
+ # Remember if external environment uses toolbars
45
+ self.toolbar = self.mpl.rcParams['toolbar']
46
+ self.mpl.rcParams['toolbar'] = 'None'
47
+
48
+ self.mininterval = max(self.mininterval, 0.5)
49
+ self.fig, ax = plt.subplots(figsize=(9, 2.2))
50
+ # self.fig.subplots_adjust(bottom=0.2)
51
+ total = self.__len__() # avoids TypeError on None #971
52
+ if total is not None:
53
+ self.xdata = []
54
+ self.ydata = []
55
+ self.zdata = []
56
+ else:
57
+ self.xdata = deque([])
58
+ self.ydata = deque([])
59
+ self.zdata = deque([])
60
+ self.line1, = ax.plot(self.xdata, self.ydata, color='b')
61
+ self.line2, = ax.plot(self.xdata, self.zdata, color='k')
62
+ ax.set_ylim(0, 0.001)
63
+ if total is not None:
64
+ ax.set_xlim(0, 100)
65
+ ax.set_xlabel("percent")
66
+ self.fig.legend((self.line1, self.line2), ("cur", "est"),
67
+ loc='center right')
68
+ # progressbar
69
+ self.hspan = plt.axhspan(0, 0.001, xmin=0, xmax=0, color=colour)
70
+ else:
71
+ # ax.set_xlim(-60, 0)
72
+ ax.set_xlim(0, 60)
73
+ ax.invert_xaxis()
74
+ ax.set_xlabel("seconds")
75
+ ax.legend(("cur", "est"), loc='lower left')
76
+ ax.grid()
77
+ # ax.set_xlabel('seconds')
78
+ ax.set_ylabel((self.unit if self.unit else "it") + "/s")
79
+ if self.unit_scale:
80
+ plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
81
+ ax.yaxis.get_offset_text().set_x(-0.15)
82
+
83
+ # Remember if external environment is interactive
84
+ self.wasion = plt.isinteractive()
85
+ plt.ion()
86
+ self.ax = ax
87
+
88
+ def close(self):
89
+ if self.disable:
90
+ return
91
+
92
+ self.disable = True
93
+
94
+ with self.get_lock():
95
+ self._instances.remove(self)
96
+
97
+ # Restore toolbars
98
+ self.mpl.rcParams['toolbar'] = self.toolbar
99
+ # Return to non-interactive mode
100
+ if not self.wasion:
101
+ self.plt.ioff()
102
+ if self.leave:
103
+ self.display()
104
+ else:
105
+ self.plt.close(self.fig)
106
+
107
+ def clear(self, *_, **__):
108
+ pass
109
+
110
+ def display(self, *_, **__):
111
+ n = self.n
112
+ cur_t = self._time()
113
+ elapsed = cur_t - self.start_t
114
+ delta_it = n - self.last_print_n
115
+ delta_t = cur_t - self.last_print_t
116
+
117
+ # Inline due to multiple calls
118
+ total = self.total
119
+ xdata = self.xdata
120
+ ydata = self.ydata
121
+ zdata = self.zdata
122
+ ax = self.ax
123
+ line1 = self.line1
124
+ line2 = self.line2
125
+ hspan = getattr(self, 'hspan', None)
126
+ # instantaneous rate
127
+ y = delta_it / delta_t
128
+ # overall rate
129
+ z = n / elapsed
130
+ # update line data
131
+ xdata.append(n * 100.0 / total if total else cur_t)
132
+ ydata.append(y)
133
+ zdata.append(z)
134
+
135
+ # Discard old values
136
+ # xmin, xmax = ax.get_xlim()
137
+ # if (not total) and elapsed > xmin * 1.1:
138
+ if (not total) and elapsed > 66:
139
+ xdata.popleft()
140
+ ydata.popleft()
141
+ zdata.popleft()
142
+
143
+ ymin, ymax = ax.get_ylim()
144
+ if y > ymax or z > ymax:
145
+ ymax = 1.1 * y
146
+ ax.set_ylim(ymin, ymax)
147
+ ax.figure.canvas.draw()
148
+
149
+ if total:
150
+ line1.set_data(xdata, ydata)
151
+ line2.set_data(xdata, zdata)
152
+ if hspan:
153
+ hspan.set_xy((0, ymin))
154
+ hspan.set_height(ymax - ymin)
155
+ hspan.set_width(n / total)
156
+ else:
157
+ t_ago = [cur_t - i for i in xdata]
158
+ line1.set_data(t_ago, ydata)
159
+ line2.set_data(t_ago, zdata)
160
+
161
+ d = self.format_dict
162
+ # remove {bar}
163
+ d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
164
+ "{bar}", "<bar/>")
165
+ msg = self.format_meter(**d)
166
+ if '<bar/>' in msg:
167
+ msg = "".join(re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
168
+ ax.set_title(msg, fontname="DejaVu Sans Mono", fontsize=11)
169
+ self.plt.pause(1e-9)
170
+
171
+
172
+ def tgrange(*args, **kwargs):
173
+ """Shortcut for `tqdm.gui.tqdm(range(*args), **kwargs)`."""
174
+ return tqdm_gui(range(*args), **kwargs)
175
+
176
+
177
+ # Aliases
178
+ tqdm = tqdm_gui
179
+ trange = tgrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/keras.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from copy import copy
2
+ from functools import partial
3
+
4
+ from .auto import tqdm as tqdm_auto
5
+
6
+ try:
7
+ import keras
8
+ except (ImportError, AttributeError) as e:
9
+ try:
10
+ from tensorflow import keras
11
+ except ImportError:
12
+ raise e
13
+ __author__ = {"github.com/": ["casperdcl"]}
14
+ __all__ = ['TqdmCallback']
15
+
16
+
17
+ class TqdmCallback(keras.callbacks.Callback):
18
+ """Keras callback for epoch and batch progress."""
19
+ @staticmethod
20
+ def bar2callback(bar, pop=None, delta=(lambda logs: 1)):
21
+ def callback(_, logs=None):
22
+ n = delta(logs)
23
+ if logs:
24
+ if pop:
25
+ logs = copy(logs)
26
+ [logs.pop(i, 0) for i in pop]
27
+ bar.set_postfix(logs, refresh=False)
28
+ bar.update(n)
29
+
30
+ return callback
31
+
32
+ def __init__(self, epochs=None, data_size=None, batch_size=None, verbose=1,
33
+ tqdm_class=tqdm_auto, **tqdm_kwargs):
34
+ """
35
+ Parameters
36
+ ----------
37
+ epochs : int, optional
38
+ data_size : int, optional
39
+ Number of training pairs.
40
+ batch_size : int, optional
41
+ Number of training pairs per batch.
42
+ verbose : int
43
+ 0: epoch, 1: batch (transient), 2: batch. [default: 1].
44
+ Will be set to `0` unless both `data_size` and `batch_size`
45
+ are given.
46
+ tqdm_class : optional
47
+ `tqdm` class to use for bars [default: `tqdm.auto.tqdm`].
48
+ tqdm_kwargs : optional
49
+ Any other arguments used for all bars.
50
+ """
51
+ if tqdm_kwargs:
52
+ tqdm_class = partial(tqdm_class, **tqdm_kwargs)
53
+ self.tqdm_class = tqdm_class
54
+ self.epoch_bar = tqdm_class(total=epochs, unit='epoch')
55
+ self.on_epoch_end = self.bar2callback(self.epoch_bar)
56
+ if data_size and batch_size:
57
+ self.batches = batches = (data_size + batch_size - 1) // batch_size
58
+ else:
59
+ self.batches = batches = None
60
+ self.verbose = verbose
61
+ if verbose == 1:
62
+ self.batch_bar = tqdm_class(total=batches, unit='batch', leave=False)
63
+ self.on_batch_end = self.bar2callback(
64
+ self.batch_bar, pop=['batch', 'size'],
65
+ delta=lambda logs: logs.get('size', 1))
66
+
67
+ def on_train_begin(self, *_, **__):
68
+ params = self.params.get
69
+ auto_total = params('epochs', params('nb_epoch', None))
70
+ if auto_total is not None and auto_total != self.epoch_bar.total:
71
+ self.epoch_bar.reset(total=auto_total)
72
+
73
+ def on_epoch_begin(self, epoch, *_, **__):
74
+ if self.epoch_bar.n < epoch:
75
+ ebar = self.epoch_bar
76
+ ebar.n = ebar.last_print_n = ebar.initial = epoch
77
+ if self.verbose:
78
+ params = self.params.get
79
+ total = params('samples', params(
80
+ 'nb_sample', params('steps', None))) or self.batches
81
+ if self.verbose == 2:
82
+ if hasattr(self, 'batch_bar'):
83
+ self.batch_bar.close()
84
+ self.batch_bar = self.tqdm_class(
85
+ total=total, unit='batch', leave=True,
86
+ unit_scale=1 / (params('batch_size', 1) or 1))
87
+ self.on_batch_end = self.bar2callback(
88
+ self.batch_bar, pop=['batch', 'size'],
89
+ delta=lambda logs: logs.get('size', 1))
90
+ elif self.verbose == 1:
91
+ self.batch_bar.unit_scale = 1 / (params('batch_size', 1) or 1)
92
+ self.batch_bar.reset(total=total)
93
+ else:
94
+ raise KeyError('Unknown verbosity')
95
+
96
+ def on_train_end(self, *_, **__):
97
+ if hasattr(self, 'batch_bar'):
98
+ self.batch_bar.close()
99
+ self.epoch_bar.close()
100
+
101
+ def display(self):
102
+ """Displays in the current cell in Notebooks."""
103
+ container = getattr(self.epoch_bar, 'container', None)
104
+ if container is None:
105
+ return
106
+ from .notebook import display
107
+ display(container)
108
+ batch_bar = getattr(self, 'batch_bar', None)
109
+ if batch_bar is not None:
110
+ display(batch_bar.container)
111
+
112
+ @staticmethod
113
+ def _implements_train_batch_hooks():
114
+ return True
115
+
116
+ @staticmethod
117
+ def _implements_test_batch_hooks():
118
+ return True
119
+
120
+ @staticmethod
121
+ def _implements_predict_batch_hooks():
122
+ return True
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/notebook.py ADDED
@@ -0,0 +1,317 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ IPython/Jupyter Notebook progressbar decorator for iterators.
3
+ Includes a default `range` iterator printing to `stderr`.
4
+
5
+ Usage:
6
+ >>> from tqdm.notebook import trange, tqdm
7
+ >>> for i in trange(10):
8
+ ... ...
9
+ """
10
+ # import compatibility functions and utilities
11
+ import re
12
+ import sys
13
+ from html import escape
14
+ from weakref import proxy
15
+
16
+ # to inherit from the tqdm class
17
+ from .std import tqdm as std_tqdm
18
+
19
+ if True: # pragma: no cover
20
+ # import IPython/Jupyter base widget and display utilities
21
+ IPY = 0
22
+ try: # IPython 4.x
23
+ import ipywidgets
24
+ IPY = 4
25
+ except ImportError: # IPython 3.x / 2.x
26
+ IPY = 32
27
+ import warnings
28
+ with warnings.catch_warnings():
29
+ warnings.filterwarnings(
30
+ 'ignore', message=".*The `IPython.html` package has been deprecated.*")
31
+ try:
32
+ import IPython.html.widgets as ipywidgets # NOQA: F401
33
+ except ImportError:
34
+ pass
35
+
36
+ try: # IPython 4.x / 3.x
37
+ if IPY == 32:
38
+ from IPython.html.widgets import HTML
39
+ from IPython.html.widgets import FloatProgress as IProgress
40
+ from IPython.html.widgets import HBox
41
+ IPY = 3
42
+ else:
43
+ from ipywidgets import HTML
44
+ from ipywidgets import FloatProgress as IProgress
45
+ from ipywidgets import HBox
46
+ except ImportError:
47
+ try: # IPython 2.x
48
+ from IPython.html.widgets import HTML
49
+ from IPython.html.widgets import ContainerWidget as HBox
50
+ from IPython.html.widgets import FloatProgressWidget as IProgress
51
+ IPY = 2
52
+ except ImportError:
53
+ IPY = 0
54
+ IProgress = None
55
+ HBox = object
56
+
57
+ try:
58
+ from IPython.display import display # , clear_output
59
+ except ImportError:
60
+ pass
61
+
62
+ __author__ = {"github.com/": ["lrq3000", "casperdcl", "alexanderkuk"]}
63
+ __all__ = ['tqdm_notebook', 'tnrange', 'tqdm', 'trange']
64
+ WARN_NOIPYW = ("IProgress not found. Please update jupyter and ipywidgets."
65
+ " See https://ipywidgets.readthedocs.io/en/stable"
66
+ "/user_install.html")
67
+
68
+
69
+ class TqdmHBox(HBox):
70
+ """`ipywidgets.HBox` with a pretty representation"""
71
+ def _json_(self, pretty=None):
72
+ pbar = getattr(self, 'pbar', None)
73
+ if pbar is None:
74
+ return {}
75
+ d = pbar.format_dict
76
+ if pretty is not None:
77
+ d["ascii"] = not pretty
78
+ return d
79
+
80
+ def __repr__(self, pretty=False):
81
+ pbar = getattr(self, 'pbar', None)
82
+ if pbar is None:
83
+ return super().__repr__()
84
+ return pbar.format_meter(**self._json_(pretty))
85
+
86
+ def _repr_pretty_(self, pp, *_, **__):
87
+ pp.text(self.__repr__(True))
88
+
89
+
90
+ class tqdm_notebook(std_tqdm):
91
+ """
92
+ Experimental IPython/Jupyter Notebook widget using tqdm!
93
+ """
94
+ @staticmethod
95
+ def status_printer(_, total=None, desc=None, ncols=None):
96
+ """
97
+ Manage the printing of an IPython/Jupyter Notebook progress bar widget.
98
+ """
99
+ # Fallback to text bar if there's no total
100
+ # DEPRECATED: replaced with an 'info' style bar
101
+ # if not total:
102
+ # return super(tqdm_notebook, tqdm_notebook).status_printer(file)
103
+
104
+ # fp = file
105
+
106
+ # Prepare IPython progress bar
107
+ if IProgress is None: # #187 #451 #558 #872
108
+ raise ImportError(WARN_NOIPYW)
109
+ if total:
110
+ pbar = IProgress(min=0, max=total)
111
+ else: # No total? Show info style bar with no progress tqdm status
112
+ pbar = IProgress(min=0, max=1)
113
+ pbar.value = 1
114
+ pbar.bar_style = 'info'
115
+ if ncols is None:
116
+ pbar.layout.width = "20px"
117
+
118
+ ltext = HTML()
119
+ rtext = HTML()
120
+ if desc:
121
+ ltext.value = desc
122
+ container = TqdmHBox(children=[ltext, pbar, rtext])
123
+ # Prepare layout
124
+ if ncols is not None: # use default style of ipywidgets
125
+ # ncols could be 100, "100px", "100%"
126
+ ncols = str(ncols) # ipywidgets only accepts string
127
+ try:
128
+ if int(ncols) > 0: # isnumeric and positive
129
+ ncols += 'px'
130
+ except ValueError:
131
+ pass
132
+ pbar.layout.flex = '2'
133
+ container.layout.width = ncols
134
+ container.layout.display = 'inline-flex'
135
+ container.layout.flex_flow = 'row wrap'
136
+
137
+ return container
138
+
139
+ def display(self, msg=None, pos=None,
140
+ # additional signals
141
+ close=False, bar_style=None, check_delay=True):
142
+ # Note: contrary to native tqdm, msg='' does NOT clear bar
143
+ # goal is to keep all infos if error happens so user knows
144
+ # at which iteration the loop failed.
145
+
146
+ # Clear previous output (really necessary?)
147
+ # clear_output(wait=1)
148
+
149
+ if not msg and not close:
150
+ d = self.format_dict
151
+ # remove {bar}
152
+ d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
153
+ "{bar}", "<bar/>")
154
+ msg = self.format_meter(**d)
155
+
156
+ ltext, pbar, rtext = self.container.children
157
+ pbar.value = self.n
158
+
159
+ if msg:
160
+ msg = msg.replace(' ', u'\u2007') # fix html space padding
161
+ # html escape special characters (like '&')
162
+ if '<bar/>' in msg:
163
+ left, right = map(escape, re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
164
+ else:
165
+ left, right = '', escape(msg)
166
+
167
+ # Update description
168
+ ltext.value = left
169
+ # never clear the bar (signal: msg='')
170
+ if right:
171
+ rtext.value = right
172
+
173
+ # Change bar style
174
+ if bar_style:
175
+ # Hack-ish way to avoid the danger bar_style being overridden by
176
+ # success because the bar gets closed after the error...
177
+ if pbar.bar_style != 'danger' or bar_style != 'success':
178
+ pbar.bar_style = bar_style
179
+
180
+ # Special signal to close the bar
181
+ if close and pbar.bar_style != 'danger': # hide only if no error
182
+ try:
183
+ self.container.close()
184
+ except AttributeError:
185
+ self.container.visible = False
186
+ self.container.layout.visibility = 'hidden' # IPYW>=8
187
+
188
+ if check_delay and self.delay > 0 and not self.displayed:
189
+ display(self.container)
190
+ self.displayed = True
191
+
192
+ @property
193
+ def colour(self):
194
+ if hasattr(self, 'container'):
195
+ return self.container.children[-2].style.bar_color
196
+
197
+ @colour.setter
198
+ def colour(self, bar_color):
199
+ if hasattr(self, 'container'):
200
+ self.container.children[-2].style.bar_color = bar_color
201
+
202
+ def __init__(self, *args, **kwargs):
203
+ """
204
+ Supports the usual `tqdm.tqdm` parameters as well as those listed below.
205
+
206
+ Parameters
207
+ ----------
208
+ display : Whether to call `display(self.container)` immediately
209
+ [default: True].
210
+ """
211
+ kwargs = kwargs.copy()
212
+ # Setup default output
213
+ file_kwarg = kwargs.get('file', sys.stderr)
214
+ if file_kwarg is sys.stderr or file_kwarg is None:
215
+ kwargs['file'] = sys.stdout # avoid the red block in IPython
216
+
217
+ # Initialize parent class + avoid printing by using gui=True
218
+ kwargs['gui'] = True
219
+ # convert disable = None to False
220
+ kwargs['disable'] = bool(kwargs.get('disable', False))
221
+ colour = kwargs.pop('colour', None)
222
+ display_here = kwargs.pop('display', True)
223
+ super().__init__(*args, **kwargs)
224
+ if self.disable or not kwargs['gui']:
225
+ self.disp = lambda *_, **__: None
226
+ return
227
+
228
+ # Get bar width
229
+ self.ncols = '100%' if self.dynamic_ncols else kwargs.get("ncols", None)
230
+
231
+ # Replace with IPython progress bar display (with correct total)
232
+ unit_scale = 1 if self.unit_scale is True else self.unit_scale or 1
233
+ total = self.total * unit_scale if self.total else self.total
234
+ self.container = self.status_printer(self.fp, total, self.desc, self.ncols)
235
+ self.container.pbar = proxy(self)
236
+ self.displayed = False
237
+ if display_here and self.delay <= 0:
238
+ display(self.container)
239
+ self.displayed = True
240
+ self.disp = self.display
241
+ self.colour = colour
242
+
243
+ # Print initial bar state
244
+ if not self.disable:
245
+ self.display(check_delay=False)
246
+
247
+ def __iter__(self):
248
+ try:
249
+ it = super().__iter__()
250
+ for obj in it:
251
+ # return super(tqdm...) will not catch exception
252
+ yield obj
253
+ # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
254
+ except: # NOQA
255
+ self.disp(bar_style='danger')
256
+ raise
257
+ # NB: don't `finally: close()`
258
+ # since this could be a shared bar which the user will `reset()`
259
+
260
+ def update(self, n=1):
261
+ try:
262
+ return super().update(n=n)
263
+ # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt
264
+ except: # NOQA
265
+ # cannot catch KeyboardInterrupt when using manual tqdm
266
+ # as the interrupt will most likely happen on another statement
267
+ self.disp(bar_style='danger')
268
+ raise
269
+ # NB: don't `finally: close()`
270
+ # since this could be a shared bar which the user will `reset()`
271
+
272
+ def close(self):
273
+ if self.disable:
274
+ return
275
+ super().close()
276
+ # Try to detect if there was an error or KeyboardInterrupt
277
+ # in manual mode: if n < total, things probably got wrong
278
+ if self.total and self.n < self.total:
279
+ self.disp(bar_style='danger', check_delay=False)
280
+ else:
281
+ if self.leave:
282
+ self.disp(bar_style='success', check_delay=False)
283
+ else:
284
+ self.disp(close=True, check_delay=False)
285
+
286
+ def clear(self, *_, **__):
287
+ pass
288
+
289
+ def reset(self, total=None):
290
+ """
291
+ Resets to 0 iterations for repeated use.
292
+
293
+ Consider combining with `leave=True`.
294
+
295
+ Parameters
296
+ ----------
297
+ total : int or float, optional. Total to use for the new bar.
298
+ """
299
+ if self.disable:
300
+ return super().reset(total=total)
301
+ _, pbar, _ = self.container.children
302
+ pbar.bar_style = ''
303
+ if total is not None:
304
+ pbar.max = total
305
+ if not self.total and self.ncols is None: # no longer unknown total
306
+ pbar.layout.width = None # reset width
307
+ return super().reset(total=total)
308
+
309
+
310
+ def tnrange(*args, **kwargs):
311
+ """Shortcut for `tqdm.notebook.tqdm(range(*args), **kwargs)`."""
312
+ return tqdm_notebook(range(*args), **kwargs)
313
+
314
+
315
+ # Aliases
316
+ tqdm = tqdm_notebook
317
+ trange = tnrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/rich.py ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ `rich.progress` decorator for iterators.
3
+
4
+ Usage:
5
+ >>> from tqdm.rich import trange, tqdm
6
+ >>> for i in trange(10):
7
+ ... ...
8
+ """
9
+ from warnings import warn
10
+
11
+ from rich.progress import (
12
+ BarColumn, Progress, ProgressColumn, Text, TimeElapsedColumn, TimeRemainingColumn, filesize)
13
+
14
+ from .std import TqdmExperimentalWarning
15
+ from .std import tqdm as std_tqdm
16
+
17
+ __author__ = {"github.com/": ["casperdcl"]}
18
+ __all__ = ['tqdm_rich', 'trrange', 'tqdm', 'trange']
19
+
20
+
21
+ class FractionColumn(ProgressColumn):
22
+ """Renders completed/total, e.g. '0.5/2.3 G'."""
23
+ def __init__(self, unit_scale=False, unit_divisor=1000):
24
+ self.unit_scale = unit_scale
25
+ self.unit_divisor = unit_divisor
26
+ super().__init__()
27
+
28
+ def render(self, task):
29
+ """Calculate common unit for completed and total."""
30
+ completed = int(task.completed)
31
+ total = int(task.total)
32
+ if self.unit_scale:
33
+ unit, suffix = filesize.pick_unit_and_suffix(
34
+ total,
35
+ ["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
36
+ self.unit_divisor,
37
+ )
38
+ else:
39
+ unit, suffix = filesize.pick_unit_and_suffix(total, [""], 1)
40
+ precision = 0 if unit == 1 else 1
41
+ return Text(
42
+ f"{completed/unit:,.{precision}f}/{total/unit:,.{precision}f} {suffix}",
43
+ style="progress.download")
44
+
45
+
46
+ class RateColumn(ProgressColumn):
47
+ """Renders human readable transfer speed."""
48
+ def __init__(self, unit="", unit_scale=False, unit_divisor=1000):
49
+ self.unit = unit
50
+ self.unit_scale = unit_scale
51
+ self.unit_divisor = unit_divisor
52
+ super().__init__()
53
+
54
+ def render(self, task):
55
+ """Show data transfer speed."""
56
+ speed = task.speed
57
+ if speed is None:
58
+ return Text(f"? {self.unit}/s", style="progress.data.speed")
59
+ if self.unit_scale:
60
+ unit, suffix = filesize.pick_unit_and_suffix(
61
+ speed,
62
+ ["", "K", "M", "G", "T", "P", "E", "Z", "Y"],
63
+ self.unit_divisor,
64
+ )
65
+ else:
66
+ unit, suffix = filesize.pick_unit_and_suffix(speed, [""], 1)
67
+ precision = 0 if unit == 1 else 1
68
+ return Text(f"{speed/unit:,.{precision}f} {suffix}{self.unit}/s",
69
+ style="progress.data.speed")
70
+
71
+
72
+ class tqdm_rich(std_tqdm): # pragma: no cover
73
+ """Experimental rich.progress GUI version of tqdm!"""
74
+ # TODO: @classmethod: write()?
75
+ def __init__(self, *args, **kwargs):
76
+ """
77
+ This class accepts the following parameters *in addition* to
78
+ the parameters accepted by `tqdm`.
79
+
80
+ Parameters
81
+ ----------
82
+ progress : tuple, optional
83
+ arguments for `rich.progress.Progress()`.
84
+ options : dict, optional
85
+ keyword arguments for `rich.progress.Progress()`.
86
+ """
87
+ kwargs = kwargs.copy()
88
+ kwargs['gui'] = True
89
+ # convert disable = None to False
90
+ kwargs['disable'] = bool(kwargs.get('disable', False))
91
+ progress = kwargs.pop('progress', None)
92
+ options = kwargs.pop('options', {}).copy()
93
+ super().__init__(*args, **kwargs)
94
+
95
+ if self.disable:
96
+ return
97
+
98
+ warn("rich is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
99
+ d = self.format_dict
100
+ if progress is None:
101
+ progress = (
102
+ "[progress.description]{task.description}"
103
+ "[progress.percentage]{task.percentage:>4.0f}%",
104
+ BarColumn(bar_width=None),
105
+ FractionColumn(
106
+ unit_scale=d['unit_scale'], unit_divisor=d['unit_divisor']),
107
+ "[", TimeElapsedColumn(), "<", TimeRemainingColumn(),
108
+ ",", RateColumn(unit=d['unit'], unit_scale=d['unit_scale'],
109
+ unit_divisor=d['unit_divisor']), "]"
110
+ )
111
+ options.setdefault('transient', not self.leave)
112
+ self._prog = Progress(*progress, **options)
113
+ self._prog.__enter__()
114
+ self._task_id = self._prog.add_task(self.desc or "", **d)
115
+
116
+ def close(self):
117
+ if self.disable:
118
+ return
119
+ self.display() # print 100%, vis #1306
120
+ super().close()
121
+ self._prog.__exit__(None, None, None)
122
+
123
+ def clear(self, *_, **__):
124
+ pass
125
+
126
+ def display(self, *_, **__):
127
+ if not hasattr(self, '_prog'):
128
+ return
129
+ self._prog.update(self._task_id, completed=self.n, description=self.desc)
130
+
131
+ def reset(self, total=None):
132
+ """
133
+ Resets to 0 iterations for repeated use.
134
+
135
+ Parameters
136
+ ----------
137
+ total : int or float, optional. Total to use for the new bar.
138
+ """
139
+ if hasattr(self, '_prog'):
140
+ self._prog.reset(total=total)
141
+ super().reset(total=total)
142
+
143
+
144
+ def trrange(*args, **kwargs):
145
+ """Shortcut for `tqdm.rich.tqdm(range(*args), **kwargs)`."""
146
+ return tqdm_rich(range(*args), **kwargs)
147
+
148
+
149
+ # Aliases
150
+ tqdm = tqdm_rich
151
+ trange = trrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/std.py ADDED
@@ -0,0 +1,1524 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Customisable progressbar decorator for iterators.
3
+ Includes a default `range` iterator printing to `stderr`.
4
+
5
+ Usage:
6
+ >>> from tqdm import trange, tqdm
7
+ >>> for i in trange(10):
8
+ ... ...
9
+ """
10
+ import sys
11
+ from collections import OrderedDict, defaultdict
12
+ from contextlib import contextmanager
13
+ from datetime import datetime, timedelta, timezone
14
+ from numbers import Number
15
+ from time import time
16
+ from warnings import warn
17
+ from weakref import WeakSet
18
+
19
+ from ._monitor import TMonitor
20
+ from .utils import (
21
+ CallbackIOWrapper, Comparable, DisableOnWriteError, FormatReplace, SimpleTextIOWrapper,
22
+ _is_ascii, _screen_shape_wrapper, _supports_unicode, _term_move_up, disp_len, disp_trim,
23
+ envwrap)
24
+
25
+ __author__ = "https://github.com/tqdm/tqdm#contributions"
26
+ __all__ = ['tqdm', 'trange',
27
+ 'TqdmTypeError', 'TqdmKeyError', 'TqdmWarning',
28
+ 'TqdmExperimentalWarning', 'TqdmDeprecationWarning',
29
+ 'TqdmMonitorWarning']
30
+
31
+
32
+ class TqdmTypeError(TypeError):
33
+ pass
34
+
35
+
36
+ class TqdmKeyError(KeyError):
37
+ pass
38
+
39
+
40
+ class TqdmWarning(Warning):
41
+ """base class for all tqdm warnings.
42
+
43
+ Used for non-external-code-breaking errors, such as garbled printing.
44
+ """
45
+ def __init__(self, msg, fp_write=None, *a, **k):
46
+ if fp_write is not None:
47
+ fp_write("\n" + self.__class__.__name__ + ": " + str(msg).rstrip() + '\n')
48
+ else:
49
+ super().__init__(msg, *a, **k)
50
+
51
+
52
+ class TqdmExperimentalWarning(TqdmWarning, FutureWarning):
53
+ """beta feature, unstable API and behaviour"""
54
+ pass
55
+
56
+
57
+ class TqdmDeprecationWarning(TqdmWarning, DeprecationWarning):
58
+ # not suppressed if raised
59
+ pass
60
+
61
+
62
+ class TqdmMonitorWarning(TqdmWarning, RuntimeWarning):
63
+ """tqdm monitor errors which do not affect external functionality"""
64
+ pass
65
+
66
+
67
+ def TRLock(*args, **kwargs):
68
+ """threading RLock"""
69
+ try:
70
+ from threading import RLock
71
+ return RLock(*args, **kwargs)
72
+ except (ImportError, OSError): # pragma: no cover
73
+ pass
74
+
75
+
76
+ class TqdmDefaultWriteLock(object):
77
+ """
78
+ Provide a default write lock for thread and multiprocessing safety.
79
+ Works only on platforms supporting `fork` (so Windows is excluded).
80
+ You must initialise a `tqdm` or `TqdmDefaultWriteLock` instance
81
+ before forking in order for the write lock to work.
82
+ On Windows, you need to supply the lock from the parent to the children as
83
+ an argument to joblib or the parallelism lib you use.
84
+ """
85
+ # global thread lock so no setup required for multithreading.
86
+ # NB: Do not create multiprocessing lock as it sets the multiprocessing
87
+ # context, disallowing `spawn()`/`forkserver()`
88
+ th_lock = TRLock()
89
+
90
+ def __init__(self):
91
+ # Create global parallelism locks to avoid racing issues with parallel
92
+ # bars works only if fork available (Linux/MacOSX, but not Windows)
93
+ cls = type(self)
94
+ root_lock = cls.th_lock
95
+ if root_lock is not None:
96
+ root_lock.acquire()
97
+ cls.create_mp_lock()
98
+ self.locks = [lk for lk in [cls.mp_lock, cls.th_lock] if lk is not None]
99
+ if root_lock is not None:
100
+ root_lock.release()
101
+
102
+ def acquire(self, *a, **k):
103
+ for lock in self.locks:
104
+ lock.acquire(*a, **k)
105
+
106
+ def release(self):
107
+ for lock in self.locks[::-1]: # Release in inverse order of acquisition
108
+ lock.release()
109
+
110
+ def __enter__(self):
111
+ self.acquire()
112
+
113
+ def __exit__(self, *exc):
114
+ self.release()
115
+
116
+ @classmethod
117
+ def create_mp_lock(cls):
118
+ if not hasattr(cls, 'mp_lock'):
119
+ try:
120
+ from multiprocessing import RLock
121
+ cls.mp_lock = RLock()
122
+ except (ImportError, OSError): # pragma: no cover
123
+ cls.mp_lock = None
124
+
125
+ @classmethod
126
+ def create_th_lock(cls):
127
+ assert hasattr(cls, 'th_lock')
128
+ warn("create_th_lock not needed anymore", TqdmDeprecationWarning, stacklevel=2)
129
+
130
+
131
+ class Bar(object):
132
+ """
133
+ `str.format`-able bar with format specifiers: `[width][type]`
134
+
135
+ - `width`
136
+ + unspecified (default): use `self.default_len`
137
+ + `int >= 0`: overrides `self.default_len`
138
+ + `int < 0`: subtract from `self.default_len`
139
+ - `type`
140
+ + `a`: ascii (`charset=self.ASCII` override)
141
+ + `u`: unicode (`charset=self.UTF` override)
142
+ + `b`: blank (`charset=" "` override)
143
+ """
144
+ ASCII = " 123456789#"
145
+ UTF = u" " + u''.join(map(chr, range(0x258F, 0x2587, -1)))
146
+ BLANK = " "
147
+ COLOUR_RESET = '\x1b[0m'
148
+ COLOUR_RGB = '\x1b[38;2;%d;%d;%dm'
149
+ COLOURS = {'BLACK': '\x1b[30m', 'RED': '\x1b[31m', 'GREEN': '\x1b[32m',
150
+ 'YELLOW': '\x1b[33m', 'BLUE': '\x1b[34m', 'MAGENTA': '\x1b[35m',
151
+ 'CYAN': '\x1b[36m', 'WHITE': '\x1b[37m'}
152
+
153
+ def __init__(self, frac, default_len=10, charset=UTF, colour=None):
154
+ if not 0 <= frac <= 1:
155
+ warn("clamping frac to range [0, 1]", TqdmWarning, stacklevel=2)
156
+ frac = max(0, min(1, frac))
157
+ assert default_len > 0
158
+ self.frac = frac
159
+ self.default_len = default_len
160
+ self.charset = charset
161
+ self.colour = colour
162
+
163
+ @property
164
+ def colour(self):
165
+ return self._colour
166
+
167
+ @colour.setter
168
+ def colour(self, value):
169
+ if not value:
170
+ self._colour = None
171
+ return
172
+ try:
173
+ if value.upper() in self.COLOURS:
174
+ self._colour = self.COLOURS[value.upper()]
175
+ elif value[0] == '#' and len(value) == 7:
176
+ self._colour = self.COLOUR_RGB % tuple(
177
+ int(i, 16) for i in (value[1:3], value[3:5], value[5:7]))
178
+ else:
179
+ raise KeyError
180
+ except (KeyError, AttributeError):
181
+ warn("Unknown colour (%s); valid choices: [hex (#00ff00), %s]" % (
182
+ value, ", ".join(self.COLOURS)),
183
+ TqdmWarning, stacklevel=2)
184
+ self._colour = None
185
+
186
+ def __format__(self, format_spec):
187
+ if format_spec:
188
+ _type = format_spec[-1].lower()
189
+ try:
190
+ charset = {'a': self.ASCII, 'u': self.UTF, 'b': self.BLANK}[_type]
191
+ except KeyError:
192
+ charset = self.charset
193
+ else:
194
+ format_spec = format_spec[:-1]
195
+ if format_spec:
196
+ N_BARS = int(format_spec)
197
+ if N_BARS < 0:
198
+ N_BARS += self.default_len
199
+ else:
200
+ N_BARS = self.default_len
201
+ else:
202
+ charset = self.charset
203
+ N_BARS = self.default_len
204
+
205
+ nsyms = len(charset) - 1
206
+ bar_length, frac_bar_length = divmod(int(self.frac * N_BARS * nsyms), nsyms)
207
+
208
+ res = charset[-1] * bar_length
209
+ if bar_length < N_BARS: # whitespace padding
210
+ res = res + charset[frac_bar_length] + charset[0] * (N_BARS - bar_length - 1)
211
+ return self.colour + res + self.COLOUR_RESET if self.colour else res
212
+
213
+
214
+ class EMA(object):
215
+ """
216
+ Exponential moving average: smoothing to give progressively lower
217
+ weights to older values.
218
+
219
+ Parameters
220
+ ----------
221
+ smoothing : float, optional
222
+ Smoothing factor in range [0, 1], [default: 0.3].
223
+ Increase to give more weight to recent values.
224
+ Ranges from 0 (yields old value) to 1 (yields new value).
225
+ """
226
+ def __init__(self, smoothing=0.3):
227
+ self.alpha = smoothing
228
+ self.last = 0
229
+ self.calls = 0
230
+
231
+ def __call__(self, x=None):
232
+ """
233
+ Parameters
234
+ ----------
235
+ x : float
236
+ New value to include in EMA.
237
+ """
238
+ beta = 1 - self.alpha
239
+ if x is not None:
240
+ self.last = self.alpha * x + beta * self.last
241
+ self.calls += 1
242
+ return self.last / (1 - beta ** self.calls) if self.calls else self.last
243
+
244
+
245
+ class tqdm(Comparable):
246
+ """
247
+ Decorate an iterable object, returning an iterator which acts exactly
248
+ like the original iterable, but prints a dynamically updating
249
+ progressbar every time a value is requested.
250
+
251
+ Parameters
252
+ ----------
253
+ iterable : iterable, optional
254
+ Iterable to decorate with a progressbar.
255
+ Leave blank to manually manage the updates.
256
+ desc : str, optional
257
+ Prefix for the progressbar.
258
+ total : int or float, optional
259
+ The number of expected iterations. If unspecified,
260
+ len(iterable) is used if possible. If float("inf") or as a last
261
+ resort, only basic progress statistics are displayed
262
+ (no ETA, no progressbar).
263
+ If `gui` is True and this parameter needs subsequent updating,
264
+ specify an initial arbitrary large positive number,
265
+ e.g. 9e9.
266
+ leave : bool, optional
267
+ If [default: True], keeps all traces of the progressbar
268
+ upon termination of iteration.
269
+ If `None`, will leave only if `position` is `0`.
270
+ file : `io.TextIOWrapper` or `io.StringIO`, optional
271
+ Specifies where to output the progress messages
272
+ (default: sys.stderr). Uses `file.write(str)` and `file.flush()`
273
+ methods. For encoding, see `write_bytes`.
274
+ ncols : int, optional
275
+ The width of the entire output message. If specified,
276
+ dynamically resizes the progressbar to stay within this bound.
277
+ If unspecified, attempts to use environment width. The
278
+ fallback is a meter width of 10 and no limit for the counter and
279
+ statistics. If 0, will not print any meter (only stats).
280
+ mininterval : float, optional
281
+ Minimum progress display update interval [default: 0.1] seconds.
282
+ maxinterval : float, optional
283
+ Maximum progress display update interval [default: 10] seconds.
284
+ Automatically adjusts `miniters` to correspond to `mininterval`
285
+ after long display update lag. Only works if `dynamic_miniters`
286
+ or monitor thread is enabled.
287
+ miniters : int or float, optional
288
+ Minimum progress display update interval, in iterations.
289
+ If 0 and `dynamic_miniters`, will automatically adjust to equal
290
+ `mininterval` (more CPU efficient, good for tight loops).
291
+ If > 0, will skip display of specified number of iterations.
292
+ Tweak this and `mininterval` to get very efficient loops.
293
+ If your progress is erratic with both fast and slow iterations
294
+ (network, skipping items, etc) you should set miniters=1.
295
+ ascii : bool or str, optional
296
+ If unspecified or False, use unicode (smooth blocks) to fill
297
+ the meter. The fallback is to use ASCII characters " 123456789#".
298
+ disable : bool, optional
299
+ Whether to disable the entire progressbar wrapper
300
+ [default: False]. If set to None, disable on non-TTY.
301
+ unit : str, optional
302
+ String that will be used to define the unit of each iteration
303
+ [default: it].
304
+ unit_scale : bool or int or float, optional
305
+ If 1 or True, the number of iterations will be reduced/scaled
306
+ automatically and a metric prefix following the
307
+ International System of Units standard will be added
308
+ (kilo, mega, etc.) [default: False]. If any other non-zero
309
+ number, will scale `total` and `n`.
310
+ dynamic_ncols : bool, optional
311
+ If set, constantly alters `ncols` and `nrows` to the
312
+ environment (allowing for window resizes) [default: False].
313
+ smoothing : float, optional
314
+ Exponential moving average smoothing factor for speed estimates
315
+ (ignored in GUI mode). Ranges from 0 (average speed) to 1
316
+ (current/instantaneous speed) [default: 0.3].
317
+ bar_format : str, optional
318
+ Specify a custom bar string formatting. May impact performance.
319
+ [default: '{l_bar}{bar}{r_bar}'], where
320
+ l_bar='{desc}: {percentage:3.0f}%|' and
321
+ r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
322
+ '{rate_fmt}{postfix}]'
323
+ Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
324
+ percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
325
+ rate, rate_fmt, rate_noinv, rate_noinv_fmt,
326
+ rate_inv, rate_inv_fmt, postfix, unit_divisor,
327
+ remaining, remaining_s, eta.
328
+ Note that a trailing ": " is automatically removed after {desc}
329
+ if the latter is empty.
330
+ initial : int or float, optional
331
+ The initial counter value. Useful when restarting a progress
332
+ bar [default: 0]. If using float, consider specifying `{n:.3f}`
333
+ or similar in `bar_format`, or specifying `unit_scale`.
334
+ position : int, optional
335
+ Specify the line offset to print this bar (starting from 0)
336
+ Automatic if unspecified.
337
+ Useful to manage multiple bars at once (eg, from threads).
338
+ postfix : dict or *, optional
339
+ Specify additional stats to display at the end of the bar.
340
+ Calls `set_postfix(**postfix)` if possible (dict).
341
+ unit_divisor : float, optional
342
+ [default: 1000], ignored unless `unit_scale` is True.
343
+ write_bytes : bool, optional
344
+ Whether to write bytes. If (default: False) will write unicode.
345
+ lock_args : tuple, optional
346
+ Passed to `refresh` for intermediate output
347
+ (initialisation, iterating, and updating).
348
+ nrows : int, optional
349
+ The screen height. If specified, hides nested bars outside this
350
+ bound. If unspecified, attempts to use environment height.
351
+ The fallback is 20.
352
+ colour : str, optional
353
+ Bar colour (e.g. 'green', '#00ff00').
354
+ delay : float, optional
355
+ Don't display until [default: 0] seconds have elapsed.
356
+ gui : bool, optional
357
+ WARNING: internal parameter - do not use.
358
+ Use tqdm.gui.tqdm(...) instead. If set, will attempt to use
359
+ matplotlib animations for a graphical output [default: False].
360
+
361
+ Returns
362
+ -------
363
+ out : decorated iterator.
364
+ """
365
+
366
+ monitor_interval = 10 # set to 0 to disable the thread
367
+ monitor = None
368
+ _instances = WeakSet()
369
+
370
+ @staticmethod
371
+ def format_sizeof(num, suffix='', divisor=1000):
372
+ """
373
+ Formats a number (greater than unity) with SI Order of Magnitude
374
+ prefixes.
375
+
376
+ Parameters
377
+ ----------
378
+ num : float
379
+ Number ( >= 1) to format.
380
+ suffix : str, optional
381
+ Post-postfix [default: ''].
382
+ divisor : float, optional
383
+ Divisor between prefixes [default: 1000].
384
+
385
+ Returns
386
+ -------
387
+ out : str
388
+ Number with Order of Magnitude SI unit postfix.
389
+ """
390
+ for unit in ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z']:
391
+ if abs(num) < 999.5:
392
+ if abs(num) < 99.95:
393
+ if abs(num) < 9.995:
394
+ return f'{num:1.2f}{unit}{suffix}'
395
+ return f'{num:2.1f}{unit}{suffix}'
396
+ return f'{num:3.0f}{unit}{suffix}'
397
+ num /= divisor
398
+ return f'{num:3.1f}Y{suffix}'
399
+
400
+ @staticmethod
401
+ def format_interval(t):
402
+ """
403
+ Formats a number of seconds as a clock time, [H:]MM:SS
404
+
405
+ Parameters
406
+ ----------
407
+ t : int
408
+ Number of seconds.
409
+
410
+ Returns
411
+ -------
412
+ out : str
413
+ [H:]MM:SS
414
+ """
415
+ mins, s = divmod(int(t), 60)
416
+ h, m = divmod(mins, 60)
417
+ return f'{h:d}:{m:02d}:{s:02d}' if h else f'{m:02d}:{s:02d}'
418
+
419
+ @staticmethod
420
+ def format_num(n):
421
+ """
422
+ Intelligent scientific notation (.3g).
423
+
424
+ Parameters
425
+ ----------
426
+ n : int or float or Numeric
427
+ A Number.
428
+
429
+ Returns
430
+ -------
431
+ out : str
432
+ Formatted number.
433
+ """
434
+ f = f'{n:.3g}'.replace('e+0', 'e+').replace('e-0', 'e-')
435
+ n = str(n)
436
+ return f if len(f) < len(n) else n
437
+
438
+ @staticmethod
439
+ def status_printer(file):
440
+ """
441
+ Manage the printing and in-place updating of a line of characters.
442
+ Note that if the string is longer than a line, then in-place
443
+ updating may not work (it will print a new line at each refresh).
444
+ """
445
+ fp = file
446
+ fp_flush = getattr(fp, 'flush', lambda: None) # pragma: no cover
447
+ if fp in (sys.stderr, sys.stdout):
448
+ getattr(sys.stderr, 'flush', lambda: None)()
449
+ getattr(sys.stdout, 'flush', lambda: None)()
450
+
451
+ def fp_write(s):
452
+ fp.write(str(s))
453
+ fp_flush()
454
+
455
+ last_len = [0]
456
+
457
+ def print_status(s):
458
+ len_s = disp_len(s)
459
+ fp_write('\r' + s + (' ' * max(last_len[0] - len_s, 0)))
460
+ last_len[0] = len_s
461
+
462
+ return print_status
463
+
464
+ @staticmethod
465
+ def format_meter(n, total, elapsed, ncols=None, prefix='', ascii=False, unit='it',
466
+ unit_scale=False, rate=None, bar_format=None, postfix=None,
467
+ unit_divisor=1000, initial=0, colour=None, **extra_kwargs):
468
+ """
469
+ Return a string-based progress bar given some parameters
470
+
471
+ Parameters
472
+ ----------
473
+ n : int or float
474
+ Number of finished iterations.
475
+ total : int or float
476
+ The expected total number of iterations. If meaningless (None),
477
+ only basic progress statistics are displayed (no ETA).
478
+ elapsed : float
479
+ Number of seconds passed since start.
480
+ ncols : int, optional
481
+ The width of the entire output message. If specified,
482
+ dynamically resizes `{bar}` to stay within this bound
483
+ [default: None]. If `0`, will not print any bar (only stats).
484
+ The fallback is `{bar:10}`.
485
+ prefix : str, optional
486
+ Prefix message (included in total width) [default: ''].
487
+ Use as {desc} in bar_format string.
488
+ ascii : bool, optional or str, optional
489
+ If not set, use unicode (smooth blocks) to fill the meter
490
+ [default: False]. The fallback is to use ASCII characters
491
+ " 123456789#".
492
+ unit : str, optional
493
+ The iteration unit [default: 'it'].
494
+ unit_scale : bool or int or float, optional
495
+ If 1 or True, the number of iterations will be printed with an
496
+ appropriate SI metric prefix (k = 10^3, M = 10^6, etc.)
497
+ [default: False]. If any other non-zero number, will scale
498
+ `total` and `n`.
499
+ rate : float, optional
500
+ Manual override for iteration rate.
501
+ If [default: None], uses n/elapsed.
502
+ bar_format : str, optional
503
+ Specify a custom bar string formatting. May impact performance.
504
+ [default: '{l_bar}{bar}{r_bar}'], where
505
+ l_bar='{desc}: {percentage:3.0f}%|' and
506
+ r_bar='| {n_fmt}/{total_fmt} [{elapsed}<{remaining}, '
507
+ '{rate_fmt}{postfix}]'
508
+ Possible vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt,
509
+ percentage, elapsed, elapsed_s, ncols, nrows, desc, unit,
510
+ rate, rate_fmt, rate_noinv, rate_noinv_fmt,
511
+ rate_inv, rate_inv_fmt, postfix, unit_divisor,
512
+ remaining, remaining_s, eta.
513
+ Note that a trailing ": " is automatically removed after {desc}
514
+ if the latter is empty.
515
+ postfix : *, optional
516
+ Similar to `prefix`, but placed at the end
517
+ (e.g. for additional stats).
518
+ Note: postfix is usually a string (not a dict) for this method,
519
+ and will if possible be set to postfix = ', ' + postfix.
520
+ However other types are supported (#382).
521
+ unit_divisor : float, optional
522
+ [default: 1000], ignored unless `unit_scale` is True.
523
+ initial : int or float, optional
524
+ The initial counter value [default: 0].
525
+ colour : str, optional
526
+ Bar colour (e.g. 'green', '#00ff00').
527
+
528
+ Returns
529
+ -------
530
+ out : Formatted meter and stats, ready to display.
531
+ """
532
+
533
+ # sanity check: total
534
+ if total and n >= (total + 0.5): # allow float imprecision (#849)
535
+ total = None
536
+
537
+ # apply custom scale if necessary
538
+ if unit_scale and unit_scale not in (True, 1):
539
+ if total:
540
+ total *= unit_scale
541
+ n *= unit_scale
542
+ if rate:
543
+ rate *= unit_scale # by default rate = self.avg_dn / self.avg_dt
544
+ unit_scale = False
545
+
546
+ elapsed_str = tqdm.format_interval(elapsed)
547
+
548
+ # if unspecified, attempt to use rate = average speed
549
+ # (we allow manual override since predicting time is an arcane art)
550
+ if rate is None and elapsed:
551
+ rate = (n - initial) / elapsed
552
+ inv_rate = 1 / rate if rate else None
553
+ format_sizeof = tqdm.format_sizeof
554
+ rate_noinv_fmt = ((format_sizeof(rate) if unit_scale else f'{rate:5.2f}')
555
+ if rate else '?') + unit + '/s'
556
+ rate_inv_fmt = (
557
+ (format_sizeof(inv_rate) if unit_scale else f'{inv_rate:5.2f}')
558
+ if inv_rate else '?') + 's/' + unit
559
+ rate_fmt = rate_inv_fmt if inv_rate and inv_rate > 1 else rate_noinv_fmt
560
+
561
+ if unit_scale:
562
+ n_fmt = format_sizeof(n, divisor=unit_divisor)
563
+ total_fmt = format_sizeof(total, divisor=unit_divisor) if total is not None else '?'
564
+ else:
565
+ n_fmt = str(n)
566
+ total_fmt = str(total) if total is not None else '?'
567
+
568
+ try:
569
+ postfix = ', ' + postfix if postfix else ''
570
+ except TypeError:
571
+ pass
572
+
573
+ remaining = (total - n) / rate if rate and total else 0
574
+ remaining_str = tqdm.format_interval(remaining) if rate else '?'
575
+ try:
576
+ eta_dt = (datetime.now() + timedelta(seconds=remaining)
577
+ if rate and total else datetime.fromtimestamp(0, timezone.utc))
578
+ except OverflowError:
579
+ eta_dt = datetime.max
580
+
581
+ # format the stats displayed to the left and right sides of the bar
582
+ if prefix:
583
+ # old prefix setup work around
584
+ bool_prefix_colon_already = (prefix[-2:] == ": ")
585
+ l_bar = prefix if bool_prefix_colon_already else prefix + ": "
586
+ else:
587
+ l_bar = ''
588
+
589
+ r_bar = f'| {n_fmt}/{total_fmt} [{elapsed_str}<{remaining_str}, {rate_fmt}{postfix}]'
590
+
591
+ # Custom bar formatting
592
+ # Populate a dict with all available progress indicators
593
+ format_dict = {
594
+ # slight extension of self.format_dict
595
+ 'n': n, 'n_fmt': n_fmt, 'total': total, 'total_fmt': total_fmt,
596
+ 'elapsed': elapsed_str, 'elapsed_s': elapsed,
597
+ 'ncols': ncols, 'desc': prefix or '', 'unit': unit,
598
+ 'rate': inv_rate if inv_rate and inv_rate > 1 else rate,
599
+ 'rate_fmt': rate_fmt, 'rate_noinv': rate,
600
+ 'rate_noinv_fmt': rate_noinv_fmt, 'rate_inv': inv_rate,
601
+ 'rate_inv_fmt': rate_inv_fmt,
602
+ 'postfix': postfix, 'unit_divisor': unit_divisor,
603
+ 'colour': colour,
604
+ # plus more useful definitions
605
+ 'remaining': remaining_str, 'remaining_s': remaining,
606
+ 'l_bar': l_bar, 'r_bar': r_bar, 'eta': eta_dt,
607
+ **extra_kwargs}
608
+
609
+ # total is known: we can predict some stats
610
+ if total:
611
+ # fractional and percentage progress
612
+ frac = n / total
613
+ percentage = frac * 100
614
+
615
+ l_bar += f'{percentage:3.0f}%|'
616
+
617
+ if ncols == 0:
618
+ return l_bar[:-1] + r_bar[1:]
619
+
620
+ format_dict.update(l_bar=l_bar)
621
+ if bar_format:
622
+ format_dict.update(percentage=percentage)
623
+
624
+ # auto-remove colon for empty `{desc}`
625
+ if not prefix:
626
+ bar_format = bar_format.replace("{desc}: ", '')
627
+ else:
628
+ bar_format = "{l_bar}{bar}{r_bar}"
629
+
630
+ full_bar = FormatReplace()
631
+ nobar = bar_format.format(bar=full_bar, **format_dict)
632
+ if not full_bar.format_called:
633
+ return nobar # no `{bar}`; nothing else to do
634
+
635
+ # Formatting progress bar space available for bar's display
636
+ full_bar = Bar(frac,
637
+ max(1, ncols - disp_len(nobar)) if ncols else 10,
638
+ charset=Bar.ASCII if ascii is True else ascii or Bar.UTF,
639
+ colour=colour)
640
+ if not _is_ascii(full_bar.charset) and _is_ascii(bar_format):
641
+ bar_format = str(bar_format)
642
+ res = bar_format.format(bar=full_bar, **format_dict)
643
+ return disp_trim(res, ncols) if ncols else res
644
+
645
+ elif bar_format:
646
+ # user-specified bar_format but no total
647
+ l_bar += '|'
648
+ format_dict.update(l_bar=l_bar, percentage=0)
649
+ full_bar = FormatReplace()
650
+ nobar = bar_format.format(bar=full_bar, **format_dict)
651
+ if not full_bar.format_called:
652
+ return nobar
653
+ full_bar = Bar(0,
654
+ max(1, ncols - disp_len(nobar)) if ncols else 10,
655
+ charset=Bar.BLANK, colour=colour)
656
+ res = bar_format.format(bar=full_bar, **format_dict)
657
+ return disp_trim(res, ncols) if ncols else res
658
+ else:
659
+ # no total: no progressbar, ETA, just progress stats
660
+ return (f'{(prefix + ": ") if prefix else ""}'
661
+ f'{n_fmt}{unit} [{elapsed_str}, {rate_fmt}{postfix}]')
662
+
663
+ def __new__(cls, *_, **__):
664
+ instance = object.__new__(cls)
665
+ with cls.get_lock(): # also constructs lock if non-existent
666
+ cls._instances.add(instance)
667
+ # create monitoring thread
668
+ if cls.monitor_interval and (cls.monitor is None
669
+ or not cls.monitor.report()):
670
+ try:
671
+ cls.monitor = TMonitor(cls, cls.monitor_interval)
672
+ except Exception as e: # pragma: nocover
673
+ warn("tqdm:disabling monitor support"
674
+ " (monitor_interval = 0) due to:\n" + str(e),
675
+ TqdmMonitorWarning, stacklevel=2)
676
+ cls.monitor_interval = 0
677
+ return instance
678
+
679
+ @classmethod
680
+ def _get_free_pos(cls, instance=None):
681
+ """Skips specified instance."""
682
+ positions = {abs(inst.pos) for inst in cls._instances
683
+ if inst is not instance and hasattr(inst, "pos")}
684
+ return min(set(range(len(positions) + 1)).difference(positions))
685
+
686
+ @classmethod
687
+ def _decr_instances(cls, instance):
688
+ """
689
+ Remove from list and reposition another unfixed bar
690
+ to fill the new gap.
691
+
692
+ This means that by default (where all nested bars are unfixed),
693
+ order is not maintained but screen flicker/blank space is minimised.
694
+ (tqdm<=4.44.1 moved ALL subsequent unfixed bars up.)
695
+ """
696
+ with cls._lock:
697
+ try:
698
+ cls._instances.remove(instance)
699
+ except KeyError:
700
+ # if not instance.gui: # pragma: no cover
701
+ # raise
702
+ pass # py2: maybe magically removed already
703
+ # else:
704
+ if not instance.gui:
705
+ last = (instance.nrows or 20) - 1
706
+ # find unfixed (`pos >= 0`) overflow (`pos >= nrows - 1`)
707
+ instances = list(filter(
708
+ lambda i: hasattr(i, "pos") and last <= i.pos,
709
+ cls._instances))
710
+ # set first found to current `pos`
711
+ if instances:
712
+ inst = min(instances, key=lambda i: i.pos)
713
+ inst.clear(nolock=True)
714
+ inst.pos = abs(instance.pos)
715
+
716
+ @classmethod
717
+ def write(cls, s, file=None, end="\n", nolock=False):
718
+ """Print a message via tqdm (without overlap with bars)."""
719
+ fp = file if file is not None else sys.stdout
720
+ with cls.external_write_mode(file=file, nolock=nolock):
721
+ # Write the message
722
+ fp.write(s)
723
+ fp.write(end)
724
+
725
+ @classmethod
726
+ @contextmanager
727
+ def external_write_mode(cls, file=None, nolock=False):
728
+ """
729
+ Disable tqdm within context and refresh tqdm when exits.
730
+ Useful when writing to standard output stream
731
+ """
732
+ fp = file if file is not None else sys.stdout
733
+
734
+ try:
735
+ if not nolock:
736
+ cls.get_lock().acquire()
737
+ # Clear all bars
738
+ inst_cleared = []
739
+ for inst in getattr(cls, '_instances', []):
740
+ # Clear instance if in the target output file
741
+ # or if write output + tqdm output are both either
742
+ # sys.stdout or sys.stderr (because both are mixed in terminal)
743
+ if hasattr(inst, "start_t") and (inst.fp == fp or all(
744
+ f in (sys.stdout, sys.stderr) for f in (fp, inst.fp))):
745
+ inst.clear(nolock=True)
746
+ inst_cleared.append(inst)
747
+ yield
748
+ # Force refresh display of bars we cleared
749
+ for inst in inst_cleared:
750
+ inst.refresh(nolock=True)
751
+ finally:
752
+ if not nolock:
753
+ cls._lock.release()
754
+
755
+ @classmethod
756
+ def set_lock(cls, lock):
757
+ """Set the global lock."""
758
+ cls._lock = lock
759
+
760
+ @classmethod
761
+ def get_lock(cls):
762
+ """Get the global lock. Construct it if it does not exist."""
763
+ if not hasattr(cls, '_lock'):
764
+ cls._lock = TqdmDefaultWriteLock()
765
+ return cls._lock
766
+
767
+ @classmethod
768
+ def pandas(cls, **tqdm_kwargs):
769
+ """
770
+ Registers the current `tqdm` class with
771
+ pandas.core.
772
+ ( frame.DataFrame
773
+ | series.Series
774
+ | groupby.(generic.)DataFrameGroupBy
775
+ | groupby.(generic.)SeriesGroupBy
776
+ ).progress_apply
777
+
778
+ A new instance will be created every time `progress_apply` is called,
779
+ and each instance will automatically `close()` upon completion.
780
+
781
+ Parameters
782
+ ----------
783
+ tqdm_kwargs : arguments for the tqdm instance
784
+
785
+ Examples
786
+ --------
787
+ >>> import pandas as pd
788
+ >>> import numpy as np
789
+ >>> from tqdm import tqdm
790
+ >>> from tqdm.gui import tqdm as tqdm_gui
791
+ >>>
792
+ >>> df = pd.DataFrame(np.random.randint(0, 100, (100000, 6)))
793
+ >>> tqdm.pandas(ncols=50) # can use tqdm_gui, optional kwargs, etc
794
+ >>> # Now you can use `progress_apply` instead of `apply`
795
+ >>> df.groupby(0).progress_apply(lambda x: x**2)
796
+
797
+ References
798
+ ----------
799
+ <https://stackoverflow.com/questions/18603270/\
800
+ progress-indicator-during-pandas-operations-python>
801
+ """
802
+ from warnings import catch_warnings, simplefilter
803
+
804
+ from pandas.core.frame import DataFrame
805
+ from pandas.core.series import Series
806
+ try:
807
+ with catch_warnings():
808
+ simplefilter("ignore", category=FutureWarning)
809
+ from pandas import Panel
810
+ except ImportError: # pandas>=1.2.0
811
+ Panel = None
812
+ Rolling, Expanding = None, None
813
+ try: # pandas>=1.0.0
814
+ from pandas.core.window.rolling import _Rolling_and_Expanding
815
+ except ImportError:
816
+ try: # pandas>=0.18.0
817
+ from pandas.core.window import _Rolling_and_Expanding
818
+ except ImportError: # pandas>=1.2.0
819
+ try: # pandas>=1.2.0
820
+ from pandas.core.window.expanding import Expanding
821
+ from pandas.core.window.rolling import Rolling
822
+ _Rolling_and_Expanding = Rolling, Expanding
823
+ except ImportError: # pragma: no cover
824
+ _Rolling_and_Expanding = None
825
+ try: # pandas>=0.25.0
826
+ from pandas.core.groupby.generic import SeriesGroupBy # , NDFrameGroupBy
827
+ from pandas.core.groupby.generic import DataFrameGroupBy
828
+ except ImportError: # pragma: no cover
829
+ try: # pandas>=0.23.0
830
+ from pandas.core.groupby.groupby import DataFrameGroupBy, SeriesGroupBy
831
+ except ImportError:
832
+ from pandas.core.groupby import DataFrameGroupBy, SeriesGroupBy
833
+ try: # pandas>=0.23.0
834
+ from pandas.core.groupby.groupby import GroupBy
835
+ except ImportError: # pragma: no cover
836
+ from pandas.core.groupby import GroupBy
837
+
838
+ try: # pandas>=0.23.0
839
+ from pandas.core.groupby.groupby import PanelGroupBy
840
+ except ImportError:
841
+ try:
842
+ from pandas.core.groupby import PanelGroupBy
843
+ except ImportError: # pandas>=0.25.0
844
+ PanelGroupBy = None
845
+
846
+ tqdm_kwargs = tqdm_kwargs.copy()
847
+ deprecated_t = [tqdm_kwargs.pop('deprecated_t', None)]
848
+
849
+ def inner_generator(df_function='apply'):
850
+ def inner(df, func, *args, **kwargs):
851
+ """
852
+ Parameters
853
+ ----------
854
+ df : (DataFrame|Series)[GroupBy]
855
+ Data (may be grouped).
856
+ func : function
857
+ To be applied on the (grouped) data.
858
+ **kwargs : optional
859
+ Transmitted to `df.apply()`.
860
+ """
861
+
862
+ # Precompute total iterations
863
+ total = tqdm_kwargs.pop("total", getattr(df, 'ngroups', None))
864
+ if total is None: # not grouped
865
+ if df_function == 'applymap':
866
+ total = df.size
867
+ elif isinstance(df, Series):
868
+ total = len(df)
869
+ elif (_Rolling_and_Expanding is None or
870
+ not isinstance(df, _Rolling_and_Expanding)):
871
+ # DataFrame or Panel
872
+ axis = kwargs.get('axis', 0)
873
+ if axis == 'index':
874
+ axis = 0
875
+ elif axis == 'columns':
876
+ axis = 1
877
+ # when axis=0, total is shape[axis1]
878
+ total = df.size // df.shape[axis]
879
+
880
+ # Init bar
881
+ if deprecated_t[0] is not None:
882
+ t = deprecated_t[0]
883
+ deprecated_t[0] = None
884
+ else:
885
+ t = cls(total=total, **tqdm_kwargs)
886
+
887
+ if len(args) > 0:
888
+ # *args intentionally not supported (see #244, #299)
889
+ TqdmDeprecationWarning(
890
+ "Except func, normal arguments are intentionally" +
891
+ " not supported by" +
892
+ " `(DataFrame|Series|GroupBy).progress_apply`." +
893
+ " Use keyword arguments instead.",
894
+ fp_write=getattr(t.fp, 'write', sys.stderr.write))
895
+
896
+ try: # pandas>=1.3.0
897
+ from pandas.core.common import is_builtin_func
898
+ except ImportError:
899
+ is_builtin_func = df._is_builtin_func
900
+ try:
901
+ func = is_builtin_func(func)
902
+ except TypeError:
903
+ pass
904
+
905
+ # Define bar updating wrapper
906
+ def wrapper(*args, **kwargs):
907
+ # update tbar correctly
908
+ # it seems `pandas apply` calls `func` twice
909
+ # on the first column/row to decide whether it can
910
+ # take a fast or slow code path; so stop when t.total==t.n
911
+ t.update(n=1 if not t.total or t.n < t.total else 0)
912
+ return func(*args, **kwargs)
913
+
914
+ # Apply the provided function (in **kwargs)
915
+ # on the df using our wrapper (which provides bar updating)
916
+ try:
917
+ return getattr(df, df_function)(wrapper, **kwargs)
918
+ finally:
919
+ t.close()
920
+
921
+ return inner
922
+
923
+ # Monkeypatch pandas to provide easy methods
924
+ # Enable custom tqdm progress in pandas!
925
+ Series.progress_apply = inner_generator()
926
+ SeriesGroupBy.progress_apply = inner_generator()
927
+ Series.progress_map = inner_generator('map')
928
+ SeriesGroupBy.progress_map = inner_generator('map')
929
+
930
+ DataFrame.progress_apply = inner_generator()
931
+ DataFrameGroupBy.progress_apply = inner_generator()
932
+ DataFrame.progress_applymap = inner_generator('applymap')
933
+ DataFrame.progress_map = inner_generator('map')
934
+ DataFrameGroupBy.progress_map = inner_generator('map')
935
+
936
+ if Panel is not None:
937
+ Panel.progress_apply = inner_generator()
938
+ if PanelGroupBy is not None:
939
+ PanelGroupBy.progress_apply = inner_generator()
940
+
941
+ GroupBy.progress_apply = inner_generator()
942
+ GroupBy.progress_aggregate = inner_generator('aggregate')
943
+ GroupBy.progress_transform = inner_generator('transform')
944
+
945
+ if Rolling is not None and Expanding is not None:
946
+ Rolling.progress_apply = inner_generator()
947
+ Expanding.progress_apply = inner_generator()
948
+ elif _Rolling_and_Expanding is not None:
949
+ _Rolling_and_Expanding.progress_apply = inner_generator()
950
+
951
+ # override defaults via env vars
952
+ @envwrap("TQDM_", is_method=True, types={'total': float, 'ncols': int, 'miniters': float,
953
+ 'position': int, 'nrows': int})
954
+ def __init__(self, iterable=None, desc=None, total=None, leave=True, file=None,
955
+ ncols=None, mininterval=0.1, maxinterval=10.0, miniters=None,
956
+ ascii=None, disable=False, unit='it', unit_scale=False,
957
+ dynamic_ncols=False, smoothing=0.3, bar_format=None, initial=0,
958
+ position=None, postfix=None, unit_divisor=1000, write_bytes=False,
959
+ lock_args=None, nrows=None, colour=None, delay=0.0, gui=False,
960
+ **kwargs):
961
+ """see tqdm.tqdm for arguments"""
962
+ if file is None:
963
+ file = sys.stderr
964
+
965
+ if write_bytes:
966
+ # Despite coercing unicode into bytes, py2 sys.std* streams
967
+ # should have bytes written to them.
968
+ file = SimpleTextIOWrapper(
969
+ file, encoding=getattr(file, 'encoding', None) or 'utf-8')
970
+
971
+ file = DisableOnWriteError(file, tqdm_instance=self)
972
+
973
+ if disable is None and hasattr(file, "isatty") and not file.isatty():
974
+ disable = True
975
+
976
+ if total is None and iterable is not None:
977
+ try:
978
+ total = len(iterable)
979
+ except (TypeError, AttributeError):
980
+ total = None
981
+ if total == float("inf"):
982
+ # Infinite iterations, behave same as unknown
983
+ total = None
984
+
985
+ if disable:
986
+ self.iterable = iterable
987
+ self.disable = disable
988
+ with self._lock:
989
+ self.pos = self._get_free_pos(self)
990
+ self._instances.remove(self)
991
+ self.n = initial
992
+ self.total = total
993
+ self.leave = leave
994
+ return
995
+
996
+ if kwargs:
997
+ self.disable = True
998
+ with self._lock:
999
+ self.pos = self._get_free_pos(self)
1000
+ self._instances.remove(self)
1001
+ raise (
1002
+ TqdmDeprecationWarning(
1003
+ "`nested` is deprecated and automated.\n"
1004
+ "Use `position` instead for manual control.\n",
1005
+ fp_write=getattr(file, 'write', sys.stderr.write))
1006
+ if "nested" in kwargs else
1007
+ TqdmKeyError("Unknown argument(s): " + str(kwargs)))
1008
+
1009
+ # Preprocess the arguments
1010
+ if (
1011
+ (ncols is None or nrows is None) and (file in (sys.stderr, sys.stdout))
1012
+ ) or dynamic_ncols: # pragma: no cover
1013
+ if dynamic_ncols:
1014
+ dynamic_ncols = _screen_shape_wrapper()
1015
+ if dynamic_ncols:
1016
+ ncols, nrows = dynamic_ncols(file)
1017
+ else:
1018
+ _dynamic_ncols = _screen_shape_wrapper()
1019
+ if _dynamic_ncols:
1020
+ _ncols, _nrows = _dynamic_ncols(file)
1021
+ if ncols is None:
1022
+ ncols = _ncols
1023
+ if nrows is None:
1024
+ nrows = _nrows
1025
+
1026
+ if miniters is None:
1027
+ miniters = 0
1028
+ dynamic_miniters = True
1029
+ else:
1030
+ dynamic_miniters = False
1031
+
1032
+ if mininterval is None:
1033
+ mininterval = 0
1034
+
1035
+ if maxinterval is None:
1036
+ maxinterval = 0
1037
+
1038
+ if ascii is None:
1039
+ ascii = not _supports_unicode(file)
1040
+
1041
+ if bar_format and ascii is not True and not _is_ascii(ascii):
1042
+ # Convert bar format into unicode since terminal uses unicode
1043
+ bar_format = str(bar_format)
1044
+
1045
+ if smoothing is None:
1046
+ smoothing = 0
1047
+
1048
+ # Store the arguments
1049
+ self.iterable = iterable
1050
+ self.desc = desc or ''
1051
+ self.total = total
1052
+ self.leave = leave
1053
+ self.fp = file
1054
+ self.ncols = ncols
1055
+ self.nrows = nrows
1056
+ self.mininterval = mininterval
1057
+ self.maxinterval = maxinterval
1058
+ self.miniters = miniters
1059
+ self.dynamic_miniters = dynamic_miniters
1060
+ self.ascii = ascii
1061
+ self.disable = disable
1062
+ self.unit = unit
1063
+ self.unit_scale = unit_scale
1064
+ self.unit_divisor = unit_divisor
1065
+ self.initial = initial
1066
+ self.lock_args = lock_args
1067
+ self.delay = delay
1068
+ self.gui = gui
1069
+ self.dynamic_ncols = dynamic_ncols
1070
+ self.smoothing = smoothing
1071
+ self._ema_dn = EMA(smoothing)
1072
+ self._ema_dt = EMA(smoothing)
1073
+ self._ema_miniters = EMA(smoothing)
1074
+ self.bar_format = bar_format
1075
+ self.postfix = None
1076
+ self.colour = colour
1077
+ self._time = time
1078
+ if postfix:
1079
+ try:
1080
+ self.set_postfix(refresh=False, **postfix)
1081
+ except TypeError:
1082
+ self.postfix = postfix
1083
+
1084
+ # Init the iterations counters
1085
+ self.last_print_n = initial
1086
+ self.n = initial
1087
+
1088
+ # if nested, at initial sp() call we replace '\r' by '\n' to
1089
+ # not overwrite the outer progress bar
1090
+ with self._lock:
1091
+ # mark fixed positions as negative
1092
+ self.pos = self._get_free_pos(self) if position is None else -position
1093
+
1094
+ if not gui:
1095
+ # Initialize the screen printer
1096
+ self.sp = self.status_printer(self.fp)
1097
+ if delay <= 0:
1098
+ self.refresh(lock_args=self.lock_args)
1099
+
1100
+ # Init the time counter
1101
+ self.last_print_t = self._time()
1102
+ # NB: Avoid race conditions by setting start_t at the very end of init
1103
+ self.start_t = self.last_print_t
1104
+
1105
+ def __bool__(self):
1106
+ if self.total is not None:
1107
+ return self.total > 0
1108
+ if self.iterable is None:
1109
+ raise TypeError('bool() undefined when iterable == total == None')
1110
+ return bool(self.iterable)
1111
+
1112
+ def __len__(self):
1113
+ return (
1114
+ self.total if self.iterable is None
1115
+ else self.iterable.shape[0] if hasattr(self.iterable, "shape")
1116
+ else len(self.iterable) if hasattr(self.iterable, "__len__")
1117
+ else self.iterable.__length_hint__() if hasattr(self.iterable, "__length_hint__")
1118
+ else getattr(self, "total", None))
1119
+
1120
+ def __reversed__(self):
1121
+ try:
1122
+ orig = self.iterable
1123
+ except AttributeError:
1124
+ raise TypeError("'tqdm' object is not reversible")
1125
+ else:
1126
+ self.iterable = reversed(self.iterable)
1127
+ return self.__iter__()
1128
+ finally:
1129
+ self.iterable = orig
1130
+
1131
+ def __contains__(self, item):
1132
+ contains = getattr(self.iterable, '__contains__', None)
1133
+ return contains(item) if contains is not None else item in self.__iter__()
1134
+
1135
+ def __enter__(self):
1136
+ return self
1137
+
1138
+ def __exit__(self, exc_type, exc_value, traceback):
1139
+ try:
1140
+ self.close()
1141
+ except AttributeError:
1142
+ # maybe eager thread cleanup upon external error
1143
+ if (exc_type, exc_value, traceback) == (None, None, None):
1144
+ raise
1145
+ warn("AttributeError ignored", TqdmWarning, stacklevel=2)
1146
+
1147
+ def __del__(self):
1148
+ self.close()
1149
+
1150
+ def __str__(self):
1151
+ return self.format_meter(**self.format_dict)
1152
+
1153
+ @property
1154
+ def _comparable(self):
1155
+ return abs(getattr(self, "pos", 1 << 31))
1156
+
1157
+ def __hash__(self):
1158
+ return id(self)
1159
+
1160
+ def __iter__(self):
1161
+ """Backward-compatibility to use: for x in tqdm(iterable)"""
1162
+
1163
+ # Inlining instance variables as locals (speed optimisation)
1164
+ iterable = self.iterable
1165
+
1166
+ # If the bar is disabled, then just walk the iterable
1167
+ # (note: keep this check outside the loop for performance)
1168
+ if self.disable:
1169
+ for obj in iterable:
1170
+ yield obj
1171
+ return
1172
+
1173
+ mininterval = self.mininterval
1174
+ last_print_t = self.last_print_t
1175
+ last_print_n = self.last_print_n
1176
+ min_start_t = self.start_t + self.delay
1177
+ n = self.n
1178
+ time = self._time
1179
+
1180
+ try:
1181
+ for obj in iterable:
1182
+ yield obj
1183
+ # Update and possibly print the progressbar.
1184
+ # Note: does not call self.update(1) for speed optimisation.
1185
+ n += 1
1186
+
1187
+ if n - last_print_n >= self.miniters:
1188
+ cur_t = time()
1189
+ dt = cur_t - last_print_t
1190
+ if dt >= mininterval and cur_t >= min_start_t:
1191
+ self.update(n - last_print_n)
1192
+ last_print_n = self.last_print_n
1193
+ last_print_t = self.last_print_t
1194
+ finally:
1195
+ self.n = n
1196
+ self.close()
1197
+
1198
+ def update(self, n=1):
1199
+ """
1200
+ Manually update the progress bar, useful for streams
1201
+ such as reading files.
1202
+ E.g.:
1203
+ >>> t = tqdm(total=filesize) # Initialise
1204
+ >>> for current_buffer in stream:
1205
+ ... ...
1206
+ ... t.update(len(current_buffer))
1207
+ >>> t.close()
1208
+ The last line is highly recommended, but possibly not necessary if
1209
+ `t.update()` will be called in such a way that `filesize` will be
1210
+ exactly reached and printed.
1211
+
1212
+ Parameters
1213
+ ----------
1214
+ n : int or float, optional
1215
+ Increment to add to the internal counter of iterations
1216
+ [default: 1]. If using float, consider specifying `{n:.3f}`
1217
+ or similar in `bar_format`, or specifying `unit_scale`.
1218
+
1219
+ Returns
1220
+ -------
1221
+ out : bool or None
1222
+ True if a `display()` was triggered.
1223
+ """
1224
+ if self.disable:
1225
+ return
1226
+
1227
+ if n < 0:
1228
+ self.last_print_n += n # for auto-refresh logic to work
1229
+ self.n += n
1230
+
1231
+ # check counter first to reduce calls to time()
1232
+ if self.n - self.last_print_n >= self.miniters:
1233
+ cur_t = self._time()
1234
+ dt = cur_t - self.last_print_t
1235
+ if dt >= self.mininterval and cur_t >= self.start_t + self.delay:
1236
+ cur_t = self._time()
1237
+ dn = self.n - self.last_print_n # >= n
1238
+ if self.smoothing and dt and dn:
1239
+ # EMA (not just overall average)
1240
+ self._ema_dn(dn)
1241
+ self._ema_dt(dt)
1242
+ self.refresh(lock_args=self.lock_args)
1243
+ if self.dynamic_miniters:
1244
+ # If no `miniters` was specified, adjust automatically to the
1245
+ # maximum iteration rate seen so far between two prints.
1246
+ # e.g.: After running `tqdm.update(5)`, subsequent
1247
+ # calls to `tqdm.update()` will only cause an update after
1248
+ # at least 5 more iterations.
1249
+ if self.maxinterval and dt >= self.maxinterval:
1250
+ self.miniters = dn * (self.mininterval or self.maxinterval) / dt
1251
+ elif self.smoothing:
1252
+ # EMA miniters update
1253
+ self.miniters = self._ema_miniters(
1254
+ dn * (self.mininterval / dt if self.mininterval and dt
1255
+ else 1))
1256
+ else:
1257
+ # max iters between two prints
1258
+ self.miniters = max(self.miniters, dn)
1259
+
1260
+ # Store old values for next call
1261
+ self.last_print_n = self.n
1262
+ self.last_print_t = cur_t
1263
+ return True
1264
+
1265
+ def close(self):
1266
+ """Cleanup and (if leave=False) close the progressbar."""
1267
+ if self.disable:
1268
+ return
1269
+
1270
+ # Prevent multiple closures
1271
+ self.disable = True
1272
+
1273
+ # decrement instance pos and remove from internal set
1274
+ pos = abs(self.pos)
1275
+ self._decr_instances(self)
1276
+
1277
+ if self.last_print_t < self.start_t + self.delay:
1278
+ # haven't ever displayed; nothing to clear
1279
+ return
1280
+
1281
+ # GUI mode
1282
+ if getattr(self, 'sp', None) is None:
1283
+ return
1284
+
1285
+ # annoyingly, _supports_unicode isn't good enough
1286
+ def fp_write(s):
1287
+ self.fp.write(str(s))
1288
+
1289
+ try:
1290
+ fp_write('')
1291
+ except ValueError as e:
1292
+ if 'closed' in str(e):
1293
+ return
1294
+ raise # pragma: no cover
1295
+
1296
+ leave = pos == 0 if self.leave is None else self.leave
1297
+
1298
+ with self._lock:
1299
+ if leave:
1300
+ # stats for overall rate (no weighted average)
1301
+ self._ema_dt = lambda: None
1302
+ self.display(pos=0)
1303
+ fp_write('\n')
1304
+ else:
1305
+ # clear previous display
1306
+ if self.display(msg='', pos=pos) and not pos:
1307
+ fp_write('\r')
1308
+
1309
+ def clear(self, nolock=False):
1310
+ """Clear current bar display."""
1311
+ if self.disable:
1312
+ return
1313
+
1314
+ if not nolock:
1315
+ self._lock.acquire()
1316
+ pos = abs(self.pos)
1317
+ if pos < (self.nrows or 20):
1318
+ self.moveto(pos)
1319
+ self.sp('')
1320
+ self.fp.write('\r') # place cursor back at the beginning of line
1321
+ self.moveto(-pos)
1322
+ if not nolock:
1323
+ self._lock.release()
1324
+
1325
+ def refresh(self, nolock=False, lock_args=None):
1326
+ """
1327
+ Force refresh the display of this bar.
1328
+
1329
+ Parameters
1330
+ ----------
1331
+ nolock : bool, optional
1332
+ If `True`, does not lock.
1333
+ If [default: `False`]: calls `acquire()` on internal lock.
1334
+ lock_args : tuple, optional
1335
+ Passed to internal lock's `acquire()`.
1336
+ If specified, will only `display()` if `acquire()` returns `True`.
1337
+ """
1338
+ if self.disable:
1339
+ return
1340
+
1341
+ if not nolock:
1342
+ if lock_args:
1343
+ if not self._lock.acquire(*lock_args):
1344
+ return False
1345
+ else:
1346
+ self._lock.acquire()
1347
+ self.display()
1348
+ if not nolock:
1349
+ self._lock.release()
1350
+ return True
1351
+
1352
+ def unpause(self):
1353
+ """Restart tqdm timer from last print time."""
1354
+ if self.disable:
1355
+ return
1356
+ cur_t = self._time()
1357
+ self.start_t += cur_t - self.last_print_t
1358
+ self.last_print_t = cur_t
1359
+
1360
+ def reset(self, total=None):
1361
+ """
1362
+ Resets to 0 iterations for repeated use.
1363
+
1364
+ Consider combining with `leave=True`.
1365
+
1366
+ Parameters
1367
+ ----------
1368
+ total : int or float, optional. Total to use for the new bar.
1369
+ """
1370
+ self.n = 0
1371
+ if total is not None:
1372
+ self.total = total
1373
+ if self.disable:
1374
+ return
1375
+ self.last_print_n = 0
1376
+ self.last_print_t = self.start_t = self._time()
1377
+ self._ema_dn = EMA(self.smoothing)
1378
+ self._ema_dt = EMA(self.smoothing)
1379
+ self._ema_miniters = EMA(self.smoothing)
1380
+ self.refresh()
1381
+
1382
+ def set_description(self, desc=None, refresh=True):
1383
+ """
1384
+ Set/modify description of the progress bar.
1385
+
1386
+ Parameters
1387
+ ----------
1388
+ desc : str, optional
1389
+ refresh : bool, optional
1390
+ Forces refresh [default: True].
1391
+ """
1392
+ self.desc = desc + ': ' if desc else ''
1393
+ if refresh:
1394
+ self.refresh()
1395
+
1396
+ def set_description_str(self, desc=None, refresh=True):
1397
+ """Set/modify description without ': ' appended."""
1398
+ self.desc = desc or ''
1399
+ if refresh:
1400
+ self.refresh()
1401
+
1402
+ def set_postfix(self, ordered_dict=None, refresh=True, **kwargs):
1403
+ """
1404
+ Set/modify postfix (additional stats)
1405
+ with automatic formatting based on datatype.
1406
+
1407
+ Parameters
1408
+ ----------
1409
+ ordered_dict : dict or OrderedDict, optional
1410
+ refresh : bool, optional
1411
+ Forces refresh [default: True].
1412
+ kwargs : dict, optional
1413
+ """
1414
+ # Sort in alphabetical order to be more deterministic
1415
+ postfix = OrderedDict([] if ordered_dict is None else ordered_dict)
1416
+ for key in sorted(kwargs.keys()):
1417
+ postfix[key] = kwargs[key]
1418
+ # Preprocess stats according to datatype
1419
+ for key in postfix.keys():
1420
+ # Number: limit the length of the string
1421
+ if isinstance(postfix[key], Number):
1422
+ postfix[key] = self.format_num(postfix[key])
1423
+ # Else for any other type, try to get the string conversion
1424
+ elif not isinstance(postfix[key], str):
1425
+ postfix[key] = str(postfix[key])
1426
+ # Else if it's a string, don't need to preprocess anything
1427
+ # Stitch together to get the final postfix
1428
+ self.postfix = ', '.join(key + '=' + postfix[key].strip()
1429
+ for key in postfix.keys())
1430
+ if refresh:
1431
+ self.refresh()
1432
+
1433
+ def set_postfix_str(self, s='', refresh=True):
1434
+ """
1435
+ Postfix without dictionary expansion, similar to prefix handling.
1436
+ """
1437
+ self.postfix = str(s)
1438
+ if refresh:
1439
+ self.refresh()
1440
+
1441
+ def moveto(self, n):
1442
+ # TODO: private method
1443
+ self.fp.write('\n' * n + _term_move_up() * -n)
1444
+ getattr(self.fp, 'flush', lambda: None)()
1445
+
1446
+ @property
1447
+ def format_dict(self):
1448
+ """Public API for read-only member access."""
1449
+ if self.disable and not hasattr(self, 'unit'):
1450
+ return defaultdict(lambda: None, {
1451
+ 'n': self.n, 'total': self.total, 'elapsed': 0, 'unit': 'it'})
1452
+ if self.dynamic_ncols:
1453
+ self.ncols, self.nrows = self.dynamic_ncols(self.fp)
1454
+ return {
1455
+ 'n': self.n, 'total': self.total,
1456
+ 'elapsed': self._time() - self.start_t if hasattr(self, 'start_t') else 0,
1457
+ 'ncols': self.ncols, 'nrows': self.nrows, 'prefix': self.desc,
1458
+ 'ascii': self.ascii, 'unit': self.unit, 'unit_scale': self.unit_scale,
1459
+ 'rate': self._ema_dn() / self._ema_dt() if self._ema_dt() else None,
1460
+ 'bar_format': self.bar_format, 'postfix': self.postfix,
1461
+ 'unit_divisor': self.unit_divisor, 'initial': self.initial,
1462
+ 'colour': self.colour}
1463
+
1464
+ def display(self, msg=None, pos=None):
1465
+ """
1466
+ Use `self.sp` to display `msg` in the specified `pos`.
1467
+
1468
+ Consider overloading this function when inheriting to use e.g.:
1469
+ `self.some_frontend(**self.format_dict)` instead of `self.sp`.
1470
+
1471
+ Parameters
1472
+ ----------
1473
+ msg : str, optional. What to display (default: `repr(self)`).
1474
+ pos : int, optional. Position to `moveto`
1475
+ (default: `abs(self.pos)`).
1476
+ """
1477
+ if pos is None:
1478
+ pos = abs(self.pos)
1479
+
1480
+ nrows = self.nrows or 20
1481
+ if pos >= nrows - 1:
1482
+ if pos >= nrows:
1483
+ return False
1484
+ if msg or msg is None: # override at `nrows - 1`
1485
+ msg = " ... (more hidden) ..."
1486
+
1487
+ if not hasattr(self, "sp"):
1488
+ raise TqdmDeprecationWarning(
1489
+ "Please use `tqdm.gui.tqdm(...)`"
1490
+ " instead of `tqdm(..., gui=True)`\n",
1491
+ fp_write=getattr(self.fp, 'write', sys.stderr.write))
1492
+
1493
+ if pos:
1494
+ self.moveto(pos)
1495
+ self.sp(self.__str__() if msg is None else msg)
1496
+ if pos:
1497
+ self.moveto(-pos)
1498
+ return True
1499
+
1500
+ @classmethod
1501
+ @contextmanager
1502
+ def wrapattr(cls, stream, method, total=None, bytes=True, **tqdm_kwargs):
1503
+ """
1504
+ stream : file-like object.
1505
+ method : str, "read" or "write". The result of `read()` and
1506
+ the first argument of `write()` should have a `len()`.
1507
+
1508
+ >>> with tqdm.wrapattr(file_obj, "read", total=file_obj.size) as fobj:
1509
+ ... while True:
1510
+ ... chunk = fobj.read(chunk_size)
1511
+ ... if not chunk:
1512
+ ... break
1513
+ """
1514
+ with cls(total=total, **tqdm_kwargs) as t:
1515
+ if bytes:
1516
+ t.unit = "B"
1517
+ t.unit_scale = True
1518
+ t.unit_divisor = 1024
1519
+ yield CallbackIOWrapper(t.update, stream, method)
1520
+
1521
+
1522
+ def trange(*args, **kwargs):
1523
+ """Shortcut for tqdm(range(*args), **kwargs)."""
1524
+ return tqdm(range(*args), **kwargs)
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/tk.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Tkinter GUI progressbar decorator for iterators.
3
+
4
+ Usage:
5
+ >>> from tqdm.tk import trange, tqdm
6
+ >>> for i in trange(10):
7
+ ... ...
8
+ """
9
+ import re
10
+ import sys
11
+ import tkinter
12
+ import tkinter.ttk as ttk
13
+ from warnings import warn
14
+
15
+ from .std import TqdmExperimentalWarning, TqdmWarning
16
+ from .std import tqdm as std_tqdm
17
+
18
+ __author__ = {"github.com/": ["richardsheridan", "casperdcl"]}
19
+ __all__ = ['tqdm_tk', 'ttkrange', 'tqdm', 'trange']
20
+
21
+
22
+ class tqdm_tk(std_tqdm): # pragma: no cover
23
+ """
24
+ Experimental Tkinter GUI version of tqdm!
25
+
26
+ Note: Window interactivity suffers if `tqdm_tk` is not running within
27
+ a Tkinter mainloop and values are generated infrequently. In this case,
28
+ consider calling `tqdm_tk.refresh()` frequently in the Tk thread.
29
+ """
30
+
31
+ # TODO: @classmethod: write()?
32
+
33
+ def __init__(self, *args, **kwargs):
34
+ """
35
+ This class accepts the following parameters *in addition* to
36
+ the parameters accepted by `tqdm`.
37
+
38
+ Parameters
39
+ ----------
40
+ grab : bool, optional
41
+ Grab the input across all windows of the process.
42
+ tk_parent : `tkinter.Wm`, optional
43
+ Parent Tk window.
44
+ cancel_callback : Callable, optional
45
+ Create a cancel button and set `cancel_callback` to be called
46
+ when the cancel or window close button is clicked.
47
+ """
48
+ kwargs = kwargs.copy()
49
+ kwargs['gui'] = True
50
+ # convert disable = None to False
51
+ kwargs['disable'] = bool(kwargs.get('disable', False))
52
+ self._warn_leave = 'leave' in kwargs
53
+ grab = kwargs.pop('grab', False)
54
+ tk_parent = kwargs.pop('tk_parent', None)
55
+ self._cancel_callback = kwargs.pop('cancel_callback', None)
56
+ super().__init__(*args, **kwargs)
57
+
58
+ if self.disable:
59
+ return
60
+
61
+ if tk_parent is None: # Discover parent widget
62
+ try:
63
+ tk_parent = tkinter._default_root
64
+ except AttributeError:
65
+ raise AttributeError(
66
+ "`tk_parent` required when using `tkinter.NoDefaultRoot()`")
67
+ if tk_parent is None: # use new default root window as display
68
+ self._tk_window = tkinter.Tk()
69
+ else: # some other windows already exist
70
+ self._tk_window = tkinter.Toplevel()
71
+ else:
72
+ self._tk_window = tkinter.Toplevel(tk_parent)
73
+
74
+ warn("GUI is experimental/alpha", TqdmExperimentalWarning, stacklevel=2)
75
+ self._tk_dispatching = self._tk_dispatching_helper()
76
+
77
+ self._tk_window.protocol("WM_DELETE_WINDOW", self.cancel)
78
+ self._tk_window.wm_title(self.desc)
79
+ self._tk_window.wm_attributes("-topmost", 1)
80
+ self._tk_window.after(0, lambda: self._tk_window.wm_attributes("-topmost", 0))
81
+ self._tk_n_var = tkinter.DoubleVar(self._tk_window, value=0)
82
+ self._tk_text_var = tkinter.StringVar(self._tk_window)
83
+ pbar_frame = ttk.Frame(self._tk_window, padding=5)
84
+ pbar_frame.pack()
85
+ _tk_label = ttk.Label(pbar_frame, textvariable=self._tk_text_var,
86
+ wraplength=600, anchor="center", justify="center")
87
+ _tk_label.pack()
88
+ self._tk_pbar = ttk.Progressbar(
89
+ pbar_frame, variable=self._tk_n_var, length=450)
90
+ if self.total is not None:
91
+ self._tk_pbar.configure(maximum=self.total)
92
+ else:
93
+ self._tk_pbar.configure(mode="indeterminate")
94
+ self._tk_pbar.pack()
95
+ if self._cancel_callback is not None:
96
+ _tk_button = ttk.Button(pbar_frame, text="Cancel", command=self.cancel)
97
+ _tk_button.pack()
98
+ if grab:
99
+ self._tk_window.grab_set()
100
+
101
+ def close(self):
102
+ if self.disable:
103
+ return
104
+
105
+ self.disable = True
106
+
107
+ with self.get_lock():
108
+ self._instances.remove(self)
109
+
110
+ def _close():
111
+ self._tk_window.after('idle', self._tk_window.destroy)
112
+ if not self._tk_dispatching:
113
+ self._tk_window.update()
114
+
115
+ self._tk_window.protocol("WM_DELETE_WINDOW", _close)
116
+
117
+ # if leave is set but we are self-dispatching, the left window is
118
+ # totally unresponsive unless the user manually dispatches
119
+ if not self.leave:
120
+ _close()
121
+ elif not self._tk_dispatching:
122
+ if self._warn_leave:
123
+ warn("leave flag ignored if not in tkinter mainloop",
124
+ TqdmWarning, stacklevel=2)
125
+ _close()
126
+
127
+ def clear(self, *_, **__):
128
+ pass
129
+
130
+ def display(self, *_, **__):
131
+ self._tk_n_var.set(self.n)
132
+ d = self.format_dict
133
+ # remove {bar}
134
+ d['bar_format'] = (d['bar_format'] or "{l_bar}<bar/>{r_bar}").replace(
135
+ "{bar}", "<bar/>")
136
+ msg = self.format_meter(**d)
137
+ if '<bar/>' in msg:
138
+ msg = "".join(re.split(r'\|?<bar/>\|?', msg, maxsplit=1))
139
+ self._tk_text_var.set(msg)
140
+ if not self._tk_dispatching:
141
+ self._tk_window.update()
142
+
143
+ def set_description(self, desc=None, refresh=True):
144
+ self.set_description_str(desc, refresh)
145
+
146
+ def set_description_str(self, desc=None, refresh=True):
147
+ self.desc = desc
148
+ if not self.disable:
149
+ self._tk_window.wm_title(desc)
150
+ if refresh and not self._tk_dispatching:
151
+ self._tk_window.update()
152
+
153
+ def cancel(self):
154
+ """
155
+ `cancel_callback()` followed by `close()`
156
+ when close/cancel buttons clicked.
157
+ """
158
+ if self._cancel_callback is not None:
159
+ self._cancel_callback()
160
+ self.close()
161
+
162
+ def reset(self, total=None):
163
+ """
164
+ Resets to 0 iterations for repeated use.
165
+
166
+ Parameters
167
+ ----------
168
+ total : int or float, optional. Total to use for the new bar.
169
+ """
170
+ if hasattr(self, '_tk_pbar'):
171
+ if total is None:
172
+ self._tk_pbar.configure(maximum=100, mode="indeterminate")
173
+ else:
174
+ self._tk_pbar.configure(maximum=total, mode="determinate")
175
+ super().reset(total=total)
176
+
177
+ @staticmethod
178
+ def _tk_dispatching_helper():
179
+ """determine if Tkinter mainloop is dispatching events"""
180
+ codes = {tkinter.mainloop.__code__, tkinter.Misc.mainloop.__code__}
181
+ for frame in sys._current_frames().values():
182
+ while frame:
183
+ if frame.f_code in codes:
184
+ return True
185
+ frame = frame.f_back
186
+ return False
187
+
188
+
189
+ def ttkrange(*args, **kwargs):
190
+ """Shortcut for `tqdm.tk.tqdm(range(*args), **kwargs)`."""
191
+ return tqdm_tk(range(*args), **kwargs)
192
+
193
+
194
+ # Aliases
195
+ tqdm = tqdm_tk
196
+ trange = ttkrange
opencompass/.eggs/tqdm-4.67.1-py3.10.egg/tqdm/tqdm.1 ADDED
@@ -0,0 +1,314 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .\" Automatically generated by Pandoc 1.19.2
2
+ .\"
3
+ .TH "TQDM" "1" "2015\-2021" "tqdm User Manuals" ""
4
+ .hy
5
+ .SH NAME
6
+ .PP
7
+ tqdm \- fast, extensible progress bar for Python and CLI
8
+ .SH SYNOPSIS
9
+ .PP
10
+ tqdm [\f[I]options\f[]]
11
+ .SH DESCRIPTION
12
+ .PP
13
+ See <https://github.com/tqdm/tqdm>.
14
+ Can be used as a pipe:
15
+ .IP
16
+ .nf
17
+ \f[C]
18
+ $\ #\ count\ lines\ of\ code
19
+ $\ cat\ *.py\ |\ tqdm\ |\ wc\ \-l
20
+ 327it\ [00:00,\ 981773.38it/s]
21
+ 327
22
+
23
+ $\ #\ find\ all\ files
24
+ $\ find\ .\ \-name\ "*.py"\ |\ tqdm\ |\ wc\ \-l
25
+ 432it\ [00:00,\ 833842.30it/s]
26
+ 432
27
+
28
+ #\ ...\ and\ more\ info
29
+ $\ find\ .\ \-name\ \[aq]*.py\[aq]\ \-exec\ wc\ \-l\ \\{}\ \\;\ \\
30
+ \ \ |\ tqdm\ \-\-total\ 432\ \-\-unit\ files\ \-\-desc\ counting\ \\
31
+ \ \ |\ awk\ \[aq]{\ sum\ +=\ $1\ };\ END\ {\ print\ sum\ }\[aq]
32
+ counting:\ 100%|█████████|\ 432/432\ [00:00<00:00,\ 794361.83files/s]
33
+ 131998
34
+ \f[]
35
+ .fi
36
+ .SH OPTIONS
37
+ .TP
38
+ .B \-h, \-\-help
39
+ Print this help and exit.
40
+ .RS
41
+ .RE
42
+ .TP
43
+ .B \-v, \-\-version
44
+ Print version and exit.
45
+ .RS
46
+ .RE
47
+ .TP
48
+ .B \-\-desc=\f[I]desc\f[]
49
+ str, optional.
50
+ Prefix for the progressbar.
51
+ .RS
52
+ .RE
53
+ .TP
54
+ .B \-\-total=\f[I]total\f[]
55
+ int or float, optional.
56
+ The number of expected iterations.
57
+ If unspecified, len(iterable) is used if possible.
58
+ If float("inf") or as a last resort, only basic progress statistics are
59
+ displayed (no ETA, no progressbar).
60
+ If \f[C]gui\f[] is True and this parameter needs subsequent updating,
61
+ specify an initial arbitrary large positive number, e.g.
62
+ 9e9.
63
+ .RS
64
+ .RE
65
+ .TP
66
+ .B \-\-leave
67
+ bool, optional.
68
+ If [default: True], keeps all traces of the progressbar upon termination
69
+ of iteration.
70
+ If \f[C]None\f[], will leave only if \f[C]position\f[] is \f[C]0\f[].
71
+ .RS
72
+ .RE
73
+ .TP
74
+ .B \-\-ncols=\f[I]ncols\f[]
75
+ int, optional.
76
+ The width of the entire output message.
77
+ If specified, dynamically resizes the progressbar to stay within this
78
+ bound.
79
+ If unspecified, attempts to use environment width.
80
+ The fallback is a meter width of 10 and no limit for the counter and
81
+ statistics.
82
+ If 0, will not print any meter (only stats).
83
+ .RS
84
+ .RE
85
+ .TP
86
+ .B \-\-mininterval=\f[I]mininterval\f[]
87
+ float, optional.
88
+ Minimum progress display update interval [default: 0.1] seconds.
89
+ .RS
90
+ .RE
91
+ .TP
92
+ .B \-\-maxinterval=\f[I]maxinterval\f[]
93
+ float, optional.
94
+ Maximum progress display update interval [default: 10] seconds.
95
+ Automatically adjusts \f[C]miniters\f[] to correspond to
96
+ \f[C]mininterval\f[] after long display update lag.
97
+ Only works if \f[C]dynamic_miniters\f[] or monitor thread is enabled.
98
+ .RS
99
+ .RE
100
+ .TP
101
+ .B \-\-miniters=\f[I]miniters\f[]
102
+ int or float, optional.
103
+ Minimum progress display update interval, in iterations.
104
+ If 0 and \f[C]dynamic_miniters\f[], will automatically adjust to equal
105
+ \f[C]mininterval\f[] (more CPU efficient, good for tight loops).
106
+ If > 0, will skip display of specified number of iterations.
107
+ Tweak this and \f[C]mininterval\f[] to get very efficient loops.
108
+ If your progress is erratic with both fast and slow iterations (network,
109
+ skipping items, etc) you should set miniters=1.
110
+ .RS
111
+ .RE
112
+ .TP
113
+ .B \-\-ascii=\f[I]ascii\f[]
114
+ bool or str, optional.
115
+ If unspecified or False, use unicode (smooth blocks) to fill the meter.
116
+ The fallback is to use ASCII characters " 123456789#".
117
+ .RS
118
+ .RE
119
+ .TP
120
+ .B \-\-disable
121
+ bool, optional.
122
+ Whether to disable the entire progressbar wrapper [default: False].
123
+ If set to None, disable on non\-TTY.
124
+ .RS
125
+ .RE
126
+ .TP
127
+ .B \-\-unit=\f[I]unit\f[]
128
+ str, optional.
129
+ String that will be used to define the unit of each iteration [default:
130
+ it].
131
+ .RS
132
+ .RE
133
+ .TP
134
+ .B \-\-unit\-scale=\f[I]unit_scale\f[]
135
+ bool or int or float, optional.
136
+ If 1 or True, the number of iterations will be reduced/scaled
137
+ automatically and a metric prefix following the International System of
138
+ Units standard will be added (kilo, mega, etc.) [default: False].
139
+ If any other non\-zero number, will scale \f[C]total\f[] and \f[C]n\f[].
140
+ .RS
141
+ .RE
142
+ .TP
143
+ .B \-\-dynamic\-ncols
144
+ bool, optional.
145
+ If set, constantly alters \f[C]ncols\f[] and \f[C]nrows\f[] to the
146
+ environment (allowing for window resizes) [default: False].
147
+ .RS
148
+ .RE
149
+ .TP
150
+ .B \-\-smoothing=\f[I]smoothing\f[]
151
+ float, optional.
152
+ Exponential moving average smoothing factor for speed estimates (ignored
153
+ in GUI mode).
154
+ Ranges from 0 (average speed) to 1 (current/instantaneous speed)
155
+ [default: 0.3].
156
+ .RS
157
+ .RE
158
+ .TP
159
+ .B \-\-bar\-format=\f[I]bar_format\f[]
160
+ str, optional.
161
+ Specify a custom bar string formatting.
162
+ May impact performance.
163
+ [default: \[aq]{l_bar}{bar}{r_bar}\[aq]], where l_bar=\[aq]{desc}:
164
+ {percentage:3.0f}%|\[aq] and r_bar=\[aq]| {n_fmt}/{total_fmt}
165
+ [{elapsed}<{remaining}, \[aq] \[aq]{rate_fmt}{postfix}]\[aq] Possible
166
+ vars: l_bar, bar, r_bar, n, n_fmt, total, total_fmt, percentage,
167
+ elapsed, elapsed_s, ncols, nrows, desc, unit, rate, rate_fmt,
168
+ rate_noinv, rate_noinv_fmt, rate_inv, rate_inv_fmt, postfix,
169
+ unit_divisor, remaining, remaining_s, eta.
170
+ Note that a trailing ": " is automatically removed after {desc} if the
171
+ latter is empty.
172
+ .RS
173
+ .RE
174
+ .TP
175
+ .B \-\-initial=\f[I]initial\f[]
176
+ int or float, optional.
177
+ The initial counter value.
178
+ Useful when restarting a progress bar [default: 0].
179
+ If using float, consider specifying \f[C]{n:.3f}\f[] or similar in
180
+ \f[C]bar_format\f[], or specifying \f[C]unit_scale\f[].
181
+ .RS
182
+ .RE
183
+ .TP
184
+ .B \-\-position=\f[I]position\f[]
185
+ int, optional.
186
+ Specify the line offset to print this bar (starting from 0) Automatic if
187
+ unspecified.
188
+ Useful to manage multiple bars at once (eg, from threads).
189
+ .RS
190
+ .RE
191
+ .TP
192
+ .B \-\-postfix=\f[I]postfix\f[]
193
+ dict or *, optional.
194
+ Specify additional stats to display at the end of the bar.
195
+ Calls \f[C]set_postfix(**postfix)\f[] if possible (dict).
196
+ .RS
197
+ .RE
198
+ .TP
199
+ .B \-\-unit\-divisor=\f[I]unit_divisor\f[]
200
+ float, optional.
201
+ [default: 1000], ignored unless \f[C]unit_scale\f[] is True.
202
+ .RS
203
+ .RE
204
+ .TP
205
+ .B \-\-write\-bytes
206
+ bool, optional.
207
+ Whether to write bytes.
208
+ If (default: False) will write unicode.
209
+ .RS
210
+ .RE
211
+ .TP
212
+ .B \-\-lock\-args=\f[I]lock_args\f[]
213
+ tuple, optional.
214
+ Passed to \f[C]refresh\f[] for intermediate output (initialisation,
215
+ iterating, and updating).
216
+ .RS
217
+ .RE
218
+ .TP
219
+ .B \-\-nrows=\f[I]nrows\f[]
220
+ int, optional.
221
+ The screen height.
222
+ If specified, hides nested bars outside this bound.
223
+ If unspecified, attempts to use environment height.
224
+ The fallback is 20.
225
+ .RS
226
+ .RE
227
+ .TP
228
+ .B \-\-colour=\f[I]colour\f[]
229
+ str, optional.
230
+ Bar colour (e.g.
231
+ \[aq]green\[aq], \[aq]#00ff00\[aq]).
232
+ .RS
233
+ .RE
234
+ .TP
235
+ .B \-\-delay=\f[I]delay\f[]
236
+ float, optional.
237
+ Don\[aq]t display until [default: 0] seconds have elapsed.
238
+ .RS
239
+ .RE
240
+ .TP
241
+ .B \-\-delim=\f[I]delim\f[]
242
+ chr, optional.
243
+ Delimiting character [default: \[aq]\\n\[aq]].
244
+ Use \[aq]\\0\[aq] for null.
245
+ N.B.: on Windows systems, Python converts \[aq]\\n\[aq] to
246
+ \[aq]\\r\\n\[aq].
247
+ .RS
248
+ .RE
249
+ .TP
250
+ .B \-\-buf\-size=\f[I]buf_size\f[]
251
+ int, optional.
252
+ String buffer size in bytes [default: 256] used when \f[C]delim\f[] is
253
+ specified.
254
+ .RS
255
+ .RE
256
+ .TP
257
+ .B \-\-bytes
258
+ bool, optional.
259
+ If true, will count bytes, ignore \f[C]delim\f[], and default
260
+ \f[C]unit_scale\f[] to True, \f[C]unit_divisor\f[] to 1024, and
261
+ \f[C]unit\f[] to \[aq]B\[aq].
262
+ .RS
263
+ .RE
264
+ .TP
265
+ .B \-\-tee
266
+ bool, optional.
267
+ If true, passes \f[C]stdin\f[] to both \f[C]stderr\f[] and
268
+ \f[C]stdout\f[].
269
+ .RS
270
+ .RE
271
+ .TP
272
+ .B \-\-update
273
+ bool, optional.
274
+ If true, will treat input as newly elapsed iterations, i.e.
275
+ numbers to pass to \f[C]update()\f[].
276
+ Note that this is slow (~2e5 it/s) since every input must be decoded as
277
+ a number.
278
+ .RS
279
+ .RE
280
+ .TP
281
+ .B \-\-update\-to
282
+ bool, optional.
283
+ If true, will treat input as total elapsed iterations, i.e.
284
+ numbers to assign to \f[C]self.n\f[].
285
+ Note that this is slow (~2e5 it/s) since every input must be decoded as
286
+ a number.
287
+ .RS
288
+ .RE
289
+ .TP
290
+ .B \-\-null
291
+ bool, optional.
292
+ If true, will discard input (no stdout).
293
+ .RS
294
+ .RE
295
+ .TP
296
+ .B \-\-manpath=\f[I]manpath\f[]
297
+ str, optional.
298
+ Directory in which to install tqdm man pages.
299
+ .RS
300
+ .RE
301
+ .TP
302
+ .B \-\-comppath=\f[I]comppath\f[]
303
+ str, optional.
304
+ Directory in which to place tqdm completion.
305
+ .RS
306
+ .RE
307
+ .TP
308
+ .B \-\-log=\f[I]log\f[]
309
+ str, optional.
310
+ CRITICAL|FATAL|ERROR|WARN(ING)|[default: \[aq]INFO\[aq]]|DEBUG|NOTSET.
311
+ .RS
312
+ .RE
313
+ .SH AUTHORS
314
+ tqdm developers <https://github.com/tqdm>.