k3priorityqueue 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,27 +42,20 @@ while True:
42
42
  print('consumed all: counts:', repr(count))
43
43
  """
44
44
 
45
- # from .proc import CalledProcessError
46
- # from .proc import ProcError
45
+ from importlib.metadata import version
47
46
 
48
- __version__ = "0.1.2"
49
- __name__ = "k3priorityqueue"
47
+ __version__ = version("k3priorityqueue")
50
48
 
51
49
  from .priorityqueue import (
52
50
  Empty,
53
-
54
51
  Producer,
55
52
  PriorityQueue,
56
-
57
53
  default_priority,
58
54
  )
59
55
 
60
56
  __all__ = [
61
- 'Empty',
62
-
63
- 'Producer',
64
- 'PriorityQueue',
65
-
66
- 'default_priority',
57
+ "Empty",
58
+ "Producer",
59
+ "PriorityQueue",
60
+ "default_priority",
67
61
  ]
68
-
@@ -30,7 +30,7 @@ class Producer(object):
30
30
  def __init__(self, producer_id, priority, iterable):
31
31
  self.consumed = 0
32
32
  self.iterable_lock = threading.RLock()
33
- self.stat = {'get': 0}
33
+ self.stat = {"get": 0}
34
34
  self.cmp_key = (0, 0)
35
35
 
36
36
  self.producer_id = producer_id
@@ -38,22 +38,20 @@ class Producer(object):
38
38
  self.set_iterable(iterable)
39
39
 
40
40
  def get(self):
41
-
42
41
  with self.iterable_lock:
43
42
  try:
44
43
  val = next(self.iterable)
45
- self.stat['get'] += 1
44
+ self.stat["get"] += 1
46
45
  self.consume()
47
46
  return val
48
47
  except StopIteration:
49
- raise Empty('no more item in ' + str(self))
48
+ raise Empty("no more item in " + str(self))
50
49
 
51
50
  def set_priority(self, priority):
52
-
53
51
  priority = float(priority)
54
52
 
55
53
  if priority <= 0:
56
- raise ValueError('priority can not be less or euqal 0: ' + str(priority))
54
+ raise ValueError("priority can not be less or euqal 0: " + str(priority))
57
55
 
58
56
  self.priority = priority
59
57
  self.item_cost = default_priority / float(self.priority)
@@ -67,7 +65,7 @@ class Producer(object):
67
65
  self.cmp_key = (self.consumed, self.item_cost)
68
66
 
69
67
  def __str__(self):
70
- return '[{producer_id}={priority} c={consumed}]'.format(
68
+ return "[{producer_id}={priority} c={consumed}]".format(
71
69
  producer_id=self.producer_id,
72
70
  priority=self.priority,
73
71
  consumed=self.consumed,
@@ -92,6 +90,7 @@ class PriorityQueue(object):
92
90
  To re-enable a producer, call `PriorityQueue.add_producer()` with the same
93
91
  `producer_id`.
94
92
  """
93
+
95
94
  def __init__(self):
96
95
  self.producer_by_id = {}
97
96
 
@@ -153,7 +152,6 @@ class PriorityQueue(object):
153
152
  del self.producer_by_id[producer_id]
154
153
 
155
154
  def _remove_from_heaps(self, producer):
156
-
157
155
  try:
158
156
  self.empty_heap.remove(producer)
159
157
  except k3heap.NotFound:
@@ -166,22 +164,20 @@ class PriorityQueue(object):
166
164
 
167
165
  def get(self):
168
166
  """
169
- Returns an item.
167
+ Returns an item.
170
168
  """
171
169
  while True:
172
-
173
170
  with self.heap_lock:
174
171
  try:
175
172
  p = self.consumable_heap.get()
176
173
  except k3heap.Empty:
177
- raise Empty('no more queue has any item')
174
+ raise Empty("no more queue has any item")
178
175
 
179
176
  try:
180
177
  # NOTE: if p.iterable blocks, everything is blocked
181
178
  val = p.get()
182
179
 
183
180
  except Empty:
184
-
185
181
  self.consumable_heap.remove(p)
186
182
  self.empty_heap.push(p)
187
183
 
@@ -197,4 +193,4 @@ class PriorityQueue(object):
197
193
  for cq in self.producer_by_id.values():
198
194
  qs.append(str(cq))
199
195
 
200
- return ' '.join(qs)
196
+ return " ".join(qs)
@@ -16,14 +16,14 @@ for _ in range(12):
16
16
  count[val] = count.get(val, 0) + 1
