Merge pull request #3 from datpy/cleanups-gardening

Meta/Docs cleanup and bytes fix
This commit is contained in:
decentral1se 2019-10-06 16:19:47 +02:00 committed by GitHub
commit 71526e64aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 70 additions and 80 deletions

View File

@ -3,9 +3,9 @@ language: python
matrix: matrix:
include: include:
- python: 3.6 - python: 3.6
env: TOXENV=py36-test env: TOXENV=py36
- python: 3.7 - python: 3.7
env: TOXENV=py37-test env: TOXENV=py37
- python: 3.7 - python: 3.7
env: TOXENV=lint env: TOXENV=lint
- python: 3.7 - python: 3.7

View File

@ -1,3 +1,12 @@
Merkle_Tree_Stream 0.0.1a2 (2019-10-06)
=======================================
Bug Fixes
---------
- MerkleTreeIterator leaf and parent functions now return bytes.
Merkle_Tree_Stream 0.0.1a1 (2019-08-07) Merkle_Tree_Stream 0.0.1a1 (2019-08-07)
======================================= =======================================

View File

@ -1,14 +1,10 @@
Get started Get started
----------- -----------
Install `Tox`_ with: Install `Tox`_.
.. _tox: http://tox.readthedocs.io/ .. _tox: http://tox.readthedocs.io/
.. code-block:: bash
$ pip install --user tox
Run tests Run tests
--------- ---------
@ -40,22 +36,6 @@ Type check source
Release Process Release Process
--------------- ---------------
Add a change entry and re-generate the changelog:
.. code-block:: bash .. code-block:: bash
$ towncrier
Make a new release tag:
.. code-block:: bash
$ git tag x.x.x
$ git push --tags
Then run the release process:
.. code-block:: bash
$ tox -e metadata-release
$ tox -e release $ tox -e release

View File

@ -61,15 +61,42 @@ reference implementation.
.. _merkle-tree-stream: https://github.com/mafintosh/merkle-tree-stream .. _merkle-tree-stream: https://github.com/mafintosh/merkle-tree-stream
.. _Python iterator: https://docs.python.org/3/c-api/iter.html .. _Python iterator: https://docs.python.org/3/c-api/iter.html
.. _example:
.. code-block:: python
from hashlib import sha256
from merkle_tree_stream import MerkleTreeIterator
def leaf(node, roots=None):
return sha256(node.data).digest()
def parent(first, second):
sha256 = hashlib.sha256()
sha256.update(first.data)
sha256.update(second.data)
return sha256.digest()
merkle_iter = MerkleTreeIterator(leaf=leaf, parent=parent)
merkle_iter.write('hello')
merkle_iter.write('hashed')
merkle_iter.write('world')
.. _documentation: .. _documentation:
Documentation Documentation
************* *************
* https://merkle-tree-stream.readthedocs.io/ * `merkle-tree-stream.readthedocs.io`_
.. _merkle-tree-stream.readthedocs.io: https://merkle-tree-stream.readthedocs.io/
Mirroring Mirroring
********* *********
* https://hack.decentral1.se/datpy/merkle-tree-stream (primary) * `hack.decentral1.se/datpy/merkle-tree-stream`_
* https://github.com/datpy/merkle-tree-stream * `github.com/datpy/merkle-tree-stream`_
.. _hack.decentral1.se/datpy/merkle-tree-stream: https://hack.decentral1.se/datpy/merkle-tree-stream
.. _github.com/datpy/merkle-tree-stream: https://github.com/datpy/merkle-tree-stream

View File

@ -23,7 +23,7 @@ class MerkleTreeNode:
parent: int parent: int
size: int size: int
data: bytes data: bytes
hash: Optional[str] = attr.Factory(str) hash: Optional[bytes] = attr.Factory(bytes)
def __attrs_post_init__(self) -> Any: def __attrs_post_init__(self) -> Any:
"""Initialise the parent index.""" """Initialise the parent index."""

View File

@ -7,8 +7,6 @@ from flat_tree import FlatTreeAccessor
from merkle_tree_stream.node import MerkleTreeNode from merkle_tree_stream.node import MerkleTreeNode
Hash = str
EMPTY_DATA = b'' EMPTY_DATA = b''
EMPTY_HASH = None EMPTY_HASH = None
@ -26,8 +24,8 @@ class MerkleTreeIterator:
:param roots: The tree roots :param roots: The tree roots
""" """
leaf: Callable[[MerkleTreeNode], Hash] leaf: Callable[[MerkleTreeNode], bytes]
parent: Callable[[MerkleTreeNode, MerkleTreeNode], Hash] parent: Callable[[MerkleTreeNode, MerkleTreeNode], bytes]
roots: List[MerkleTreeNode] = attr.Factory(list) roots: List[MerkleTreeNode] = attr.Factory(list)
_position: int = 0 _position: int = 0

View File

@ -15,7 +15,7 @@ include = '\.pyi?$'
[tool.towncrier] [tool.towncrier]
directory = "changelog/" directory = "changelog/"
filename = "CHANGELOG.rst" filename = "CHANGELOG.rst"
package = "merkle-tree-stream" package = "merkle_tree_stream"
package_dir = "merkle_tree_stream" package_dir = "merkle_tree_stream"
[[tool.towncrier.type]] [[tool.towncrier.type]]

View File

