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:
include:
- python: 3.6
env: TOXENV=py36-test
env: TOXENV=py36
- python: 3.7
env: TOXENV=py37-test
env: TOXENV=py37
- python: 3.7
env: TOXENV=lint
- 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)
=======================================

View File

@ -1,14 +1,10 @@
Get started
-----------
Install `Tox`_ with:
Install `Tox`_.
.. _tox: http://tox.readthedocs.io/
.. code-block:: bash
$ pip install --user tox
Run tests
---------
@ -40,22 +36,6 @@ Type check source
Release Process
---------------
Add a change entry and re-generate the changelog:
.. 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

View File

@ -61,15 +61,42 @@ reference implementation.
.. _merkle-tree-stream: https://github.com/mafintosh/merkle-tree-stream
.. _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
*************
* https://merkle-tree-stream.readthedocs.io/
* `merkle-tree-stream.readthedocs.io`_
.. _merkle-tree-stream.readthedocs.io: https://merkle-tree-stream.readthedocs.io/
Mirroring
*********
* https://hack.decentral1.se/datpy/merkle-tree-stream (primary)
* https://github.com/datpy/merkle-tree-stream
* `hack.decentral1.se/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
size: int
data: bytes
hash: Optional[str] = attr.Factory(str)
hash: Optional[bytes] = attr.Factory(bytes)
def __attrs_post_init__(self) -> Any:
"""Initialise the parent index."""

View File

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

View File

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

View File

@ -37,7 +37,7 @@ install_requires =
[options]
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 =
setuptools_scm
setuptools_scm_git_archive
@ -47,7 +47,7 @@ packages = find:
zip_safe = False
install_requires =
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]
where = .

View File

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

View File

@ -17,26 +17,18 @@ def test_hashes(leaf, parent):
assert len(merkle_iter) == expected_count
assert next(merkle_iter) == MerkleTreeNode(
index=0,
parent=1,
hash=hashlib.sha256(b'a').hexdigest(),
size=1,
data=b'a',
index=0, parent=1, hash=hashlib.sha256(b'a').digest(), size=1, data=b'a'
)
assert next(merkle_iter) == MerkleTreeNode(
index=2,
parent=1,
hash=hashlib.sha256(b'b').hexdigest(),
size=1,
data=b'b',
index=2, parent=1, hash=hashlib.sha256(b'b').digest(), size=1, data=b'b'
)
hashed = hashlib.sha256(b'a')
hashed.update(b'b')
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):

50
tox.ini
View File

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