17
17
  print(val)
18
18
 
19
- print('respect priority ratio: counts:', repr(count))
19
+ print("respect priority ratio: counts:", repr(count))
20
20
 
21
21
  while True:
22
22
  try:
23
23
  val = pq.get()
24
- except k3priorityqueue.Empty as e:
24
+ except k3priorityqueue.Empty:
25
25
  break
26
26
  count[val] = count.get(val, 0) + 1
27
27
  print(val)
28
28
 
29
- print('consumed all: counts:', repr(count))
29
+ print("consumed all: counts:", repr(count))
@@ -1,25 +1,39 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: k3priorityqueue
3
- Version: 0.1.2
4
- Summary: priorityQueue is a queue with priority support
5
- Home-page: https://github.com/pykit3/k3priorityqueue
6
- Author: Zhang Yanpo
7
- Author-email: drdr.xp@gmail.com
3
+ Version: 0.1.3
4
+ Summary: Priority queue with weighted producer support
5
+ Author-email: Zhang Yanpo <drdr.xp@gmail.com>
8
6
  License: MIT
9
- Keywords: python,priorityqueue
10
- Platform: UNKNOWN
7
+ Project-URL: Homepage, https://github.com/pykit3/k3priorityqueue
8
+ Project-URL: Documentation, https://k3priorityqueue.readthedocs.io
9
+ Keywords: queue,priority-queue,producer,weighted
11
10
  Classifier: Development Status :: 4 - Beta
12
11
  Classifier: Intended Audience :: Developers
13
12
  Classifier: Topic :: Software Development :: Libraries
14
- Classifier: Programming Language :: Python :: 3.6
15
- Classifier: Programming Language :: Python :: 3.7
16
- Classifier: Programming Language :: Python :: 3.8
17
- Classifier: Programming Language :: Python :: Implementation :: PyPy
18
- Requires-Python: >=3.0
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.9
19
20
  Description-Content-Type: text/markdown
20
- Requires-Dist: k3ut (<0.2,>=0.1.15)
21
- Requires-Dist: k3heap (<0.2,>=0.1.5)
22
- Requires-Dist: k3thread (<0.2,>=0.1.0)
21
+ License-File: LICENSE
22
+ Requires-Dist: k3heap
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: ruff; extra == "dev"
26
+ Requires-Dist: coverage; extra == "dev"
27
+ Requires-Dist: k3thread; extra == "dev"
28
+ Provides-Extra: publish
29
+ Requires-Dist: build; extra == "publish"
30
+ Requires-Dist: twine; extra == "publish"
31
+ Requires-Dist: pk3; extra == "publish"
32
+ Provides-Extra: docs
33
+ Requires-Dist: mkdocs>=1.5; extra == "docs"
34
+ Requires-Dist: mkdocs-material>=9.0; extra == "docs"
35
+ Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
36
+ Dynamic: license-file
23
37
 
24
38
  # k3priorityqueue
25
39
 
@@ -126,4 +140,3 @@ Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
126
140
 
127
141
 
128
142
  [pykit3]: https://github.com/pykit3
129
-
@@ -0,0 +1,8 @@
1
+ k3priorityqueue/__init__.py,sha256=P6snvBPPuHqLNIu9RSnhnfX6yeZI5WAEHEqhw3rziHY,1181
2
+ k3priorityqueue/priorityqueue.py,sha256=Uf88QQ39CIQi4Z2anRaOI5PuqidHd8rki7fxrIIxVgg,6381
3
+ k3priorityqueue/synopsis.py,sha256=7SWhWJfKeSrKvrvlayhVg8miTLZtkkiJPAtV3icHQgs,593
4
+ k3priorityqueue-0.1.3.dist-info/licenses/LICENSE,sha256=efDc2MufKQpsx8k2CaRX7tYYsmT6CyOa76by7YATdm0,1066
5
+ k3priorityqueue-0.1.3.dist-info/METADATA,sha256=oE96mVKPTsR9XjMuM_0FT-Tt1IMtN8jcI8CX2H5ypuI,3945
6
+ k3priorityqueue-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ k3priorityqueue-0.1.3.dist-info/top_level.txt,sha256=xsFjs-FCGWMfu_k_yPPYAwXFbAWiIvW1uTqjR4abf_c,16
8
+ k3priorityqueue-0.1.3.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.36.2)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 张炎泼
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
k3priorityqueue/setup.py DELETED
@@ -1,23 +0,0 @@
1
- # DO NOT EDIT!!! built with `python _building/build_setup.py`
2
- import setuptools
3
- setuptools.setup(
4
- name="k3priorityqueue",
5
- packages=["k3priorityqueue"],
6
- version="0.1.2",
7
- license='MIT',
8
- description='priorityQueue is a queue with priority support',
9
- long_description="# k3priorityqueue\n\n[![Action-CI](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml/badge.svg)](https://github.com/pykit3/k3priorityqueue/actions/workflows/python-package.yml)\n[![Build Status](https://travis-ci.com/pykit3/k3priorityqueue.svg?branch=master)](https://travis-ci.com/pykit3/k3priorityqueue)\n[![Documentation Status](https://readthedocs.org/projects/k3priorityqueue/badge/?version=stable)](https://k3priorityqueue.readthedocs.io/en/stable/?badge=stable)\n[![Package](https://img.shields.io/pypi/pyversions/k3priorityqueue)](https://pypi.org/project/k3priorityqueue)\n\npriorityQueue is a queue with priority support\n\nk3priorityqueue is a component of [pykit3] project: a python3 toolkit set.\n\n\nPriorityQueue is a queue with priority support:\n\nThe numbers of items it pops from each producer matches exactly the ratio of their priority:\nIf the priorities of 3 producer A, B and C are 1, 3 and 7, and it runs long\nenough, it is expected that the number of items popped from A, B and C are\n1:3:7.\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n\n\n\n\n# Install\n\n```\npip install k3priorityqueue\n```\n\n# Synopsis\n\n```python\n\nimport k3priorityqueue\n\nproducers = (\n # id, priority, iterable\n (1, 1, [1] * 10),\n (2, 2, [2] * 10),\n (3, 3, [3] * 10),\n)\npq = k3priorityqueue.PriorityQueue()\nfor pid, prio, itr in producers:\n pq.add_producer(pid, prio, itr)\n\ncount = {}\nfor _ in range(12):\n val = pq.get()\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('respect priority ratio: counts:', repr(count))\n\nwhile True:\n try:\n val = pq.get()\n except k3priorityqueue.Empty as e:\n break\n count[val] = count.get(val, 0) + 1\n print(val)\n\nprint('consumed all: counts:', repr(count))\n```\n\n# Author\n\nZhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n# Copyright and License\n\nThe MIT License (MIT)\n\nCopyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>\n\n\n[pykit3]: https://github.com/pykit3",
10
- long_description_content_type="text/markdown",
11
- author='Zhang Yanpo',
12
- author_email='drdr.xp@gmail.com',
13
- url='https://github.com/pykit3/k3priorityqueue',
14
- keywords=['python', 'priorityqueue'],
15
- python_requires='>=3.0',
16
-
17
- install_requires=['k3ut>=0.1.15,<0.2', 'k3heap>=0.1.5,<0.2', 'k3thread>=0.1.0,<0.2'],
18
- classifiers=[
19
- 'Development Status :: 4 - Beta',
20
- 'Intended Audience :: Developers',
21
- 'Topic :: Software Development :: Libraries',
22
- ] + ['Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: Implementation :: PyPy'],
23
- )
@@ -1,8 +0,0 @@
1
- k3priorityqueue/__init__.py,sha256=-vq5WAJCt3jhl2uDu128V0BjK3ab-O8tYAM-BgctT48,1226
2
- k3priorityqueue/priorityqueue.py,sha256=JsCy7CdChf5Sn08g2zs1GMZTbXe6XyqXxCARW4SleqE,6389
3
- k3priorityqueue/setup.py,sha256=NvgpbHFr62c4e2xIbpckou8-PP5MXWGq4fUID-SkdFQ,3592
4
- k3priorityqueue/synopsis.py,sha256=IXZyCRgE6MXiut681ZW5qSyczlzl-z1B7jzsKmz6l4U,598
5
- k3priorityqueue-0.1.2.dist-info/METADATA,sha256=FribGlDXvmwg_BJJpztHmbaHhczWUzLjH-1aPF4I7U4,3336
6
- k3priorityqueue-0.1.2.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
7
- k3priorityqueue-0.1.2.dist-info/top_level.txt,sha256=xsFjs-FCGWMfu_k_yPPYAwXFbAWiIvW1uTqjR4abf_c,16
8
- k3priorityqueue-0.1.2.dist-info/RECORD,,