@ -37,7 +37,7 @@ install_requires =
[options] [options]
use_scm_version = True use_scm_version = True
python_requires = !=2.7.*, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.* python_requires = >=3.6
setup_requires = setup_requires =
setuptools_scm setuptools_scm
setuptools_scm_git_archive setuptools_scm_git_archive
@ -47,7 +47,7 @@ packages = find:
zip_safe = False zip_safe = False
install_requires = install_requires =
attrs >= 19.1.0, < 20.0 attrs >= 19.1.0, < 20.0
flat-tree == 0.0.1a3 # TODO(decentral1se): use bounds when 0.0.1 lands flat-tree >= 0.0.1a3, < 1.0
[options.packages.find] [options.packages.find]
where = . where = .

View File

@ -6,7 +6,7 @@ import pytest
@pytest.fixture @pytest.fixture
def leaf(): def leaf():
def _leaf(node, roots=None): def _leaf(node, roots=None):
return hashlib.sha256(node.data).hexdigest() return hashlib.sha256(node.data).digest()
return _leaf return _leaf
@ -17,6 +17,6 @@ def parent():
sha256 = hashlib.sha256() sha256 = hashlib.sha256()
sha256.update(first.data) sha256.update(first.data)
sha256.update(second.data) sha256.update(second.data)
return sha256.hexdigest() return sha256.digest()
return _parent return _parent

View File

@ -17,26 +17,18 @@ def test_hashes(leaf, parent):
assert len(merkle_iter) == expected_count assert len(merkle_iter) == expected_count
assert next(merkle_iter) == MerkleTreeNode( assert next(merkle_iter) == MerkleTreeNode(
index=0, index=0, parent=1, hash=hashlib.sha256(b'a').digest(), size=1, data=b'a'
parent=1,
hash=hashlib.sha256(b'a').hexdigest(),
size=1,
data=b'a',
) )
assert next(merkle_iter) == MerkleTreeNode( assert next(merkle_iter) == MerkleTreeNode(
index=2, index=2, parent=1, hash=hashlib.sha256(b'b').digest(), size=1, data=b'b'
parent=1,
hash=hashlib.sha256(b'b').hexdigest(),
size=1,
data=b'b',
) )
hashed = hashlib.sha256(b'a') hashed = hashlib.sha256(b'a')
hashed.update(b'b') hashed.update(b'b')
assert next(merkle_iter) == MerkleTreeNode( assert next(merkle_iter) == MerkleTreeNode(
index=1, parent=3, hash=hashed.hexdigest(), size=2, data=b'' index=1, parent=3, hash=hashed.digest(), size=2, data=b''
) )
with pytest.raises(StopIteration): with pytest.raises(StopIteration):

50
tox.ini
View File

@ -1,6 +1,6 @@
[tox] [tox]
envlist = envlist =
{py36,py37}-test {py36,py37}
lint lint
sort sort
format format
@ -17,70 +17,54 @@ deps =
pytest pytest
pytest-cov pytest-cov
pytest-mock pytest-mock
commands = commands = pytest test/ --cov={toxinidir}/merkle_tree_stream/ --no-cov-on-fail {posargs}
pytest test/ --cov={toxinidir}/merkle_tree_stream/ --no-cov-on-fail {posargs}
[testenv:lint] [testenv:lint]
description = lint the source description = lint the source
skipdist = True skipdist = True
deps = deps = flake8
flake8 commands = flake8 {posargs} merkle_tree_stream/ test/
commands =
flake8 {posargs} merkle_tree_stream/ test/
[testenv:sort] [testenv:sort]
description = sort the source description = sort the source
skipdist = True skipdist = True
deps = deps = isort
isort commands = isort {posargs:-rc -c} -sp setup.cfg merkle_tree_stream/ test/
commands =
isort {posargs:-rc -c} -sp setup.cfg merkle_tree_stream/ test/
[testenv:format] [testenv:format]
description = format the source description = format the source
skipdist = True skipdist = True
basepython = python3.6 basepython = python3.6
deps = deps = black
black commands = black {posargs:--check} merkle_tree_stream/ test/
commands =
black {posargs:--check} merkle_tree_stream/ test/
[testenv:type] [testenv:type]
description = type check the source description = type check the source
basepython = python3.7 basepython = python3.7
skipdist = True skipdist = True
deps = deps = mypy
mypy commands = mypy merkle_tree_stream/ test/
commands =
mypy merkle_tree_stream/ test/
[testenv:docs] [testenv:docs]
description = build the documentation description = build the documentation
skipdist = True skipdist = True
extras = extras = docs
docs commands = python -m setup build_sphinx
commands =
python -m setup build_sphinx
[testenv:changelog] [testenv:changelog]
description = draft the changelog description = draft the changelog
skipdist = True skipdist = True
extras = extras = changelog
changelog commands = towncrier --draft
commands =
towncrier --draft
[testenv:metadata-release] [testenv:metadata-release]
description = validate the package metadata description = validate the package metadata
deps = deps = twine
twine commands = twine check {toxworkdir}/dist/*
commands =
twine check .tox/dist/*
[testenv:release] [testenv:release]
description = make a release description = make a release
deps = deps = {[testenv:metadata-release]deps}
{[testenv:metadata-release]deps}
commands = commands =
python -m setup sdist bdist_wheel python -m setup sdist bdist_wheel
twine upload {toxworkdir}/dist/* twine upload {toxworkdir}/dist/*