Skip to content
Snippets Groups Projects
Commit 4e159530 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files
parents 04b713ef 88bc421f
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ jobs: ...@@ -7,7 +7,7 @@ jobs:
environment: Env1 environment: Env1
strategy: strategy:
matrix: matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "pypy3.9" ] python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps: steps:
- uses: actions/checkout@main - uses: actions/checkout@main
- uses: actions/setup-python@main - uses: actions/setup-python@main
......
stages:
- test
- build
pages:
image: zoo.smok.co/build/build:latest
stage: build
script:
- cd docs
- make html
- cd ..
- mv docs/_build/html public
artifacts:
paths:
- public
.test:
stage: test
before_script:
- pip install --break-system-packages --upgrade pytest setuptools pip coverage nose2
- pip install ".[dev,test]"
script:
- pytest -n 8 -vv --cov=satella
- coverage xml
- coverage report
coverage: /TOTAL.*\s+(\d+\%)/
test_python37:
extends: .test
image: python:3.7
test_python38:
extends: .test
image: python:3.8
test_python39:
extends: .test
image: python:3.9
test_pypy310:
extends: .test
image: pypy:3.10
when: manual
test_pypy39:
extends: .test
image: pypy:3.9
when: manual
test_python310:
extends: .test
image: python:3.10
test_python311:
extends: .test
image: python:3.11
build_python:
stage: build
before_script:
- pip install --break-system-packages --upgrade Cython setuptools pip twine
script:
- python setup.py bdist_wheel
- mv dist/*.whl .
artifacts:
paths:
- "*.whl"
after_script:
- TWINE_PASSWORD=${CI_JOB_TOKEN} TWINE_USERNAME=gitlab-ci-token python3 -m twine upload --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi *.whl
only:
- tags
except:
- branches
# v2.25.5
* slight optimization for Heap.push_many
* bugfix for Heap.push and a deprecation
# v2.25.4 # v2.25.4
* add JSONAbleDataObject * add JSONAbleDataObject
......
__version__ = '2.25.4' __version__ = '2.25.5'
...@@ -7,14 +7,6 @@ from satella.coding.decorators.decorators import wraps ...@@ -7,14 +7,6 @@ from satella.coding.decorators.decorators import wraps
from satella.coding.typing import T, Predicate from satella.coding.typing import T, Predicate
def _extras_to_one(fun):
@wraps(fun)
def inner(self, a, *args, **kwargs):
return fun(self, ((a,) + args) if len(args) > 0 else a, **kwargs)
return inner
class Heap(collections.UserList, tp.Generic[T]): class Heap(collections.UserList, tp.Generic[T]):
""" """
Sane heap as object - not like heapq. Sane heap as object - not like heapq.
...@@ -30,8 +22,17 @@ class Heap(collections.UserList, tp.Generic[T]): ...@@ -30,8 +22,17 @@ class Heap(collections.UserList, tp.Generic[T]):
heapq.heapify(self.data) heapq.heapify(self.data)
def push_many(self, items: tp.Iterable[T]) -> None: def push_many(self, items: tp.Iterable[T]) -> None:
for item in items: """
self.push(item) Put multiple items on the heap.
Faster than
>>> for item in items:
>>> heap.push(item)
:param: an iterable with items to put
"""
self.data.extend(items)
heapq.heapify(self.data)
def pop_item(self, item: T) -> T: def pop_item(self, item: T) -> T:
""" """
...@@ -43,8 +44,7 @@ class Heap(collections.UserList, tp.Generic[T]): ...@@ -43,8 +44,7 @@ class Heap(collections.UserList, tp.Generic[T]):
heapq.heapify(self.data) heapq.heapify(self.data)
return item return item
@_extras_to_one def push(self, item: T, *args) -> None:
def push(self, item: T) -> None:
""" """
Use it like: Use it like:
...@@ -53,7 +53,14 @@ class Heap(collections.UserList, tp.Generic[T]): ...@@ -53,7 +53,14 @@ class Heap(collections.UserList, tp.Generic[T]):
or: or:
>>> heap.push(4, myobject) >>> heap.push(4, myobject)
However this syntax is
.. deprecated:: 2.25.5
It's not legible
""" """
if args:
item = (item, *args)
heapq.heappush(self.data, item) heapq.heappush(self.data, item)
def __deepcopy__(self, memo={}) -> 'Heap': def __deepcopy__(self, memo={}) -> 'Heap':
...@@ -138,6 +145,13 @@ class SetHeap(Heap): ...@@ -138,6 +145,13 @@ class SetHeap(Heap):
#notthreadsafe #notthreadsafe
""" """
def push_many(self, items: tp.Iterable[T]) -> None:
"""
Not that much faster than inserting anything by hand
"""
for item in items:
self.push(item)
def __init__(self, from_list: tp.Optional[tp.Iterable[T]] = None): def __init__(self, from_list: tp.Optional[tp.Iterable[T]] = None):
super().__init__(from_list=from_list) super().__init__(from_list=from_list)
self.set = set(self.data) self.set = set(self.data)
......
...@@ -37,6 +37,13 @@ def continue_testing_omni(self, omni_class): ...@@ -37,6 +37,13 @@ def continue_testing_omni(self, omni_class):
class TestStructures(unittest.TestCase): class TestStructures(unittest.TestCase):
def test_heap_bugfix(self):
heap = Heap()
heap.push_many([(1, object()), (2, object())])
item = heap.pop()
self.assertEqual(item[0], 1)
def test_onstronlyname(self): def test_onstronlyname(self):
class MyEnum(OnStrOnlyName, Enum): class MyEnum(OnStrOnlyName, Enum):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment