From dc9f04c18f9a96d6e0252275bab454c793fe1e44 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Fri, 3 May 2019 14:45:31 -0700 Subject: [PATCH 001/102] Skip venv in template filler & print progress --- .project-template/fill_template_vars.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.project-template/fill_template_vars.sh b/.project-template/fill_template_vars.sh index f09e8ffe..c9cb8261 100755 --- a/.project-template/fill_template_vars.sh +++ b/.project-template/fill_template_vars.sh @@ -29,7 +29,8 @@ echo "What is a one-liner describing the project?" read SHORT_DESCRIPTION _replace() { - local find_cmd=(find "$PROJECT_ROOT" ! -perm -u=x ! -path '*/.git/*' -type f) + echo "Replacing values: $1" + local find_cmd=(find "$PROJECT_ROOT" ! -perm -u=x ! -path '*/.git/*' ! -path '*/venv*/*' -type f) if [[ $(uname) == Darwin ]]; then "${find_cmd[@]}" -exec sed -i '' "$1" {} + From 4ab4a01a360d2e6b61f4c144f5613f7c5a9acddd Mon Sep 17 00:00:00 2001 From: Nick Gheorghita Date: Thu, 12 Dec 2019 13:21:22 +0100 Subject: [PATCH 002/102] Add MANIFEST.in file --- MANIFEST.in | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 00000000..fbff9807 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,8 @@ +include LICENSE +include README.md +include requirements-docs.txt + +global-include *.pyi + +recursive-exclude * __pycache__ +recursive-exclude * *.py[co] From c8f686f0771d18ea5fdb45db7f38f1b981f02c88 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Fri, 24 Jan 2020 11:07:11 -0800 Subject: [PATCH 003/102] Update MIT License to 2020 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index d93175ab..17bc694e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2019 The Ethereum Foundation +Copyright (c) 2020 The Ethereum Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From e6e69625bb32c8a595a19f750aa8e8fdd6725e2b Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Fri, 24 Jan 2020 11:21:24 -0800 Subject: [PATCH 004/102] Replace web3 reference with Some hard-coded references to web3.py slipped through. Clearly this user path is not tested very often. In eth-abi, it still said EthereumAlarmClock X) --- docs/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/Makefile b/docs/Makefile index 32800935..aa0085b3 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -85,17 +85,17 @@ qthelp: @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" - @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/web3.qhcp" + @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/.qhcp" @echo "To view the help file:" - @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/web3.qhc" + @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" - @echo "# mkdir -p $$HOME/.local/share/devhelp/web3" - @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/web3" + @echo "# mkdir -p $$HOME/.local/share/devhelp/" + @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/" @echo "# devhelp" epub: From 6d75c9aa8d4bd3f8e5791bdf936ee319a9abb1dd Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Fri, 24 Jan 2020 11:28:54 -0800 Subject: [PATCH 005/102] Update docs copyright to the year 2020 --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index aaf6fb6e..977f3ab1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -54,7 +54,7 @@ master_doc = 'index' # General information about the project. project = '' -copyright = '2019, The Ethereum Foundation' +copyright = '2020, The Ethereum Foundation' __version__ = setup_version # The version info for the project you're documenting, acts as replacement for From 4195de314249a740de65a91c6644fec921c05d10 Mon Sep 17 00:00:00 2001 From: Piper Merriam Date: Thu, 23 Apr 2020 09:13:32 -0600 Subject: [PATCH 006/102] Update testing and lint deps --- setup.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 54dbd6ca..845b8ab8 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ from setuptools import ( extras_require = { 'test': [ - "pytest==3.3.2", + "pytest==5.4.1", "pytest-xdist", - "tox>=2.9.1,<3", + "tox==3.14.6", ], 'lint': [ - "flake8==3.4.1", + "flake8==3.7.9", "isort>=4.2.15,<5", - "mypy==0.701", + "mypy==0.770", "pydocstyle>=3.0.0,<4", ], 'doc': [ From c447735449cf0d7b633bcc10395f024f5292238f Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Mon, 11 May 2020 13:55:17 -0700 Subject: [PATCH 007/102] Better error if bump missing in make notes/release --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5e087e37..264cd190 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,12 @@ docs: build-docs linux-docs: build-docs xdg-open docs/_build/html/index.html -notes: +check-bump: +ifndef bump + $(error bump must be set, typically: major, minor, patch, or devnum) +endif + +notes: check-bump # Let UPCOMING_VERSION be the version that is used for the current bump $(eval UPCOMING_VERSION=$(shell bumpversion $(bump) --dry-run --list | grep new_version= | sed 's/new_version=//g')) # Now generate the release notes to have them included in the release commit @@ -59,7 +64,7 @@ notes: make build-docs git commit -m "Compile release notes" -release: clean +release: check-bump clean # require that you be on a branch that's linked to upstream/master git status -s -b | head -1 | grep "\.\.upstream/master" # verify that docs build correctly From ea7038bd263ccc9ba981b12044e41bee14774e8f Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 1 Sep 2020 11:29:19 -0700 Subject: [PATCH 008/102] Update link to correct URL for release notes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3ceb98c9..92b70bea 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ -Read more in the [documentation on ReadTheDocs](https://.readthedocs.io/). [View the change log](https://.readthedocs.io/en/latest/releases.html). +Read more in the [documentation on ReadTheDocs](https://.readthedocs.io/). [View the change log](https://.readthedocs.io/en/latest/release_notes.html). ## Quickstart From d74a5e2bd8383dafe2f981df37e2f012736d9d24 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 2 Sep 2020 15:54:34 -0700 Subject: [PATCH 009/102] Latest mypy refuses package with file path --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 953e83ab..07b2179c 100644 --- a/tox.ini +++ b/tox.ini @@ -38,7 +38,7 @@ whitelist_externals=make basepython=python extras=lint commands= - mypy -p {toxinidir}/ --config-file {toxinidir}/mypy.ini + mypy -p --config-file {toxinidir}/mypy.ini flake8 {toxinidir}/ {toxinidir}/tests isort --recursive --check-only --diff {toxinidir}/ {toxinidir}/tests pydocstyle {toxinidir}/ {toxinidir}/tests From 27d0c7f0e56d023587baf6bac81ac2531d7f2517 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 24 Sep 2020 08:46:51 -0700 Subject: [PATCH 010/102] Customize section title, because default is bad It has weird capitalization rules, in particular. --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index a9724ba6..b03fe29e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,6 +4,7 @@ package = "" filename = "docs/release_notes.rst" directory = "newsfragments" underlines = ["-", "~", "^"] +title_format = " v{version} ({project_date})" issue_format = "`#{issue} /issues/{issue}>`__" [[tool.towncrier.type]] From be1c3242048035106bc137ed2558424c5f4d860b Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 24 Sep 2020 08:58:58 -0700 Subject: [PATCH 011/102] Add some Makefile doc strings --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 264cd190..68ed4174 100644 --- a/Makefile +++ b/Makefile @@ -6,9 +6,12 @@ help: @echo "clean-build - remove build artifacts" @echo "clean-pyc - remove Python file artifacts" @echo "lint - check style with flake8" + @echo "lint-roll - automatically fix problems with isort, flake8, etc" @echo "test - run tests quickly with the default Python" @echo "testall - run tests on every Python version with tox" - @echo "release - package and upload a release" + @echo "docs - generate docs and open in browser (linux-docs for version on linux)" + @echo "notes - consume towncrier newsfragments/ and update release notes in docs/" + @echo "release - package and upload a release (does not run notes target)" @echo "dist - package" clean: clean-build clean-pyc From 4d0358f67b56335d395aee4d49abd5276811a6b5 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 24 Sep 2020 08:59:09 -0700 Subject: [PATCH 012/102] Be sure to remove py3 cache files --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 68ed4174..d38ac9d9 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ clean-pyc: find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyo' -exec rm -f {} + find . -name '*~' -exec rm -f {} + + find . -name '__pycache__' -exec rm -rf {} + lint: tox -elint From 57f829250d5704e12f9bbd347fcaf565f7c596fa Mon Sep 17 00:00:00 2001 From: Tiffany McKenzie <25855566+tmckenzie51@users.noreply.github.com> Date: Mon, 7 Dec 2020 11:18:39 -0500 Subject: [PATCH 013/102] update .gitignore --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0e057278..b43bb7b3 100644 --- a/.gitignore +++ b/.gitignore @@ -97,9 +97,10 @@ logs # IntelliJ /out/ +.idea* -# mpeltonen/sbt-idea plugin -.idea_modules/ +#pip wheel metadata +pip-wheel-metadata # JIRA plugin atlassian-ide-plugin.xml From f962541b66cf5febf78c76b237203e9cad1f03c9 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 15:30:31 -0800 Subject: [PATCH 014/102] Export type annotations to importing projects --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 845b8ab8..3e3cdf05 100644 --- a/setup.py +++ b/setup.py @@ -64,6 +64,7 @@ setup( zip_safe=False, keywords='ethereum', packages=find_packages(exclude=["tests", "tests.*"]), + package_data={'': ['py.typed']}, classifiers=[ 'Development Status :: 3 - Alpha', 'Intended Audience :: Developers', From 8434801bfc740f35ceeb27e76af1c3d2ce0db1b8 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 15:45:12 -0800 Subject: [PATCH 015/102] Upgrade pydocstyle to v5 Fixes https://github.com/ethereum/ethereum-python-project-template/issues/52 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 845b8ab8..40edee8b 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ extras_require = { "flake8==3.7.9", "isort>=4.2.15,<5", "mypy==0.770", - "pydocstyle>=3.0.0,<4", + "pydocstyle>=5.0.0,<6", ], 'doc': [ "Sphinx>=1.6.5,<2", From 9d0cbd4a9fca511fab6e8f8ee49edc8c750bf4c3 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 15:51:46 -0800 Subject: [PATCH 016/102] Add pip-wheel-metadata & .pytest_cache to ignore Fixes https://github.com/ethereum/ethereum-python-project-template/issues/51 --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b43bb7b3..0ec1cd37 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ develop-eggs .installed.cfg lib lib64 +pip-wheel-metadata venv* # Installer logs @@ -55,6 +56,7 @@ chains # tox/pytest cache .cache +.pytest_cache # Test output logs logs From f4f5c051f59122e1889ddb68c6e4720b1243eb94 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 15:55:52 -0800 Subject: [PATCH 017/102] Clean up IntelliJ .gitignore a bit --- .gitignore | 49 ++++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 0ec1cd37..011ac1c8 100644 --- a/.gitignore +++ b/.gitignore @@ -60,31 +60,6 @@ chains # Test output logs logs -### JetBrains template -# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm -# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 - -# User-specific stuff: -.idea/workspace.xml -.idea/tasks.xml -.idea/dictionaries -.idea/vcs.xml -.idea/jsLibraryMappings.xml - -# Sensitive or high-churn files: -.idea/dataSources.ids -.idea/dataSources.xml -.idea/dataSources.local.xml -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# Gradle: -.idea/gradle.xml -.idea/libraries - -# Mongo Explorer plugin: -.idea/mongoSettings.xml # VIM temp files *.sw[op] @@ -92,24 +67,32 @@ logs # mypy .mypy_cache +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# For a more precise, explicit template, see: +# https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +## General +.idea/* +.idea_modules/* + ## File-based project format: *.iws +## IntelliJ +out/ + ## Plugin-specific files: -# IntelliJ -/out/ -.idea* +### mpeltonen/sbt-idea plugin +.idea_modules/ -#pip wheel metadata -pip-wheel-metadata - -# JIRA plugin +### JIRA plugin atlassian-ide-plugin.xml -# Crashlytics plugin (for Android Studio and IntelliJ) +### Crashlytics plugin (for Android Studio and IntelliJ) com_crashlytics_export_strings.xml crashlytics.properties crashlytics-build.properties fabric.properties +# END JetBrains section From 8c7f30b0b7276bc33e10d8fe57e3e34d1c5b8f18 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 16:14:16 -0800 Subject: [PATCH 018/102] Add supported OS's Fixes https://github.com/ethereum/ethereum-python-project-template/issues/37 --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index 40edee8b..a78d2afa 100644 --- a/setup.py +++ b/setup.py @@ -69,6 +69,8 @@ setup( 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', + 'Operating System :: MacOS', + 'Operating System :: POSIX', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', From b7baeca0cd92dda123f34931a695e30556b4b270 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Tue, 19 Jan 2021 16:15:22 -0800 Subject: [PATCH 019/102] Pin sphinx-rtd-theme to =1.6.5,<2", - "sphinx_rtd_theme>=0.1.9", + "sphinx_rtd_theme>=0.1.9,<1", "towncrier>=19.2.0, <20", ], 'dev': [ From 1410bcb22028fc92b9dec180cc88571742eac2c2 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 21 Jan 2021 11:35:29 -0800 Subject: [PATCH 020/102] Fix the type annotations export, adding py.typed Fixes https://github.com/ethereum/ethereum-python-project-template/issues/30 --- .project-template/fill_template_vars.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.project-template/fill_template_vars.sh b/.project-template/fill_template_vars.sh index c9cb8261..250f5512 100755 --- a/.project-template/fill_template_vars.sh +++ b/.project-template/fill_template_vars.sh @@ -47,3 +47,4 @@ _replace "s//$SHORT_DESCRIPTION/g" mkdir -p "$PROJECT_ROOT/$MODULE_NAME" touch "$PROJECT_ROOT/$MODULE_NAME/__init__.py" +touch "$PROJECT_ROOT/$MODULE_NAME/py.typed" From 765b2e441461217a8fada93d51ecf6969cdcda75 Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Nov 2021 13:43:20 -0700 Subject: [PATCH 021/102] Add python3.8 support --- .circleci/config.yml | 6 ++++++ setup.py | 1 + tox.ini | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa7691e6..0027cef1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -60,6 +60,12 @@ jobs: - image: circleci/python:3.7 environment: TOXENV: py37-core + py38-core: + <<: *common + docker: + - image: circleci/python:3.8 + environment: + TOXENV: py38-core pypy3-core: <<: *common docker: diff --git a/setup.py b/setup.py index 2b8c7201..65d7904a 100644 --- a/setup.py +++ b/setup.py @@ -75,6 +75,7 @@ setup( 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: Implementation :: PyPy', ], ) diff --git a/tox.ini b/tox.ini index 07b2179c..33b16f2b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist= - py{36,37,py3}-core + py{36,37,38,py3}-core lint docs @@ -28,6 +28,7 @@ basepython = docs: python py36: python3.6 py37: python3.7 + py37: python3.8 pypy3: pypy3 extras= test From fcb5577fa1e20ebe489e26e3a1e588fe87ba1211 Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Nov 2021 13:43:36 -0700 Subject: [PATCH 022/102] Add python 3.9 support --- .circleci/config.yml | 6 ++++++ setup.py | 1 + tox.ini | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0027cef1..35ab4b8a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,6 +66,12 @@ jobs: - image: circleci/python:3.8 environment: TOXENV: py38-core + py39-core: + <<: *common + docker: + - image: circleci/python:3.9 + environment: + TOXENV: py39-core pypy3-core: <<: *common docker: diff --git a/setup.py b/setup.py index 65d7904a..14567643 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ setup( 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', + 'Programming Language :: Python :: 3.9', 'Programming Language :: Python :: Implementation :: PyPy', ], ) diff --git a/tox.ini b/tox.ini index 33b16f2b..049e8e3a 100644 --- a/tox.ini +++ b/tox.ini @@ -28,7 +28,8 @@ basepython = docs: python py36: python3.6 py37: python3.7 - py37: python3.8 + py38: python3.8 + py39: python3.9 pypy3: pypy3 extras= test From d21d58250bc5547993a0e2ec5ab88c3de06a473c Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Nov 2021 13:48:19 -0700 Subject: [PATCH 023/102] Add python 3.10 support --- .circleci/config.yml | 6 ++++++ setup.py | 1 + tox.ini | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 35ab4b8a..167ae520 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -72,6 +72,12 @@ jobs: - image: circleci/python:3.9 environment: TOXENV: py39-core + py310-core: + <<: *common + docker: + - image: circleci/python:3.10 + environment: + TOXENV: py310-core pypy3-core: <<: *common docker: diff --git a/setup.py b/setup.py index 14567643..79241342 100644 --- a/setup.py +++ b/setup.py @@ -77,6 +77,7 @@ setup( 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', + 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: Implementation :: PyPy', ], ) diff --git a/tox.ini b/tox.ini index 049e8e3a..3148e02b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist= - py{36,37,38,py3}-core + py{36,37,38,39,310,py3}-core lint docs @@ -30,6 +30,7 @@ basepython = py37: python3.7 py38: python3.8 py39: python3.9 + py310: python3.10 pypy3: pypy3 extras= test From 0649062150d7894dd74b00f589f62c7823e3a1ae Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 19 Nov 2021 13:51:55 -0700 Subject: [PATCH 024/102] Update pytest to support python 3.10, pin pytest-xdist, bump eth-utils to >=2,<3 --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 79241342..38e0d78b 100644 --- a/setup.py +++ b/setup.py @@ -7,8 +7,8 @@ from setuptools import ( extras_require = { 'test': [ - "pytest==5.4.1", - "pytest-xdist", + "pytest>=6.2.5,<7", + "pytest-xdist>=2.4.0,<3", "tox==3.14.6", ], 'lint': [ @@ -55,7 +55,7 @@ setup( url='https://github.com/ethereum/', include_package_data=True, install_requires=[ - "eth-utils>=1,<2", + "eth-utils>=2,<3", ], python_requires='>=3.6, <4', extras_require=extras_require, From c6f13bfd943282c452e29dafbde595186010ee53 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 18 May 2022 12:19:24 -0700 Subject: [PATCH 025/102] Show full explanation for pydocstyle failures --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index 3148e02b..edd1dcde 100644 --- a/tox.ini +++ b/tox.ini @@ -44,4 +44,4 @@ commands= mypy -p --config-file {toxinidir}/mypy.ini flake8 {toxinidir}/ {toxinidir}/tests isort --recursive --check-only --diff {toxinidir}/ {toxinidir}/tests - pydocstyle {toxinidir}/ {toxinidir}/tests + pydocstyle --explain {toxinidir}/ {toxinidir}/tests From d3a5a3e9e5ccaac942115ef95bdb87db1644d118 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Fri, 20 May 2022 10:18:36 -0700 Subject: [PATCH 026/102] Exclude huge and unnecessary venv*/ from dist See an example issue here: https://github.com/ethereum/eth-account/issues/150 --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index fbff9807..0d9ffe93 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,3 +6,4 @@ global-include *.pyi recursive-exclude * __pycache__ recursive-exclude * *.py[co] +recursive-exclude * venv* From 2e22e2d0b64850ff03356a9d52c06e79c23ef65f Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 20 May 2022 14:12:01 -0600 Subject: [PATCH 027/102] Add breaking change type to newsfragment (#61) * Add breaking change type to newsfragment * Move breaking-change -> breaking --- newsfragments/README.md | 1 + newsfragments/validate_files.py | 1 + pyproject.toml | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/newsfragments/README.md b/newsfragments/README.md index 09a10ddc..bcb0412a 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -15,6 +15,7 @@ Each file should be named like `..rst`, where * `internal` * `removal` * `misc` +* `breaking` So for example: `123.feature.rst`, `456.bugfix.rst` diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index c0e9b289..0a13ec2a 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -8,6 +8,7 @@ import pathlib import sys ALLOWED_EXTENSIONS = { + '.breaking.rst', '.bugfix.rst', '.doc.rst', '.feature.rst', diff --git a/pyproject.toml b/pyproject.toml index b03fe29e..31433140 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,3 +41,8 @@ showcontent = true directory = "misc" name = "Miscellaneous changes" showcontent = false + +[[tool.towncrier.type]] +directory = "breaking" +name = "Breaking changes" +showcontent = true From e2e1f9d079093737402e31b4f8b65e2be47d22de Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 26 May 2022 14:01:42 -0700 Subject: [PATCH 028/102] Use prune instead of recursive-exclude for venv* Frankly not sure why recursive-exclude doesn't work here, but prune does, and that's good enough for me now. It's also probably preferable to only exclude venv* at the root, anyway. --- MANIFEST.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 0d9ffe93..bb1b0f3e 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,4 +6,4 @@ global-include *.pyi recursive-exclude * __pycache__ recursive-exclude * *.py[co] -recursive-exclude * venv* +prune venv* From 5e100467599407e2aeff854f7624b34c0efff511 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 1 Jun 2022 13:05:34 -0700 Subject: [PATCH 029/102] Use updated CircleCI images See https://discuss.circleci.com/t/legacy-convenience-image-deprecation/41034 --- .circleci/config.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 167ae520..9664ee14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,43 +39,43 @@ jobs: docs: <<: *common docker: - - image: circleci/python:3.6 + - image: cimg/python:3.6 environment: TOXENV: docs lint: <<: *common docker: - - image: circleci/python:3.6 + - image: cimg/python:3.6 environment: TOXENV: lint py36-core: <<: *common docker: - - image: circleci/python:3.6 + - image: cimg/python:3.6 environment: TOXENV: py36-core py37-core: <<: *common docker: - - image: circleci/python:3.7 + - image: cimg/python:3.7 environment: TOXENV: py37-core py38-core: <<: *common docker: - - image: circleci/python:3.8 + - image: cimg/python:3.8 environment: TOXENV: py38-core py39-core: <<: *common docker: - - image: circleci/python:3.9 + - image: cimg/python:3.9 environment: TOXENV: py39-core py310-core: <<: *common docker: - - image: circleci/python:3.10 + - image: cimg/python:3.10 environment: TOXENV: py310-core pypy3-core: From cb112ef9c12e16d2caaf71f7f0c067663499fddf Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 2 Jun 2022 15:36:24 -0700 Subject: [PATCH 030/102] Upgrade towncrier to fix the duplicate title bug --- Makefile | 4 ++-- setup.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d38ac9d9..bc398812 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ build-docs: $(MAKE) -C docs html $(MAKE) -C docs doctest ./newsfragments/validate_files.py - towncrier --draft --version preview + towncrier build --draft --version preview docs: build-docs open docs/_build/html/index.html @@ -63,7 +63,7 @@ notes: check-bump # Let UPCOMING_VERSION be the version that is used for the current bump $(eval UPCOMING_VERSION=$(shell bumpversion $(bump) --dry-run --list | grep new_version= | sed 's/new_version=//g')) # Now generate the release notes to have them included in the release commit - towncrier --yes --version $(UPCOMING_VERSION) + towncrier build --yes --version $(UPCOMING_VERSION) # Before we bump the version, make sure that the towncrier-generated docs will build make build-docs git commit -m "Compile release notes" diff --git a/setup.py b/setup.py index 38e0d78b..6f0abaf1 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ extras_require = { 'doc': [ "Sphinx>=1.6.5,<2", "sphinx_rtd_theme>=0.1.9,<1", - "towncrier>=19.2.0, <20", + "towncrier>=21,<22", ], 'dev': [ "bumpversion>=0.5.3,<1", From 160c0feb056ece2b3d1f2f92d0991c3180bf5de3 Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 22 Jun 2022 13:55:56 -0600 Subject: [PATCH 031/102] Add a validate docs command (#64) --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index bc398812..03e193ba 100644 --- a/Makefile +++ b/Makefile @@ -45,10 +45,12 @@ build-docs: $(MAKE) -C docs clean $(MAKE) -C docs html $(MAKE) -C docs doctest - ./newsfragments/validate_files.py - towncrier build --draft --version preview -docs: build-docs +validate-docs: + python ./newsfragments/validate_files.py + towncrier --draft --version preview + +docs: build-docs validate-docs open docs/_build/html/index.html linux-docs: build-docs From 007725e84d2913c1faace60fec9df1c677f7a3be Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Wed, 31 Aug 2022 14:31:13 -0700 Subject: [PATCH 032/102] Don't push .tox file to tar.gz release It can get big with installed libraries. On a relatively small release of eth-portal, this one change cut the .tar.gz release size from 574Kb to 14Kb. --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index bb1b0f3e..e870a411 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -6,4 +6,5 @@ global-include *.pyi recursive-exclude * __pycache__ recursive-exclude * *.py[co] +prune .tox prune venv* From 99af2f4d53ec9da9abe3a5bfa46d37d32f5c7885 Mon Sep 17 00:00:00 2001 From: kclowes Date: Mon, 19 Sep 2022 14:35:39 -0600 Subject: [PATCH 033/102] Misc Updates (#65) * Tweaks to release process * Drop python 3.6 --- .bumpversion.cfg | 8 +- .circleci/config.yml | 14 ++-- Makefile | 9 ++- docs/conf.py | 169 ++++++++++++++++++++++------------------ newsfragments/README.md | 2 +- pytest.ini | 1 - setup.py | 66 ++++++++-------- tox.ini | 6 +- 8 files changed, 144 insertions(+), 131 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index eefe4ad9..f683001f 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -3,14 +3,14 @@ current_version = 0.1.0-alpha.0 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[^.]*)\.(?P\d+))? -serialize = +serialize = {major}.{minor}.{patch}-{stage}.{devnum} {major}.{minor}.{patch} [bumpversion:part:stage] optional_value = stable first_value = stable -values = +values = alpha beta stable @@ -18,6 +18,6 @@ values = [bumpversion:part:devnum] [bumpversion:file:setup.py] -search = version='{current_version}', -replace = version='{new_version}', +search = version="{current_version}", +replace = version="{new_version}", diff --git a/.circleci/config.yml b/.circleci/config.yml index 9664ee14..b67caf4e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,21 +39,15 @@ jobs: docs: <<: *common docker: - - image: cimg/python:3.6 + - image: cimg/python:3.7 environment: TOXENV: docs lint: <<: *common docker: - - image: cimg/python:3.6 + - image: cimg/python:3.7 environment: TOXENV: lint - py36-core: - <<: *common - docker: - - image: cimg/python:3.6 - environment: - TOXENV: py36-core py37-core: <<: *common docker: @@ -90,6 +84,8 @@ workflows: jobs: - docs - lint - - py36-core - py37-core + - py38-core + - py39-core + - py310-core - pypy3-core diff --git a/Makefile b/Makefile index 03e193ba..541c166d 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,7 @@ lint: lint-roll: isort --recursive tests + black {toxinidir}/ {toxinidir}/tests setup.py $(MAKE) lint test: @@ -48,12 +49,14 @@ build-docs: validate-docs: python ./newsfragments/validate_files.py - towncrier --draft --version preview + towncrier build --draft --version preview -docs: build-docs validate-docs +check-docs: build-docs validate-docs + +docs: check-docs open docs/_build/html/index.html -linux-docs: build-docs +linux-docs: check-docs xdg-open docs/_build/html/index.html check-bump: diff --git a/docs/conf.py b/docs/conf.py index 977f3ab1..8264b456 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,46 +15,46 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -#sys.path.insert(0, os.path.abspath('.')) +# sys.path.insert(0, os.path.abspath('.')) import os -DIR = os.path.dirname('__file__') -with open (os.path.join(DIR, '../setup.py'), 'r') as f: +DIR = os.path.dirname("__file__") +with open(os.path.join(DIR, "../setup.py"), "r") as f: for line in f: - if 'version=' in line: - setup_version = line.split('\'')[1] + if "version=" in line: + setup_version = line.split('"')[1] break # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.doctest', - 'sphinx.ext.intersphinx', + "sphinx.ext.autodoc", + "sphinx.ext.doctest", + "sphinx.ext.intersphinx", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = '' -copyright = '2020, The Ethereum Foundation' +project = "" +copyright = "2020, The Ethereum Foundation" __version__ = setup_version # The version info for the project you're documenting, acts as replacement for @@ -62,176 +62,179 @@ __version__ = setup_version # built documents. # # The short X.Y version. -version = '.'.join(__version__.split('.')[:2]) +version = ".".join(__version__.split(".")[:2]) # The full version, including alpha/beta/rc tags. release = __version__ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [ - '_build', - 'modules.rst', + "_build", + "modules.rst", ] # The reST default role (used for this markup: `text`) to use for all # documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'doc' +htmlhelp_basename = "doc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', - -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', - -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', '.tex', ' Documentation', - 'The Ethereum Foundation', 'manual'), + ( + "index", + ".tex", + " Documentation", + "The Ethereum Foundation", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output --------------------------------------- @@ -239,12 +242,17 @@ latex_documents = [ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', '', ' Documentation', - ['The Ethereum Foundation'], 1) + ( + "index", + "", + " Documentation", + ["The Ethereum Foundation"], + 1, + ) ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -253,34 +261,41 @@ man_pages = [ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', '', ' Documentation', - 'The Ethereum Foundation', '', '', - 'Miscellaneous'), + ( + "index", + "", + " Documentation", + "The Ethereum Foundation", + "", + "", + "Miscellaneous", + ), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # -- Intersphinx configuration ------------------------------------------------ intersphinx_mapping = { - 'python': ('https://docs.python.org/3.6', None), + "python": ("https://docs.python.org/3.10", None), } # -- Doctest configuration ---------------------------------------- import doctest -doctest_default_flags = (0 +doctest_default_flags = ( + 0 | doctest.DONT_ACCEPT_TRUE_FOR_1 | doctest.ELLIPSIS | doctest.IGNORE_EXCEPTION_DETAIL diff --git a/newsfragments/README.md b/newsfragments/README.md index bcb0412a..f98aef6e 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -24,5 +24,5 @@ then open up the PR first and use the PR number for the newsfragment. Note that the `towncrier` tool will automatically reflow your text, so don't try to do any fancy formatting. Run - `towncrier --draft` to get a preview of what the release notes entry + `towncrier build --draft` to get a preview of what the release notes entry will look like in the final release notes. diff --git a/pytest.ini b/pytest.ini index f5fdc0ec..ae90934f 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,5 @@ [pytest] addopts= -v --showlocals --durations 10 -python_paths= . xfail_strict=true [pytest-watch] diff --git a/setup.py b/setup.py index 6f0abaf1..e319e3e0 100644 --- a/setup.py +++ b/setup.py @@ -6,23 +6,24 @@ from setuptools import ( ) extras_require = { - 'test': [ + "test": [ "pytest>=6.2.5,<7", "pytest-xdist>=2.4.0,<3", "tox==3.14.6", ], - 'lint': [ + "lint": [ "flake8==3.7.9", "isort>=4.2.15,<5", "mypy==0.770", "pydocstyle>=5.0.0,<6", + "black>=22,<23", ], - 'doc': [ + "doc": [ "Sphinx>=1.6.5,<2", "sphinx_rtd_theme>=0.1.9,<1", "towncrier>=21,<22", ], - 'dev': [ + "dev": [ "bumpversion>=0.5.3,<1", "pytest-watch>=4.1.0,<5", "wheel", @@ -31,53 +32,52 @@ extras_require = { ], } -extras_require['dev'] = ( - extras_require['dev'] + # noqa: W504 - extras_require['test'] + # noqa: W504 - extras_require['lint'] + # noqa: W504 - extras_require['doc'] +extras_require["dev"] = ( + extras_require["dev"] + + extras_require["test"] + + extras_require["lint"] + + extras_require["doc"] ) -with open('./README.md') as readme: +with open("./README.md") as readme: long_description = readme.read() setup( - name='', + name="", # *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme - version='0.1.0-alpha.0', + version="0.1.0-alpha.0", description=""": """, long_description=long_description, - long_description_content_type='text/markdown', - author='The Ethereum Foundation', - author_email='snakecharmers@ethereum.org', - url='https://github.com/ethereum/', + long_description_content_type="text/markdown", + author="The Ethereum Foundation", + author_email="snakecharmers@ethereum.org", + url="https://github.com/ethereum/", include_package_data=True, install_requires=[ "eth-utils>=2,<3", ], - python_requires='>=3.6, <4', + python_requires=">=3.7, <4", extras_require=extras_require, - py_modules=[''], + py_modules=[""], license="MIT", zip_safe=False, - keywords='ethereum', + keywords="ethereum", packages=find_packages(exclude=["tests", "tests.*"]), - package_data={'': ['py.typed']}, + package_data={"": ["py.typed"]}, classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: MIT License', - 'Natural Language :: English', - 'Operating System :: MacOS', - 'Operating System :: POSIX', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.6', - 'Programming Language :: Python :: 3.7', - 'Programming Language :: Python :: 3.8', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', - 'Programming Language :: Python :: Implementation :: PyPy', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Natural Language :: English", + "Operating System :: MacOS", + "Operating System :: POSIX", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: Implementation :: PyPy", ], ) diff --git a/tox.ini b/tox.ini index edd1dcde..afe023cf 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist= - py{36,37,38,39,310,py3}-core + py{37,38,39,310,py3}-core lint docs @@ -23,10 +23,9 @@ ignore= usedevelop=True commands= core: pytest {posargs:tests/core} - docs: make build-docs + docs: make check-docs basepython = docs: python - py36: python3.6 py37: python3.7 py38: python3.8 py39: python3.9 @@ -45,3 +44,4 @@ commands= flake8 {toxinidir}/ {toxinidir}/tests isort --recursive --check-only --diff {toxinidir}/ {toxinidir}/tests pydocstyle --explain {toxinidir}/ {toxinidir}/tests + black --check {toxinidir}/ {toxinidir}/tests setup.py From e785138a21bd8486653e09dd74e2dba1269a235d Mon Sep 17 00:00:00 2001 From: kclowes Date: Mon, 19 Sep 2022 14:55:43 -0600 Subject: [PATCH 034/102] Use updated tox command in CI (#67) --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b67caf4e..4ce05a43 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,7 +25,7 @@ common: &common command: pip install --user tox - run: name: run tox - command: ~/.local/bin/tox -r + command: python -m tox -r - save_cache: paths: - .hypothesis From 8a4cb1d938c36cac47e60af313d012e2f0fd8065 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 22 Sep 2022 13:38:20 -0700 Subject: [PATCH 035/102] Upgrade isort to v5 for black support --- Makefile | 2 +- setup.py | 2 +- tox.ini | 7 ++----- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 541c166d..231b2b20 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ lint: tox -elint lint-roll: - isort --recursive tests + isort tests black {toxinidir}/ {toxinidir}/tests setup.py $(MAKE) lint diff --git a/setup.py b/setup.py index e319e3e0..1c8088af 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ extras_require = { ], "lint": [ "flake8==3.7.9", - "isort>=4.2.15,<5", + "isort>=5.10.1,<6", "mypy==0.770", "pydocstyle>=5.0.0,<6", "black>=22,<23", diff --git a/tox.ini b/tox.ini index afe023cf..d1dc3e66 100644 --- a/tox.ini +++ b/tox.ini @@ -7,12 +7,9 @@ envlist= [isort] combine_as_imports=True force_sort_within_sections=True -include_trailing_comma=True known_third_party=hypothesis,pytest known_first_party= -line_length=21 -multi_line_output=3 -use_parentheses=True +profile=black [flake8] max-line-length= 100 @@ -42,6 +39,6 @@ extras=lint commands= mypy -p --config-file {toxinidir}/mypy.ini flake8 {toxinidir}/ {toxinidir}/tests - isort --recursive --check-only --diff {toxinidir}/ {toxinidir}/tests + isort --check-only --diff {toxinidir}/ {toxinidir}/tests pydocstyle --explain {toxinidir}/ {toxinidir}/tests black --check {toxinidir}/ {toxinidir}/tests setup.py From 94eacb9c30cb84085038f1eb2991623f459114a7 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 22 Sep 2022 13:38:32 -0700 Subject: [PATCH 036/102] A couple extra tweaks for black support --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index d1dc3e66..0e5a8a1d 100644 --- a/tox.ini +++ b/tox.ini @@ -14,7 +14,7 @@ profile=black [flake8] max-line-length= 100 exclude= venv*,.tox,docs,build -ignore= +extend-ignore= E203 [testenv] usedevelop=True @@ -36,6 +36,7 @@ whitelist_externals=make [testenv:lint] basepython=python extras=lint +whitelist_externals=black commands= mypy -p --config-file {toxinidir}/mypy.ini flake8 {toxinidir}/ {toxinidir}/tests From 4bd024028b4f6e4c7bd69d610d84201b666660fa Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 22 Sep 2022 13:47:14 -0700 Subject: [PATCH 037/102] Fix a copy-paste mistake from #65 toxinidir won't mean anything in a Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 231b2b20..abf94549 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ lint: lint-roll: isort tests - black {toxinidir}/ {toxinidir}/tests setup.py + black tests setup.py $(MAKE) lint test: From 7b0bc76f6ff430b7530324dc17f1895ebc38c70c Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 9 Nov 2022 11:11:28 -0700 Subject: [PATCH 038/102] Add Python 3.11, add more black checks, remove upper pins (#69) --- .circleci/config.yml | 7 +++++++ setup.py | 21 +++++++++++---------- tox.ini | 5 +++-- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4ce05a43..db95741c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -72,6 +72,12 @@ jobs: - image: cimg/python:3.10 environment: TOXENV: py310-core + py311-core: + <<: *common + docker: + - image: cimg/python:3.11 + environment: + TOXENV: py311-core pypy3-core: <<: *common docker: @@ -88,4 +94,5 @@ workflows: - py38-core - py39-core - py310-core + - py311-core - pypy3-core diff --git a/setup.py b/setup.py index 1c8088af..9dfbf788 100644 --- a/setup.py +++ b/setup.py @@ -7,25 +7,25 @@ from setuptools import ( extras_require = { "test": [ - "pytest>=6.2.5,<7", + "pytest>=6.2.5", "pytest-xdist>=2.4.0,<3", "tox==3.14.6", ], "lint": [ "flake8==3.7.9", - "isort>=5.10.1,<6", + "isort>=5.10.1", "mypy==0.770", - "pydocstyle>=5.0.0,<6", - "black>=22,<23", + "pydocstyle>=5.0.0", + "black>=22", ], "doc": [ - "Sphinx>=1.6.5,<2", - "sphinx_rtd_theme>=0.1.9,<1", - "towncrier>=21,<22", + "Sphinx>=1.6.5", + "sphinx_rtd_theme>=0.1.9", + "towncrier>=21", ], "dev": [ - "bumpversion>=0.5.3,<1", - "pytest-watch>=4.1.0,<5", + "bumpversion>=0.5.3", + "pytest-watch>=4.1.0", "wheel", "twine", "ipython", @@ -56,7 +56,7 @@ setup( url="https://github.com/ethereum/", include_package_data=True, install_requires=[ - "eth-utils>=2,<3", + "eth-utils>=2", ], python_requires=">=3.7, <4", extras_require=extras_require, @@ -78,6 +78,7 @@ setup( "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: PyPy", ], ) diff --git a/tox.ini b/tox.ini index 0e5a8a1d..00ca4463 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] envlist= - py{37,38,39,310,py3}-core + py{37,38,39,310,311,py3}-core lint docs @@ -27,6 +27,7 @@ basepython = py38: python3.8 py39: python3.9 py310: python3.10 + py311: python3.11 pypy3: pypy3 extras= test @@ -42,4 +43,4 @@ commands= flake8 {toxinidir}/ {toxinidir}/tests isort --check-only --diff {toxinidir}/ {toxinidir}/tests pydocstyle --explain {toxinidir}/ {toxinidir}/tests - black --check {toxinidir}/ {toxinidir}/tests setup.py + black --check {toxinidir}/ {toxinidir}/docs {toxinidir}/tests {toxinidir}/setup.py From 3ff1c9cf5d6d1867bc1216e586c65f787e15c0e3 Mon Sep 17 00:00:00 2001 From: fselmo Date: Mon, 21 Nov 2022 17:25:08 -0700 Subject: [PATCH 039/102] Minor refactoring / cleanup - Clean up github PR template to remove double links to the newsfragment README.md - Clean up some typos and make some minor refactors. --- .github/PULL_REQUEST_TEMPLATE.md | 10 +++------- newsfragments/README.md | 4 ++-- newsfragments/validate_files.py | 28 +++++++++++++++------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 21d4db59..54da5516 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,18 +1,14 @@ -## What was wrong? +### What was wrong? -Issue # +Related to issue # -## How was it fixed? - -Summary of approach. +### How was it fixed? ### To-Do [//]: # (Stay ahead of things, add list items here!) - [ ] Clean up commit history -[//]: # (For important changes that should go into the release notes please add a newsfragment file as explained here: https://github.com/ethereum//blob/master/newsfragments/README.md) - [//]: # (See: https://.readthedocs.io/en/latest/contributing.html#pull-requests) - [ ] Add entry to the [release notes](https://github.com/ethereum//blob/master/newsfragments/README.md) diff --git a/newsfragments/README.md b/newsfragments/README.md index f98aef6e..e4740e4b 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -6,7 +6,7 @@ commit message and PR description, which are a description of the change as relevant to people working on the code itself.) Each file should be named like `..rst`, where -`` is an issue numbers, and `` is one of: +`` is an issue number, and `` is one of: * `feature` * `bugfix` @@ -24,5 +24,5 @@ then open up the PR first and use the PR number for the newsfragment. Note that the `towncrier` tool will automatically reflow your text, so don't try to do any fancy formatting. Run - `towncrier build --draft` to get a preview of what the release notes entry +`towncrier build --draft` to get a preview of what the release notes entry will look like in the final release notes. diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index 0a13ec2a..684c7987 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -8,19 +8,19 @@ import pathlib import sys ALLOWED_EXTENSIONS = { - '.breaking.rst', - '.bugfix.rst', - '.doc.rst', - '.feature.rst', - '.internal.rst', - '.misc.rst', - '.performance.rst', - '.removal.rst', + ".breaking.rst", + ".bugfix.rst", + ".doc.rst", + ".feature.rst", + ".internal.rst", + ".misc.rst", + ".performance.rst", + ".removal.rst", } ALLOWED_FILES = { - 'validate_files.py', - 'README.md', + "validate_files.py", + "README.md", } THIS_DIR = pathlib.Path(__file__).parent @@ -28,7 +28,7 @@ THIS_DIR = pathlib.Path(__file__).parent num_args = len(sys.argv) - 1 assert num_args in {0, 1} if num_args == 1: - assert sys.argv[1] in ('is-empty', ) + assert sys.argv[1] in ("is-empty",) for fragment_file in THIS_DIR.iterdir(): @@ -38,7 +38,9 @@ for fragment_file in THIS_DIR.iterdir(): full_extension = "".join(fragment_file.suffixes) if full_extension not in ALLOWED_EXTENSIONS: raise Exception(f"Unexpected file: {fragment_file}") - elif sys.argv[1] == 'is-empty': + elif sys.argv[1] == "is-empty": raise Exception(f"Unexpected file: {fragment_file}") else: - raise RuntimeError("Strange: arguments {sys.argv} were validated, but not found") + raise RuntimeError( + f"Strange: arguments {sys.argv} were validated, but not found" + ) From 7c85f95a4dfb0e6bbf425b1d22dd69c6c27cf98e Mon Sep 17 00:00:00 2001 From: fselmo Date: Mon, 21 Nov 2022 17:27:18 -0700 Subject: [PATCH 040/102] Do not invoke ``setup.py`` directly - It is not recommended to invoke ``setup.py`` directly, instead opting for ``python -m build`` for the commands in this commit (see: https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html) - Add newsfragment for #70 --- Makefile | 6 +++--- newsfragments/70.internal.rst | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 newsfragments/70.internal.rst diff --git a/Makefile b/Makefile index 541c166d..9ec20499 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ clean-pyc: find . -name '__pycache__' -exec rm -rf {} + lint: - tox -elint + tox -e lint lint-roll: isort --recursive tests @@ -83,11 +83,11 @@ release: check-bump clean git config commit.gpgSign true bumpversion $(bump) git push upstream && git push upstream --tags - python setup.py sdist bdist_wheel + python -m build twine upload dist/* git config commit.gpgSign "$(CURRENT_SIGN_SETTING)" dist: clean - python setup.py sdist bdist_wheel + python -m build ls -l dist diff --git a/newsfragments/70.internal.rst b/newsfragments/70.internal.rst new file mode 100644 index 00000000..2e2fd5f9 --- /dev/null +++ b/newsfragments/70.internal.rst @@ -0,0 +1 @@ +Do not invoke ``setup.py`` directly. Minor cleanup and refactors in newsfragment ``README.md`` and newsfragment validation. Minot cleanup in ``Makefile``. From af2dfa6560c9737fe202ac30a0b3511949406689 Mon Sep 17 00:00:00 2001 From: kclowes Date: Thu, 8 Dec 2022 15:19:05 -0700 Subject: [PATCH 041/102] Fix auto project template errors for MacOS (#71) --- .project-template/fill_template_vars.sh | 2 +- .project-template/refill_template_vars.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.project-template/fill_template_vars.sh b/.project-template/fill_template_vars.sh index 250f5512..157c89d3 100755 --- a/.project-template/fill_template_vars.sh +++ b/.project-template/fill_template_vars.sh @@ -33,7 +33,7 @@ _replace() { local find_cmd=(find "$PROJECT_ROOT" ! -perm -u=x ! -path '*/.git/*' ! -path '*/venv*/*' -type f) if [[ $(uname) == Darwin ]]; then - "${find_cmd[@]}" -exec sed -i '' "$1" {} + + LC_ALL=C "${find_cmd[@]}" -exec sed -i '' "$1" {} + else "${find_cmd[@]}" -exec sed -i "$1" {} + fi diff --git a/.project-template/refill_template_vars.sh b/.project-template/refill_template_vars.sh index 6e7943fb..70832d3d 100755 --- a/.project-template/refill_template_vars.sh +++ b/.project-template/refill_template_vars.sh @@ -1,2 +1,2 @@ -TEMPLATE_DIR=$(dirname $(readlink -f "$0")) +TEMPLATE_DIR=$(dirname "$0") <"$TEMPLATE_DIR/template_vars.txt" "$TEMPLATE_DIR/fill_template_vars.sh" From 642ae9627cd28fc9ba8c0c745375a0becbc202eb Mon Sep 17 00:00:00 2001 From: kclowes Date: Fri, 9 Dec 2022 11:25:55 -0700 Subject: [PATCH 042/102] Update isort CLI commands (#72) --- tox.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tox.ini b/tox.ini index 00ca4463..23729cfc 100644 --- a/tox.ini +++ b/tox.ini @@ -6,9 +6,11 @@ envlist= [isort] combine_as_imports=True +force_grid_wrap=1 force_sort_within_sections=True known_third_party=hypothesis,pytest known_first_party= +multi_line_output=3 profile=black [flake8] From fe19f5a77a5fbba712da052ef3d25f187257ed3c Mon Sep 17 00:00:00 2001 From: pacrob Date: Mon, 3 Apr 2023 14:01:03 -0600 Subject: [PATCH 043/102] bump docs dependencies --- .readthedocs.yml | 5 +++++ docs/conf.py | 1 + newsfragments/70.internal.rst | 1 - setup.py | 6 +++--- 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .readthedocs.yml delete mode 100644 newsfragments/70.internal.rst diff --git a/.readthedocs.yml b/.readthedocs.yml new file mode 100644 index 00000000..ed4fab3c --- /dev/null +++ b/.readthedocs.yml @@ -0,0 +1,5 @@ +version: 2 + +python: + install: + - requirements: requirements-docs.txt \ No newline at end of file diff --git a/docs/conf.py b/docs/conf.py index 8264b456..df931f1a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -38,6 +38,7 @@ extensions = [ "sphinx.ext.autodoc", "sphinx.ext.doctest", "sphinx.ext.intersphinx", + "sphinx_rtd_theme", ] # Add any paths that contain templates here, relative to this directory. diff --git a/newsfragments/70.internal.rst b/newsfragments/70.internal.rst deleted file mode 100644 index 2e2fd5f9..00000000 --- a/newsfragments/70.internal.rst +++ /dev/null @@ -1 +0,0 @@ -Do not invoke ``setup.py`` directly. Minor cleanup and refactors in newsfragment ``README.md`` and newsfragment validation. Minot cleanup in ``Makefile``. diff --git a/setup.py b/setup.py index 9dfbf788..04028b11 100644 --- a/setup.py +++ b/setup.py @@ -19,9 +19,9 @@ extras_require = { "black>=22", ], "doc": [ - "Sphinx>=1.6.5", - "sphinx_rtd_theme>=0.1.9", - "towncrier>=21", + "sphinx>=5.0.0", + "sphinx_rtd_theme>=1.0.0", + "towncrier>=21,<22", ], "dev": [ "bumpversion>=0.5.3", From 89e5d8ef9c637c9ac8fbefa11230b3beeb4a2e54 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 5 Apr 2023 18:00:29 -0600 Subject: [PATCH 044/102] new github issue and pr templates (#75) * new issue and pr templates --- .github/ISSUE_TEMPLATE.md | 38 ------------ .github/ISSUE_TEMPLATE/bug_report.yml | 70 ++++++++++++++++++++++ .github/ISSUE_TEMPLATE/config.yml | 5 ++ .github/ISSUE_TEMPLATE/feature_request.yml | 11 ++++ .github/PULL_REQUEST_TEMPLATE.md | 17 ------ .github/pull_request_template.md | 17 ++++++ 6 files changed, 103 insertions(+), 55 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/ISSUE_TEMPLATE/bug_report.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request.yml delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/pull_request_template.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 5ff4880e..00000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,38 +0,0 @@ - _If this is a bug report, please fill in the following sections. -If this is a feature request, delete and describe what you would like with examples._ - -## What was wrong? - -### Code that produced the error - -```py -CODE_TO_REPRODUCE -``` - -### Full error output - -```sh -ERROR_HERE -``` - -### Expected Result - -_This section may be deleted if the expectation is "don't crash"._ - -```sh -EXPECTED_RESULT -``` - -### Environment - -```sh -# run this: -$ python -m eth_utils - -# then copy the output here: -OUTPUT_HERE -``` - -## How can it be fixed? - -Fill this section in if you know how this could or should be fixed. diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000..5f1ddfd8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,70 @@ +name: Bug Report +description: File a bug report +labels: ["bug"] +body: + - type: markdown + attributes: + value: "## What was wrong" + - type: textarea + id: what-happened + attributes: + label: What happened? + description: Also tell us what you expected to happen + validations: + required: true + - type: textarea + id: code-that-caused + attributes: + label: Code that produced the error + description: Formats to Python, no backticks needed + render: python + validations: + required: false + - type: textarea + id: error-output + attributes: + label: Full error output + description: Formats to shell, no backticks needed + render: shell + validations: + required: false + - type: markdown + attributes: + value: "## Potential Solutions" + - type: textarea + id: how-to-fix + attributes: + label: Fill this section in if you know how this could or should be fixed + description: Include any relevant examples or reference material + validations: + required: false + - type: input + id: lib-version + attributes: + label: Version + description: Which version of are you using? + placeholder: x.x.x + validations: + required: false + - type: input + id: py-version + attributes: + label: Python Version + description: Which version of Python are you using? + placeholder: x.x.x + validations: + required: false + - type: input + id: os + attributes: + label: Operating System + description: Which operating system are you using? + placeholder: osx/linux/win + validations: + required: false + - type: textarea + id: pip-freeze + attributes: + label: Output from pip-freeze + description: Run `pip-freeze` and paste the output below + render: shell diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 00000000..9853c794 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,5 @@ +blank_issues_enabled: true +contact_links: + - name: Questions about using ? + url: https://discord.gg/GHryRvPB84 + about: You can ask and answer usage questions on the Ethereum Python Community Discord diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 00000000..041c8fd1 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,11 @@ +name: Feature Request +description: Request a new feature +labels: ["feature_request"] +body: + - type: textarea + id: feature-description + attributes: + label: What feature should we add? + description: Include any relevant examples or reference material + validations: + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 54da5516..00000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,17 +0,0 @@ -### What was wrong? - -Related to issue # - -### How was it fixed? - -### To-Do - -[//]: # (Stay ahead of things, add list items here!) -- [ ] Clean up commit history - -[//]: # (See: https://.readthedocs.io/en/latest/contributing.html#pull-requests) -- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/master/newsfragments/README.md) - -#### Cute Animal Picture - -![put a cute animal picture link inside the parentheses]() diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..93fb355e --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,17 @@ +### What was wrong? + +Related to Issue # +Closes Issue # + +### How was it fixed? + +### Todo: +- [ ] Clean up commit history + +- [ ] Add or update documentation related to these changes + +- [ ] Add entry to the [release notes](https://github.com/ethereum/web3.py/blob/master/newsfragments/README.md) + +#### Cute Animal Picture + +![Put a link to a cute animal picture inside the parenthesis-->]() \ No newline at end of file From 180777d7db608b8db4a271c5502d0568107d8931 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Fri, 7 Apr 2023 10:22:12 -0600 Subject: [PATCH 045/102] convert bash scripts to py (#77) * convert bash scripts to py --- .project-template/fill_template_vars.py | 68 +++++++++++++++++++++++ .project-template/fill_template_vars.sh | 50 ----------------- .project-template/refill_template_vars.py | 39 +++++++++++++ .project-template/refill_template_vars.sh | 2 - 4 files changed, 107 insertions(+), 52 deletions(-) create mode 100644 .project-template/fill_template_vars.py delete mode 100755 .project-template/fill_template_vars.sh create mode 100644 .project-template/refill_template_vars.py delete mode 100755 .project-template/refill_template_vars.sh diff --git a/.project-template/fill_template_vars.py b/.project-template/fill_template_vars.py new file mode 100644 index 00000000..8d4bc35f --- /dev/null +++ b/.project-template/fill_template_vars.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import os +import sys +import re +from pathlib import Path + + +def _find_files(project_root): + path_exclude_pattern = r"\.git($|\/)|venv|_build" + file_exclude_pattern = r"fill_template_vars\.py|\.swp$" + filepaths = [] + for dir_path, _dir_names, file_names in os.walk(project_root): + if not re.search(path_exclude_pattern, dir_path): + for file in file_names: + if not re.search(file_exclude_pattern, file): + filepaths.append(str(Path(dir_path, file))) + + return filepaths + + +def _replace(pattern, replacement, project_root): + print(f"Replacing values: {pattern}") + for file in _find_files(project_root): + with open(file) as f: + content = f.read() + content = re.sub(pattern, replacement, content) + with open(file, "w") as f: + f.write(content) + + +def main(): + project_root = Path(os.path.realpath(sys.argv[0])).parent.parent + + module_name = input("What is your python module name? ") + + pypi_input = input(f"What is your pypi package name? (default: {module_name}) ") + pypi_name = pypi_input or module_name + + repo_input = input(f"What is your github project name? (default: {pypi_name}) ") + repo_name = repo_input or pypi_name + + rtd_input = input( + f"What is your readthedocs.org project name? (default: {pypi_name}) " + ) + rtd_name = rtd_input or pypi_name + + project_input = input( + f"What is your project name (ex: at the top of the README)? (default: {repo_name}) " + ) + project_name = project_input or repo_name + + short_description = input("What is a one-liner describing the project? ") + + _replace("", module_name, project_root) + _replace("", pypi_name, project_root) + _replace("", repo_name, project_root) + _replace("", rtd_name, project_root) + _replace("", project_name, project_root) + _replace("", short_description, project_root) + + os.makedirs(project_root / module_name, exist_ok=True) + Path(project_root / module_name / "__init__.py").touch() + Path(project_root / module_name / "py.typed").touch() + + +if __name__ == "__main__": + main() diff --git a/.project-template/fill_template_vars.sh b/.project-template/fill_template_vars.sh deleted file mode 100755 index 157c89d3..00000000 --- a/.project-template/fill_template_vars.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o nounset -set -o pipefail - -PROJECT_ROOT=$(dirname $(dirname $(python -c 'import os, sys; sys.stdout.write(os.path.realpath(sys.argv[1]))' "$0"))) - -echo "What is your python module name?" -read MODULE_NAME - -echo "What is your pypi package name? (default: $MODULE_NAME)" -read PYPI_INPUT -PYPI_NAME=${PYPI_INPUT:-$MODULE_NAME} - -echo "What is your github project name? (default: $PYPI_NAME)" -read REPO_INPUT -REPO_NAME=${REPO_INPUT:-$PYPI_NAME} - -echo "What is your readthedocs.org project name? (default: $PYPI_NAME)" -read RTD_INPUT -RTD_NAME=${RTD_INPUT:-$PYPI_NAME} - -echo "What is your project name (ex: at the top of the README)? (default: $REPO_NAME)" -read PROJECT_INPUT -PROJECT_NAME=${PROJECT_INPUT:-$REPO_NAME} - -echo "What is a one-liner describing the project?" -read SHORT_DESCRIPTION - -_replace() { - echo "Replacing values: $1" - local find_cmd=(find "$PROJECT_ROOT" ! -perm -u=x ! -path '*/.git/*' ! -path '*/venv*/*' -type f) - - if [[ $(uname) == Darwin ]]; then - LC_ALL=C "${find_cmd[@]}" -exec sed -i '' "$1" {} + - else - "${find_cmd[@]}" -exec sed -i "$1" {} + - fi -} -_replace "s//$MODULE_NAME/g" -_replace "s//$PYPI_NAME/g" -_replace "s//$REPO_NAME/g" -_replace "s//$RTD_NAME/g" -_replace "s//$PROJECT_NAME/g" -_replace "s//$SHORT_DESCRIPTION/g" - -mkdir -p "$PROJECT_ROOT/$MODULE_NAME" -touch "$PROJECT_ROOT/$MODULE_NAME/__init__.py" -touch "$PROJECT_ROOT/$MODULE_NAME/py.typed" diff --git a/.project-template/refill_template_vars.py b/.project-template/refill_template_vars.py new file mode 100644 index 00000000..03ab7c0c --- /dev/null +++ b/.project-template/refill_template_vars.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import os +import sys +from pathlib import Path +import subprocess + + +def main(): + template_dir = Path(os.path.dirname(sys.argv[0])) + template_vars_file = template_dir / "template_vars.txt" + fill_template_vars_script = template_dir / "fill_template_vars.py" + + with open(template_vars_file, "r") as input_file: + content_lines = input_file.readlines() + + process = subprocess.Popen( + [sys.executable, str(fill_template_vars_script)], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + text=True, + ) + + for line in content_lines: + process.stdin.write(line) + process.stdin.flush() + + stdout, stderr = process.communicate() + + if process.returncode != 0: + print(f"Error occurred: {stderr}") + sys.exit(1) + + print(stdout) + + +if __name__ == "__main__": + main() diff --git a/.project-template/refill_template_vars.sh b/.project-template/refill_template_vars.sh deleted file mode 100755 index 70832d3d..00000000 --- a/.project-template/refill_template_vars.sh +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE_DIR=$(dirname "$0") -<"$TEMPLATE_DIR/template_vars.txt" "$TEMPLATE_DIR/fill_template_vars.sh" From ffd6ad8b9fe4fce1ddd38d3212dca0b14b89a79e Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:10:15 -0600 Subject: [PATCH 046/102] Various template default updates (#74) * bump versions in dependencies and ci builds * move tox to [dev] per issue #34 * move RTD deps pointer into .readthedocs.yml * unpin flake8 add flake8-bugbear to lint deps --- .circleci/config.yml | 43 ++++++++++++++++++++++++++++++++----------- .readthedocs.yml | 5 ++++- requirements-docs.txt | 1 - setup.py | 12 ++++++------ tox.ini | 22 +++++++++++++++------- 5 files changed, 57 insertions(+), 26 deletions(-) delete mode 100644 requirements-docs.txt diff --git a/.circleci/config.yml b/.circleci/config.yml index db95741c..237a3f62 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,60 +39,81 @@ jobs: docs: <<: *common docker: - - image: cimg/python:3.7 + - image: cimg/python:3.8 environment: TOXENV: docs - lint: + py37-lint: <<: *common docker: - image: cimg/python:3.7 environment: - TOXENV: lint + TOXENV: py37-lint py37-core: <<: *common docker: - image: cimg/python:3.7 environment: TOXENV: py37-core + py38-lint: + <<: *common + docker: + - image: cimg/python:3.8 + environment: + TOXENV: py38-lint py38-core: <<: *common docker: - image: cimg/python:3.8 environment: TOXENV: py38-core + py39-lint: + <<: *common + docker: + - image: cimg/python:3.9 + environment: + TOXENV: py39-lint py39-core: <<: *common docker: - image: cimg/python:3.9 environment: TOXENV: py39-core + py310-lint: + <<: *common + docker: + - image: cimg/python:3.10 + environment: + TOXENV: py310-lint py310-core: <<: *common docker: - image: cimg/python:3.10 environment: TOXENV: py310-core + py311-lint: + <<: *common + docker: + - image: cimg/python:3.11 + environment: + TOXENV: py311-lint py311-core: <<: *common docker: - image: cimg/python:3.11 environment: TOXENV: py311-core - pypy3-core: - <<: *common - docker: - - image: pypy - environment: - TOXENV: pypy3-core workflows: version: 2 test: jobs: - docs - - lint + - py37-lint + - py38-lint + - py39-lint + - py310-lint + - py311-lint - py37-core - py38-core - py39-core - py310-core - py311-core - - pypy3-core diff --git a/.readthedocs.yml b/.readthedocs.yml index ed4fab3c..959cf717 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -2,4 +2,7 @@ version: 2 python: install: - - requirements: requirements-docs.txt \ No newline at end of file + - method: pip + path: . + extra_requirements: + - doc diff --git a/requirements-docs.txt b/requirements-docs.txt deleted file mode 100644 index 1b49b744..00000000 --- a/requirements-docs.txt +++ /dev/null @@ -1 +0,0 @@ -[doc] diff --git a/setup.py b/setup.py index 04028b11..33f94256 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ from setuptools import ( extras_require = { "test": [ - "pytest>=6.2.5", - "pytest-xdist>=2.4.0,<3", - "tox==3.14.6", + "pytest>=7.0.0", + "pytest-xdist>=2.4.0", ], "lint": [ - "flake8==3.7.9", + "flake8>=5.0.0", + "flake8-bugbear>=22.0.0", "isort>=5.10.1", - "mypy==0.770", + "mypy==0.971", "pydocstyle>=5.0.0", "black>=22", ], @@ -26,6 +26,7 @@ extras_require = { "dev": [ "bumpversion>=0.5.3", "pytest-watch>=4.1.0", + "tox>=3.18.0", "wheel", "twine", "ipython", @@ -79,6 +80,5 @@ setup( "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: Implementation :: PyPy", ], ) diff --git a/tox.ini b/tox.ini index 23729cfc..64147d4f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist= - py{37,38,39,310,311,py3}-core - lint + py{37,38,39,310,311}-core + py{37,38,39,310,311}-lint docs [isort] @@ -14,7 +14,7 @@ multi_line_output=3 profile=black [flake8] -max-line-length= 100 +max-line-length= 88 exclude= venv*,.tox,docs,build extend-ignore= E203 @@ -30,19 +30,27 @@ basepython = py39: python3.9 py310: python3.10 py311: python3.11 - pypy3: pypy3 extras= test docs: doc -whitelist_externals=make +allowlist_externals=make -[testenv:lint] +[common-lint] basepython=python extras=lint -whitelist_externals=black +allowlist_externals=black commands= mypy -p --config-file {toxinidir}/mypy.ini flake8 {toxinidir}/ {toxinidir}/tests isort --check-only --diff {toxinidir}/ {toxinidir}/tests pydocstyle --explain {toxinidir}/ {toxinidir}/tests black --check {toxinidir}/ {toxinidir}/docs {toxinidir}/tests {toxinidir}/setup.py + +[testenv:lint] +basepython: python +extras: {[common-lint]extras} +commands: {[common-lint]commands} + +[testenv:py{37,38,39,310,311}-lint] +extras: {[common-lint]extras} +commands: {[common-lint]commands} From 91d93efdd09189d841a733ce0329f234c73a908c Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Mon, 10 Apr 2023 11:11:35 -0600 Subject: [PATCH 047/102] remove outdated sections of README (#76) * remove gitter, testing setup, and pandoc sections, add quotes to dev install --- README.md | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/README.md b/README.md index 92b70bea..a3bc2c7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # -[![Join the chat at https://gitter.im/ethereum/](https://badges.gitter.im/ethereum/.svg)](https://gitter.im/ethereum/?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://circleci.com/gh/ethereum/.svg?style=shield)](https://circleci.com/gh/ethereum/) [![PyPI version](https://badge.fury.io/py/.svg)](https://badge.fury.io/py/) [![Python versions](https://img.shields.io/pypi/pyversions/.svg)](https://pypi.python.org/pypi/) @@ -37,43 +36,11 @@ git clone git@github.com:ethereum/.git cd virtualenv -p python3 venv . venv/bin/activate -pip install -e .[dev] -``` - -### Testing Setup - -During development, you might like to have tests run on every file save. - -Show flake8 errors on file change: - -```sh -# Test flake8 -when-changed -v -s -r -1 / tests/ -c "clear; flake8 tests && echo 'flake8 success' || echo 'error'" -``` - -Run multi-process tests in one command, but without color: - -```sh -# in the project root: -pytest --numprocesses=4 --looponfail --maxfail=1 -# the same thing, succinctly: -pytest -n 4 -f --maxfail=1 -``` - -Run in one thread, with color and desktop notifications: - -```sh -cd venv -ptw --onfail "notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 3 test on failed'" ../tests ../ +pip install -e ".[dev]" ``` ### Release setup -For Debian-like systems: -``` -apt install pandoc -``` - To release a new version: ```sh From 68d37fa50ff45980823c2259178d1339520870d8 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:02:45 -0600 Subject: [PATCH 048/102] repin flake8 and misc updates (#79) * repin flake8, bump tox to >=4.0.0 as that's where whitelist was deprecated, misc updates --- .circleci/config.yml | 1 + .project-template/fill_template_vars.py | 2 +- MANIFEST.in | 1 - setup.py | 6 +++--- tox.ini | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 237a3f62..eb10bbe3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,6 +102,7 @@ jobs: - image: cimg/python:3.11 environment: TOXENV: py311-core + workflows: version: 2 test: diff --git a/.project-template/fill_template_vars.py b/.project-template/fill_template_vars.py index 8d4bc35f..bbbe2f7f 100644 --- a/.project-template/fill_template_vars.py +++ b/.project-template/fill_template_vars.py @@ -7,7 +7,7 @@ from pathlib import Path def _find_files(project_root): - path_exclude_pattern = r"\.git($|\/)|venv|_build" + path_exclude_pattern = r"\.git($|\/)|venv|_build|\.tox" file_exclude_pattern = r"fill_template_vars\.py|\.swp$" filepaths = [] for dir_path, _dir_names, file_names in os.walk(project_root): diff --git a/MANIFEST.in b/MANIFEST.in index e870a411..22c6165d 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,5 @@ include LICENSE include README.md -include requirements-docs.txt global-include *.pyi diff --git a/setup.py b/setup.py index 33f94256..a18d9bc4 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ extras_require = { "pytest-xdist>=2.4.0", ], "lint": [ - "flake8>=5.0.0", - "flake8-bugbear>=22.0.0", + "flake8==6.0.0", + "flake8-bugbear==23.3.23", "isort>=5.10.1", "mypy==0.971", "pydocstyle>=5.0.0", @@ -26,7 +26,7 @@ extras_require = { "dev": [ "bumpversion>=0.5.3", "pytest-watch>=4.1.0", - "tox>=3.18.0", + "tox>=4.0.0", "wheel", "twine", "ipython", diff --git a/tox.ini b/tox.ini index 64147d4f..e5255baa 100644 --- a/tox.ini +++ b/tox.ini @@ -14,16 +14,16 @@ multi_line_output=3 profile=black [flake8] -max-line-length= 88 -exclude= venv*,.tox,docs,build -extend-ignore= E203 +max-line-length=88 +exclude=venv*,.tox,docs,build +extend-ignore=E203 [testenv] usedevelop=True commands= core: pytest {posargs:tests/core} docs: make check-docs -basepython = +basepython= docs: python py37: python3.7 py38: python3.8 From 431db897535642e3b4f1616e3cb393171ae1c063 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 12 Apr 2023 15:35:34 -0600 Subject: [PATCH 049/102] template cleanup following initial merge with py-evm (#80) * template cleanup following initial merge with py-evm * add flake8 pin comment * correct license years * add pin note to mypy --- .circleci/config.yml | 4 ++-- .project-template/fill_template_vars.py | 15 +++++++++------ LICENSE | 2 +- README.md | 3 ++- docs/_static/.suppress-sphinx-build-warning | 0 newsfragments/validate_files.py | 1 - pytest.ini | 5 ++++- setup.py | 8 ++++---- tests/core/conftest.py | 0 tests/core/test_import.py | 2 -- 10 files changed, 22 insertions(+), 18 deletions(-) delete mode 100644 docs/_static/.suppress-sphinx-build-warning delete mode 100644 tests/core/conftest.py diff --git a/.circleci/config.yml b/.circleci/config.yml index eb10bbe3..b4b822ad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ common: &common when: on_fail - restore_cache: keys: - - cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - run: name: install dependencies command: pip install --user tox @@ -33,7 +33,7 @@ common: &common - ~/.cache/pip - ~/.local - ./eggs - key: cache-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} jobs: docs: diff --git a/.project-template/fill_template_vars.py b/.project-template/fill_template_vars.py index bbbe2f7f..52ceb02b 100644 --- a/.project-template/fill_template_vars.py +++ b/.project-template/fill_template_vars.py @@ -7,7 +7,7 @@ from pathlib import Path def _find_files(project_root): - path_exclude_pattern = r"\.git($|\/)|venv|_build|\.tox" + path_exclude_pattern = r"\.git($|\/)|venv|_build" file_exclude_pattern = r"fill_template_vars\.py|\.swp$" filepaths = [] for dir_path, _dir_names, file_names in os.walk(project_root): @@ -22,11 +22,14 @@ def _find_files(project_root): def _replace(pattern, replacement, project_root): print(f"Replacing values: {pattern}") for file in _find_files(project_root): - with open(file) as f: - content = f.read() - content = re.sub(pattern, replacement, content) - with open(file, "w") as f: - f.write(content) + try: + with open(file) as f: + content = f.read() + content = re.sub(pattern, replacement, content) + with open(file, "w") as f: + f.write(content) + except UnicodeDecodeError: + pass def main(): diff --git a/LICENSE b/LICENSE index 17bc694e..b76b24d4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 The Ethereum Foundation +Copyright (c) 2019-2023 The Ethereum Foundation Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a3bc2c7c..86b1e410 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # +[![Join the conversation on Discord](https://img.shields.io/discord/809793915578089484?color=blue&label=chat&logo=discord&logoColor=white)](https://discord.gg/GHryRvPB84) [![Build Status](https://circleci.com/gh/ethereum/.svg?style=shield)](https://circleci.com/gh/ethereum/) [![PyPI version](https://badge.fury.io/py/.svg)](https://badge.fury.io/py/) [![Python versions](https://img.shields.io/pypi/pyversions/.svg)](https://pypi.python.org/pypi/) -[![Docs build](https://readthedocs.org/projects//badge/?version=latest)](http://.readthedocs.io/en/latest/?badge=latest) +[![Docs build](https://readthedocs.org/projects//badge/?version=latest)](https://.readthedocs.io/en/latest/?badge=latest) diff --git a/docs/_static/.suppress-sphinx-build-warning b/docs/_static/.suppress-sphinx-build-warning deleted file mode 100644 index e69de29b..00000000 diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index 684c7987..c4bd29f6 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -3,7 +3,6 @@ # Towncrier silently ignores files that do not match the expected ending. # We use this script to ensure we catch these as errors in CI. -import os import pathlib import sys diff --git a/pytest.ini b/pytest.ini index ae90934f..95a6b2d6 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,9 @@ [pytest] -addopts= -v --showlocals --durations 10 +addopts= -v --showlocals --durations 10 xfail_strict=true +log_format = %(levelname)8s %(asctime)s %(filename)20s %(message)s +log_date_format = %m-%d %H:%M:%S +timeout = 300 [pytest-watch] runner= pytest --failed-first --maxfail=1 --no-success-flaky-report diff --git a/setup.py b/setup.py index a18d9bc4..c359d0be 100644 --- a/setup.py +++ b/setup.py @@ -11,11 +11,11 @@ extras_require = { "pytest-xdist>=2.4.0", ], "lint": [ - "flake8==6.0.0", - "flake8-bugbear==23.3.23", + "flake8==6.0.0", # flake8 claims semver but adds new warnings at minor releases, leave it pinned. + "flake8-bugbear==23.3.23", # flake8-bugbear does not follow semver, leave it pinned. "isort>=5.10.1", - "mypy==0.971", - "pydocstyle>=5.0.0", + "mypy==0.971", # mypy does not follow semver, leave it pinned. + "pydocstyle>=6.0.0", "black>=22", ], "doc": [ diff --git a/tests/core/conftest.py b/tests/core/conftest.py deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/core/test_import.py b/tests/core/test_import.py index f146ae79..07b2a18e 100644 --- a/tests/core/test_import.py +++ b/tests/core/test_import.py @@ -1,4 +1,2 @@ - - def test_import(): import # noqa: F401 From 3314247037b6e686f372aae98ff0f32cffb5b48a Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Thu, 13 Apr 2023 12:47:12 -0600 Subject: [PATCH 050/102] apply template updates found following merge with eth-typing (#81) * apply template updates found following merge with eth-typing * add build as a dev dependency * remove timeout from pytest.ini, it doesn't do anything without pytest-timeout as a dep --- .github/pull_request_template.md | 4 ++-- docs/conf.py | 2 +- pyproject.toml | 2 +- pytest.ini | 3 +-- setup.py | 5 ++--- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 93fb355e..b3298852 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,7 @@ ### What was wrong? Related to Issue # -Closes Issue # +Closes # ### How was it fixed? @@ -10,7 +10,7 @@ Closes Issue # - [ ] Add or update documentation related to these changes -- [ ] Add entry to the [release notes](https://github.com/ethereum/web3.py/blob/master/newsfragments/README.md) +- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/master/newsfragments/README.md) #### Cute Animal Picture diff --git a/docs/conf.py b/docs/conf.py index df931f1a..6469208c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,7 +55,7 @@ master_doc = "index" # General information about the project. project = "" -copyright = "2020, The Ethereum Foundation" +copyright = "2019-2023, The Ethereum Foundation" __version__ = setup_version # The version info for the project you're documenting, acts as replacement for diff --git a/pyproject.toml b/pyproject.toml index 31433140..73483504 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.towncrier] -# Read https://github.com/ethereum//newsfragments/README.md for instructions +# Read https://github.com/ethereum//blob/master/newsfragments/README.md for instructions package = "" filename = "docs/release_notes.rst" directory = "newsfragments" diff --git a/pytest.ini b/pytest.ini index 95a6b2d6..fd5ea7cb 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,9 +1,8 @@ [pytest] -addopts= -v --showlocals --durations 10 +addopts= -v --showlocals --durations 10 xfail_strict=true log_format = %(levelname)8s %(asctime)s %(filename)20s %(message)s log_date_format = %m-%d %H:%M:%S -timeout = 300 [pytest-watch] runner= pytest --failed-first --maxfail=1 --no-success-flaky-report diff --git a/setup.py b/setup.py index c359d0be..e4d82fac 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ extras_require = { "bumpversion>=0.5.3", "pytest-watch>=4.1.0", "tox>=4.0.0", + "build>=0.9.0", "wheel", "twine", "ipython", @@ -59,7 +60,7 @@ setup( install_requires=[ "eth-utils>=2", ], - python_requires=">=3.7, <4", + python_requires=">=3.7.2, <4", extras_require=extras_require, py_modules=[""], license="MIT", @@ -72,8 +73,6 @@ setup( "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", - "Operating System :: MacOS", - "Operating System :: POSIX", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", From 484b6b55cd09757c9721fcaa50e6c39d8cee34af Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 19 Apr 2023 14:00:40 -0600 Subject: [PATCH 051/102] Template updates post ssz and ethabi (#82) * add updates found when merging template with py-ssz and eth-abi * add wheel and wheel-windows to ci and reorg --- .circleci/config.yml | 142 +++++++++++++++++++++++--------- .gitignore | 9 +- docs/conf.py | 2 +- newsfragments/README.md | 15 ++-- newsfragments/validate_files.py | 1 + pyproject.toml | 27 +++--- setup.py | 4 +- tox.ini | 31 +++++++ 8 files changed, 170 insertions(+), 61 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b4b822ad..0eb6f4ae 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,4 @@ -version: 2.0 +version: 2.1 # heavily inspired by https://raw.githubusercontent.com/pinax/pinax-wiki/6bd2a99ab6f702e300d708532a6d1d9aa638b9f8/.circleci/config.yml @@ -22,7 +22,7 @@ common: &common - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - run: name: install dependencies - command: pip install --user tox + command: python -m pip install --user tox - run: name: run tox command: python -m tox -r @@ -35,6 +35,30 @@ common: &common - ./eggs key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} +orbs: + win: circleci/windows@5.0.0 + +windows_steps: &windows_steps + executor: + name: win/default + shell: bash.exe + working_directory: C:\Users\circleci\project\ + steps: + - checkout + - restore_cache: + keys: + - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + - run: + name: install dependencies + command: python -m pip install --user tox + - run: + name: run tox + command: python -m tox -r + - save_cache: + paths: + - .tox + key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + jobs: docs: <<: *common @@ -42,60 +66,31 @@ jobs: - image: cimg/python:3.8 environment: TOXENV: docs - py37-lint: - <<: *common - docker: - - image: cimg/python:3.7 - environment: - TOXENV: py37-lint + py37-core: <<: *common docker: - image: cimg/python:3.7 environment: TOXENV: py37-core - py38-lint: - <<: *common - docker: - - image: cimg/python:3.8 - environment: - TOXENV: py38-lint py38-core: <<: *common docker: - image: cimg/python:3.8 environment: TOXENV: py38-core - py39-lint: - <<: *common - docker: - - image: cimg/python:3.9 - environment: - TOXENV: py39-lint py39-core: <<: *common docker: - image: cimg/python:3.9 environment: TOXENV: py39-core - py310-lint: - <<: *common - docker: - - image: cimg/python:3.10 - environment: - TOXENV: py310-lint py310-core: <<: *common docker: - image: cimg/python:3.10 environment: TOXENV: py310-core - py311-lint: - <<: *common - docker: - - image: cimg/python:3.11 - environment: - TOXENV: py311-lint py311-core: <<: *common docker: @@ -103,18 +98,91 @@ jobs: environment: TOXENV: py311-core + py37-lint: + <<: *common + docker: + - image: cimg/python:3.7 + environment: + TOXENV: py37-lint + py38-lint: + <<: *common + docker: + - image: cimg/python:3.8 + environment: + TOXENV: py38-lint + py39-lint: + <<: *common + docker: + - image: cimg/python:3.9 + environment: + TOXENV: py39-lint + py310-lint: + <<: *common + docker: + - image: cimg/python:3.10 + environment: + TOXENV: py310-lint + py311-lint: + <<: *common + docker: + - image: cimg/python:3.11 + environment: + TOXENV: py311-lint + + py37-wheel: + <<: *common + docker: + - image: cimg/python:3.7 + environment: + TOXENV: py37-wheel + py38-wheel: + <<: *common + docker: + - image: cimg/python:3.8 + environment: + TOXENV: py38-wheel + py39-wheel: + <<: *common + docker: + - image: cimg/python:3.9 + environment: + TOXENV: py39-wheel + py310-wheel: + <<: *common + docker: + - image: cimg/python:3.10 + environment: + TOXENV: py310-wheel + py311-wheel: + <<: *common + docker: + - image: cimg/python:3.11 + environment: + TOXENV: py311-wheel + + py311-wheel-windows: + <<: *windows_steps + environment: + TOXENV: py311-wheel-windows + workflows: version: 2 test: jobs: - docs - - py37-lint - - py38-lint - - py39-lint - - py310-lint - - py311-lint - py37-core - py38-core - py39-core - py310-core - py311-core + - py37-lint + - py38-lint + - py39-lint + - py310-lint + - py311-lint + - py37-wheel + - py38-wheel + - py39-wheel + - py310-wheel + - py311-wheel + - py311-wheel-windows diff --git a/.gitignore b/.gitignore index 011ac1c8..e0e2be56 100644 --- a/.gitignore +++ b/.gitignore @@ -67,6 +67,12 @@ logs # mypy .mypy_cache +# macOS +.DS_Store + +# pyenv +.python-version + # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # For a more precise, explicit template, see: # https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 @@ -83,9 +89,6 @@ out/ ## Plugin-specific files: -### mpeltonen/sbt-idea plugin -.idea_modules/ - ### JIRA plugin atlassian-ide-plugin.xml diff --git a/docs/conf.py b/docs/conf.py index 6469208c..db3f3492 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -141,7 +141,7 @@ html_theme = "sphinx_rtd_theme" # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +# html_static_path = ["_static"] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied diff --git a/newsfragments/README.md b/newsfragments/README.md index e4740e4b..0e9b74a2 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -8,14 +8,15 @@ relevant to people working on the code itself.) Each file should be named like `..rst`, where `` is an issue number, and `` is one of: -* `feature` -* `bugfix` -* `performance` -* `doc` -* `internal` -* `removal` -* `misc` * `breaking` +* `bugfix` +* `deprecation`, +* `doc` +* `feature` +* `internal` +* `misc` +* `performance` +* `removal` So for example: `123.feature.rst`, `456.bugfix.rst` diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index c4bd29f6..edd5e050 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -9,6 +9,7 @@ import sys ALLOWED_EXTENSIONS = { ".breaking.rst", ".bugfix.rst", + ".deprecation.rst", ".doc.rst", ".feature.rst", ".internal.rst", diff --git a/pyproject.toml b/pyproject.toml index 73483504..64f8b8af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,12 +4,12 @@ package = "" filename = "docs/release_notes.rst" directory = "newsfragments" underlines = ["-", "~", "^"] -title_format = " v{version} ({project_date})" +title_format = " v{version} ({project_date})" issue_format = "`#{issue} /issues/{issue}>`__" [[tool.towncrier.type]] -directory = "feature" -name = "Features" +directory = "breaking" +name = "Breaking Changes" showcontent = true [[tool.towncrier.type]] @@ -18,8 +18,8 @@ name = "Bugfixes" showcontent = true [[tool.towncrier.type]] -directory = "performance" -name = "Performance improvements" +directory = "deprecation" +name = "Deprecations" showcontent = true [[tool.towncrier.type]] @@ -28,21 +28,26 @@ name = "Improved Documentation" showcontent = true [[tool.towncrier.type]] -directory = "removal" -name = "Deprecations and Removals" +directory = "feature" +name = "Features" showcontent = true [[tool.towncrier.type]] directory = "internal" -name = "Internal Changes - for Contributors" +name = "Internal Changes - for Contributors" showcontent = true [[tool.towncrier.type]] directory = "misc" -name = "Miscellaneous changes" +name = "Miscellaneous Changes" showcontent = false [[tool.towncrier.type]] -directory = "breaking" -name = "Breaking changes" +directory = "performance" +name = "Performance Improvements" +showcontent = true + +[[tool.towncrier.type]] +directory = "removal" +name = "Removals" showcontent = true diff --git a/setup.py b/setup.py index e4d82fac..00994c25 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ extras_require = { "isort>=5.10.1", "mypy==0.971", # mypy does not follow semver, leave it pinned. "pydocstyle>=6.0.0", - "black>=22", + "black>=23", ], "doc": [ "sphinx>=5.0.0", @@ -60,7 +60,7 @@ setup( install_requires=[ "eth-utils>=2", ], - python_requires=">=3.7.2, <4", + python_requires=">=3.7, <4", extras_require=extras_require, py_modules=[""], license="MIT", diff --git a/tox.ini b/tox.ini index e5255baa..35503e26 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,8 @@ envlist= py{37,38,39,310,311}-core py{37,38,39,310,311}-lint + py{37,38,39,310,311}-wheel + py311-wheel-windows docs [isort] @@ -54,3 +56,32 @@ commands: {[common-lint]commands} [testenv:py{37,38,39,310,311}-lint] extras: {[common-lint]extras} commands: {[common-lint]commands} + +[testenv:py{37,38,39,310,311}-wheel] +deps= + wheel + build[virtualenv] +allowlist_externals= + /bin/rm + /bin/bash +commands= + python -m pip install --upgrade pip + /bin/rm -rf build dist + python -m build + /bin/bash -c 'python -m pip install --upgrade "$(ls dist/-*-py3-none-any.whl)" --progress-bar off' + python -c "import " +skip_install=true + +[testenv:py311-wheel-windows] +deps= + wheel + build[virtualenv] +allowlist_externals= + bash.exe +commands= + python -m pip install --upgrade pip + bash.exe -c "rm -rf build dist" + python -m build + bash.exe -c 'python -m pip install --upgrade "$(ls dist/-*-py3-none-any.whl)" --progress-bar off' + python -c "import " +skip_install=true From 28dbedcbfad5b03f50505e0d990c4d63dba27c36 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:21:09 -0600 Subject: [PATCH 052/102] upgrade pip and remove --user from tox install during ci (#85) --- .circleci/config.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0eb6f4ae..b00ff6b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,7 +22,9 @@ common: &common - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - run: name: install dependencies - command: python -m pip install --user tox + command: | + python -m pip install --upgrade pip + python -m pip install tox - run: name: run tox command: python -m tox -r @@ -50,7 +52,9 @@ windows_steps: &windows_steps - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - run: name: install dependencies - command: python -m pip install --user tox + command: | + python -m pip install --upgrade pip + python -m pip install tox - run: name: run tox command: python -m tox -r From da9b95f37c2b9c33582e430d0e7b4d858dec2212 Mon Sep 17 00:00:00 2001 From: Marc Garreau <3621728+wolovim@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:45:59 -0600 Subject: [PATCH 053/102] introduce contributing doc + main branch convention (#84) --- Makefile | 4 +- README.md | 11 +- docs/contributing.rst | 161 ++++++++++++++++++++++++ docs/fragments/virtualenv_explainer.rst | 25 ++++ docs/index.rst | 6 + pyproject.toml | 2 +- 6 files changed, 200 insertions(+), 9 deletions(-) create mode 100644 docs/contributing.rst create mode 100644 docs/fragments/virtualenv_explainer.rst diff --git a/Makefile b/Makefile index a8af4eba..5f731893 100644 --- a/Makefile +++ b/Makefile @@ -74,8 +74,8 @@ notes: check-bump git commit -m "Compile release notes" release: check-bump clean - # require that you be on a branch that's linked to upstream/master - git status -s -b | head -1 | grep "\.\.upstream/master" + # require that you be on a branch that's linked to upstream/main + git status -s -b | head -1 | grep "\.\.upstream/main" # verify that docs build correctly ./newsfragments/validate_files.py is-empty make build-docs diff --git a/README.md b/README.md index 86b1e410..7d126455 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,6 @@ [![PyPI version](https://badge.fury.io/py/.svg)](https://badge.fury.io/py/) [![Python versions](https://img.shields.io/pypi/pyversions/.svg)](https://pypi.python.org/pypi/) [![Docs build](https://readthedocs.org/projects//badge/?version=latest)](https://.readthedocs.io/en/latest/?badge=latest) - @@ -23,10 +22,10 @@ If you would like to hack on , please check out the [Snake Charmers Tactical Manual](https://github.com/ethereum/snake-charmers-tactical-manual) for information on how we do: -- Testing -- Pull Requests -- Code Style -- Documentation +- Testing +- Pull Requests +- Code Style +- Documentation ### Development Environment Setup @@ -55,7 +54,7 @@ The version format for this repo is `{major}.{minor}.{patch}` for stable, and To issue the next version in line, specify which part to bump, like `make release bump=minor` or `make release bump=devnum`. This is typically done from the -master branch, except when releasing a beta (in which case the beta is released from master, +main branch, except when releasing a beta (in which case the beta is released from main, and the previous stable branch is released from said branch). If you are in a beta version, `make release bump=stage` will switch to a stable. diff --git a/docs/contributing.rst b/docs/contributing.rst new file mode 100644 index 00000000..926b87ce --- /dev/null +++ b/docs/contributing.rst @@ -0,0 +1,161 @@ +Contributing +------------ + +Thank you for your interest in contributing! We welcome all contributions no matter their size. Please read along to learn how to get started. + + +Setting the stage +~~~~~~~~~~~~~~~~~ + +First, we need to clone the repository: + +.. code:: sh + + $ git clone https://github.com/ethereum/.git + + +.. include:: /fragments/virtualenv_explainer.rst + +After we have activated our virtual environment, we need to install all dependencies that are needed to run, develop, and test. +This is as easy as navigating to the directory and running: + +.. code:: sh + + pip install -e ".[dev]" + + +Running the tests +~~~~~~~~~~~~~~~~~ + +A great way to explore the code base is to run the tests. + +We can run all tests with: + +.. code:: sh + + pytest tests + +However, you may just want to run a subset instead, like: + +.. code:: sh + + pytest tests/core/padding-utils/test_padding.py + + +We can also install ``tox`` to run the full test suite which also covers things like testing the code against different Python versions, linting etc. + +It is important to understand that each Pull Request must pass the full test suite as part of the CI check, hence it is often convenient to have ``tox`` installed locally as well. + + +Code Style +~~~~~~~~~~ + +When multiple people are working on the same body of code, it is important that they write code that conforms to a similar style. It often doesn't matter as much which style, but rather that they conform to one style. + +To ensure your contribution conforms to the style being used in this project, we encourage you to read our `style guide `_. + + +Type Hints +~~~~~~~~~~ + +This codebase uses `type hints `_. Type hints make it easy to prevent certain types of bugs, enable richer tooling, and enhance the documentation, making the code easier to follow. + +All new code is required to land with type hints, with the exception of test code that is not expected to use type hints. + +All parameters, as well as the return type of defs, are expected to be typed, with the exception of ``self`` and ``cls`` as seen in the following example. + +.. code:: python + + def __init__(self, wrapped_db: DatabaseAPI) -> None: + self.wrapped_db = wrapped_db + self.reset() + + +Documentation +~~~~~~~~~~~~~ + +Good documentation will lead to quicker adoption and happier users. Please check out our guide +on `how to create documentation for the Python Ethereum ecosystem `_. + + +Pull Requests +~~~~~~~~~~~~~ + +It's a good idea to make pull requests early on. A pull request represents the +start of a discussion, and doesn't necessarily need to be the final, finished +submission. + +GitHub's documentation for working on pull requests is `available here `_. + +Once you've made a pull request, take a look at the Circle CI build status in the +GitHub interface and make sure all tests are passing. In general pull requests that +do not pass the CI build yet won't get reviewed unless explicitly requested. + +If the pull request introduces changes that should be reflected in the release notes, +please add a `newsfragment` file as explained +`here /blob/main/newsfragments/README.md>`_. + +If possible, the change to the release notes file should be included in the commit that introduces the +feature or bugfix. + + +Releasing +~~~~~~~~~ + + +Final test before each release +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Before releasing a new version, build and test the package that will be released: + +.. code:: sh + + git checkout main && git pull + + make package + + + # Preview the upcoming release notes + towncrier --draft + + +Build the release notes +^^^^^^^^^^^^^^^^^^^^^^^ + +Before bumping the version number, build the release notes. +You must include the part of the version to bump (see below), +which changes how the version number will show in the release notes. + +.. code:: sh + + make notes bump=$$VERSION_PART_TO_BUMP$$ + +If there are any errors, be sure to re-run ``make notes`` until it works. + + +Push the release to github & pypi +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +After confirming that the release package looks okay, release a new version: + +.. code:: sh + + make release bump=$$VERSION_PART_TO_BUMP$$ + + +Which version part to bump +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The version format for this repo is ``{major}.{minor}.{patch}`` for +stable, and ``{major}.{minor}.{patch}-{stage}.{devnum}`` for unstable +(``stage`` can be alpha or beta). + +During a release, specify which part to bump, like +``make release bump=minor`` or ``make release bump=devnum``. + +If you are in a beta version, ``make release bump=stage`` will switch to a +stable. + +To issue an unstable version when the current version is stable, specify +the new version explicitly, like +``make release bump="--new-version 4.0.0-alpha.1 devnum"`` diff --git a/docs/fragments/virtualenv_explainer.rst b/docs/fragments/virtualenv_explainer.rst new file mode 100644 index 00000000..ecc6d4c6 --- /dev/null +++ b/docs/fragments/virtualenv_explainer.rst @@ -0,0 +1,25 @@ +**Optional:** Often, the best way to guarantee a clean Python 3 environment is with +`virtualenv `_. If we don't have ``virtualenv`` installed +already, we first need to install it via pip. + +.. code:: sh + + pip install virtualenv + +Then, we can initialize a new virtual environment ``venv``, like: + +.. code:: sh + + virtualenv -p python3 venv + +This creates a new directory ``venv`` where packages are installed isolated from any other global +packages. + +To activate the virtual directory we have to *source* it + +.. code:: sh + + . venv/bin/activate + + # and when leaving this context: + deactivate diff --git a/docs/index.rst b/docs/index.rst index 89815efa..4f1f0b31 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,6 +11,12 @@ Contents release_notes + +.. toctree:: + :maxdepth: 1 + :caption: Community + + contributing Indices and tables diff --git a/pyproject.toml b/pyproject.toml index 64f8b8af..aa7ddcd0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.towncrier] -# Read https://github.com/ethereum//blob/master/newsfragments/README.md for instructions +# Read https://github.com/ethereum//blob/main/newsfragments/README.md for instructions package = "" filename = "docs/release_notes.rst" directory = "newsfragments" From cc24e7e468d652f59ac9f484f9600460f6b8a295 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Tue, 25 Apr 2023 15:20:55 -0600 Subject: [PATCH 054/102] update tox calls to use run, update all pip calls to use python -m (#86) --- .circleci/config.yml | 4 ++-- .github/ISSUE_TEMPLATE/bug_report.yml | 6 ++++-- Makefile | 4 ++-- README.md | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b00ff6b8..791a433d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,7 +27,7 @@ common: &common python -m pip install tox - run: name: run tox - command: python -m tox -r + command: python -m tox run -r - save_cache: paths: - .hypothesis @@ -57,7 +57,7 @@ windows_steps: &windows_steps python -m pip install tox - run: name: run tox - command: python -m tox -r + command: python -m tox run -r - save_cache: paths: - .tox diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 5f1ddfd8..a0c80c07 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -65,6 +65,8 @@ body: - type: textarea id: pip-freeze attributes: - label: Output from pip-freeze - description: Run `pip-freeze` and paste the output below + label: Output from `pip freeze` + description: Run `python -m pip freeze` and paste the output below render: shell + validations: + required: false diff --git a/Makefile b/Makefile index 5f731893..b674c553 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ clean-pyc: find . -name '__pycache__' -exec rm -rf {} + lint: - tox -e lint + tox run -e lint lint-roll: isort tests @@ -39,7 +39,7 @@ test: pytest tests test-all: - tox + tox run build-docs: sphinx-apidoc -o docs/ . setup.py "*conftest*" diff --git a/README.md b/README.md index 7d126455..b3be7487 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Read more in the [documentation on ReadTheDocs](https://.readthedocs.i ## Quickstart ```sh -pip install +python -m pip install ``` ## Developer Setup @@ -36,7 +36,7 @@ git clone git@github.com:ethereum/.git cd virtualenv -p python3 venv . venv/bin/activate -pip install -e ".[dev]" +python -m pip install -e ".[dev]" ``` ### Release setup From 1f5fc7208bbd7d86a35ef466cf58d5129d4852f9 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Thu, 27 Apr 2023 14:02:54 -0600 Subject: [PATCH 055/102] Remove testall (#88) * remove testall because it doesnt work --- .github/pull_request_template.md | 2 +- Makefile | 4 ---- newsfragments/README.md | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index b3298852..2ff2e071 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -10,7 +10,7 @@ Closes # - [ ] Add or update documentation related to these changes -- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/master/newsfragments/README.md) +- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/main/newsfragments/README.md) #### Cute Animal Picture diff --git a/Makefile b/Makefile index b674c553..67a75732 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,6 @@ help: @echo "lint - check style with flake8" @echo "lint-roll - automatically fix problems with isort, flake8, etc" @echo "test - run tests quickly with the default Python" - @echo "testall - run tests on every Python version with tox" @echo "docs - generate docs and open in browser (linux-docs for version on linux)" @echo "notes - consume towncrier newsfragments/ and update release notes in docs/" @echo "release - package and upload a release (does not run notes target)" @@ -38,9 +37,6 @@ lint-roll: test: pytest tests -test-all: - tox run - build-docs: sphinx-apidoc -o docs/ . setup.py "*conftest*" $(MAKE) -C docs clean diff --git a/newsfragments/README.md b/newsfragments/README.md index 0e9b74a2..93ae2c0a 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -26,4 +26,4 @@ then open up the PR first and use the PR number for the newsfragment. Note that the `towncrier` tool will automatically reflow your text, so don't try to do any fancy formatting. Run `towncrier build --draft` to get a preview of what the release notes entry - will look like in the final release notes. +will look like in the final release notes. From 2a1c8f83b49c97c57838098fef30f3b59baf755a Mon Sep 17 00:00:00 2001 From: pacrob Date: Mon, 1 May 2023 16:25:14 -0600 Subject: [PATCH 056/102] minor formatting updates, remove contributing docs --- README.md | 8 +- docs/contributing.rst | 161 ------------------------ docs/fragments/virtualenv_explainer.rst | 25 ---- docs/index.rst | 6 - newsfragments/README.md | 2 +- 5 files changed, 5 insertions(+), 197 deletions(-) delete mode 100644 docs/contributing.rst delete mode 100644 docs/fragments/virtualenv_explainer.rst diff --git a/README.md b/README.md index b3be7487..5acd94db 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,10 @@ If you would like to hack on , please check out the [Snake Charmers Tactical Manual](https://github.com/ethereum/snake-charmers-tactical-manual) for information on how we do: -- Testing -- Pull Requests -- Code Style -- Documentation +- Testing +- Pull Requests +- Code Style +- Documentation ### Development Environment Setup diff --git a/docs/contributing.rst b/docs/contributing.rst deleted file mode 100644 index 926b87ce..00000000 --- a/docs/contributing.rst +++ /dev/null @@ -1,161 +0,0 @@ -Contributing ------------- - -Thank you for your interest in contributing! We welcome all contributions no matter their size. Please read along to learn how to get started. - - -Setting the stage -~~~~~~~~~~~~~~~~~ - -First, we need to clone the repository: - -.. code:: sh - - $ git clone https://github.com/ethereum/.git - - -.. include:: /fragments/virtualenv_explainer.rst - -After we have activated our virtual environment, we need to install all dependencies that are needed to run, develop, and test. -This is as easy as navigating to the directory and running: - -.. code:: sh - - pip install -e ".[dev]" - - -Running the tests -~~~~~~~~~~~~~~~~~ - -A great way to explore the code base is to run the tests. - -We can run all tests with: - -.. code:: sh - - pytest tests - -However, you may just want to run a subset instead, like: - -.. code:: sh - - pytest tests/core/padding-utils/test_padding.py - - -We can also install ``tox`` to run the full test suite which also covers things like testing the code against different Python versions, linting etc. - -It is important to understand that each Pull Request must pass the full test suite as part of the CI check, hence it is often convenient to have ``tox`` installed locally as well. - - -Code Style -~~~~~~~~~~ - -When multiple people are working on the same body of code, it is important that they write code that conforms to a similar style. It often doesn't matter as much which style, but rather that they conform to one style. - -To ensure your contribution conforms to the style being used in this project, we encourage you to read our `style guide `_. - - -Type Hints -~~~~~~~~~~ - -This codebase uses `type hints `_. Type hints make it easy to prevent certain types of bugs, enable richer tooling, and enhance the documentation, making the code easier to follow. - -All new code is required to land with type hints, with the exception of test code that is not expected to use type hints. - -All parameters, as well as the return type of defs, are expected to be typed, with the exception of ``self`` and ``cls`` as seen in the following example. - -.. code:: python - - def __init__(self, wrapped_db: DatabaseAPI) -> None: - self.wrapped_db = wrapped_db - self.reset() - - -Documentation -~~~~~~~~~~~~~ - -Good documentation will lead to quicker adoption and happier users. Please check out our guide -on `how to create documentation for the Python Ethereum ecosystem `_. - - -Pull Requests -~~~~~~~~~~~~~ - -It's a good idea to make pull requests early on. A pull request represents the -start of a discussion, and doesn't necessarily need to be the final, finished -submission. - -GitHub's documentation for working on pull requests is `available here `_. - -Once you've made a pull request, take a look at the Circle CI build status in the -GitHub interface and make sure all tests are passing. In general pull requests that -do not pass the CI build yet won't get reviewed unless explicitly requested. - -If the pull request introduces changes that should be reflected in the release notes, -please add a `newsfragment` file as explained -`here /blob/main/newsfragments/README.md>`_. - -If possible, the change to the release notes file should be included in the commit that introduces the -feature or bugfix. - - -Releasing -~~~~~~~~~ - - -Final test before each release -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -Before releasing a new version, build and test the package that will be released: - -.. code:: sh - - git checkout main && git pull - - make package - - - # Preview the upcoming release notes - towncrier --draft - - -Build the release notes -^^^^^^^^^^^^^^^^^^^^^^^ - -Before bumping the version number, build the release notes. -You must include the part of the version to bump (see below), -which changes how the version number will show in the release notes. - -.. code:: sh - - make notes bump=$$VERSION_PART_TO_BUMP$$ - -If there are any errors, be sure to re-run ``make notes`` until it works. - - -Push the release to github & pypi -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -After confirming that the release package looks okay, release a new version: - -.. code:: sh - - make release bump=$$VERSION_PART_TO_BUMP$$ - - -Which version part to bump -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -The version format for this repo is ``{major}.{minor}.{patch}`` for -stable, and ``{major}.{minor}.{patch}-{stage}.{devnum}`` for unstable -(``stage`` can be alpha or beta). - -During a release, specify which part to bump, like -``make release bump=minor`` or ``make release bump=devnum``. - -If you are in a beta version, ``make release bump=stage`` will switch to a -stable. - -To issue an unstable version when the current version is stable, specify -the new version explicitly, like -``make release bump="--new-version 4.0.0-alpha.1 devnum"`` diff --git a/docs/fragments/virtualenv_explainer.rst b/docs/fragments/virtualenv_explainer.rst deleted file mode 100644 index ecc6d4c6..00000000 --- a/docs/fragments/virtualenv_explainer.rst +++ /dev/null @@ -1,25 +0,0 @@ -**Optional:** Often, the best way to guarantee a clean Python 3 environment is with -`virtualenv `_. If we don't have ``virtualenv`` installed -already, we first need to install it via pip. - -.. code:: sh - - pip install virtualenv - -Then, we can initialize a new virtual environment ``venv``, like: - -.. code:: sh - - virtualenv -p python3 venv - -This creates a new directory ``venv`` where packages are installed isolated from any other global -packages. - -To activate the virtual directory we have to *source* it - -.. code:: sh - - . venv/bin/activate - - # and when leaving this context: - deactivate diff --git a/docs/index.rst b/docs/index.rst index 4f1f0b31..472a482a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -12,12 +12,6 @@ Contents release_notes -.. toctree:: - :maxdepth: 1 - :caption: Community - - contributing - Indices and tables ------------------ diff --git a/newsfragments/README.md b/newsfragments/README.md index 93ae2c0a..2ef923e8 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -10,7 +10,7 @@ Each file should be named like `..rst`, where * `breaking` * `bugfix` -* `deprecation`, +* `deprecation` * `doc` * `feature` * `internal` From f802bd04398df7f915916dabbc1ba2b129796be0 Mon Sep 17 00:00:00 2001 From: pacrob Date: Wed, 3 May 2023 10:53:12 -0600 Subject: [PATCH 057/102] bump sphinx version and set py version rtd uses to 3.8 --- .readthedocs.yml | 8 ++++++++ setup.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 959cf717..bb96642a 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,5 +1,13 @@ version: 2 +build: + os: ubuntu-22.04 + tools: + python: "3.8" + +sphinx: + configuration: docs/conf.py + python: install: - method: pip diff --git a/setup.py b/setup.py index 00994c25..dc1a39f1 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ extras_require = { "black>=23", ], "doc": [ - "sphinx>=5.0.0", + "sphinx>=6.0.0", "sphinx_rtd_theme>=1.0.0", "towncrier>=21,<22", ], From 23a192f62c6ad5bff2beb54284652c215971dfa6 Mon Sep 17 00:00:00 2001 From: pacrob Date: Wed, 3 May 2023 14:05:29 -0600 Subject: [PATCH 058/102] change references to doc to all be docs --- .readthedocs.yml | 2 +- docs/conf.py | 2 +- newsfragments/README.md | 2 +- newsfragments/validate_files.py | 2 +- pyproject.toml | 2 +- setup.py | 4 ++-- tox.ini | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index bb96642a..50b9b384 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -13,4 +13,4 @@ python: - method: pip path: . extra_requirements: - - doc + - docs diff --git a/docs/conf.py b/docs/conf.py index db3f3492..1d0560df 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -190,7 +190,7 @@ html_theme = "sphinx_rtd_theme" # html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = "doc" +htmlhelp_basename = "docs" # -- Options for LaTeX output --------------------------------------------- diff --git a/newsfragments/README.md b/newsfragments/README.md index 2ef923e8..7c8981fa 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -11,7 +11,7 @@ Each file should be named like `..rst`, where * `breaking` * `bugfix` * `deprecation` -* `doc` +* `docs` * `feature` * `internal` * `misc` diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index edd5e050..bc68bfe5 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -10,7 +10,7 @@ ALLOWED_EXTENSIONS = { ".breaking.rst", ".bugfix.rst", ".deprecation.rst", - ".doc.rst", + ".docs.rst", ".feature.rst", ".internal.rst", ".misc.rst", diff --git a/pyproject.toml b/pyproject.toml index aa7ddcd0..d94ebfd9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -23,7 +23,7 @@ name = "Deprecations" showcontent = true [[tool.towncrier.type]] -directory = "doc" +directory = "docs" name = "Improved Documentation" showcontent = true diff --git a/setup.py b/setup.py index dc1a39f1..859008ec 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ extras_require = { "pydocstyle>=6.0.0", "black>=23", ], - "doc": [ + "docs": [ "sphinx>=6.0.0", "sphinx_rtd_theme>=1.0.0", "towncrier>=21,<22", @@ -38,7 +38,7 @@ extras_require["dev"] = ( extras_require["dev"] + extras_require["test"] + extras_require["lint"] - + extras_require["doc"] + + extras_require["docs"] ) diff --git a/tox.ini b/tox.ini index 35503e26..b1dae72a 100644 --- a/tox.ini +++ b/tox.ini @@ -34,7 +34,7 @@ basepython= py311: python3.11 extras= test - docs: doc + docs allowlist_externals=make [common-lint] From 86b5d52149e561080c2c5629e68a9810f8552090 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Fri, 12 May 2023 14:47:15 -0600 Subject: [PATCH 059/102] Update .gitignore spelling error --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e0e2be56..0d725c74 100644 --- a/.gitignore +++ b/.gitignore @@ -51,7 +51,7 @@ docs/*._utils.* # Blockchain chains -# Hypothese Property base testing +# Hypothesis Property base testing .hypothesis # tox/pytest cache From 42be4de76cba63fddccd95fb0f4c5289b777b403 Mon Sep 17 00:00:00 2001 From: pacrob Date: Thu, 25 May 2023 14:33:14 -0600 Subject: [PATCH 060/102] fix typos in ci config and Makefile --- .circleci/config.yml | 2 +- Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 791a433d..0f1436c0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -14,7 +14,7 @@ common: &common command: ./.circleci/merge_pr.sh when: on_fail - run: - name: merge pull request base (3nd try) + name: merge pull request base (3rd try) command: ./.circleci/merge_pr.sh when: on_fail - restore_cache: diff --git a/Makefile b/Makefile index 67a75732..06d85b7c 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ CURRENT_SIGN_SETTING := $(shell git config commit.gpgSign) help: @echo "clean-build - remove build artifacts" @echo "clean-pyc - remove Python file artifacts" - @echo "lint - check style with flake8" - @echo "lint-roll - automatically fix problems with isort, flake8, etc" + @echo "lint - check style with mypy, flake8, isort, pydocstyle, and black" + @echo "lint-roll - automatically fix problems with flake8 and black" @echo "test - run tests quickly with the default Python" @echo "docs - generate docs and open in browser (linux-docs for version on linux)" @echo "notes - consume towncrier newsfragments/ and update release notes in docs/" From 024f9dbd54735d7d00b0c537bb9976bcb08c813d Mon Sep 17 00:00:00 2001 From: kclowes Date: Wed, 14 Jun 2023 07:59:07 -0600 Subject: [PATCH 061/102] Add tests to distribution by default (#97) --- MANIFEST.in | 2 ++ Makefile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index 22c6165d..a122460c 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,6 +1,8 @@ include LICENSE include README.md +recursive-include tests * + global-include *.pyi recursive-exclude * __pycache__ diff --git a/Makefile b/Makefile index 06d85b7c..f91dd720 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,7 @@ notes: check-bump make build-docs git commit -m "Compile release notes" -release: check-bump clean +release: check-bump test clean # require that you be on a branch that's linked to upstream/main git status -s -b | head -1 | grep "\.\.upstream/main" # verify that docs build correctly From 37841d57ed4d8fa89973414d68a5e4e738812100 Mon Sep 17 00:00:00 2001 From: Stuart Reed Date: Tue, 13 Jun 2023 09:46:18 -0600 Subject: [PATCH 062/102] Update release command to check remote for upstream --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f91dd720..60ed00e4 100644 --- a/Makefile +++ b/Makefile @@ -69,9 +69,9 @@ notes: check-bump make build-docs git commit -m "Compile release notes" -release: check-bump test clean - # require that you be on a branch that's linked to upstream/main - git status -s -b | head -1 | grep "\.\.upstream/main" +release: check-bump clean + # require that upstream is configured for ethereum/ + git remote -v | grep "upstream\tgit@github.com:ethereum/.git (push)\|upstream\thttps://github.com/ethereum/ (push)" # verify that docs build correctly ./newsfragments/validate_files.py is-empty make build-docs From 8a57adf9503919c9f273d742ce257042211ae082 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:29:30 -0600 Subject: [PATCH 063/102] Update .gitignore add `.venv*` to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0d725c74..7d6b0b06 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ lib lib64 pip-wheel-metadata venv* +.venv* # Installer logs pip-log.txt From 4245675648f6e0937e5865c31fc2176344af3a80 Mon Sep 17 00:00:00 2001 From: pacrob Date: Thu, 14 Sep 2023 12:11:55 -0600 Subject: [PATCH 064/102] ignore flake8 F401 errors in __init__.py files --- tox.ini | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index b1dae72a..cdb3560c 100644 --- a/tox.ini +++ b/tox.ini @@ -16,9 +16,10 @@ multi_line_output=3 profile=black [flake8] -max-line-length=88 exclude=venv*,.tox,docs,build extend-ignore=E203 +max-line-length=88 +per-file-ignores=__init__.py:F401 [testenv] usedevelop=True From 26005569ce71ab26ce1e847ea2122a860bbb9b2d Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:40:01 -0600 Subject: [PATCH 065/102] Update .gitignore add `.build` to be ignored --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7d6b0b06..f9dcb54c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.egg-info dist build +.build eggs .eggs parts From 23d8fb5bf77a62d6472b29758f1b8424bfab7aa6 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 11:40:49 -0600 Subject: [PATCH 066/102] Update .readthedocs.yml fix indent, add sphinx fail_on_warning --- .readthedocs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 50b9b384..593793c2 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -6,7 +6,8 @@ build: python: "3.8" sphinx: - configuration: docs/conf.py + configuration: docs/conf.py + fail_on_warning: true python: install: From efcb97c348892b7e85a6300226e26e41bcceb4b9 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:13:56 -0600 Subject: [PATCH 067/102] Update .gitignore gitignore local vs-code settings --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index f9dcb54c..5127a4df 100644 --- a/.gitignore +++ b/.gitignore @@ -75,6 +75,9 @@ logs # pyenv .python-version +# vs-code +.vscode + # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # For a more precise, explicit template, see: # https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 From 7099bbaaa48504ec9609d3b34648f0177dbccba8 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:32:07 -0600 Subject: [PATCH 068/102] Add pre commit (#103) * add pre-commit * run pre-commit * skip lint on README.md as it breaks template filling --- .bumpversion.cfg | 1 - .circleci/config.yml | 9 ++--- .../{bug_report.yml => bug_report.yaml} | 0 .../{config.yml => config.yaml} | 0 ...ature_request.yml => feature_request.yaml} | 0 .github/pull_request_template.md | 9 +++-- .pre-commit-config.yaml | 37 ++++++++++++++++++ .readthedocs.yml => .readthedocs.yaml | 0 Makefile | 10 +---- README.md | 7 +++- docs/index.rst | 2 +- newsfragments/README.md | 18 ++++----- newsfragments/validate_files.py | 1 - setup.py | 38 +++++++------------ tox.ini | 17 +++------ 15 files changed, 82 insertions(+), 67 deletions(-) rename .github/ISSUE_TEMPLATE/{bug_report.yml => bug_report.yaml} (100%) rename .github/ISSUE_TEMPLATE/{config.yml => config.yaml} (100%) rename .github/ISSUE_TEMPLATE/{feature_request.yml => feature_request.yaml} (100%) create mode 100644 .pre-commit-config.yaml rename .readthedocs.yml => .readthedocs.yaml (100%) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f683001f..39ae22d4 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -20,4 +20,3 @@ values = [bumpversion:file:setup.py] search = version="{current_version}", replace = version="{new_version}", - diff --git a/.circleci/config.yml b/.circleci/config.yml index 0f1436c0..bbc90296 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,6 +25,9 @@ common: &common command: | python -m pip install --upgrade pip python -m pip install tox + - run: + name: install pre-commit + command: python -m pip install --progress-bar=off pre-commit - run: name: run tox command: python -m tox run -r @@ -102,12 +105,6 @@ jobs: environment: TOXENV: py311-core - py37-lint: - <<: *common - docker: - - image: cimg/python:3.7 - environment: - TOXENV: py37-lint py38-lint: <<: *common docker: diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_report.yml rename to .github/ISSUE_TEMPLATE/bug_report.yaml diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/config.yml rename to .github/ISSUE_TEMPLATE/config.yaml diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yaml similarity index 100% rename from .github/ISSUE_TEMPLATE/feature_request.yml rename to .github/ISSUE_TEMPLATE/feature_request.yaml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2ff2e071..3691f6b9 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -6,12 +6,13 @@ Closes # ### How was it fixed? ### Todo: -- [ ] Clean up commit history -- [ ] Add or update documentation related to these changes +- \[ \] Clean up commit history -- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/main/newsfragments/README.md) +- \[ \] Add or update documentation related to these changes + +- \[ \] Add entry to the [release notes](https://github.com/ethereum/%3CREPO_NAME%3E/blob/main/newsfragments/README.md) #### Cute Animal Picture -![Put a link to a cute animal picture inside the parenthesis-->]() \ No newline at end of file +![Put a link to a cute animal picture inside the parenthesis-->](<>) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..58f9e1d8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +exclude: '.project-template|docs/conf.py' +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.4.0 + hooks: + - id: check-yaml + - id: check-toml + - id: end-of-file-fixer + - id: trailing-whitespace +- repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black +- repo: https://github.com/PyCQA/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear==23.9.16 + exclude: setup.py +- repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort +- repo: https://github.com/pycqa/pydocstyle + rev: 6.3.0 + hooks: + - id: pydocstyle +- repo: https://github.com/executablebooks/mdformat + rev: 0.7.17 + hooks: + - id: mdformat +- repo: https://github.com/pre-commit/mirrors-mypy + rev: v1.5.1 + hooks: + - id: mypy + exclude: tests/ diff --git a/.readthedocs.yml b/.readthedocs.yaml similarity index 100% rename from .readthedocs.yml rename to .readthedocs.yaml diff --git a/Makefile b/Makefile index 60ed00e4..28d7fa46 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,7 @@ CURRENT_SIGN_SETTING := $(shell git config commit.gpgSign) help: @echo "clean-build - remove build artifacts" @echo "clean-pyc - remove Python file artifacts" - @echo "lint - check style with mypy, flake8, isort, pydocstyle, and black" - @echo "lint-roll - automatically fix problems with flake8 and black" + @echo "lint - fix linting issues with pre-commit @echo "test - run tests quickly with the default Python" @echo "docs - generate docs and open in browser (linux-docs for version on linux)" @echo "notes - consume towncrier newsfragments/ and update release notes in docs/" @@ -27,12 +26,7 @@ clean-pyc: find . -name '__pycache__' -exec rm -rf {} + lint: - tox run -e lint - -lint-roll: - isort tests - black tests setup.py - $(MAKE) lint + pre-commit run --all-files --show-diff-on-failure test: pytest tests diff --git a/README.md b/README.md index 5acd94db..fa56f2e3 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,13 @@ for information on how we do: - Testing - Pull Requests -- Code Style - Documentation +We use [pre-commit](https://pre-commit.com/) to maintain consistent code style. Once +installed, it will run automatically with every commit. You can also run it manually +with `make lint`. If you need to make a commit that skips the `pre-commit` checks, you +can do so with `git commit --no-verify`. + ### Development Environment Setup You can set up your dev environment with: @@ -37,6 +41,7 @@ cd virtualenv -p python3 venv . venv/bin/activate python -m pip install -e ".[dev]" +pre-commit install ``` ### Release setup diff --git a/docs/index.rst b/docs/index.rst index 472a482a..89815efa 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,7 +11,7 @@ Contents release_notes - + Indices and tables ------------------ diff --git a/newsfragments/README.md b/newsfragments/README.md index 7c8981fa..177d6492 100644 --- a/newsfragments/README.md +++ b/newsfragments/README.md @@ -8,15 +8,15 @@ relevant to people working on the code itself.) Each file should be named like `..rst`, where `` is an issue number, and `` is one of: -* `breaking` -* `bugfix` -* `deprecation` -* `docs` -* `feature` -* `internal` -* `misc` -* `performance` -* `removal` +- `breaking` +- `bugfix` +- `deprecation` +- `docs` +- `feature` +- `internal` +- `misc` +- `performance` +- `removal` So for example: `123.feature.rst`, `456.bugfix.rst` diff --git a/newsfragments/validate_files.py b/newsfragments/validate_files.py index bc68bfe5..02b0e3ef 100755 --- a/newsfragments/validate_files.py +++ b/newsfragments/validate_files.py @@ -31,7 +31,6 @@ if num_args == 1: assert sys.argv[1] in ("is-empty",) for fragment_file in THIS_DIR.iterdir(): - if fragment_file.name in ALLOWED_FILES: continue elif num_args == 0: diff --git a/setup.py b/setup.py index 859008ec..5efcc3cd 100644 --- a/setup.py +++ b/setup.py @@ -1,44 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- from setuptools import ( - setup, find_packages, + setup, ) extras_require = { - "test": [ - "pytest>=7.0.0", - "pytest-xdist>=2.4.0", - ], - "lint": [ - "flake8==6.0.0", # flake8 claims semver but adds new warnings at minor releases, leave it pinned. - "flake8-bugbear==23.3.23", # flake8-bugbear does not follow semver, leave it pinned. - "isort>=5.10.1", - "mypy==0.971", # mypy does not follow semver, leave it pinned. - "pydocstyle>=6.0.0", - "black>=23", + "dev": [ + "build>=0.9.0", + "bumpversion>=0.5.3", + "ipython", + "pre-commit>=3.4.0", + "pytest-watch>=4.1.0", + "tox>=4.0.0", + "twine", + "wheel", ], "docs": [ "sphinx>=6.0.0", "sphinx_rtd_theme>=1.0.0", "towncrier>=21,<22", ], - "dev": [ - "bumpversion>=0.5.3", - "pytest-watch>=4.1.0", - "tox>=4.0.0", - "build>=0.9.0", - "wheel", - "twine", - "ipython", + "test": [ + "pytest>=7.0.0", + "pytest-xdist>=2.4.0", ], } extras_require["dev"] = ( - extras_require["dev"] - + extras_require["test"] - + extras_require["lint"] - + extras_require["docs"] + extras_require["dev"] + extras_require["docs"] + extras_require["test"] ) diff --git a/tox.ini b/tox.ini index cdb3560c..cf23aa2e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] envlist= py{37,38,39,310,311}-core - py{37,38,39,310,311}-lint + py{38,39,310,311}-lint py{37,38,39,310,311}-wheel py311-wheel-windows docs @@ -36,26 +36,19 @@ basepython= extras= test docs -allowlist_externals=make +allowlist_externals=make,pre-commit [common-lint] basepython=python -extras=lint -allowlist_externals=black +deps=pre-commit commands= - mypy -p --config-file {toxinidir}/mypy.ini - flake8 {toxinidir}/ {toxinidir}/tests - isort --check-only --diff {toxinidir}/ {toxinidir}/tests - pydocstyle --explain {toxinidir}/ {toxinidir}/tests - black --check {toxinidir}/ {toxinidir}/docs {toxinidir}/tests {toxinidir}/setup.py + pre-commit run --all-files --show-diff-on-failure [testenv:lint] basepython: python -extras: {[common-lint]extras} commands: {[common-lint]commands} -[testenv:py{37,38,39,310,311}-lint] -extras: {[common-lint]extras} +[testenv:py{38,39,310,311}-lint] commands: {[common-lint]commands} [testenv:py{37,38,39,310,311}-wheel] From 2ed5fba28d19109150175cd37394ab1e745d6633 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:51:01 -0600 Subject: [PATCH 069/102] Update pull_request_template.md fix linting broke template formatting --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3691f6b9..3f52eebd 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -11,7 +11,7 @@ Closes # - \[ \] Add or update documentation related to these changes -- \[ \] Add entry to the [release notes](https://github.com/ethereum/%3CREPO_NAME%3E/blob/main/newsfragments/README.md) +- \[ \] Add entry to the [release notes](https://github.com/ethereum//blob/main/newsfragments/README.md) #### Cute Animal Picture From 0065691db7c072eb818f125e7595afb59db205f9 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 13:55:19 -0600 Subject: [PATCH 070/102] Update Makefile missing doublequote --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 28d7fa46..74f1640c 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CURRENT_SIGN_SETTING := $(shell git config commit.gpgSign) help: @echo "clean-build - remove build artifacts" @echo "clean-pyc - remove Python file artifacts" - @echo "lint - fix linting issues with pre-commit + @echo "lint - fix linting issues with pre-commit" @echo "test - run tests quickly with the default Python" @echo "docs - generate docs and open in browser (linux-docs for version on linux)" @echo "notes - consume towncrier newsfragments/ and update release notes in docs/" From 82425694f63c6eb610e10451cb1c93317dbb6eeb Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:36:57 -0600 Subject: [PATCH 071/102] drop py37 support (#104) --- .circleci/config.yml | 15 --------------- setup.py | 3 +-- tox.ini | 7 +++---- 3 files changed, 4 insertions(+), 21 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bbc90296..2a438f57 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -74,12 +74,6 @@ jobs: environment: TOXENV: docs - py37-core: - <<: *common - docker: - - image: cimg/python:3.7 - environment: - TOXENV: py37-core py38-core: <<: *common docker: @@ -130,12 +124,6 @@ jobs: environment: TOXENV: py311-lint - py37-wheel: - <<: *common - docker: - - image: cimg/python:3.7 - environment: - TOXENV: py37-wheel py38-wheel: <<: *common docker: @@ -171,17 +159,14 @@ workflows: test: jobs: - docs - - py37-core - py38-core - py39-core - py310-core - py311-core - - py37-lint - py38-lint - py39-lint - py310-lint - py311-lint - - py37-wheel - py38-wheel - py39-wheel - py310-wheel diff --git a/setup.py b/setup.py index 5efcc3cd..ad552d5d 100644 --- a/setup.py +++ b/setup.py @@ -50,7 +50,7 @@ setup( install_requires=[ "eth-utils>=2", ], - python_requires=">=3.7, <4", + python_requires=">=3.8, <4", extras_require=extras_require, py_modules=[""], license="MIT", @@ -64,7 +64,6 @@ setup( "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/tox.ini b/tox.ini index cf23aa2e..df00ee6d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist= - py{37,38,39,310,311}-core + py{38,39,310,311}-core py{38,39,310,311}-lint - py{37,38,39,310,311}-wheel + py{38,39,310,311}-wheel py311-wheel-windows docs @@ -28,7 +28,6 @@ commands= docs: make check-docs basepython= docs: python - py37: python3.7 py38: python3.8 py39: python3.9 py310: python3.10 @@ -51,7 +50,7 @@ commands: {[common-lint]commands} [testenv:py{38,39,310,311}-lint] commands: {[common-lint]commands} -[testenv:py{37,38,39,310,311}-wheel] +[testenv:py{38,39,310,311}-wheel] deps= wheel build[virtualenv] From 146a3a9b020b87ccbbf44b783c254a84be1b34b2 Mon Sep 17 00:00:00 2001 From: pacrob Date: Wed, 11 Oct 2023 10:11:13 -0600 Subject: [PATCH 072/102] drop egg references --- .circleci/config.yml | 1 - Makefile | 1 - 2 files changed, 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2a438f57..5dcf0010 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,6 @@ common: &common - .tox - ~/.cache/pip - ~/.local - - ./eggs key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} orbs: diff --git a/Makefile b/Makefile index 74f1640c..9deaab82 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,6 @@ clean: clean-build clean-pyc clean-build: rm -fr build/ rm -fr dist/ - rm -fr *.egg-info clean-pyc: find . -name '*.pyc' -exec rm -f {} + From c3c29ddf43ed091d7e3bd92841503d3a15f564ee Mon Sep 17 00:00:00 2001 From: pacrob Date: Wed, 11 Oct 2023 08:31:24 -0600 Subject: [PATCH 073/102] bump pre-commit to 4.5 and add github-flavored markdown linting extension --- .github/pull_request_template.md | 6 +++--- .pre-commit-config.yaml | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 3f52eebd..18c01e24 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -7,11 +7,11 @@ Closes # ### Todo: -- \[ \] Clean up commit history +- [ ] Clean up commit history -- \[ \] Add or update documentation related to these changes +- [ ] Add or update documentation related to these changes -- \[ \] Add entry to the [release notes](https://github.com/ethereum//blob/main/newsfragments/README.md) +- [ ] Add entry to the [release notes](https://github.com/ethereum//blob/main/newsfragments/README.md) #### Cute Animal Picture diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 58f9e1d8..3ad4843d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: '.project-template|docs/conf.py' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: check-toml @@ -30,6 +30,8 @@ repos: rev: 0.7.17 hooks: - id: mdformat + additional_dependencies: + - mdformat-gfm - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.5.1 hooks: From 86440ee879a96dfc9410010ae3fad829c21277fa Mon Sep 17 00:00:00 2001 From: pacrob Date: Thu, 12 Oct 2023 08:57:17 -0600 Subject: [PATCH 074/102] add autoflake to lint and move config to pyproject.toml --- .pre-commit-config.yaml | 6 ++++ .pydocstyle.ini | 30 ------------------ Makefile | 5 ++- mypy.ini | 16 ---------- pyproject.toml | 68 +++++++++++++++++++++++++++++++++++++++++ pytest.ini | 8 ----- tox.ini | 9 ------ 7 files changed, 78 insertions(+), 64 deletions(-) delete mode 100644 .pydocstyle.ini delete mode 100644 mypy.ini delete mode 100644 pytest.ini diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3ad4843d..d2fae1c9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,6 +18,10 @@ repos: additional_dependencies: - flake8-bugbear==23.9.16 exclude: setup.py +- repo: https://github.com/PyCQA/autoflake + rev: v2.2.1 + hooks: + - id: autoflake - repo: https://github.com/pycqa/isort rev: 5.12.0 hooks: @@ -26,6 +30,8 @@ repos: rev: 6.3.0 hooks: - id: pydocstyle + additional_dependencies: + - tomli # required until >= python311 - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: diff --git a/.pydocstyle.ini b/.pydocstyle.ini deleted file mode 100644 index 0d40aa88..00000000 --- a/.pydocstyle.ini +++ /dev/null @@ -1,30 +0,0 @@ -[pydocstyle] -; All error codes found here: -; http://www.pydocstyle.org/en/3.0.0/error_codes.html -; -; Ignored: -; D1 - Missing docstring error codes -; -; Selected: -; D2 - Whitespace error codes -; D3 - Quote error codes -; D4 - Content related error codes -select=D2,D3,D4 - -; Extra ignores: -; D200 - One-line docstring should fit on one line with quotes -; D203 - 1 blank line required before class docstring -; D204 - 1 blank line required after class docstring -; D205 - 1 blank line required between summary line and description -; D212 - Multi-line docstring summary should start at the first line -; D302 - Use u""" for Unicode docstrings -; D400 - First line should end with a period -; D401 - First line should be in imperative mood -; D412 - No blank lines allowed between a section header and its content -add-ignore=D200,D203,D204,D205,D212,D302,D400,D401,D412 - -; Explanation: -; D400 - Enabling this error code seems to make it a requirement that the first -; sentence in a docstring is not split across two lines. It also makes it a -; requirement that no docstring can have a multi-sentence description without a -; summary line. Neither one of those requirements seem appropriate. diff --git a/Makefile b/Makefile index 9deaab82..fd94b2ce 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,10 @@ clean-pyc: find . -name '__pycache__' -exec rm -rf {} + lint: - pre-commit run --all-files --show-diff-on-failure + @pre-commit run --all-files --show-diff-on-failure || ( \ + echo "\n\n\n * pre-commit should have fixed the errors above. Running again to make sure everything is good..." \ + && pre-commit run --all-files --show-diff-on-failure \ + ) test: pytest tests diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index 1fcbd14c..00000000 --- a/mypy.ini +++ /dev/null @@ -1,16 +0,0 @@ -[mypy] - -check_untyped_defs = True -disallow_incomplete_defs = True -disallow_untyped_defs = True -disallow_any_generics = True -disallow_untyped_calls = True -disallow_untyped_decorators = True -disallow_subclassing_any = True -ignore_missing_imports = True -strict_optional = True -strict_equality = True -warn_redundant_casts = True -warn_return_any = True -warn_unused_configs = True -warn_unused_ignores = True diff --git a/pyproject.toml b/pyproject.toml index d94ebfd9..5abd4c29 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,71 @@ +[tool.autoflake] +remove_all_unused_imports = "True" +exclude = "__init__.py" + +[tool.isort] +combine_as_imports = "True" +extra_standard_library = "pytest" +force_grid_wrap = 1 +force_sort_within_sections = "True" +known_third_party = "hypothesis,pytest" +known_first_party = "" +multi_line_output = 3 +profile = "black" + +[tool.mypy] +check_untyped_defs = "True" +disallow_incomplete_defs = "True" +disallow_untyped_defs = "True" +disallow_any_generics = "True" +disallow_untyped_calls = "True" +disallow_untyped_decorators = "True" +disallow_subclassing_any = "True" +ignore_missing_imports = "True" +strict_optional = "True" +strict_equality = "True" +warn_redundant_casts = "True" +warn_return_any = "True" +warn_unused_configs = "True" +warn_unused_ignores = "True" + + +[tool.pydocstyle] +# All error codes found here: +# http://www.pydocstyle.org/en/3.0.0/error_codes.html +# +# Ignored: +# D1 - Missing docstring error codes +# +# Selected: +# D2 - Whitespace error codes +# D3 - Quote error codes +# D4 - Content related error codes +select = "D2,D3,D4" + +# Extra ignores: +# D200 - One-line docstring should fit on one line with quotes +# D203 - 1 blank line required before class docstring +# D204 - 1 blank line required after class docstring +# D205 - 1 blank line required between summary line and description +# D212 - Multi-line docstring summary should start at the first line +# D302 - Use u""" for Unicode docstrings +# D400 - First line should end with a period +# D401 - First line should be in imperative mood +# D412 - No blank lines allowed between a section header and its content +add-ignore = "D200,D203,D204,D205,D212,D302,D400,D401,D412,D415" + +# Explanation: +# D400 - Enabling this error code seems to make it a requirement that the first +# sentence in a docstring is not split across two lines. It also makes it a +# requirement that no docstring can have a multi-sentence description without a +# summary line. Neither one of those requirements seem appropriate. + +[tool.pytest.ini_options] +addopts = "-v --showlocals --durations 10" +xfail_strict = "True" +log_format = "%(levelname)8s %(asctime)s %(filename)20s %(message)s" +log_date_format = "%m-%d %H:%M:%S" + [tool.towncrier] # Read https://github.com/ethereum//blob/main/newsfragments/README.md for instructions package = "" diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index fd5ea7cb..00000000 --- a/pytest.ini +++ /dev/null @@ -1,8 +0,0 @@ -[pytest] -addopts= -v --showlocals --durations 10 -xfail_strict=true -log_format = %(levelname)8s %(asctime)s %(filename)20s %(message)s -log_date_format = %m-%d %H:%M:%S - -[pytest-watch] -runner= pytest --failed-first --maxfail=1 --no-success-flaky-report diff --git a/tox.ini b/tox.ini index df00ee6d..2742f06a 100644 --- a/tox.ini +++ b/tox.ini @@ -6,15 +6,6 @@ envlist= py311-wheel-windows docs -[isort] -combine_as_imports=True -force_grid_wrap=1 -force_sort_within_sections=True -known_third_party=hypothesis,pytest -known_first_party= -multi_line_output=3 -profile=black - [flake8] exclude=venv*,.tox,docs,build extend-ignore=E203 From 662b35d09a8e33bd5bd4cbc611142fd06b0d1956 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Thu, 12 Oct 2023 12:14:28 -0600 Subject: [PATCH 075/102] Update pyproject.toml Add description of pydocstyle D415 rule --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 5abd4c29..8c23be36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,7 @@ select = "D2,D3,D4" # D400 - First line should end with a period # D401 - First line should be in imperative mood # D412 - No blank lines allowed between a section header and its content +# D415 - First line should end with a period, question mark, or exclamation point add-ignore = "D200,D203,D204,D205,D212,D302,D400,D401,D412,D415" # Explanation: From 8d5d92ddd8fe0cb45f648fd7fa276c16987b5d82 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Thu, 26 Oct 2023 12:54:07 -0600 Subject: [PATCH 076/102] Update setup.py drop pytest-watch from dev dependencies --- setup.py | 1 - 1 file changed, 1 deletion(-) diff --git a/setup.py b/setup.py index ad552d5d..193ed7be 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,6 @@ extras_require = { "bumpversion>=0.5.3", "ipython", "pre-commit>=3.4.0", - "pytest-watch>=4.1.0", "tox>=4.0.0", "twine", "wheel", From 885bef7b5e7792af12fbe8f365e6410035f07fc5 Mon Sep 17 00:00:00 2001 From: pacrob Date: Fri, 27 Oct 2023 12:13:12 -0600 Subject: [PATCH 077/102] condense tox lint envs as linting now a pre-commit call, not tox --- tox.ini | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tox.ini b/tox.ini index 2742f06a..f52da5f8 100644 --- a/tox.ini +++ b/tox.ini @@ -28,19 +28,11 @@ extras= docs allowlist_externals=make,pre-commit -[common-lint] -basepython=python +[testenv:py{38,39,310,311}-lint] deps=pre-commit commands= pre-commit run --all-files --show-diff-on-failure -[testenv:lint] -basepython: python -commands: {[common-lint]commands} - -[testenv:py{38,39,310,311}-lint] -commands: {[common-lint]commands} - [testenv:py{38,39,310,311}-wheel] deps= wheel From 3c654831215dafd772e220d314b3c9221417f461 Mon Sep 17 00:00:00 2001 From: fselmo Date: Tue, 7 Nov 2023 12:07:54 -0700 Subject: [PATCH 078/102] update the grep command for upstream branch check - Sometimes 'www.' is used in the url for https --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fd94b2ce..29815fad 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,9 @@ notes: check-bump release: check-bump clean # require that upstream is configured for ethereum/ - git remote -v | grep "upstream\tgit@github.com:ethereum/.git (push)\|upstream\thttps://github.com/ethereum/ (push)" + @git remote -v | grep \ + -e "upstream\tgit@github.com:ethereum/.git (push)" \ + -Ee "upstream\thttps://(www.)?github.com/ethereum/ \(push\)" # verify that docs build correctly ./newsfragments/validate_files.py is-empty make build-docs From 7f75b270a530924a91c776f32c708c9a82881771 Mon Sep 17 00:00:00 2001 From: fselmo Date: Tue, 7 Nov 2023 12:13:48 -0700 Subject: [PATCH 079/102] Use upcoming version in make notes commit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29815fad..6afbaf3a 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ notes: check-bump towncrier build --yes --version $(UPCOMING_VERSION) # Before we bump the version, make sure that the towncrier-generated docs will build make build-docs - git commit -m "Compile release notes" + git commit -m "Compile release notes for v$(UPCOMING_VERSION)" release: check-bump clean # require that upstream is configured for ethereum/ From 4d17820fca41d23d1e69cfd21282cd6e89f03231 Mon Sep 17 00:00:00 2001 From: fselmo Date: Mon, 27 Nov 2023 13:02:31 -0700 Subject: [PATCH 080/102] Further generalize the grep command for remote check --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6afbaf3a..c5956da1 100644 --- a/Makefile +++ b/Makefile @@ -67,9 +67,7 @@ notes: check-bump release: check-bump clean # require that upstream is configured for ethereum/ - @git remote -v | grep \ - -e "upstream\tgit@github.com:ethereum/.git (push)" \ - -Ee "upstream\thttps://(www.)?github.com/ethereum/ \(push\)" + @git remote -v | grep -E "upstream\tgit@github.com:ethereum/.git \(push\)|upstream\thttps://(www.)?github.com/ethereum/ \(push\)" # verify that docs build correctly ./newsfragments/validate_files.py is-empty make build-docs From 67c0fb4f7b2e72be5161942af68b27a11a7b0e9d Mon Sep 17 00:00:00 2001 From: Stuart Reed Date: Mon, 27 Nov 2023 15:51:31 -0700 Subject: [PATCH 081/102] Ignore all __pycache__ directories (#114) * Ignore all __pycache__ directories * Newsfragment * Revert Newsfragment --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 5127a4df..57eac529 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,9 @@ chains .cache .pytest_cache +# pycache +__pycache__/ + # Test output logs logs From 0b0593880dbcebbfd6ae496b08e63f01ad814418 Mon Sep 17 00:00:00 2001 From: pacrob Date: Tue, 28 Nov 2023 09:21:12 -0700 Subject: [PATCH 082/102] add formats key to RTD to make downloadable docs available --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 593793c2..e55e07e4 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -15,3 +15,6 @@ python: path: . extra_requirements: - docs + +# Build all formats for RTD Downloads - htmlzip, pdf, epub +formats: all From d1395aaad2b26dffc61aec7ee821c597784ae816 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Fri, 1 Dec 2023 16:01:08 -0700 Subject: [PATCH 083/102] add .bumpversion.cfg to pre-commit ignore Causes problems with releasing when pre-commit changes the file after bumpversion updates it --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d2fae1c9..789b16cd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: '.project-template|docs/conf.py' +exclude: '.project-template|docs/conf.py|.bumpversion.cfg' repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 From 621cd56059b73ea60f315ebef437a998d15481be Mon Sep 17 00:00:00 2001 From: pacrob Date: Thu, 7 Dec 2023 14:39:09 -0700 Subject: [PATCH 084/102] add pyupgrade to pre-commit hooks --- .pre-commit-config.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 789b16cd..d1aa72ce 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,3 +43,8 @@ repos: hooks: - id: mypy exclude: tests/ +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] From cb3f556315ba864450c975b88058f08da0a9c399 Mon Sep 17 00:00:00 2001 From: pacrob Date: Sat, 9 Dec 2023 12:12:52 -0700 Subject: [PATCH 085/102] move pyupgrade before black --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1aa72ce..82b01b7c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,6 +7,11 @@ repos: - id: check-toml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: [--py38-plus] - repo: https://github.com/psf/black rev: 23.9.1 hooks: @@ -43,8 +48,3 @@ repos: hooks: - id: mypy exclude: tests/ -- repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 - hooks: - - id: pyupgrade - args: [--py38-plus] From 30e3c1de20dedffc78d799017bfddd7d29ab6cef Mon Sep 17 00:00:00 2001 From: pacrob Date: Wed, 3 Jan 2024 11:11:09 -0700 Subject: [PATCH 086/102] toml bools should be lowercase w/o quotes --- pyproject.toml | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8c23be36..f244df2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,32 +1,32 @@ [tool.autoflake] -remove_all_unused_imports = "True" +remove_all_unused_imports = true exclude = "__init__.py" [tool.isort] -combine_as_imports = "True" +combine_as_imports = true extra_standard_library = "pytest" force_grid_wrap = 1 -force_sort_within_sections = "True" +force_sort_within_sections = true known_third_party = "hypothesis,pytest" known_first_party = "" multi_line_output = 3 profile = "black" [tool.mypy] -check_untyped_defs = "True" -disallow_incomplete_defs = "True" -disallow_untyped_defs = "True" -disallow_any_generics = "True" -disallow_untyped_calls = "True" -disallow_untyped_decorators = "True" -disallow_subclassing_any = "True" -ignore_missing_imports = "True" -strict_optional = "True" -strict_equality = "True" -warn_redundant_casts = "True" -warn_return_any = "True" -warn_unused_configs = "True" -warn_unused_ignores = "True" +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_untyped_defs = true +disallow_any_generics = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_subclassing_any = true +ignore_missing_imports = true +strict_optional = true +strict_equality = true +warn_redundant_casts = true +warn_return_any = true +warn_unused_configs = true +warn_unused_ignores = true [tool.pydocstyle] @@ -63,7 +63,7 @@ add-ignore = "D200,D203,D204,D205,D212,D302,D400,D401,D412,D415" [tool.pytest.ini_options] addopts = "-v --showlocals --durations 10" -xfail_strict = "True" +xfail_strict = true log_format = "%(levelname)8s %(asctime)s %(filename)20s %(message)s" log_date_format = "%m-%d %H:%M:%S" From e342fe762491aa61a4f21be0683fe507f0ee89ba Mon Sep 17 00:00:00 2001 From: pacrob Date: Mon, 8 Jan 2024 16:18:53 -0700 Subject: [PATCH 087/102] add version to import test --- tests/core/test_import.py | 2 -- tests/core/test_import_and_version.py | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 tests/core/test_import.py create mode 100644 tests/core/test_import_and_version.py diff --git a/tests/core/test_import.py b/tests/core/test_import.py deleted file mode 100644 index 07b2a18e..00000000 --- a/tests/core/test_import.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_import(): - import # noqa: F401 diff --git a/tests/core/test_import_and_version.py b/tests/core/test_import_and_version.py new file mode 100644 index 00000000..37b44197 --- /dev/null +++ b/tests/core/test_import_and_version.py @@ -0,0 +1,4 @@ +def test_import(): + import + version = .__version__ + assert isinstance(version, str) From 4ac9e871667803eb84ab23dd01cc0dd3502bc997 Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:35:27 -0700 Subject: [PATCH 088/102] Update test_import_and_version.py clean up test_import_and_version --- tests/core/test_import_and_version.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/core/test_import_and_version.py b/tests/core/test_import_and_version.py index 37b44197..17e01b84 100644 --- a/tests/core/test_import_and_version.py +++ b/tests/core/test_import_and_version.py @@ -1,4 +1,3 @@ -def test_import(): +def test_import_and_version(): import - version = .__version__ - assert isinstance(version, str) + assert isinstance(.__version__, str) From 608a0a954bdb1e51186bf46e9a3a485889d5637a Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:36:12 -0700 Subject: [PATCH 089/102] Update test_import_and_version.py clean up test_import_and_version --- tests/core/test_import_and_version.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/test_import_and_version.py b/tests/core/test_import_and_version.py index 17e01b84..6a2f8ea5 100644 --- a/tests/core/test_import_and_version.py +++ b/tests/core/test_import_and_version.py @@ -1,3 +1,4 @@ def test_import_and_version(): import + assert isinstance(.__version__, str) From 3fed49fb497ca322a747564634f5888b3bbea71d Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:50:29 -0700 Subject: [PATCH 090/102] Update config.yml Drop the `install pre-commit` step here, as it is installed for all linting ci via the tox env deps --- .circleci/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 5dcf0010..25d1d7b3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -25,9 +25,6 @@ common: &common command: | python -m pip install --upgrade pip python -m pip install tox - - run: - name: install pre-commit - command: python -m pip install --progress-bar=off pre-commit - run: name: run tox command: python -m tox run -r From 8ffe3b8900139eeb2602fd44249835fe77f1f68a Mon Sep 17 00:00:00 2001 From: Paul Robinson <5199899+pacrob@users.noreply.github.com> Date: Fri, 12 Jan 2024 15:03:07 -0700 Subject: [PATCH 091/102] Update tox.ini Add `pre-commit install` here since it was removed from ci config --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index f52da5f8..75c4d54a 100644 --- a/tox.ini +++ b/tox.ini @@ -31,6 +31,7 @@ allowlist_externals=make,pre-commit [testenv:py{38,39,310,311}-lint] deps=pre-commit commands= + pre-commit install pre-commit run --all-files --show-diff-on-failure [testenv:py{38,39,310,311}-wheel] From b853f5ccdf0fc45b2168ffaffc52adccbe098ac1 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Fri, 26 Jan 2024 11:14:40 -0700 Subject: [PATCH 092/102] add py312 support --- .circleci/config.yml | 21 +++++++++++++++++++++ setup.py | 1 + tox.ini | 11 ++++++----- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 25d1d7b3..113f401d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,6 +94,12 @@ jobs: - image: cimg/python:3.11 environment: TOXENV: py311-core + py312-core: + <<: *common + docker: + - image: cimg/python:3.12 + environment: + TOXENV: py312-core py38-lint: <<: *common @@ -119,6 +125,12 @@ jobs: - image: cimg/python:3.11 environment: TOXENV: py311-lint + py312-lint: + <<: *common + docker: + - image: cimg/python:3.12 + environment: + TOXENV: py312-lint py38-wheel: <<: *common @@ -144,6 +156,12 @@ jobs: - image: cimg/python:3.11 environment: TOXENV: py311-wheel + py312-wheel: + <<: *common + docker: + - image: cimg/python:3.12 + environment: + TOXENV: py312-wheel py311-wheel-windows: <<: *windows_steps @@ -159,12 +177,15 @@ workflows: - py39-core - py310-core - py311-core + - py312-core - py38-lint - py39-lint - py310-lint - py311-lint + - py312-lint - py38-wheel - py39-wheel - py310-wheel - py311-wheel + - py312-wheel - py311-wheel-windows diff --git a/setup.py b/setup.py index 193ed7be..c2247fee 100644 --- a/setup.py +++ b/setup.py @@ -67,5 +67,6 @@ setup( "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ], ) diff --git a/tox.ini b/tox.ini index 75c4d54a..2f61829e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,8 @@ [tox] envlist= - py{38,39,310,311}-core - py{38,39,310,311}-lint - py{38,39,310,311}-wheel + py{38,39,310,311,312}-core + py{38,39,310,311,312}-lint + py{38,39,310,311,312}-wheel py311-wheel-windows docs @@ -23,18 +23,19 @@ basepython= py39: python3.9 py310: python3.10 py311: python3.11 + py312: python3.12 extras= test docs allowlist_externals=make,pre-commit -[testenv:py{38,39,310,311}-lint] +[testenv:py{38,39,310,311,312}-lint] deps=pre-commit commands= pre-commit install pre-commit run --all-files --show-diff-on-failure -[testenv:py{38,39,310,311}-wheel] +[testenv:py{38,39,310,311,312}-wheel] deps= wheel build[virtualenv] From 2eff6f8be8603022915ad1a20978d57da977e304 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:02:54 -0700 Subject: [PATCH 093/102] update windows wheel ci jobs to use pyenv, add py312 job --- .circleci/config.yml | 99 ++++++++++++++++++++++++++++++++------------ tox.ini | 6 ++- 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 113f401d..fdc4c841 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -39,28 +39,51 @@ common: &common orbs: win: circleci/windows@5.0.0 -windows_steps: &windows_steps - executor: - name: win/default - shell: bash.exe - working_directory: C:\Users\circleci\project\ - steps: - - checkout - - restore_cache: - keys: - - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - - run: - name: install dependencies - command: | - python -m pip install --upgrade pip - python -m pip install tox - - run: - name: run tox - command: python -m tox run -r - - save_cache: - paths: - - .tox - key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} +windows-wheel-steps: + windows-wheel-setup: &windows-wheel-setup + executor: + name: win/default + shell: bash.exe + working_directory: C:\Users\circleci\project\ + environment: + TOXENV: windows-wheel + restore-cache-step: &restore-cache-step + restore_cache: + keys: + - cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + install-pyenv-step: &install-pyenv-step + run: + name: install pyenv + command: | + pip install pyenv-win --target $HOME/.pyenv + echo 'export PYENV="$HOME/.pyenv/pyenv-win/"' >> $BASH_ENV + echo 'export PYENV_ROOT="$HOME/.pyenv/pyenv-win/"' >> $BASH_ENV + echo 'export PYENV_USERPROFILE="$HOME/.pyenv/pyenv-win/"' >> $BASH_ENV + echo 'export PATH="$PATH:$HOME/.pyenv/pyenv-win/bin"' >> $BASH_ENV + echo 'export PATH="$PATH:$HOME/.pyenv/pyenv-win/shims"' >> $BASH_ENV + source $BASH_ENV + pyenv update + install-latest-python-step: &install-latest-python-step + run: + name: install latest python version and tox + command: | + LATEST_VERSION=$(pyenv install --list | grep -E "${MINOR_VERSION}\.[0-9]+$" | tail -1) + echo "installing python version $LATEST_VERSION" + pyenv install $LATEST_VERSION + pyenv global $LATEST_VERSION + python3 -m pip install --upgrade pip + python3 -m pip install tox + run-tox-step: &run-tox-step + run: + name: run tox + command: | + echo 'running tox with' $(python3 --version) + python3 -m tox run -r + save-cache-step: &save-cache-step + save_cache: + paths: + - .tox + key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} jobs: docs: @@ -163,10 +186,31 @@ jobs: environment: TOXENV: py312-wheel - py311-wheel-windows: - <<: *windows_steps - environment: - TOXENV: py311-wheel-windows + py311-windows-wheel: + <<: *windows-wheel-setup + steps: + - checkout + - <<: *restore-cache-step + - <<: *install-pyenv-step + - run: + name: set minor version + command: echo "export MINOR_VERSION='3.11'" >> $BASH_ENV + - <<: *install-latest-python-step + - <<: *run-tox-step + - <<: *save-cache-step + + py312-windows-wheel: + <<: *windows-wheel-setup + steps: + - checkout + - <<: *restore-cache-step + - <<: *install-pyenv-step + - run: + name: set minor version + command: echo "export MINOR_VERSION='3.12'" >> $BASH_ENV + - <<: *install-latest-python-step + - <<: *run-tox-step + - <<: *save-cache-step workflows: version: 2 @@ -188,4 +232,5 @@ workflows: - py310-wheel - py311-wheel - py312-wheel - - py311-wheel-windows + - py311-windows-wheel + - py312-windows-wheel diff --git a/tox.ini b/tox.ini index 2f61829e..728d47d1 100644 --- a/tox.ini +++ b/tox.ini @@ -3,7 +3,7 @@ envlist= py{38,39,310,311,312}-core py{38,39,310,311,312}-lint py{38,39,310,311,312}-wheel - py311-wheel-windows + windows-wheel docs [flake8] @@ -19,6 +19,7 @@ commands= docs: make check-docs basepython= docs: python + windows-wheel: python py38: python3.8 py39: python3.9 py310: python3.10 @@ -50,13 +51,14 @@ commands= python -c "import " skip_install=true -[testenv:py311-wheel-windows] +[testenv:windows-wheel] deps= wheel build[virtualenv] allowlist_externals= bash.exe commands= + python --version python -m pip install --upgrade pip bash.exe -c "rm -rf build dist" python -m build From bdd1a342d9f88761caa99ed97fc5104096fc5efd Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Wed, 31 Jan 2024 15:00:58 -0700 Subject: [PATCH 094/102] add docs build path for ci to check pdf and epub --- .circleci/config.yml | 12 +++++++++++- Makefile | 10 ++++++++-- tox.ini | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fdc4c841..d9e28eb9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,10 +84,20 @@ windows-wheel-steps: paths: - .tox key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} + +docs: &docs + docker: + - image: common + steps: + - run: + name: install latexpdf dependencies + command: | + sudo apt-get update + sudo apt-get install latexmk tex-gyre texlive-fonts-extra jobs: docs: - <<: *common + <<: *docs docker: - image: cimg/python:3.8 environment: diff --git a/Makefile b/Makefile index c5956da1..d1c5c7a2 100644 --- a/Makefile +++ b/Makefile @@ -38,12 +38,18 @@ build-docs: $(MAKE) -C docs clean $(MAKE) -C docs html $(MAKE) -C docs doctest + +build-docs-ci: + $(MAKE) -C docs latexpdf + $(MAKE) -C docs epub -validate-docs: +validate-newsfragments: python ./newsfragments/validate_files.py towncrier build --draft --version preview -check-docs: build-docs validate-docs +check-docs: build-docs validate-newsfragments + +check-docs-ci: build-docs build-docs-ci validate-newsfragments docs: check-docs open docs/_build/html/index.html diff --git a/tox.ini b/tox.ini index 728d47d1..ce1da94b 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ per-file-ignores=__init__.py:F401 usedevelop=True commands= core: pytest {posargs:tests/core} - docs: make check-docs + docs: make check-docs-ci basepython= docs: python windows-wheel: python From 94483714a3fbc13d52aadd8ea58d6f91b43ee446 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Mon, 19 Feb 2024 15:56:20 -0700 Subject: [PATCH 095/102] run lint and fix errors, except mypy --- .bumpversion.cfg | 4 +- .circleci/config.yml | 2 +- .github/ISSUE_TEMPLATE/bug_report.yml | 8 +- .github/ISSUE_TEMPLATE/enhancement.yml | 2 +- .github/ISSUE_TEMPLATE/feature_request.yml | 2 +- .github/pull_request_template.md | 6 +- .gitignore | 1 - .pre-commit-config.yaml | 20 +- LICENSE-APACHE | 1 - Makefile | 2 +- README.md | 195 ++- examples/chat/chat.py | 21 +- examples/echo/echo.py | 27 +- libp2p/__init__.py | 72 +- libp2p/crypto/authenticated_encryption.py | 20 +- libp2p/crypto/ecc.py | 28 +- libp2p/crypto/ed25519.py | 20 +- libp2p/crypto/exceptions.py | 12 +- libp2p/crypto/key_exchange.py | 20 +- libp2p/crypto/keys.py | 20 +- libp2p/crypto/pb/crypto.proto | 2 +- libp2p/crypto/pb/crypto_pb2.py | 280 ++-- libp2p/crypto/pb/crypto_pb2.pyi | 72 +- libp2p/crypto/rsa.py | 19 +- libp2p/crypto/secp256k1.py | 7 +- libp2p/crypto/serialization.py | 24 +- libp2p/host/basic_host.py | 85 +- libp2p/host/defaults.py | 25 +- libp2p/host/exceptions.py | 4 +- libp2p/host/host_interface.py | 44 +- libp2p/host/ping.py | 25 +- libp2p/host/routed_host.py | 25 +- libp2p/identity/identify/pb/identify.proto | 2 +- libp2p/identity/identify/pb/identify_pb2.py | 224 ++- libp2p/identity/identify/pb/identify_pb2.pyi | 85 +- libp2p/identity/identify/protocol.py | 25 +- libp2p/io/abc.py | 5 +- libp2p/io/exceptions.py | 4 +- libp2p/io/msgio.py | 23 +- libp2p/io/trio.py | 8 +- libp2p/io/utils.py | 8 +- libp2p/network/connection/exceptions.py | 4 +- .../connection/net_connection_interface.py | 20 +- libp2p/network/connection/raw_connection.py | 16 +- .../connection/raw_connection_interface.py | 4 +- libp2p/network/connection/swarm_connection.py | 33 +- libp2p/network/exceptions.py | 4 +- libp2p/network/network_interface.py | 44 +- libp2p/network/notifee_interface.py | 21 +- libp2p/network/stream/exceptions.py | 4 +- libp2p/network/stream/net_stream.py | 29 +- libp2p/network/stream/net_stream_interface.py | 17 +- libp2p/network/swarm.py | 125 +- libp2p/peer/README.md | 4 +- libp2p/peer/addrbook_interface.py | 22 +- libp2p/peer/id.py | 8 +- libp2p/peer/peerdata.py | 21 +- libp2p/peer/peerdata_interface.py | 24 +- libp2p/peer/peerinfo.py | 10 +- libp2p/peer/peermetadata_interface.py | 13 +- libp2p/peer/peerstore.py | 39 +- libp2p/peer/peerstore_interface.py | 36 +- libp2p/protocol_muxer/exceptions.py | 4 +- libp2p/protocol_muxer/multiselect.py | 29 +- libp2p/protocol_muxer/multiselect_client.py | 27 +- .../multiselect_client_interface.py | 21 +- .../multiselect_communicator.py | 29 +- .../multiselect_communicator_interface.py | 11 +- .../multiselect_muxer_interface.py | 25 +- libp2p/pubsub/abc.py | 31 +- libp2p/pubsub/exceptions.py | 4 +- libp2p/pubsub/floodsub.py | 36 +- libp2p/pubsub/gossipsub.py | 154 +- libp2p/pubsub/mcache.py | 19 +- libp2p/pubsub/pb/rpc_pb2.py | 1397 ++++++++++------- libp2p/pubsub/pb/rpc_pb2.pyi | 477 ++++-- libp2p/pubsub/pubsub.py | 119 +- libp2p/pubsub/pubsub_notifee.py | 25 +- libp2p/pubsub/subscription.py | 26 +- libp2p/pubsub/typing.py | 14 +- libp2p/pubsub/validators.py | 12 +- libp2p/routing/interfaces.py | 29 +- libp2p/security/base_session.py | 23 +- libp2p/security/base_transport.py | 16 +- libp2p/security/exceptions.py | 4 +- libp2p/security/insecure/pb/plaintext_pb2.py | 130 +- libp2p/security/insecure/pb/plaintext_pb2.pyi | 31 +- libp2p/security/insecure/transport.py | 70 +- libp2p/security/noise/exceptions.py | 10 +- libp2p/security/noise/io.py | 18 +- libp2p/security/noise/messages.py | 13 +- libp2p/security/noise/patterns.py | 47 +- libp2p/security/noise/pb/noise_pb2.py | 147 +- libp2p/security/noise/pb/noise_pb2.pyi | 37 +- libp2p/security/noise/transport.py | 30 +- libp2p/security/secio/exceptions.py | 12 +- libp2p/security/secio/pb/spipe.proto | 2 +- libp2p/security/secio/pb/spipe_pb2.py | 302 ++-- libp2p/security/secio/pb/spipe_pb2.pyi | 119 +- libp2p/security/secio/transport.py | 84 +- libp2p/security/secure_conn_interface.py | 23 +- libp2p/security/secure_session.py | 21 +- libp2p/security/secure_transport_interface.py | 18 +- libp2p/security/security_multistream.py | 49 +- libp2p/stream_muxer/abc.py | 36 +- libp2p/stream_muxer/exceptions.py | 4 +- libp2p/stream_muxer/mplex/constants.py | 4 +- libp2p/stream_muxer/mplex/datastructures.py | 4 +- libp2p/stream_muxer/mplex/mplex.py | 83 +- libp2p/stream_muxer/mplex/mplex_stream.py | 67 +- libp2p/stream_muxer/muxer_multistream.py | 41 +- libp2p/tools/constants.py | 9 +- libp2p/tools/factories.py | 177 ++- libp2p/tools/interop/daemon.py | 43 +- libp2p/tools/interop/process.py | 12 +- libp2p/tools/interop/utils.py | 24 +- libp2p/tools/pubsub/dummy_account_node.py | 31 +- .../floodsub_integration_test_settings.py | 17 +- libp2p/tools/pubsub/utils.py | 20 +- libp2p/tools/utils.py | 31 +- libp2p/transport/exceptions.py | 4 +- libp2p/transport/listener_interface.py | 17 +- libp2p/transport/tcp/tcp.py | 52 +- libp2p/transport/transport_interface.py | 25 +- libp2p/transport/typing.py | 23 +- libp2p/transport/upgrader.py | 52 +- libp2p/typing.py | 7 +- libp2p/utils.py | 18 +- scripts/release/test_package.py | 29 +- setup.py | 1 - tests/conftest.py | 4 +- tests/core/test_import_and_version.py | 2 +- tests/crypto/test_ed25519.py | 9 +- tests/crypto/test_secp256k1.py | 9 +- tests/examples/test_examples.py | 16 +- tests/host/test_basic_host.py | 20 +- tests/host/test_ping.py | 9 +- tests/host/test_routed_host.py | 13 +- tests/identity/identify/test_protocol.py | 13 +- tests/libp2p/test_libp2p.py | 26 +- tests/network/test_net_stream.py | 10 +- tests/network/test_notify.py | 24 +- tests/network/test_swarm.py | 20 +- tests/network/test_swarm_conn.py | 4 +- tests/peer/test_addrbook.py | 9 +- tests/peer/test_interop.py | 8 +- tests/peer/test_peerid.py | 8 +- tests/peer/test_peerinfo.py | 10 +- tests/peer/test_peermetadata.py | 5 +- tests/peer/test_peerstore.py | 17 +- tests/protocol_muxer/test_protocol_muxer.py | 12 +- tests/pubsub/test_dummyaccount_demo.py | 8 +- tests/pubsub/test_floodsub.py | 12 +- tests/pubsub/test_gossipsub.py | 38 +- .../test_gossipsub_backward_compatibility.py | 8 +- tests/pubsub/test_mcache.py | 4 +- tests/pubsub/test_pubsub.py | 50 +- tests/pubsub/test_subscription.py | 8 +- tests/security/noise/test_msg_read_writer.py | 9 +- tests/security/noise/test_noise.py | 9 +- tests/security/test_secio.py | 21 +- tests/security/test_security_multistream.py | 17 +- tests/stream_muxer/conftest.py | 5 +- tests/stream_muxer/test_mplex_stream.py | 12 +- tests/transport/test_tcp.py | 20 +- tests_interop/conftest.py | 40 +- tests_interop/test_bindings.py | 8 +- tests_interop/test_echo.py | 35 +- tests_interop/test_net_stream.py | 10 +- tests_interop/test_pubsub.py | 32 +- tox.ini | 2 +- 171 files changed, 4809 insertions(+), 2290 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index f5384618..a830d2b7 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -3,14 +3,14 @@ current_version = 0.1.5 commit = True tag = True parse = (?P\d+)\.(?P\d+)\.(?P\d+)(-(?P[^.]*)\.(?P\d+))? -serialize = +serialize = {major}.{minor}.{patch}-{stage}.{devnum} {major}.{minor}.{patch} [bumpversion:part:stage] optional_value = stable first_value = stable -values = +values = alpha beta stable diff --git a/.circleci/config.yml b/.circleci/config.yml index f70d22cf..079315ad 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,7 +84,7 @@ windows-wheel-steps: paths: - .tox key: cache-v1-{{ arch }}-{{ .Environment.CIRCLE_JOB }}-{{ checksum "setup.py" }}-{{ checksum "tox.ini" }} - + docs: &docs docker: - image: common diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 444ecb02..e961cfd6 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -15,13 +15,13 @@ body: - type: textarea attributes: label: Expected behavior - description: Describe what you expect to happen. + description: Describe what you expect to happen. validations: required: true - type: textarea attributes: label: Actual behavior - description: Describe what actually happens. + description: Describe what actually happens. validations: required: true - type: textarea @@ -34,13 +34,13 @@ body: - type: textarea attributes: label: Possible Solution - description: Suggest a fix/reason for the bug, or ideas how to implement the addition or change. + description: Suggest a fix/reason for the bug, or ideas how to implement the addition or change. validations: required: false - type: textarea attributes: label: Environment - description: Run this: `$ python -m eth_utils` and put the results here. + description: Run `$ python -m eth_utils` and put the results here. render: shell validations: required: false diff --git a/.github/ISSUE_TEMPLATE/enhancement.yml b/.github/ISSUE_TEMPLATE/enhancement.yml index 7c6bc2b9..b4458826 100644 --- a/.github/ISSUE_TEMPLATE/enhancement.yml +++ b/.github/ISSUE_TEMPLATE/enhancement.yml @@ -4,7 +4,7 @@ body: - type: textarea attributes: label: Description - description: Describe the enhancement that you are proposing. + description: Describe the enhancement that you are proposing. validations: required: true - type: textarea diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 191af5b8..d78dd66f 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -21,7 +21,7 @@ body: attributes: label: Requirements description: Write a list of what you want this feature to do. - placeholder: "1." + placeholder: "1." validations: required: true - type: textarea diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 85ec186d..cb2c87e3 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -8,12 +8,10 @@ Summary of approach. ### To-Do -[//]: # (Stay ahead of things, add list items here!) - [ ] Clean up commit history -[//]: # (See: https://py-libp2p.readthedocs.io/en/latest/contributing.html#pull-requests) -- [ ] Add entry to the [release notes](https://github.com/libp2p/py-libp2p/blob/main/newsfragments/README.md) +* [ ] Add entry to the [release notes](https://github.com/libp2p/py-libp2p/blob/main/newsfragments/README.md) #### Cute Animal Picture -![put a cute animal picture link inside the parentheses]() +![put a cute animal picture link inside the parentheses](<>) diff --git a/.gitignore b/.gitignore index 43bc1435..33f68437 100644 --- a/.gitignore +++ b/.gitignore @@ -194,4 +194,3 @@ env.bak/ # mkdocs documentation /site - diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 82870756..38caecd8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,11 +13,11 @@ repos: - id: pyupgrade args: [--py38-plus] - repo: https://github.com/psf/black - rev: 19.3b0 + rev: 23.9.1 hooks: - id: black - repo: https://github.com/PyCQA/flake8 - rev: 3.7.9 + rev: 6.1.0 hooks: - id: flake8 additional_dependencies: @@ -28,7 +28,7 @@ repos: hooks: - id: autoflake - repo: https://github.com/pycqa/isort - rev: 4.3.21 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/pycqa/pydocstyle @@ -43,10 +43,10 @@ repos: - id: mdformat additional_dependencies: - mdformat-gfm -- repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.780 - hooks: - - id: mypy - additional_dependencies: - - mypy-protobuf - exclude: tests/ +# - repo: https://github.com/pre-commit/mirrors-mypy +# rev: v1.5.1 +# hooks: +# - id: mypy +# additional_dependencies: +# - mypy-protobuf +# exclude: 'tests/|tests_interop/|crypto/|identity/|pubsub/|insecure/|noise/|security/' diff --git a/LICENSE-APACHE b/LICENSE-APACHE index e90f716b..62a42049 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -5,4 +5,3 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - diff --git a/Makefile b/Makefile index 55e939ed..218c2861 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,7 @@ build-docs: $(MAKE) -C docs clean $(MAKE) -C docs html $(MAKE) -C docs doctest - + build-docs-ci: $(MAKE) -C docs latexpdf $(MAKE) -C docs epub diff --git a/README.md b/README.md index 31192c54..31c9669d 100644 --- a/README.md +++ b/README.md @@ -9,12 +9,12 @@ [![Matrix](https://img.shields.io/badge/matrix-%23libp2p%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#libp2p:permaweb.io) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/66KBrm2) -

py-libp2p hex logo

## WARNING + py-libp2p is an experimental and work-in-progress repo under heavy development. We do not yet recommend using py-libp2p in production environments. The Python implementation of the libp2p networking stack @@ -22,9 +22,11 @@ The Python implementation of the libp2p networking stack Read more in the [documentation on ReadTheDocs](https://py-libp2p.readthedocs.io/). [View the release notes](https://py-libp2p.readthedocs.io/en/latest/release_notes.html). ## Sponsorship + This project is graciously sponsored by the Ethereum Foundation through [Wave 5 of their Grants Program](https://blog.ethereum.org/2019/02/21/ethereum-foundation-grants-program-wave-5/). ## Maintainers + The py-libp2p team consists of: [@zixuanzh](https://github.com/zixuanzh) [@alexh](https://github.com/alexh) [@stuckinaboot](https://github.com/stuckinaboot) [@robzajac](https://github.com/robzajac) [@carver](https://github.com/carver) @@ -70,125 +72,114 @@ ptw --onfail "notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 3 test Note that tests/libp2p/test_libp2p.py contains an end-to-end messaging test between two libp2p hosts, which is the bulk of our proof of concept. - ### Release setup -<<<<<<< HEAD +\<\<\<\<\<\<\< HEAD Releases follow the same basic pattern as releases of some tangentially-related projects, -like Trinity. See [Trinity's release instructions]( -https://trinity-client.readthedocs.io/en/latest/contributing.html#releasing). +like Trinity. See [Trinity's release instructions](https://trinity-client.readthedocs.io/en/latest/contributing.html#releasing). ## Requirements -======= + +\======= To release a new version: ->>>>>>> template + +> > > > > > > template The protobuf description in this repository was generated by `protoc` at version `3.7.1`. ## Feature Breakdown + py-libp2p aims for conformity with [the standard libp2p modules](https://github.com/libp2p/libp2p/blob/master/REQUIREMENTS.md#libp2p-modules-implementations). Below is a breakdown of the modules we have developed, are developing, and may develop in the future. -> Legend: :green_apple: Done   :lemon: In Progress   :tomato: Missing   :chestnut: Not planned +> Legend: :green_apple: Done   :lemon: In Progress   :tomato: Missing   :chestnut: Not planned -| libp2p Node | Status | -| -------------------------------------------- | :-----------: | -| **`libp2p`** | :green_apple: | +| libp2p Node | Status | +| ------------ | :-----------: | +| **`libp2p`** | :green_apple: | +| Identify Protocol | Status | +| ----------------- | :-----: | +| **`Identify`** | :lemon: | -| Identify Protocol | Status | -| -------------------------------------------- | :-----------: | -| **`Identify`** | :lemon: | +| Transport Protocols | Status | +| ------------------- | :-----------: | +| **`TCP`** | :green_apple: | +| **`UDP`** | :tomato: | +| **`WebSockets`** | :chestnut: | +| **`UTP`** | :chestnut: | +| **`WebRTC`** | :chestnut: | +| **`SCTP`** | :chestnut: | +| **`Tor`** | :chestnut: | +| **`i2p`** | :chestnut: | +| **`cjdns`** | :chestnut: | +| **`Bluetooth LE`** | :chestnut: | +| **`Audio TP`** | :chestnut: | +| **`Zerotier`** | :chestnut: | +| **`QUIC`** | :chestnut: | +| Stream Muxers | Status | +| ---------------- | :-----------: | +| **`multiplex`** | :green_apple: | +| **`yamux`** | :tomato: | +| **`benchmarks`** | :chestnut: | +| **`muxado`** | :chestnut: | +| **`spdystream`** | :chestnut: | +| **`spdy`** | :chestnut: | +| **`http2`** | :chestnut: | +| **`QUIC`** | :chestnut: | -| Transport Protocols | Status | -| -------------------------------------------- | :-----------: | -| **`TCP`** | :green_apple: | -| **`UDP`** | :tomato: | -| **`WebSockets`** | :chestnut: | -| **`UTP`** | :chestnut: | -| **`WebRTC`** | :chestnut: | -| **`SCTP`** | :chestnut: | -| **`Tor`** | :chestnut: | -| **`i2p`** | :chestnut: | -| **`cjdns`** | :chestnut: | -| **`Bluetooth LE`** | :chestnut: | -| **`Audio TP`** | :chestnut: | -| **`Zerotier`** | :chestnut: | -| **`QUIC`** | :chestnut: | +| Protocol Muxers | Status | +| ----------------- | :-----------: | +| **`multiselect`** | :green_apple: | +| Switch (Swarm) | Status | +| ------------------ | :-----------: | +| **`Switch`** | :green_apple: | +| **`Dialer stack`** | :green_apple: | -| Stream Muxers | Status | -| -------------------------------------------- | :-----------: | -| **`multiplex`** | :green_apple: | -| **`yamux`** | :tomato: | -| **`benchmarks`** | :chestnut: | -| **`muxado`** | :chestnut: | -| **`spdystream`** | :chestnut: | -| **`spdy`** | :chestnut: | -| **`http2`** | :chestnut: | -| **`QUIC`** | :chestnut: | +| Peer Discovery | Status | +| -------------------- | :--------: | +| **`bootstrap list`** | :tomato: | +| **`Kademlia DHT`** | :chestnut: | +| **`mDNS`** | :chestnut: | +| **`PEX`** | :chestnut: | +| **`DNS`** | :chestnut: | +| Content Routing | Status | +| ------------------ | :-----------: | +| **`Kademlia DHT`** | :chestnut: | +| **`floodsub`** | :green_apple: | +| **`gossipsub`** | :green_apple: | +| **`PHT`** | :chestnut: | -| Protocol Muxers | Status | -| -------------------------------------------- | :-----------: | -| **`multiselect`** | :green_apple: | +| Peer Routing | Status | +| ------------------ | :-----------: | +| **`Kademlia DHT`** | :chestnut: | +| **`floodsub`** | :green_apple: | +| **`gossipsub`** | :green_apple: | +| **`PHT`** | :chestnut: | +| NAT Traversal | Status | +| ------------------------ | :--------: | +| **`nat-pmp`** | :chestnut: | +| **`upnp`** | :chestnut: | +| **`ext addr discovery`** | :chestnut: | +| **`STUN-like`** | :chestnut: | +| **`line-switch relay`** | :chestnut: | +| **`pkt-switch relay`** | :chestnut: | -| Switch (Swarm) | Status | -| -------------------------------------------- | :-----------: | -| **`Switch`** | :green_apple: | -| **`Dialer stack`** | :green_apple: | - - -| Peer Discovery | Status | -| -------------------------------------------- | :-----------: | -| **`bootstrap list`** | :tomato: | -| **`Kademlia DHT`** | :chestnut: | -| **`mDNS`** | :chestnut: | -| **`PEX`** | :chestnut: | -| **`DNS`** | :chestnut: | - - -| Content Routing | Status | -| -------------------------------------------- | :-----------: | -| **`Kademlia DHT`** | :chestnut: | -| **`floodsub`** | :green_apple: | -| **`gossipsub`** | :green_apple: | -| **`PHT`** | :chestnut: | - - -| Peer Routing | Status | -| -------------------------------------------- | :-----------: | -| **`Kademlia DHT`** | :chestnut: | -| **`floodsub`** | :green_apple: | -| **`gossipsub`** | :green_apple: | -| **`PHT`** | :chestnut: | - - -| NAT Traversal | Status | -| -------------------------------------------- | :-----------: | -| **`nat-pmp`** | :chestnut: | -| **`upnp`** | :chestnut: | -| **`ext addr discovery`** | :chestnut: | -| **`STUN-like`** | :chestnut: | -| **`line-switch relay`** | :chestnut: | -| **`pkt-switch relay`** | :chestnut: | - - -| Exchange | Status | -| -------------------------------------------- | :-----------: | -| **`HTTP`** | :chestnut: | -| **`Bitswap`** | :chestnut: | -| **`Bittorrent`** | :chestnut: | - - -| Consensus | Status | -| -------------------------------------------- | :-----------: | -| **`Paxos`** | :chestnut: | -| **`Raft`** | :chestnut: | -| **`PBTF`** | :chestnut: | -| **`Nakamoto`** | :chestnut: | +| Exchange | Status | +| ---------------- | :--------: | +| **`HTTP`** | :chestnut: | +| **`Bitswap`** | :chestnut: | +| **`Bittorrent`** | :chestnut: | +| Consensus | Status | +| -------------- | :--------: | +| **`Paxos`** | :chestnut: | +| **`Raft`** | :chestnut: | +| **`PBTF`** | :chestnut: | +| **`Nakamoto`** | :chestnut: | ## Explanation of Basic Two Node Communication @@ -199,12 +190,12 @@ _(non-normative, useful for team notes, not a reference)_ Several components of the libp2p stack take part when establishing a connection between two nodes: 1. **Host**: a node in the libp2p network. -2. **Connection**: the layer 3 connection between two nodes in a libp2p network. -3. **Transport**: the component that creates a _Connection_, e.g. TCP, UDP, QUIC, etc. -3. **Streams**: an abstraction on top of a _Connection_ representing parallel conversations about different matters, each of which is identified by a protocol ID. Multiple streams are layered on top of a _Connection_ via the _Multiplexer_. -4. **Multiplexer**: a component that is responsible for wrapping messages sent on a stream with an envelope that identifies the stream they pertain to, normally via an ID. The multiplexer on the other unwraps the message and routes it internally based on the stream identification. -5. **Secure channel**: optionally establishes a secure, encrypted, and authenticated channel over the _Connection_. -5. **Upgrader**: a component that takes a raw layer 3 connection returned by the _Transport_, and performs the security and multiplexing negotiation to set up a secure, multiplexed channel on top of which _Streams_ can be opened. +1. **Connection**: the layer 3 connection between two nodes in a libp2p network. +1. **Transport**: the component that creates a _Connection_, e.g. TCP, UDP, QUIC, etc. +1. **Streams**: an abstraction on top of a _Connection_ representing parallel conversations about different matters, each of which is identified by a protocol ID. Multiple streams are layered on top of a _Connection_ via the _Multiplexer_. +1. **Multiplexer**: a component that is responsible for wrapping messages sent on a stream with an envelope that identifies the stream they pertain to, normally via an ID. The multiplexer on the other unwraps the message and routes it internally based on the stream identification. +1. **Secure channel**: optionally establishes a secure, encrypted, and authenticated channel over the _Connection_. +1. **Upgrader**: a component that takes a raw layer 3 connection returned by the _Transport_, and performs the security and multiplexing negotiation to set up a secure, multiplexed channel on top of which _Streams_ can be opened. ### Communication between two hosts X and Y diff --git a/examples/chat/chat.py b/examples/chat/chat.py index 81f3891b..7c6b2fed 100755 --- a/examples/chat/chat.py +++ b/examples/chat/chat.py @@ -4,13 +4,21 @@ import sys import multiaddr import trio -from libp2p import new_host -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.peer.peerinfo import info_from_p2p_addr -from libp2p.typing import TProtocol +from libp2p import ( + new_host, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.peer.peerinfo import ( + info_from_p2p_addr, +) +from libp2p.typing import ( + TProtocol, +) PROTOCOL_ID = TProtocol("/chat/1.0.0") -MAX_READ_LEN = 2 ** 32 - 1 +MAX_READ_LEN = 2**32 - 1 async def read_data(stream: INetStream) -> None: @@ -58,7 +66,8 @@ async def run(port: int, destination: str) -> None: # Associate the peer with local ip address await host.connect(info) # Start a stream with the destination. - # Multiaddress of the destination peer is fetched from the peerstore using 'peerId'. + # Multiaddress of the destination peer is fetched from the peerstore + # using 'peerId'. stream = await host.new_stream(info.peer_id, [PROTOCOL_ID]) nursery.start_soon(read_data, stream) diff --git a/examples/echo/echo.py b/examples/echo/echo.py index 5ea8ab4a..c1fa2c98 100644 --- a/examples/echo/echo.py +++ b/examples/echo/echo.py @@ -3,11 +3,21 @@ import argparse import multiaddr import trio -from libp2p import new_host -from libp2p.crypto.secp256k1 import create_new_key_pair -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.peer.peerinfo import info_from_p2p_addr -from libp2p.typing import TProtocol +from libp2p import ( + new_host, +) +from libp2p.crypto.secp256k1 import ( + create_new_key_pair, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.peer.peerinfo import ( + info_from_p2p_addr, +) +from libp2p.typing import ( + TProtocol, +) PROTOCOL_ID = TProtocol("/echo/1.0.0") @@ -36,11 +46,9 @@ async def run(port: int, destination: str, seed: int = None) -> None: host = new_host(key_pair=create_new_key_pair(secret)) async with host.run(listen_addrs=[listen_addr]): - print(f"I am {host.get_id().to_string()}") if not destination: # its the server - host.set_stream_handler(PROTOCOL_ID, _echo_stream_handler) print( @@ -59,7 +67,8 @@ async def run(port: int, destination: str, seed: int = None) -> None: await host.connect(info) # Start a stream with the destination. - # Multiaddress of the destination peer is fetched from the peerstore using 'peerId'. + # Multiaddress of the destination peer is fetched from the peerstore + # using 'peerId'. stream = await host.new_stream(info.peer_id, [PROTOCOL_ID]) msg = b"hi, there!\n" @@ -99,7 +108,7 @@ def main() -> None: "-s", "--seed", type=int, - help="provide a seed to the random number generator (e.g. to fix peer IDs across runs)", + help="provide a seed to the random number generator (e.g. to fix peer IDs across runs)", # noqa: E501 ) args = parser.parse_args() diff --git a/libp2p/__init__.py b/libp2p/__init__.py index 4d91b9da..9afbf6a2 100644 --- a/libp2p/__init__.py +++ b/libp2p/__init__.py @@ -1,21 +1,58 @@ -from libp2p.crypto.keys import KeyPair -from libp2p.crypto.rsa import create_new_key_pair -from libp2p.host.basic_host import BasicHost -from libp2p.host.host_interface import IHost -from libp2p.host.routed_host import RoutedHost -from libp2p.network.network_interface import INetworkService -from libp2p.network.swarm import Swarm -from libp2p.peer.id import ID -from libp2p.peer.peerstore import PeerStore -from libp2p.peer.peerstore_interface import IPeerStore -from libp2p.routing.interfaces import IPeerRouting -from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID, InsecureTransport +from libp2p.crypto.keys import ( + KeyPair, +) +from libp2p.crypto.rsa import ( + create_new_key_pair, +) +from libp2p.host.basic_host import ( + BasicHost, +) +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.host.routed_host import ( + RoutedHost, +) +from libp2p.network.network_interface import ( + INetworkService, +) +from libp2p.network.swarm import ( + Swarm, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerstore import ( + PeerStore, +) +from libp2p.peer.peerstore_interface import ( + IPeerStore, +) +from libp2p.routing.interfaces import ( + IPeerRouting, +) +from libp2p.security.insecure.transport import ( + PLAINTEXT_PROTOCOL_ID, + InsecureTransport, +) import libp2p.security.secio.transport as secio -from libp2p.stream_muxer.mplex.mplex import MPLEX_PROTOCOL_ID, Mplex -from libp2p.transport.tcp.tcp import TCP -from libp2p.transport.typing import TMuxerOptions, TSecurityOptions -from libp2p.transport.upgrader import TransportUpgrader -from libp2p.typing import TProtocol +from libp2p.stream_muxer.mplex.mplex import ( + MPLEX_PROTOCOL_ID, + Mplex, +) +from libp2p.transport.tcp.tcp import ( + TCP, +) +from libp2p.transport.typing import ( + TMuxerOptions, + TSecurityOptions, +) +from libp2p.transport.upgrader import ( + TransportUpgrader, +) +from libp2p.typing import ( + TProtocol, +) def generate_new_rsa_identity() -> KeyPair: @@ -42,7 +79,6 @@ def new_swarm( :param peerstore_opt: optional peerstore :return: return a default swarm instance """ - if key_pair is None: key_pair = generate_new_rsa_identity() diff --git a/libp2p/crypto/authenticated_encryption.py b/libp2p/crypto/authenticated_encryption.py index d931f273..80cfb0ff 100644 --- a/libp2p/crypto/authenticated_encryption.py +++ b/libp2p/crypto/authenticated_encryption.py @@ -1,8 +1,14 @@ -from dataclasses import dataclass +from dataclasses import ( + dataclass, +) import hmac -from typing import Tuple +from typing import ( + Tuple, +) -from Crypto.Cipher import AES +from Crypto.Cipher import ( + AES, +) import Crypto.Util.Counter as Counter @@ -61,9 +67,11 @@ class MacAndCipher: def initialize_pair( cipher_type: str, hash_type: str, secret: bytes ) -> Tuple[EncryptionParameters, EncryptionParameters]: - """Return a pair of ``Keys`` for use in securing a communications channel + """ + Return a pair of ``Keys`` for use in securing a communications channel with authenticated encryption derived from the ``secret`` and using the - requested ``cipher_type`` and ``hash_type``.""" + requested ``cipher_type`` and ``hash_type``. + """ if cipher_type != "AES-128": raise NotImplementedError() if hash_type != "SHA256": @@ -72,7 +80,7 @@ def initialize_pair( iv_size = 16 cipher_key_size = 16 hmac_key_size = 20 - seed = "key expansion".encode() + seed = b"key expansion" params_size = iv_size + cipher_key_size + hmac_key_size result = bytearray(2 * params_size) diff --git a/libp2p/crypto/ecc.py b/libp2p/crypto/ecc.py index a9afe385..2afec9a4 100644 --- a/libp2p/crypto/ecc.py +++ b/libp2p/crypto/ecc.py @@ -1,13 +1,25 @@ +from fastecdsa import ( + keys, + point, +) from fastecdsa import curve as curve_types -from fastecdsa import keys, point -from fastecdsa.encoding.sec1 import SEC1Encoder +from fastecdsa.encoding.sec1 import ( + SEC1Encoder, +) -from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + KeyType, + PrivateKey, + PublicKey, +) def infer_local_type(curve: str) -> curve_types.Curve: - """converts a ``str`` representation of some elliptic curve to a - representation understood by the backend of this module.""" + """ + Convert a ``str`` representation of some elliptic curve to a + representation understood by the backend of this module. + """ if curve == "P-256": return curve_types.P256 else: @@ -61,8 +73,10 @@ class ECCPrivateKey(PrivateKey): def create_new_key_pair(curve: str) -> KeyPair: - """Return a new ECC keypair with the requested ``curve`` type, e.g. - "P-256".""" + """ + Return a new ECC keypair with the requested ``curve`` type, e.g. + "P-256". + """ private_key = ECCPrivateKey.new(curve) public_key = private_key.get_public_key() return KeyPair(private_key, public_key) diff --git a/libp2p/crypto/ed25519.py b/libp2p/crypto/ed25519.py index 00c76588..0b6636b0 100644 --- a/libp2p/crypto/ed25519.py +++ b/libp2p/crypto/ed25519.py @@ -1,11 +1,23 @@ -from Crypto.Hash import SHA256 -from nacl.exceptions import BadSignatureError +from Crypto.Hash import ( + SHA256, +) +from nacl.exceptions import ( + BadSignatureError, +) from nacl.public import PrivateKey as PrivateKeyImpl from nacl.public import PublicKey as PublicKeyImpl -from nacl.signing import SigningKey, VerifyKey +from nacl.signing import ( + SigningKey, + VerifyKey, +) import nacl.utils as utils -from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + KeyType, + PrivateKey, + PublicKey, +) class Ed25519PublicKey(PublicKey): diff --git a/libp2p/crypto/exceptions.py b/libp2p/crypto/exceptions.py index fdb049c2..1aee8eaa 100644 --- a/libp2p/crypto/exceptions.py +++ b/libp2p/crypto/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class CryptographyError(BaseLibp2pError): @@ -6,7 +8,7 @@ class CryptographyError(BaseLibp2pError): class MissingDeserializerError(CryptographyError): - """Raise if the requested deserialization routine is missing for some type - of cryptographic key.""" - - pass + """ + Raise if the requested deserialization routine is missing for some type + of cryptographic key. + """ diff --git a/libp2p/crypto/key_exchange.py b/libp2p/crypto/key_exchange.py index 2af4030d..706de638 100644 --- a/libp2p/crypto/key_exchange.py +++ b/libp2p/crypto/key_exchange.py @@ -1,9 +1,21 @@ -from typing import Callable, Tuple, cast +from typing import ( + Callable, + Tuple, + cast, +) -from fastecdsa.encoding import util +from fastecdsa.encoding import ( + util, +) -from libp2p.crypto.ecc import ECCPrivateKey, ECCPublicKey, create_new_key_pair -from libp2p.crypto.keys import PublicKey +from libp2p.crypto.ecc import ( + ECCPrivateKey, + ECCPublicKey, + create_new_key_pair, +) +from libp2p.crypto.keys import ( + PublicKey, +) SharedKeyGenerator = Callable[[bytes], bytes] diff --git a/libp2p/crypto/keys.py b/libp2p/crypto/keys.py index dff8780a..f5af513b 100644 --- a/libp2p/crypto/keys.py +++ b/libp2p/crypto/keys.py @@ -1,6 +1,14 @@ -from abc import ABC, abstractmethod -from dataclasses import dataclass -from enum import Enum, unique +from abc import ( + ABC, + abstractmethod, +) +from dataclasses import ( + dataclass, +) +from enum import ( + Enum, + unique, +) from .pb import crypto_pb2 as protobuf @@ -38,8 +46,10 @@ class PublicKey(Key): @abstractmethod def verify(self, data: bytes, signature: bytes) -> bool: - """Verify that ``signature`` is the cryptographic signature of the hash - of ``data``.""" + """ + Verify that ``signature`` is the cryptographic signature of the hash + of ``data``. + """ ... def _serialize_to_protobuf(self) -> protobuf.PublicKey: diff --git a/libp2p/crypto/pb/crypto.proto b/libp2p/crypto/pb/crypto.proto index a12f7b6a..fe729a9d 100644 --- a/libp2p/crypto/pb/crypto.proto +++ b/libp2p/crypto/pb/crypto.proto @@ -17,4 +17,4 @@ message PublicKey { message PrivateKey { required KeyType key_type = 1; required bytes data = 2; -} \ No newline at end of file +} diff --git a/libp2p/crypto/pb/crypto_pb2.py b/libp2p/crypto/pb/crypto_pb2.py index 93282111..fda8fa41 100644 --- a/libp2p/crypto/pb/crypto_pb2.py +++ b/libp2p/crypto/pb/crypto_pb2.py @@ -1,56 +1,53 @@ -# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/crypto/pb/crypto.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf.internal import enum_type_wrapper from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/crypto/pb/crypto.proto', - package='crypto.pb', - syntax='proto2', - serialized_options=None, - serialized_pb=_b('\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb\"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c\"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03') + name="libp2p/crypto/pb/crypto.proto", + package="crypto.pb", + syntax="proto2", + serialized_options=None, + serialized_pb=_b( + '\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03' + ), ) _KEYTYPE = _descriptor.EnumDescriptor( - name='KeyType', - full_name='crypto.pb.KeyType', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='RSA', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='Ed25519', index=1, number=1, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='Secp256k1', index=2, number=2, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='ECDSA', index=3, number=3, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=175, - serialized_end=232, + name="KeyType", + full_name="crypto.pb.KeyType", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="RSA", index=0, number=0, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="Ed25519", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="Secp256k1", index=2, number=2, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="ECDSA", index=3, number=3, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=175, + serialized_end=232, ) _sym_db.RegisterEnumDescriptor(_KEYTYPE) @@ -61,101 +58,146 @@ Secp256k1 = 2 ECDSA = 3 - _PUBLICKEY = _descriptor.Descriptor( - name='PublicKey', - full_name='crypto.pb.PublicKey', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key_type', full_name='crypto.pb.PublicKey.key_type', index=0, - number=1, type=14, cpp_type=8, label=2, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='data', full_name='crypto.pb.PublicKey.data', index=1, - number=2, type=12, cpp_type=9, label=2, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=44, - serialized_end=107, + name="PublicKey", + full_name="crypto.pb.PublicKey", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="key_type", + full_name="crypto.pb.PublicKey.key_type", + index=0, + number=1, + type=14, + cpp_type=8, + label=2, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data", + full_name="crypto.pb.PublicKey.data", + index=1, + number=2, + type=12, + cpp_type=9, + label=2, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=44, + serialized_end=107, ) _PRIVATEKEY = _descriptor.Descriptor( - name='PrivateKey', - full_name='crypto.pb.PrivateKey', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='key_type', full_name='crypto.pb.PrivateKey.key_type', index=0, - number=1, type=14, cpp_type=8, label=2, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='data', full_name='crypto.pb.PrivateKey.data', index=1, - number=2, type=12, cpp_type=9, label=2, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=109, - serialized_end=173, + name="PrivateKey", + full_name="crypto.pb.PrivateKey", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="key_type", + full_name="crypto.pb.PrivateKey.key_type", + index=0, + number=1, + type=14, + cpp_type=8, + label=2, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data", + full_name="crypto.pb.PrivateKey.data", + index=1, + number=2, + type=12, + cpp_type=9, + label=2, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=109, + serialized_end=173, ) -_PUBLICKEY.fields_by_name['key_type'].enum_type = _KEYTYPE -_PRIVATEKEY.fields_by_name['key_type'].enum_type = _KEYTYPE -DESCRIPTOR.message_types_by_name['PublicKey'] = _PUBLICKEY -DESCRIPTOR.message_types_by_name['PrivateKey'] = _PRIVATEKEY -DESCRIPTOR.enum_types_by_name['KeyType'] = _KEYTYPE +_PUBLICKEY.fields_by_name["key_type"].enum_type = _KEYTYPE +_PRIVATEKEY.fields_by_name["key_type"].enum_type = _KEYTYPE +DESCRIPTOR.message_types_by_name["PublicKey"] = _PUBLICKEY +DESCRIPTOR.message_types_by_name["PrivateKey"] = _PRIVATEKEY +DESCRIPTOR.enum_types_by_name["KeyType"] = _KEYTYPE _sym_db.RegisterFileDescriptor(DESCRIPTOR) -PublicKey = _reflection.GeneratedProtocolMessageType('PublicKey', (_message.Message,), { - 'DESCRIPTOR' : _PUBLICKEY, - '__module__' : 'libp2p.crypto.pb.crypto_pb2' - # @@protoc_insertion_point(class_scope:crypto.pb.PublicKey) - }) +PublicKey = _reflection.GeneratedProtocolMessageType( + "PublicKey", + (_message.Message,), + { + "DESCRIPTOR": _PUBLICKEY, + "__module__": "libp2p.crypto.pb.crypto_pb2" + # @@protoc_insertion_point(class_scope:crypto.pb.PublicKey) + }, +) _sym_db.RegisterMessage(PublicKey) -PrivateKey = _reflection.GeneratedProtocolMessageType('PrivateKey', (_message.Message,), { - 'DESCRIPTOR' : _PRIVATEKEY, - '__module__' : 'libp2p.crypto.pb.crypto_pb2' - # @@protoc_insertion_point(class_scope:crypto.pb.PrivateKey) - }) +PrivateKey = _reflection.GeneratedProtocolMessageType( + "PrivateKey", + (_message.Message,), + { + "DESCRIPTOR": _PRIVATEKEY, + "__module__": "libp2p.crypto.pb.crypto_pb2" + # @@protoc_insertion_point(class_scope:crypto.pb.PrivateKey) + }, +) _sym_db.RegisterMessage(PrivateKey) diff --git a/libp2p/crypto/pb/crypto_pb2.pyi b/libp2p/crypto/pb/crypto_pb2.pyi index 2b3cb1b6..08656f0a 100644 --- a/libp2p/crypto/pb/crypto_pb2.pyi +++ b/libp2p/crypto/pb/crypto_pb2.pyi @@ -19,7 +19,6 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class KeyType(int): DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... @classmethod @@ -36,6 +35,7 @@ class KeyType(int): Ed25519 = typing___cast(KeyType, 1) Secp256k1 = typing___cast(KeyType, 2) ECDSA = typing___cast(KeyType, 3) + RSA = typing___cast(KeyType, 0) Ed25519 = typing___cast(KeyType, 1) Secp256k1 = typing___cast(KeyType, 2) @@ -43,42 +43,72 @@ ECDSA = typing___cast(KeyType, 3) class PublicKey(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - key_type = ... # type: KeyType - data = ... # type: bytes + key_type = ... # type: KeyType + data = ... # type: bytes - def __init__(self, + def __init__( + self, *, - key_type : KeyType, - data : bytes, - ) -> None: ... + key_type: KeyType, + data: bytes, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> PublicKey: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["data", "key_type"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["data", "key_type"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "data", b"data", "key_type", b"key_type" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", b"data", "key_type", b"key_type" + ], + ) -> None: ... class PrivateKey(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - key_type = ... # type: KeyType - data = ... # type: bytes + key_type = ... # type: KeyType + data = ... # type: bytes - def __init__(self, + def __init__( + self, *, - key_type : KeyType, - data : bytes, - ) -> None: ... + key_type: KeyType, + data: bytes, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> PrivateKey: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["data", "key_type"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["data", "key_type"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "data", b"data", "key_type", b"key_type" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", b"data", "key_type", b"key_type" + ], + ) -> None: ... diff --git a/libp2p/crypto/rsa.py b/libp2p/crypto/rsa.py index b059a187..5f14ce95 100644 --- a/libp2p/crypto/rsa.py +++ b/libp2p/crypto/rsa.py @@ -1,9 +1,20 @@ -from Crypto.Hash import SHA256 +from Crypto.Hash import ( + SHA256, +) import Crypto.PublicKey.RSA as RSA -from Crypto.PublicKey.RSA import RsaKey -from Crypto.Signature import pkcs1_15 +from Crypto.PublicKey.RSA import ( + RsaKey, +) +from Crypto.Signature import ( + pkcs1_15, +) -from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + KeyType, + PrivateKey, + PublicKey, +) class RSAPublicKey(PublicKey): diff --git a/libp2p/crypto/secp256k1.py b/libp2p/crypto/secp256k1.py index aabb153a..6ed97190 100644 --- a/libp2p/crypto/secp256k1.py +++ b/libp2p/crypto/secp256k1.py @@ -1,6 +1,11 @@ import coincurve -from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + KeyType, + PrivateKey, + PublicKey, +) class Secp256k1PublicKey(PublicKey): diff --git a/libp2p/crypto/serialization.py b/libp2p/crypto/serialization.py index fe4ffeb1..174130cc 100644 --- a/libp2p/crypto/serialization.py +++ b/libp2p/crypto/serialization.py @@ -1,8 +1,22 @@ -from libp2p.crypto.ed25519 import Ed25519PrivateKey, Ed25519PublicKey -from libp2p.crypto.exceptions import MissingDeserializerError -from libp2p.crypto.keys import KeyType, PrivateKey, PublicKey -from libp2p.crypto.rsa import RSAPublicKey -from libp2p.crypto.secp256k1 import Secp256k1PrivateKey, Secp256k1PublicKey +from libp2p.crypto.ed25519 import ( + Ed25519PrivateKey, + Ed25519PublicKey, +) +from libp2p.crypto.exceptions import ( + MissingDeserializerError, +) +from libp2p.crypto.keys import ( + KeyType, + PrivateKey, + PublicKey, +) +from libp2p.crypto.rsa import ( + RSAPublicKey, +) +from libp2p.crypto.secp256k1 import ( + Secp256k1PrivateKey, + Secp256k1PublicKey, +) key_type_to_public_key_deserializer = { KeyType.Secp256k1.value: Secp256k1PublicKey.from_bytes, diff --git a/libp2p/host/basic_host.py b/libp2p/host/basic_host.py index cc5ff8c6..76ffff12 100644 --- a/libp2p/host/basic_host.py +++ b/libp2p/host/basic_host.py @@ -1,28 +1,70 @@ import logging -from typing import TYPE_CHECKING, AsyncIterator, List, Sequence +from typing import ( + TYPE_CHECKING, + AsyncIterator, + List, + Sequence, +) -from async_generator import asynccontextmanager -from async_service import background_trio_service +from async_generator import ( + asynccontextmanager, +) +from async_service import ( + background_trio_service, +) import multiaddr -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.host.defaults import get_default_protocols -from libp2p.host.exceptions import StreamFailure -from libp2p.network.network_interface import INetworkService -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo -from libp2p.peer.peerstore_interface import IPeerStore -from libp2p.protocol_muxer.exceptions import MultiselectClientError, MultiselectError -from libp2p.protocol_muxer.multiselect import Multiselect -from libp2p.protocol_muxer.multiselect_client import MultiselectClient -from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator -from libp2p.typing import StreamHandlerFn, TProtocol +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.host.defaults import ( + get_default_protocols, +) +from libp2p.host.exceptions import ( + StreamFailure, +) +from libp2p.network.network_interface import ( + INetworkService, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) +from libp2p.peer.peerstore_interface import ( + IPeerStore, +) +from libp2p.protocol_muxer.exceptions import ( + MultiselectClientError, + MultiselectError, +) +from libp2p.protocol_muxer.multiselect import ( + Multiselect, +) +from libp2p.protocol_muxer.multiselect_client import ( + MultiselectClient, +) +from libp2p.protocol_muxer.multiselect_communicator import ( + MultiselectCommunicator, +) +from libp2p.typing import ( + StreamHandlerFn, + TProtocol, +) -from .host_interface import IHost +from .host_interface import ( + IHost, +) if TYPE_CHECKING: - from collections import OrderedDict + from collections import ( + OrderedDict, + ) # Upon host creation, host takes in options, # including the list of addresses on which to listen. @@ -108,7 +150,7 @@ class BasicHost(IHost): self, listen_addrs: Sequence[multiaddr.Multiaddr] ) -> AsyncIterator[None]: """ - run the host instance and listen to ``listen_addrs``. + Run the host instance and listen to ``listen_addrs``. :param listen_addrs: a sequence of multiaddrs that we want to listen to """ @@ -121,7 +163,7 @@ class BasicHost(IHost): self, protocol_id: TProtocol, stream_handler: StreamHandlerFn ) -> None: """ - set stream handler for given `protocol_id` + Set stream handler for given `protocol_id` :param protocol_id: protocol id used on stream :param stream_handler: a stream handler function @@ -136,7 +178,6 @@ class BasicHost(IHost): :param protocol_ids: available protocol ids to use for stream :return: stream: new stream created """ - net_stream = await self._network.new_stream(peer_id) # Perform protocol muxing to determine protocol to use @@ -154,7 +195,7 @@ class BasicHost(IHost): async def connect(self, peer_info: PeerInfo) -> None: """ - connect ensures there is a connection between this host and the peer + Ensure there is a connection between this host and the peer with given `peer_info.peer_id`. connect will absorb the addresses in peer_info into its internal peerstore. If there is not an active connection, connect will issue a dial, and block until a connection is diff --git a/libp2p/host/defaults.py b/libp2p/host/defaults.py index a5d63bae..cfc95e76 100644 --- a/libp2p/host/defaults.py +++ b/libp2p/host/defaults.py @@ -1,14 +1,27 @@ -from collections import OrderedDict -from typing import TYPE_CHECKING +from collections import ( + OrderedDict, +) +from typing import ( + TYPE_CHECKING, +) -from libp2p.host.host_interface import IHost +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.host.ping import ( + handle_ping, +) from libp2p.host.ping import ID as PingID -from libp2p.host.ping import handle_ping +from libp2p.identity.identify.protocol import ( + identify_handler_for, +) from libp2p.identity.identify.protocol import ID as IdentifyID -from libp2p.identity.identify.protocol import identify_handler_for if TYPE_CHECKING: - from libp2p.typing import TProtocol, StreamHandlerFn + from libp2p.typing import ( + StreamHandlerFn, + TProtocol, + ) def get_default_protocols(host: IHost) -> "OrderedDict[TProtocol, StreamHandlerFn]": diff --git a/libp2p/host/exceptions.py b/libp2p/host/exceptions.py index 521f87e3..8d8d8f57 100644 --- a/libp2p/host/exceptions.py +++ b/libp2p/host/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class HostException(BaseLibp2pError): diff --git a/libp2p/host/host_interface.py b/libp2p/host/host_interface.py index 59146e7f..f71792b5 100644 --- a/libp2p/host/host_interface.py +++ b/libp2p/host/host_interface.py @@ -1,14 +1,36 @@ -from abc import ABC, abstractmethod -from typing import Any, AsyncContextManager, List, Sequence +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Any, + AsyncContextManager, + List, + Sequence, +) import multiaddr -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.network.network_interface import INetworkService -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo -from libp2p.typing import StreamHandlerFn, TProtocol +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.network.network_interface import ( + INetworkService, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) +from libp2p.typing import ( + StreamHandlerFn, + TProtocol, +) class IHost(ABC): @@ -54,7 +76,7 @@ class IHost(ABC): self, listen_addrs: Sequence[multiaddr.Multiaddr] ) -> AsyncContextManager[None]: """ - run the host instance and listen to ``listen_addrs``. + Run the host instance and listen to ``listen_addrs``. :param listen_addrs: a sequence of multiaddrs that we want to listen to """ @@ -64,7 +86,7 @@ class IHost(ABC): self, protocol_id: TProtocol, stream_handler: StreamHandlerFn ) -> None: """ - set stream handler for host. + Set stream handler for host. :param protocol_id: protocol id used on stream :param stream_handler: a stream handler function @@ -85,7 +107,7 @@ class IHost(ABC): @abstractmethod async def connect(self, peer_info: PeerInfo) -> None: """ - connect ensures there is a connection between this host and the peer + Ensure there is a connection between this host and the peer with given peer_info.peer_id. connect will absorb the addresses in peer_info into its internal peerstore. If there is not an active connection, connect will issue a dial, and block until a connection is diff --git a/libp2p/host/ping.py b/libp2p/host/ping.py index 01102451..905942cf 100644 --- a/libp2p/host/ping.py +++ b/libp2p/host/ping.py @@ -2,10 +2,18 @@ import logging import trio -from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset -from libp2p.network.stream.net_stream_interface import INetStream +from libp2p.network.stream.exceptions import ( + StreamClosed, + StreamEOF, + StreamReset, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) from libp2p.peer.id import ID as PeerID -from libp2p.typing import TProtocol +from libp2p.typing import ( + TProtocol, +) ID = TProtocol("/ipfs/ping/1.0.0") PING_LENGTH = 32 @@ -15,8 +23,9 @@ logger = logging.getLogger("libp2p.host.ping") async def _handle_ping(stream: INetStream, peer_id: PeerID) -> bool: - """Return a boolean indicating if we expect more pings from the peer at - ``peer_id``.""" + """ + Return a boolean indicating if we expect more pings from the peer at ``peer_id``. + """ try: with trio.fail_after(RESP_TIMEOUT): payload = await stream.read(PING_LENGTH) @@ -46,8 +55,10 @@ async def _handle_ping(stream: INetStream, peer_id: PeerID) -> bool: async def handle_ping(stream: INetStream) -> None: - """``handle_ping`` responds to incoming ping requests until one side errors - or closes the ``stream``.""" + """ + Respond to incoming ping requests until one side errors + or closes the ``stream``. + """ peer_id = stream.muxed_conn.peer_id while True: diff --git a/libp2p/host/routed_host.py b/libp2p/host/routed_host.py index 91264c71..3a4b1a28 100644 --- a/libp2p/host/routed_host.py +++ b/libp2p/host/routed_host.py @@ -1,8 +1,18 @@ -from libp2p.host.basic_host import BasicHost -from libp2p.host.exceptions import ConnectionFailure -from libp2p.network.network_interface import INetworkService -from libp2p.peer.peerinfo import PeerInfo -from libp2p.routing.interfaces import IPeerRouting +from libp2p.host.basic_host import ( + BasicHost, +) +from libp2p.host.exceptions import ( + ConnectionFailure, +) +from libp2p.network.network_interface import ( + INetworkService, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) +from libp2p.routing.interfaces import ( + IPeerRouting, +) # RoutedHost is a p2p Host that includes a routing system. @@ -16,7 +26,7 @@ class RoutedHost(BasicHost): async def connect(self, peer_info: PeerInfo) -> None: """ - connect ensures there is a connection between this host and the peer + Ensure there is a connection between this host and the peer with given `peer_info.peer_id`. See (basic_host).connect for more information. @@ -26,7 +36,8 @@ class RoutedHost(BasicHost): :param peer_info: peer_info of the peer we want to connect to :type peer_info: peer.peerinfo.PeerInfo """ - # check if we were given some addresses, otherwise, find some with the routing system. + # check if we were given some addresses, otherwise, find some with the + # routing system. if not peer_info.addrs: found_peer_info = await self._router.find_peer(peer_info.peer_id) if not found_peer_info: diff --git a/libp2p/identity/identify/pb/identify.proto b/libp2p/identity/identify/pb/identify.proto index c9390bb1..cc4392a0 100644 --- a/libp2p/identity/identify/pb/identify.proto +++ b/libp2p/identity/identify/pb/identify.proto @@ -9,4 +9,4 @@ message Identify { repeated bytes listen_addrs = 2; optional bytes observed_addr = 4; repeated string protocols = 3; -} \ No newline at end of file +} diff --git a/libp2p/identity/identify/pb/identify_pb2.py b/libp2p/identity/identify/pb/identify_pb2.py index a843465a..87ff9ccf 100644 --- a/libp2p/identity/identify/pb/identify_pb2.py +++ b/libp2p/identity/identify/pb/identify_pb2.py @@ -1,104 +1,170 @@ -# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/identity/identify/pb/identify.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/identity/identify/pb/identify.proto', - package='identify.pb', - syntax='proto2', - serialized_options=None, - serialized_pb=_b('\n*libp2p/identity/identify/pb/identify.proto\x12\x0bidentify.pb\"\x8f\x01\n\x08Identify\x12\x18\n\x10protocol_version\x18\x05 \x01(\t\x12\x15\n\ragent_version\x18\x06 \x01(\t\x12\x12\n\npublic_key\x18\x01 \x01(\x0c\x12\x14\n\x0clisten_addrs\x18\x02 \x03(\x0c\x12\x15\n\robserved_addr\x18\x04 \x01(\x0c\x12\x11\n\tprotocols\x18\x03 \x03(\t') + name="libp2p/identity/identify/pb/identify.proto", + package="identify.pb", + syntax="proto2", + serialized_options=None, + serialized_pb=_b( + '\n*libp2p/identity/identify/pb/identify.proto\x12\x0bidentify.pb"\x8f\x01\n\x08Identify\x12\x18\n\x10protocol_version\x18\x05 \x01(\t\x12\x15\n\ragent_version\x18\x06 \x01(\t\x12\x12\n\npublic_key\x18\x01 \x01(\x0c\x12\x14\n\x0clisten_addrs\x18\x02 \x03(\x0c\x12\x15\n\robserved_addr\x18\x04 \x01(\x0c\x12\x11\n\tprotocols\x18\x03 \x03(\t' + ), ) - - _IDENTIFY = _descriptor.Descriptor( - name='Identify', - full_name='identify.pb.Identify', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='protocol_version', full_name='identify.pb.Identify.protocol_version', index=0, - number=5, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='agent_version', full_name='identify.pb.Identify.agent_version', index=1, - number=6, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='public_key', full_name='identify.pb.Identify.public_key', index=2, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='listen_addrs', full_name='identify.pb.Identify.listen_addrs', index=3, - number=2, type=12, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='observed_addr', full_name='identify.pb.Identify.observed_addr', index=4, - number=4, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='protocols', full_name='identify.pb.Identify.protocols', index=5, - number=3, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=60, - serialized_end=203, + name="Identify", + full_name="identify.pb.Identify", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="protocol_version", + full_name="identify.pb.Identify.protocol_version", + index=0, + number=5, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="agent_version", + full_name="identify.pb.Identify.agent_version", + index=1, + number=6, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="public_key", + full_name="identify.pb.Identify.public_key", + index=2, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="listen_addrs", + full_name="identify.pb.Identify.listen_addrs", + index=3, + number=2, + type=12, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="observed_addr", + full_name="identify.pb.Identify.observed_addr", + index=4, + number=4, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="protocols", + full_name="identify.pb.Identify.protocols", + index=5, + number=3, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=60, + serialized_end=203, ) -DESCRIPTOR.message_types_by_name['Identify'] = _IDENTIFY +DESCRIPTOR.message_types_by_name["Identify"] = _IDENTIFY _sym_db.RegisterFileDescriptor(DESCRIPTOR) -Identify = _reflection.GeneratedProtocolMessageType('Identify', (_message.Message,), { - 'DESCRIPTOR' : _IDENTIFY, - '__module__' : 'libp2p.identity.identify.pb.identify_pb2' - # @@protoc_insertion_point(class_scope:identify.pb.Identify) - }) +Identify = _reflection.GeneratedProtocolMessageType( + "Identify", + (_message.Message,), + { + "DESCRIPTOR": _IDENTIFY, + "__module__": "libp2p.identity.identify.pb.identify_pb2" + # @@protoc_insertion_point(class_scope:identify.pb.Identify) + }, +) _sym_db.RegisterMessage(Identify) diff --git a/libp2p/identity/identify/pb/identify_pb2.pyi b/libp2p/identity/identify/pb/identify_pb2.pyi index 9ad73501..d548a3a7 100644 --- a/libp2p/identity/identify/pb/identify_pb2.pyi +++ b/libp2p/identity/identify/pb/identify_pb2.pyi @@ -22,32 +22,79 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class Identify(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - protocol_version = ... # type: typing___Text - agent_version = ... # type: typing___Text - public_key = ... # type: bytes - listen_addrs = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] - observed_addr = ... # type: bytes - protocols = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] + protocol_version = ... # type: typing___Text + agent_version = ... # type: typing___Text + public_key = ... # type: bytes + listen_addrs = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] + observed_addr = ... # type: bytes + protocols = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] - def __init__(self, + def __init__( + self, *, - protocol_version : typing___Optional[typing___Text] = None, - agent_version : typing___Optional[typing___Text] = None, - public_key : typing___Optional[bytes] = None, - listen_addrs : typing___Optional[typing___Iterable[bytes]] = None, - observed_addr : typing___Optional[bytes] = None, - protocols : typing___Optional[typing___Iterable[typing___Text]] = None, - ) -> None: ... + protocol_version: typing___Optional[typing___Text] = None, + agent_version: typing___Optional[typing___Text] = None, + public_key: typing___Optional[bytes] = None, + listen_addrs: typing___Optional[typing___Iterable[bytes]] = None, + observed_addr: typing___Optional[bytes] = None, + protocols: typing___Optional[typing___Iterable[typing___Text]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> Identify: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"agent_version",u"observed_addr",u"protocol_version",u"public_key"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"agent_version",u"listen_addrs",u"observed_addr",u"protocol_version",u"protocols",u"public_key"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "agent_version", "observed_addr", "protocol_version", "public_key" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "agent_version", + "listen_addrs", + "observed_addr", + "protocol_version", + "protocols", + "public_key", + ], + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"agent_version",b"agent_version",u"observed_addr",b"observed_addr",u"protocol_version",b"protocol_version",u"public_key",b"public_key"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"agent_version",b"agent_version",u"listen_addrs",b"listen_addrs",u"observed_addr",b"observed_addr",u"protocol_version",b"protocol_version",u"protocols",b"protocols",u"public_key",b"public_key"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "agent_version", + b"agent_version", + "observed_addr", + b"observed_addr", + "protocol_version", + b"protocol_version", + "public_key", + b"public_key", + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "agent_version", + b"agent_version", + "listen_addrs", + b"listen_addrs", + "observed_addr", + b"observed_addr", + "protocol_version", + b"protocol_version", + "protocols", + b"protocols", + "public_key", + b"public_key", + ], + ) -> None: ... diff --git a/libp2p/identity/identify/protocol.py b/libp2p/identity/identify/protocol.py index 092deb4a..db203e7e 100644 --- a/libp2p/identity/identify/protocol.py +++ b/libp2p/identity/identify/protocol.py @@ -1,13 +1,26 @@ import logging -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.host.host_interface import IHost -from libp2p.network.stream.exceptions import StreamClosed -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.typing import StreamHandlerFn, TProtocol +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.network.stream.exceptions import ( + StreamClosed, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.typing import ( + StreamHandlerFn, + TProtocol, +) -from .pb.identify_pb2 import Identify +from .pb.identify_pb2 import ( + Identify, +) ID = TProtocol("/ipfs/id/1.0.0") PROTOCOL_VERSION = "ipfs/0.1.0" diff --git a/libp2p/io/abc.py b/libp2p/io/abc.py index b7be31f2..d87da7af 100644 --- a/libp2p/io/abc.py +++ b/libp2p/io/abc.py @@ -1,4 +1,7 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) class Closer(ABC): diff --git a/libp2p/io/exceptions.py b/libp2p/io/exceptions.py index 2c237c93..1ba3da22 100644 --- a/libp2p/io/exceptions.py +++ b/libp2p/io/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class IOException(BaseLibp2pError): diff --git a/libp2p/io/msgio.py b/libp2p/io/msgio.py index 457f0553..9556de6a 100644 --- a/libp2p/io/msgio.py +++ b/libp2p/io/msgio.py @@ -5,13 +5,26 @@ from that repo: "a simple package to r/w length-delimited slices." NOTE: currently missing the capability to indicate lengths by "varint" method. """ -from abc import abstractmethod +from abc import ( + abstractmethod, +) -from libp2p.io.abc import MsgReadWriteCloser, Reader, ReadWriteCloser -from libp2p.io.utils import read_exactly -from libp2p.utils import decode_uvarint_from_stream, encode_varint_prefixed +from libp2p.io.abc import ( + MsgReadWriteCloser, + Reader, + ReadWriteCloser, +) +from libp2p.io.utils import ( + read_exactly, +) +from libp2p.utils import ( + decode_uvarint_from_stream, + encode_varint_prefixed, +) -from .exceptions import MessageTooLarge +from .exceptions import ( + MessageTooLarge, +) BYTE_ORDER = "big" diff --git a/libp2p/io/trio.py b/libp2p/io/trio.py index 465e4eaa..3998dbef 100644 --- a/libp2p/io/trio.py +++ b/libp2p/io/trio.py @@ -2,8 +2,12 @@ import logging import trio -from libp2p.io.abc import ReadWriteCloser -from libp2p.io.exceptions import IOException +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.io.exceptions import ( + IOException, +) logger = logging.getLogger("libp2p.io.trio") diff --git a/libp2p/io/utils.py b/libp2p/io/utils.py index 1a6e0a36..8f873ea0 100644 --- a/libp2p/io/utils.py +++ b/libp2p/io/utils.py @@ -1,5 +1,9 @@ -from libp2p.io.abc import Reader -from libp2p.io.exceptions import IncompleteReadError +from libp2p.io.abc import ( + Reader, +) +from libp2p.io.exceptions import ( + IncompleteReadError, +) DEFAULT_RETRY_READ_COUNT = 100 diff --git a/libp2p/network/connection/exceptions.py b/libp2p/network/connection/exceptions.py index ecbf3fa1..946fbdfa 100644 --- a/libp2p/network/connection/exceptions.py +++ b/libp2p/network/connection/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.io.exceptions import IOException +from libp2p.io.exceptions import ( + IOException, +) class RawConnError(IOException): diff --git a/libp2p/network/connection/net_connection_interface.py b/libp2p/network/connection/net_connection_interface.py index f1bcac24..e9de8da5 100644 --- a/libp2p/network/connection/net_connection_interface.py +++ b/libp2p/network/connection/net_connection_interface.py @@ -1,11 +1,21 @@ -from abc import abstractmethod -from typing import Tuple +from abc import ( + abstractmethod, +) +from typing import ( + Tuple, +) import trio -from libp2p.io.abc import Closer -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.stream_muxer.abc import IMuxedConn +from libp2p.io.abc import ( + Closer, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, +) class INetConn(Closer): diff --git a/libp2p/network/connection/raw_connection.py b/libp2p/network/connection/raw_connection.py index 2d8409f7..98961296 100644 --- a/libp2p/network/connection/raw_connection.py +++ b/libp2p/network/connection/raw_connection.py @@ -1,8 +1,16 @@ -from libp2p.io.abc import ReadWriteCloser -from libp2p.io.exceptions import IOException +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.io.exceptions import ( + IOException, +) -from .exceptions import RawConnError -from .raw_connection_interface import IRawConnection +from .exceptions import ( + RawConnError, +) +from .raw_connection_interface import ( + IRawConnection, +) class RawConnection(IRawConnection): diff --git a/libp2p/network/connection/raw_connection_interface.py b/libp2p/network/connection/raw_connection_interface.py index d08e4676..6f2bab2b 100644 --- a/libp2p/network/connection/raw_connection_interface.py +++ b/libp2p/network/connection/raw_connection_interface.py @@ -1,4 +1,6 @@ -from libp2p.io.abc import ReadWriteCloser +from libp2p.io.abc import ( + ReadWriteCloser, +) class IRawConnection(ReadWriteCloser): diff --git a/libp2p/network/connection/swarm_connection.py b/libp2p/network/connection/swarm_connection.py index baa9df50..9dbc1052 100644 --- a/libp2p/network/connection/swarm_connection.py +++ b/libp2p/network/connection/swarm_connection.py @@ -1,11 +1,24 @@ -from typing import TYPE_CHECKING, Set, Tuple +from typing import ( + TYPE_CHECKING, + Set, + Tuple, +) import trio -from libp2p.network.connection.net_connection_interface import INetConn -from libp2p.network.stream.net_stream import NetStream -from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream -from libp2p.stream_muxer.exceptions import MuxedConnUnavailable +from libp2p.network.connection.net_connection_interface import ( + INetConn, +) +from libp2p.network.stream.net_stream import ( + NetStream, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, + IMuxedStream, +) +from libp2p.stream_muxer.exceptions import ( + MuxedConnUnavailable, +) if TYPE_CHECKING: from libp2p.network.swarm import Swarm # noqa: F401 @@ -48,8 +61,8 @@ class SwarmConn(INetConn): # We *could* optimize this but it really isn't worth it. for stream in self.streams.copy(): await stream.reset() - # Force context switch for stream handlers to process the stream reset event we just emit - # before we cancel the stream handler tasks. + # Force context switch for stream handlers to process the stream reset event we + # just emit before we cancel the stream handler tasks. await trio.sleep(0.1) await self._notify_disconnected() @@ -63,13 +76,15 @@ class SwarmConn(INetConn): except MuxedConnUnavailable: await self.close() break - # Asynchronously handle the accepted stream, to avoid blocking the next stream. + # Asynchronously handle the accepted stream, to avoid blocking + # the next stream. nursery.start_soon(self._handle_muxed_stream, stream) async def _handle_muxed_stream(self, muxed_stream: IMuxedStream) -> None: net_stream = await self._add_stream(muxed_stream) try: - # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 + # Ignore type here since mypy complains: + # https://github.com/python/mypy/issues/2427 await self.swarm.common_stream_handler(net_stream) # type: ignore finally: # As long as `common_stream_handler`, remove the stream. diff --git a/libp2p/network/exceptions.py b/libp2p/network/exceptions.py index 92be9b81..06849011 100644 --- a/libp2p/network/exceptions.py +++ b/libp2p/network/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class SwarmException(BaseLibp2pError): diff --git a/libp2p/network/network_interface.py b/libp2p/network/network_interface.py index 70fb7295..db640465 100644 --- a/libp2p/network/network_interface.py +++ b/libp2p/network/network_interface.py @@ -1,23 +1,45 @@ -from abc import ABC, abstractmethod -from typing import TYPE_CHECKING, Dict, Sequence +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + TYPE_CHECKING, + Dict, + Sequence, +) -from async_service import ServiceAPI -from multiaddr import Multiaddr +from async_service import ( + ServiceAPI, +) +from multiaddr import ( + Multiaddr, +) -from libp2p.network.connection.net_connection_interface import INetConn -from libp2p.peer.id import ID -from libp2p.peer.peerstore_interface import IPeerStore -from libp2p.transport.listener_interface import IListener -from libp2p.typing import StreamHandlerFn +from libp2p.network.connection.net_connection_interface import ( + INetConn, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerstore_interface import ( + IPeerStore, +) +from libp2p.transport.listener_interface import ( + IListener, +) +from libp2p.typing import ( + StreamHandlerFn, +) -from .stream.net_stream_interface import INetStream +from .stream.net_stream_interface import ( + INetStream, +) if TYPE_CHECKING: from .notifee_interface import INotifee # noqa: F401 class INetwork(ABC): - peerstore: IPeerStore connections: Dict[ID, INetConn] listeners: Dict[str, IListener] diff --git a/libp2p/network/notifee_interface.py b/libp2p/network/notifee_interface.py index c31f4732..22deb575 100644 --- a/libp2p/network/notifee_interface.py +++ b/libp2p/network/notifee_interface.py @@ -1,10 +1,21 @@ -from abc import ABC, abstractmethod -from typing import TYPE_CHECKING +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + TYPE_CHECKING, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.network.connection.net_connection_interface import INetConn -from libp2p.network.stream.net_stream_interface import INetStream +from libp2p.network.connection.net_connection_interface import ( + INetConn, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) if TYPE_CHECKING: from .network_interface import INetwork # noqa: F401 diff --git a/libp2p/network/stream/exceptions.py b/libp2p/network/stream/exceptions.py index 7af28ec1..46a4af2e 100644 --- a/libp2p/network/stream/exceptions.py +++ b/libp2p/network/stream/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.io.exceptions import IOException +from libp2p.io.exceptions import ( + IOException, +) class StreamError(IOException): diff --git a/libp2p/network/stream/net_stream.py b/libp2p/network/stream/net_stream.py index dab19204..8b99cca0 100644 --- a/libp2p/network/stream/net_stream.py +++ b/libp2p/network/stream/net_stream.py @@ -1,22 +1,33 @@ -from typing import Optional +from typing import ( + Optional, +) -from libp2p.stream_muxer.abc import IMuxedStream +from libp2p.stream_muxer.abc import ( + IMuxedStream, +) from libp2p.stream_muxer.exceptions import ( MuxedStreamClosed, MuxedStreamEOF, MuxedStreamReset, ) -from libp2p.typing import TProtocol +from libp2p.typing import ( + TProtocol, +) -from .exceptions import StreamClosed, StreamEOF, StreamReset -from .net_stream_interface import INetStream +from .exceptions import ( + StreamClosed, + StreamEOF, + StreamReset, +) +from .net_stream_interface import ( + INetStream, +) # TODO: Handle exceptions from `muxed_stream` # TODO: Add stream state # - Reference: https://github.com/libp2p/go-libp2p-swarm/blob/99831444e78c8f23c9335c17d8f7c700ba25ca14/swarm_stream.go # noqa: E501 class NetStream(INetStream): - muxed_stream: IMuxedStream protocol_id: Optional[TProtocol] @@ -39,7 +50,7 @@ class NetStream(INetStream): async def read(self, n: int = None) -> bytes: """ - reads from stream. + Read from stream. :param n: number of bytes to read :return: bytes of input @@ -53,7 +64,7 @@ class NetStream(INetStream): async def write(self, data: bytes) -> None: """ - write to stream. + Write to stream. :return: number of bytes written """ @@ -63,7 +74,7 @@ class NetStream(INetStream): raise StreamClosed() from error async def close(self) -> None: - """close stream.""" + """Close stream.""" await self.muxed_stream.close() async def reset(self) -> None: diff --git a/libp2p/network/stream/net_stream_interface.py b/libp2p/network/stream/net_stream_interface.py index 66c611c4..4662cbee 100644 --- a/libp2p/network/stream/net_stream_interface.py +++ b/libp2p/network/stream/net_stream_interface.py @@ -1,12 +1,19 @@ -from abc import abstractmethod +from abc import ( + abstractmethod, +) -from libp2p.io.abc import ReadWriteCloser -from libp2p.stream_muxer.abc import IMuxedConn -from libp2p.typing import TProtocol +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, +) +from libp2p.typing import ( + TProtocol, +) class INetStream(ReadWriteCloser): - muxed_conn: IMuxedConn @abstractmethod diff --git a/libp2p/network/swarm.py b/libp2p/network/swarm.py index 2c870dd0..54dbd9ca 100644 --- a/libp2p/network/swarm.py +++ b/libp2p/network/swarm.py @@ -1,33 +1,75 @@ import logging -from typing import Dict, List, Optional +from typing import ( + Dict, + List, + Optional, +) -from async_service import Service -from multiaddr import Multiaddr +from async_service import ( + Service, +) +from multiaddr import ( + Multiaddr, +) import trio -from libp2p.io.abc import ReadWriteCloser -from libp2p.network.connection.net_connection_interface import INetConn -from libp2p.peer.id import ID -from libp2p.peer.peerstore import PeerStoreError -from libp2p.peer.peerstore_interface import IPeerStore -from libp2p.stream_muxer.abc import IMuxedConn +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.network.connection.net_connection_interface import ( + INetConn, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerstore import ( + PeerStoreError, +) +from libp2p.peer.peerstore_interface import ( + IPeerStore, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, +) from libp2p.transport.exceptions import ( MuxerUpgradeFailure, OpenConnectionError, SecurityUpgradeFailure, ) -from libp2p.transport.listener_interface import IListener -from libp2p.transport.transport_interface import ITransport -from libp2p.transport.upgrader import TransportUpgrader -from libp2p.typing import StreamHandlerFn +from libp2p.transport.listener_interface import ( + IListener, +) +from libp2p.transport.transport_interface import ( + ITransport, +) +from libp2p.transport.upgrader import ( + TransportUpgrader, +) +from libp2p.typing import ( + StreamHandlerFn, +) -from ..exceptions import MultiError -from .connection.raw_connection import RawConnection -from .connection.swarm_connection import SwarmConn -from .exceptions import SwarmException -from .network_interface import INetworkService -from .notifee_interface import INotifee -from .stream.net_stream_interface import INetStream +from ..exceptions import ( + MultiError, +) +from .connection.raw_connection import ( + RawConnection, +) +from .connection.swarm_connection import ( + SwarmConn, +) +from .exceptions import ( + SwarmException, +) +from .network_interface import ( + INetworkService, +) +from .notifee_interface import ( + INotifee, +) +from .stream.net_stream_interface import ( + INetStream, +) logger = logging.getLogger("libp2p.network.swarm") @@ -40,7 +82,6 @@ def create_default_stream_handler(network: INetworkService) -> StreamHandlerFn: class Swarm(Service, INetworkService): - self_id: ID peerstore: IPeerStore upgrader: TransportUpgrader @@ -72,7 +113,8 @@ class Swarm(Service, INetworkService): # Create Notifee array self.notifees = [] - # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 + # Ignore type here since mypy complains: + # https://github.com/python/mypy/issues/2427 self.common_stream_handler = create_default_stream_handler(self) # type: ignore self.listener_nursery = None @@ -95,18 +137,18 @@ class Swarm(Service, INetworkService): return self.self_id def set_stream_handler(self, stream_handler: StreamHandlerFn) -> None: - # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 + # Ignore type here since mypy complains: + # https://github.com/python/mypy/issues/2427 self.common_stream_handler = stream_handler # type: ignore async def dial_peer(self, peer_id: ID) -> INetConn: """ - dial_peer try to create a connection to peer_id. + Try to create a connection to peer_id. :param peer_id: peer if we want to dial :raises SwarmException: raised when an error occurs :return: muxed connection """ - if peer_id in self.connections: # If muxed connection already exists for peer_id, # set muxed connection equal to existing muxed connection @@ -140,20 +182,19 @@ class Swarm(Service, INetworkService): # Tried all addresses, raising exception. raise SwarmException( - f"unable to connect to {peer_id}, no addresses established a successful connection " - "(with exceptions)" + f"unable to connect to {peer_id}, no addresses established a successful " + "connection (with exceptions)" ) from MultiError(exceptions) async def dial_addr(self, addr: Multiaddr, peer_id: ID) -> INetConn: """ - dial_addr try to create a connection to peer_id with addr. + Try to create a connection to peer_id with addr. :param addr: the address we want to connect with :param peer_id: the peer we want to connect to :raises SwarmException: raised when an error occurs :return: network connection """ - # Dial peer (connection to peer does not yet exist) # Transport dials peer (gets back a raw conn) try: @@ -231,11 +272,13 @@ class Swarm(Service, INetworkService): if str(maddr) in self.listeners: return True - async def conn_handler(read_write_closer: ReadWriteCloser) -> None: + async def conn_handler( + read_write_closer: ReadWriteCloser, maddr=maddr + ) -> None: raw_conn = RawConnection(read_write_closer, False) - # Per, https://discuss.libp2p.io/t/multistream-security/130, we first secure - # the conn and then mux the conn + # Per, https://discuss.libp2p.io/t/multistream-security/130, we first + # secure the conn and then mux the conn try: # FIXME: This dummy `ID(b"")` for the remote peer is useless. secured_conn = await self.upgrader.upgrade_security( @@ -264,8 +307,8 @@ class Swarm(Service, INetworkService): await self.add_conn(muxed_conn) logger.debug("successfully opened connection to peer %s", peer_id) - # NOTE: This is a intentional barrier to prevent from the handler exiting and - # closing the connection. + # NOTE: This is a intentional barrier to prevent from the handler + # exiting and closing the connection. await self.manager.wait_finished() try: @@ -282,7 +325,7 @@ class Swarm(Service, INetworkService): await self.notify_listen(maddr) return True - except IOError: + except OSError: # Failed. Continue looping. logger.debug("fail to listen on: %s", maddr) @@ -304,9 +347,11 @@ class Swarm(Service, INetworkService): logger.debug("successfully close the connection to peer %s", peer_id) async def add_conn(self, muxed_conn: IMuxedConn) -> SwarmConn: - """Add a `IMuxedConn` to `Swarm` as a `SwarmConn`, notify "connected", + """ + Add a `IMuxedConn` to `Swarm` as a `SwarmConn`, notify "connected", and start to monitor the connection for its new streams and - disconnection.""" + disconnection. + """ swarm_conn = SwarmConn(muxed_conn, self) self.manager.run_task(muxed_conn.start) await muxed_conn.event_started.wait() @@ -319,8 +364,10 @@ class Swarm(Service, INetworkService): return swarm_conn def remove_conn(self, swarm_conn: SwarmConn) -> None: - """Simply remove the connection from Swarm's records, without closing - the connection.""" + """ + Simply remove the connection from Swarm's records, without closing + the connection. + """ peer_id = swarm_conn.muxed_conn.peer_id if peer_id not in self.connections: return diff --git a/libp2p/peer/README.md b/libp2p/peer/README.md index df710f81..b5bbe1eb 100644 --- a/libp2p/peer/README.md +++ b/libp2p/peer/README.md @@ -1,5 +1,5 @@ # PeerStore -The PeerStore contains a mapping of peer IDs to PeerData objects. Each PeerData object represents a peer, and each PeerData contains a collection of protocols, addresses, and a mapping of metadata. PeerStore implements the IPeerStore (peer protocols), IAddrBook (address book), and IPeerMetadata (peer metadata) interfaces, which allows the peer store to effectively function as a dictionary for peer ID to protocol, address, and metadata. +The PeerStore contains a mapping of peer IDs to PeerData objects. Each PeerData object represents a peer, and each PeerData contains a collection of protocols, addresses, and a mapping of metadata. PeerStore implements the IPeerStore (peer protocols), IAddrBook (address book), and IPeerMetadata (peer metadata) interfaces, which allows the peer store to effectively function as a dictionary for peer ID to protocol, address, and metadata. -Note: PeerInfo represents a read-only summary of a PeerData object. Only the attributes assigned in PeerInfo are readable by references to PeerInfo objects. \ No newline at end of file +Note: PeerInfo represents a read-only summary of a PeerData object. Only the attributes assigned in PeerInfo are readable by references to PeerInfo objects. diff --git a/libp2p/peer/addrbook_interface.py b/libp2p/peer/addrbook_interface.py index 849600e4..ddbe5c7b 100644 --- a/libp2p/peer/addrbook_interface.py +++ b/libp2p/peer/addrbook_interface.py @@ -1,9 +1,19 @@ -from abc import ABC, abstractmethod -from typing import List, Sequence +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + List, + Sequence, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from .id import ID +from .id import ( + ID, +) class IAddrBook(ABC): @@ -15,7 +25,7 @@ class IAddrBook(ABC): :param peer_id: the peer to add address for :param addr: multiaddress of the peer :param ttl: time-to-live for the address (after this time, address is no longer valid) - """ + """ # noqa: E501 @abstractmethod def add_addrs(self, peer_id: ID, addrs: Sequence[Multiaddr], ttl: int) -> None: @@ -28,7 +38,7 @@ class IAddrBook(ABC): :param peer_id: the peer to add address for :param addr: multiaddresses of the peer :param ttl: time-to-live for the address (after this time, address is no longer valid - """ + """ # noqa: E501 @abstractmethod def addrs(self, peer_id: ID) -> List[Multiaddr]: diff --git a/libp2p/peer/id.py b/libp2p/peer/id.py index 0a55739c..06c7674f 100644 --- a/libp2p/peer/id.py +++ b/libp2p/peer/id.py @@ -1,10 +1,14 @@ import hashlib -from typing import Union +from typing import ( + Union, +) import base58 import multihash -from libp2p.crypto.keys import PublicKey +from libp2p.crypto.keys import ( + PublicKey, +) # NOTE: On inlining... # See: https://github.com/libp2p/specs/issues/138 diff --git a/libp2p/peer/peerdata.py b/libp2p/peer/peerdata.py index 02df07ec..017def66 100644 --- a/libp2p/peer/peerdata.py +++ b/libp2p/peer/peerdata.py @@ -1,14 +1,25 @@ -from typing import Any, Dict, List, Sequence +from typing import ( + Any, + Dict, + List, + Sequence, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.crypto.keys import PrivateKey, PublicKey +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) -from .peerdata_interface import IPeerData +from .peerdata_interface import ( + IPeerData, +) class PeerData(IPeerData): - pubkey: PublicKey privkey: PrivateKey metadata: Dict[Any, Any] diff --git a/libp2p/peer/peerdata_interface.py b/libp2p/peer/peerdata_interface.py index ab9016ed..cf762307 100644 --- a/libp2p/peer/peerdata_interface.py +++ b/libp2p/peer/peerdata_interface.py @@ -1,11 +1,25 @@ -from abc import ABC, abstractmethod -from typing import Any, List, Sequence +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Any, + List, + Sequence, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.crypto.keys import PrivateKey, PublicKey +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) -from .peermetadata_interface import IPeerMetadata +from .peermetadata_interface import ( + IPeerMetadata, +) class IPeerData(ABC): diff --git a/libp2p/peer/peerinfo.py b/libp2p/peer/peerinfo.py index 889b6f61..101ccd68 100644 --- a/libp2p/peer/peerinfo.py +++ b/libp2p/peer/peerinfo.py @@ -1,8 +1,14 @@ -from typing import Any, List, Sequence +from typing import ( + Any, + List, + Sequence, +) import multiaddr -from .id import ID +from .id import ( + ID, +) class PeerInfo: diff --git a/libp2p/peer/peermetadata_interface.py b/libp2p/peer/peermetadata_interface.py index 6273a714..39d8967d 100644 --- a/libp2p/peer/peermetadata_interface.py +++ b/libp2p/peer/peermetadata_interface.py @@ -1,7 +1,14 @@ -from abc import ABC, abstractmethod -from typing import Any +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Any, +) -from .id import ID +from .id import ( + ID, +) class IPeerMetadata(ABC): diff --git a/libp2p/peer/peerstore.py b/libp2p/peer/peerstore.py index 0314308d..da2378ff 100644 --- a/libp2p/peer/peerstore.py +++ b/libp2p/peer/peerstore.py @@ -1,18 +1,39 @@ -from collections import defaultdict -from typing import Any, Dict, List, Sequence +from collections import ( + defaultdict, +) +from typing import ( + Any, + Dict, + List, + Sequence, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.crypto.keys import KeyPair, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + PrivateKey, + PublicKey, +) -from .id import ID -from .peerdata import PeerData, PeerDataError -from .peerinfo import PeerInfo -from .peerstore_interface import IPeerStore +from .id import ( + ID, +) +from .peerdata import ( + PeerData, + PeerDataError, +) +from .peerinfo import ( + PeerInfo, +) +from .peerstore_interface import ( + IPeerStore, +) class PeerStore(IPeerStore): - peer_data_map: Dict[ID, PeerData] def __init__(self) -> None: diff --git a/libp2p/peer/peerstore_interface.py b/libp2p/peer/peerstore_interface.py index a9790b07..d23725fe 100644 --- a/libp2p/peer/peerstore_interface.py +++ b/libp2p/peer/peerstore_interface.py @@ -1,14 +1,34 @@ -from abc import abstractmethod -from typing import Any, List, Sequence +from abc import ( + abstractmethod, +) +from typing import ( + Any, + List, + Sequence, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.crypto.keys import KeyPair, PrivateKey, PublicKey +from libp2p.crypto.keys import ( + KeyPair, + PrivateKey, + PublicKey, +) -from .addrbook_interface import IAddrBook -from .id import ID -from .peerinfo import PeerInfo -from .peermetadata_interface import IPeerMetadata +from .addrbook_interface import ( + IAddrBook, +) +from .id import ( + ID, +) +from .peerinfo import ( + PeerInfo, +) +from .peermetadata_interface import ( + IPeerMetadata, +) class IPeerStore(IAddrBook, IPeerMetadata): diff --git a/libp2p/protocol_muxer/exceptions.py b/libp2p/protocol_muxer/exceptions.py index ffcc5d57..8caffe72 100644 --- a/libp2p/protocol_muxer/exceptions.py +++ b/libp2p/protocol_muxer/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class MultiselectCommunicatorError(BaseLibp2pError): diff --git a/libp2p/protocol_muxer/multiselect.py b/libp2p/protocol_muxer/multiselect.py index c3cced3a..e51dd3f4 100644 --- a/libp2p/protocol_muxer/multiselect.py +++ b/libp2p/protocol_muxer/multiselect.py @@ -1,19 +1,34 @@ -from typing import Dict, Tuple +from typing import ( + Dict, + Tuple, +) -from libp2p.typing import StreamHandlerFn, TProtocol +from libp2p.typing import ( + StreamHandlerFn, + TProtocol, +) -from .exceptions import MultiselectCommunicatorError, MultiselectError -from .multiselect_communicator_interface import IMultiselectCommunicator -from .multiselect_muxer_interface import IMultiselectMuxer +from .exceptions import ( + MultiselectCommunicatorError, + MultiselectError, +) +from .multiselect_communicator_interface import ( + IMultiselectCommunicator, +) +from .multiselect_muxer_interface import ( + IMultiselectMuxer, +) MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0" PROTOCOL_NOT_FOUND_MSG = "na" class Multiselect(IMultiselectMuxer): - """Multiselect module that is responsible for responding to a multiselect + """ + Multiselect module that is responsible for responding to a multiselect client and deciding on a specific protocol and handler pair to use for - communication.""" + communication. + """ handlers: Dict[TProtocol, StreamHandlerFn] diff --git a/libp2p/protocol_muxer/multiselect_client.py b/libp2p/protocol_muxer/multiselect_client.py index 50c4fefb..b5a7263f 100644 --- a/libp2p/protocol_muxer/multiselect_client.py +++ b/libp2p/protocol_muxer/multiselect_client.py @@ -1,18 +1,31 @@ -from typing import Sequence +from typing import ( + Sequence, +) -from libp2p.typing import TProtocol +from libp2p.typing import ( + TProtocol, +) -from .exceptions import MultiselectClientError, MultiselectCommunicatorError -from .multiselect_client_interface import IMultiselectClient -from .multiselect_communicator_interface import IMultiselectCommunicator +from .exceptions import ( + MultiselectClientError, + MultiselectCommunicatorError, +) +from .multiselect_client_interface import ( + IMultiselectClient, +) +from .multiselect_communicator_interface import ( + IMultiselectCommunicator, +) MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0" PROTOCOL_NOT_FOUND_MSG = "na" class MultiselectClient(IMultiselectClient): - """Client for communicating with receiver's multiselect module in order to - select a protocol id to communicate over.""" + """ + Client for communicating with receiver's multiselect module in order to + select a protocol id to communicate over. + """ async def handshake(self, communicator: IMultiselectCommunicator) -> None: """ diff --git a/libp2p/protocol_muxer/multiselect_client_interface.py b/libp2p/protocol_muxer/multiselect_client_interface.py index fffc2fbe..d7ff1739 100644 --- a/libp2p/protocol_muxer/multiselect_client_interface.py +++ b/libp2p/protocol_muxer/multiselect_client_interface.py @@ -1,16 +1,26 @@ -from abc import ABC, abstractmethod -from typing import Sequence +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Sequence, +) from libp2p.protocol_muxer.multiselect_communicator_interface import ( IMultiselectCommunicator, ) -from libp2p.typing import TProtocol +from libp2p.typing import ( + TProtocol, +) class IMultiselectClient(ABC): - """Client for communicating with receiver's multiselect module in order to - select a protocol id to communicate over.""" + """ + Client for communicating with receiver's multiselect module in order to + select a protocol id to communicate over. + """ + @abstractmethod async def handshake(self, communicator: IMultiselectCommunicator) -> None: """ Ensure that the client and multiselect are both using the same @@ -34,6 +44,7 @@ class IMultiselectClient(ABC): :return: selected protocol """ + @abstractmethod async def try_select( self, communicator: IMultiselectCommunicator, protocol: TProtocol ) -> TProtocol: diff --git a/libp2p/protocol_muxer/multiselect_communicator.py b/libp2p/protocol_muxer/multiselect_communicator.py index 6f7b715d..f4ecc369 100644 --- a/libp2p/protocol_muxer/multiselect_communicator.py +++ b/libp2p/protocol_muxer/multiselect_communicator.py @@ -1,10 +1,23 @@ -from libp2p.exceptions import ParseError -from libp2p.io.abc import ReadWriteCloser -from libp2p.io.exceptions import IOException -from libp2p.utils import encode_delim, read_delim +from libp2p.exceptions import ( + ParseError, +) +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.io.exceptions import ( + IOException, +) +from libp2p.utils import ( + encode_delim, + read_delim, +) -from .exceptions import MultiselectCommunicatorError -from .multiselect_communicator_interface import IMultiselectCommunicator +from .exceptions import ( + MultiselectCommunicatorError, +) +from .multiselect_communicator_interface import ( + IMultiselectCommunicator, +) class MultiselectCommunicator(IMultiselectCommunicator): @@ -16,7 +29,7 @@ class MultiselectCommunicator(IMultiselectCommunicator): async def write(self, msg_str: str) -> None: """ :raise MultiselectCommunicatorError: raised when failed to write to underlying reader - """ + """ # noqa: E501 msg_bytes = encode_delim(msg_str.encode()) try: await self.read_writer.write(msg_bytes) @@ -28,7 +41,7 @@ class MultiselectCommunicator(IMultiselectCommunicator): async def read(self) -> str: """ :raise MultiselectCommunicatorError: raised when failed to read from underlying reader - """ + """ # noqa: E501 try: data = await read_delim(self.read_writer) # `IOException` includes `IncompleteReadError` and `StreamError` diff --git a/libp2p/protocol_muxer/multiselect_communicator_interface.py b/libp2p/protocol_muxer/multiselect_communicator_interface.py index 1fad2897..c6e097c0 100644 --- a/libp2p/protocol_muxer/multiselect_communicator_interface.py +++ b/libp2p/protocol_muxer/multiselect_communicator_interface.py @@ -1,10 +1,15 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) class IMultiselectCommunicator(ABC): - """Communicator helper class that ensures both the client and multistream + """ + Communicator helper class that ensures both the client and multistream module will follow the same multistream protocol, which is necessary for - them to work.""" + them to work. + """ @abstractmethod async def write(self, msg_str: str) -> None: diff --git a/libp2p/protocol_muxer/multiselect_muxer_interface.py b/libp2p/protocol_muxer/multiselect_muxer_interface.py index 935545f6..867ca51d 100644 --- a/libp2p/protocol_muxer/multiselect_muxer_interface.py +++ b/libp2p/protocol_muxer/multiselect_muxer_interface.py @@ -1,15 +1,28 @@ -from abc import ABC, abstractmethod -from typing import Dict, Tuple +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Dict, + Tuple, +) -from libp2p.typing import StreamHandlerFn, TProtocol +from libp2p.typing import ( + StreamHandlerFn, + TProtocol, +) -from .multiselect_communicator_interface import IMultiselectCommunicator +from .multiselect_communicator_interface import ( + IMultiselectCommunicator, +) class IMultiselectMuxer(ABC): - """Multiselect module that is responsible for responding to a multiselect + """ + Multiselect module that is responsible for responding to a multiselect client and deciding on a specific protocol and handler pair to use for - communication.""" + communication. + """ handlers: Dict[TProtocol, StreamHandlerFn] diff --git a/libp2p/pubsub/abc.py b/libp2p/pubsub/abc.py index da37b6a1..aec6f8a4 100644 --- a/libp2p/pubsub/abc.py +++ b/libp2p/pubsub/abc.py @@ -1,4 +1,7 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) from typing import ( TYPE_CHECKING, AsyncContextManager, @@ -8,13 +11,23 @@ from typing import ( Tuple, ) -from async_service import ServiceAPI +from async_service import ( + ServiceAPI, +) -from libp2p.peer.id import ID -from libp2p.typing import TProtocol +from libp2p.peer.id import ( + ID, +) +from libp2p.typing import ( + TProtocol, +) -from .pb import rpc_pb2 -from .typing import ValidatorFn +from .pb import ( + rpc_pb2, +) +from .typing import ( + ValidatorFn, +) if TYPE_CHECKING: from .pubsub import Pubsub # noqa: F401 @@ -69,9 +82,9 @@ class IPubsubRouter(ABC): """ Invoked to process control messages in the RPC envelope. It is invoked after subscriptions and payload messages have been processed - TODO: Check if this interface is ok. It's not the exact same as the go code, but the go - code is really confusing with the msg origin, they specify `rpc.from` even when the rpc - shouldn't have a from + TODO: Check if this interface is ok. It's not the exact same as the go code, but + the go code is really confusing with the msg origin, they specify `rpc.from` + even when the rpc shouldn't have a from :param rpc: rpc message """ diff --git a/libp2p/pubsub/exceptions.py b/libp2p/pubsub/exceptions.py index 55afde04..e203cad3 100644 --- a/libp2p/pubsub/exceptions.py +++ b/libp2p/pubsub/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class PubsubRouterError(BaseLibp2pError): diff --git a/libp2p/pubsub/floodsub.py b/libp2p/pubsub/floodsub.py index d9c1a9c9..41628b3b 100644 --- a/libp2p/pubsub/floodsub.py +++ b/libp2p/pubsub/floodsub.py @@ -1,16 +1,34 @@ import logging -from typing import Iterable, List, Sequence +from typing import ( + Iterable, + List, + Sequence, +) import trio -from libp2p.network.stream.exceptions import StreamClosed -from libp2p.peer.id import ID -from libp2p.typing import TProtocol -from libp2p.utils import encode_varint_prefixed +from libp2p.network.stream.exceptions import ( + StreamClosed, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.typing import ( + TProtocol, +) +from libp2p.utils import ( + encode_varint_prefixed, +) -from .abc import IPubsubRouter -from .pb import rpc_pb2 -from .pubsub import Pubsub +from .abc import ( + IPubsubRouter, +) +from .pb import ( + rpc_pb2, +) +from .pubsub import ( + Pubsub, +) PROTOCOL_ID = TProtocol("/floodsub/1.0.0") @@ -18,7 +36,6 @@ logger = logging.getLogger("libp2p.pubsub.floodsub") class FloodSub(IPubsubRouter): - protocols: List[TProtocol] pubsub: Pubsub @@ -80,7 +97,6 @@ class FloodSub(IPubsubRouter): :param msg_forwarder: peer ID of the peer who forwards the message to us :param pubsub_msg: pubsub message in protobuf. """ - peers_gen = set( self._get_peers_to_send( pubsub_msg.topicIDs, diff --git a/libp2p/pubsub/gossipsub.py b/libp2p/pubsub/gossipsub.py index 4d25c254..77cbd6f9 100644 --- a/libp2p/pubsub/gossipsub.py +++ b/libp2p/pubsub/gossipsub.py @@ -1,23 +1,58 @@ -from ast import literal_eval -from collections import defaultdict +from ast import ( + literal_eval, +) +from collections import ( + defaultdict, +) import logging import random -from typing import Any, DefaultDict, Dict, Iterable, List, Sequence, Set, Tuple +from typing import ( + Any, + DefaultDict, + Dict, + Iterable, + List, + Sequence, + Set, + Tuple, +) -from async_service import Service +from async_service import ( + Service, +) import trio -from libp2p.network.stream.exceptions import StreamClosed -from libp2p.peer.id import ID -from libp2p.pubsub import floodsub -from libp2p.typing import TProtocol -from libp2p.utils import encode_varint_prefixed +from libp2p.network.stream.exceptions import ( + StreamClosed, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.pubsub import ( + floodsub, +) +from libp2p.typing import ( + TProtocol, +) +from libp2p.utils import ( + encode_varint_prefixed, +) -from .abc import IPubsubRouter -from .exceptions import NoPubsubAttached -from .mcache import MessageCache -from .pb import rpc_pb2 -from .pubsub import Pubsub +from .abc import ( + IPubsubRouter, +) +from .exceptions import ( + NoPubsubAttached, +) +from .mcache import ( + MessageCache, +) +from .pb import ( + rpc_pb2, +) +from .pubsub import ( + Pubsub, +) PROTOCOL_ID = TProtocol("/meshsub/1.0.0") @@ -120,10 +155,10 @@ class GossipSub(IPubsubRouter, Service): logger.debug("adding peer %s with protocol %s", peer_id, protocol_id) if protocol_id not in (PROTOCOL_ID, floodsub.PROTOCOL_ID): - # We should never enter here. Becuase the `protocol_id` is registered by your pubsub - # instance in multistream-select, but it is not the protocol that gossipsub supports. - # In this case, probably we registered gossipsub to a wrong `protocol_id` - # in multistream-select, or wrong versions. + # We should never enter here. Becuase the `protocol_id` is registered by + # your pubsub instance in multistream-select, but it is not the protocol + # that gossipsub supports. In this case, probably we registered gossipsub + # to a wrong `protocol_id` in multistream-select, or wrong versions. raise ValueError(f"Protocol={protocol_id} is not supported.") self.peer_protocol[peer_id] = protocol_id @@ -208,11 +243,11 @@ class GossipSub(IPubsubRouter, Service): continue # floodsub peers - floodsub_peers: Set[ID] = set( + floodsub_peers: Set[ID] = { peer_id for peer_id in self.pubsub.peer_topics[topic] if self.peer_protocol[peer_id] == floodsub.PROTOCOL_ID - ) + } send_to.update(floodsub_peers) # gossipsub peers @@ -220,9 +255,9 @@ class GossipSub(IPubsubRouter, Service): if topic in self.mesh: gossipsub_peers = self.mesh[topic] else: - # When we publish to a topic that we have not subscribe to, we randomly pick - # `self.degree` number of peers who have subscribed to the topic and add them - # as our `fanout` peers. + # When we publish to a topic that we have not subscribe to, we randomly + # pick `self.degree` number of peers who have subscribed to the topic + # and add them as our `fanout` peers. topic_in_fanout: bool = topic in self.fanout fanout_peers: Set[ID] = self.fanout[topic] if topic_in_fanout else set() fanout_size = len(fanout_peers) @@ -270,7 +305,7 @@ class GossipSub(IPubsubRouter, Service): # Combine fanout peers with selected peers fanout_peers.update(selected_peers) - # Add fanout peers to mesh and notifies them with a GRAFT(topic) control message. + # Add fanout peers to mesh and notifies them with a GRAFT(topic) control message for peer in fanout_peers: self.mesh[topic].add(peer) await self.emit_graft(topic, peer) @@ -369,10 +404,10 @@ class GossipSub(IPubsubRouter, Service): """ Call individual heartbeats. - Note: the heartbeats are called with awaits because each heartbeat depends on the - state changes in the preceding heartbeat + Note: the heartbeats are called with awaits because each heartbeat depends on + the state changes in the preceding heartbeat """ - # Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # Noqa: E501 + # Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # noqa: E501 await trio.sleep(self.heartbeat_initial_delay) while True: # Maintain mesh and keep track of which peers to send GRAFT or PRUNE to @@ -381,7 +416,8 @@ class GossipSub(IPubsubRouter, Service): self.fanout_heartbeat() # Get the peers to send IHAVE to peers_to_gossip = self.gossip_heartbeat() - # Pack GRAFT, PRUNE and IHAVE for the same peer into one control message and send it + # Pack GRAFT, PRUNE and IHAVE for the same peer into one control message and + # send it await self._emit_control_msgs( peers_to_graft, peers_to_prune, peers_to_gossip ) @@ -391,7 +427,7 @@ class GossipSub(IPubsubRouter, Service): await trio.sleep(self.heartbeat_interval) def mesh_heartbeat( - self + self, ) -> Tuple[DefaultDict[ID, List[str]], DefaultDict[ID, List[str]]]: peers_to_graft: DefaultDict[ID, List[str]] = defaultdict(list) peers_to_prune: DefaultDict[ID, List[str]] = defaultdict(list) @@ -402,7 +438,7 @@ class GossipSub(IPubsubRouter, Service): num_mesh_peers_in_topic = len(self.mesh[topic]) if num_mesh_peers_in_topic < self.degree_low: - # Select D - |mesh[topic]| peers from peers.gossipsub[topic] - mesh[topic] + # Select D - |mesh[topic]| peers from peers.gossipsub[topic] - mesh[topic] # noqa: E501 selected_peers = self._get_in_topic_gossipsub_peers_from_minus( topic, self.degree - num_mesh_peers_in_topic, self.mesh[topic] ) @@ -436,7 +472,7 @@ class GossipSub(IPubsubRouter, Service): # Remove topic from fanout del self.fanout[topic] else: - # Check if fanout peers are still in the topic and remove the ones that are not + # Check if fanout peers are still in the topic and remove the ones that are not # noqa: E501 # ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L498-L504 # noqa: E501 in_topic_fanout_peers = [ peer @@ -448,7 +484,7 @@ class GossipSub(IPubsubRouter, Service): # If |fanout[topic]| < D if num_fanout_peers_in_topic < self.degree: - # Select D - |fanout[topic]| peers from peers.gossipsub[topic] - fanout[topic] + # Select D - |fanout[topic]| peers from peers.gossipsub[topic] - fanout[topic] # noqa: E501 selected_peers = self._get_in_topic_gossipsub_peers_from_minus( topic, self.degree - num_fanout_peers_in_topic, @@ -462,11 +498,14 @@ class GossipSub(IPubsubRouter, Service): for topic in self.mesh: msg_ids = self.mcache.window(topic) if msg_ids: - # Get all pubsub peers in a topic and only add them if they are gossipsub peers too + # Get all pubsub peers in a topic and only add them if they are + # gossipsub peers too if topic in self.pubsub.peer_topics: # Select D peers from peers.gossipsub[topic] - peers_to_emit_ihave_to = self._get_in_topic_gossipsub_peers_from_minus( - topic, self.degree, self.mesh[topic] + peers_to_emit_ihave_to = ( + self._get_in_topic_gossipsub_peers_from_minus( + topic, self.degree, self.mesh[topic] + ) ) msg_id_strs = [str(msg_id) for msg_id in msg_ids] @@ -478,11 +517,14 @@ class GossipSub(IPubsubRouter, Service): for topic in self.fanout: msg_ids = self.mcache.window(topic) if msg_ids: - # Get all pubsub peers in topic and only add if they are gossipsub peers also + # Get all pubsub peers in topic and only add if they are + # gossipsub peers also if topic in self.pubsub.peer_topics: # Select D peers from peers.gossipsub[topic] - peers_to_emit_ihave_to = self._get_in_topic_gossipsub_peers_from_minus( - topic, self.degree, self.fanout[topic] + peers_to_emit_ihave_to = ( + self._get_in_topic_gossipsub_peers_from_minus( + topic, self.degree, self.fanout[topic] + ) ) msg_id_strs = [str(msg) for msg in msg_ids] for peer in peers_to_emit_ihave_to: @@ -494,7 +536,8 @@ class GossipSub(IPubsubRouter, Service): num_to_select: int, pool: Iterable[Any], minus: Iterable[Any] ) -> List[Any]: """ - Select at most num_to_select subset of elements from the set (pool - minus) randomly. + Select at most num_to_select subset of elements from the set + (pool - minus) randomly. :param num_to_select: number of elements to randomly select :param pool: list of items to select from (excluding elements in minus) :param minus: elements to be excluded from selection pool @@ -508,8 +551,9 @@ class GossipSub(IPubsubRouter, Service): # Don't create a new selection_pool if we are not subbing anything selection_pool = list(pool) - # If num_to_select > size(selection_pool), then return selection_pool (which has the most - # possible elements s.t. the number of elements is less than num_to_select) + # If num_to_select > size(selection_pool), then return selection_pool (which has + # the most possible elements s.t. the number of elements is less than + # num_to_select) if num_to_select >= len(selection_pool): return selection_pool @@ -521,11 +565,11 @@ class GossipSub(IPubsubRouter, Service): def _get_in_topic_gossipsub_peers_from_minus( self, topic: str, num_to_select: int, minus: Iterable[ID] ) -> List[ID]: - gossipsub_peers_in_topic = set( + gossipsub_peers_in_topic = { peer_id for peer_id in self.pubsub.peer_topics[topic] if self.peer_protocol[peer_id] == PROTOCOL_ID - ) + } return self.select_from_minus(num_to_select, gossipsub_peers_in_topic, minus) # RPC handlers @@ -533,15 +577,15 @@ class GossipSub(IPubsubRouter, Service): async def handle_ihave( self, ihave_msg: rpc_pb2.ControlIHave, sender_peer_id: ID ) -> None: - """Checks the seen set and requests unknown messages with an IWANT - message.""" - # Get list of all seen (seqnos, from) from the (seqno, from) tuples in seen_messages cache + """Checks the seen set and requests unknown messages with an IWANT message.""" + # Get list of all seen (seqnos, from) from the (seqno, from) tuples in + # seen_messages cache seen_seqnos_and_peers = [ seqno_and_from for seqno_and_from in self.pubsub.seen_messages.keys() ] - # Add all unknown message ids (ids that appear in ihave_msg but not in seen_seqnos) to list - # of messages we want to request + # Add all unknown message ids (ids that appear in ihave_msg but not in + # seen_seqnos) to list of messages we want to request # FIXME: Update type of message ID msg_ids_wanted: List[Any] = [ msg_id @@ -556,8 +600,10 @@ class GossipSub(IPubsubRouter, Service): async def handle_iwant( self, iwant_msg: rpc_pb2.ControlIWant, sender_peer_id: ID ) -> None: - """Forwards all request messages that are present in mcache to the - requesting peer.""" + """ + Forwards all request messages that are present in mcache to the + requesting peer. + """ # FIXME: Update type of message ID # FIXME: Find a better way to parse the msg ids msg_ids: List[Any] = [literal_eval(msg) for msg in iwant_msg.messageIDs] @@ -572,8 +618,8 @@ class GossipSub(IPubsubRouter, Service): msgs_to_forward.append(msg) # Forward messages to requesting peer - # Should this just be publishing? No - # because then the message will forwarded to peers in the topics contained in the messages. + # Should this just be publishing? No, because then the message will forwarded to + # peers in the topics contained in the messages. # We should # 1) Package these messages into a single packet packet: rpc_pb2.RPC = rpc_pb2.RPC() @@ -643,7 +689,6 @@ class GossipSub(IPubsubRouter, Service): async def emit_ihave(self, topic: str, msg_ids: Any, to_peer: ID) -> None: """Emit ihave message, sent to to_peer, for topic and msg_ids.""" - ihave_msg: rpc_pb2.ControlIHave = rpc_pb2.ControlIHave() ihave_msg.messageIDs.extend(msg_ids) ihave_msg.topicID = topic @@ -655,7 +700,6 @@ class GossipSub(IPubsubRouter, Service): async def emit_iwant(self, msg_ids: Any, to_peer: ID) -> None: """Emit iwant message, sent to to_peer, for msg_ids.""" - iwant_msg: rpc_pb2.ControlIWant = rpc_pb2.ControlIWant() iwant_msg.messageIDs.extend(msg_ids) @@ -666,7 +710,6 @@ class GossipSub(IPubsubRouter, Service): async def emit_graft(self, topic: str, to_peer: ID) -> None: """Emit graft message, sent to to_peer, for topic.""" - graft_msg: rpc_pb2.ControlGraft = rpc_pb2.ControlGraft() graft_msg.topicID = topic @@ -677,7 +720,6 @@ class GossipSub(IPubsubRouter, Service): async def emit_prune(self, topic: str, to_peer: ID) -> None: """Emit graft message, sent to to_peer, for topic.""" - prune_msg: rpc_pb2.ControlPrune = rpc_pb2.ControlPrune() prune_msg.topicID = topic diff --git a/libp2p/pubsub/mcache.py b/libp2p/pubsub/mcache.py index c8489123..c02d7b2e 100644 --- a/libp2p/pubsub/mcache.py +++ b/libp2p/pubsub/mcache.py @@ -1,10 +1,17 @@ -from typing import Dict, List, Optional, Sequence, Tuple +from typing import ( + Dict, + List, + Optional, + Sequence, + Tuple, +) -from .pb import rpc_pb2 +from .pb import ( + rpc_pb2, +) class CacheEntry: - mid: Tuple[bytes, bytes] topics: List[str] @@ -24,7 +31,6 @@ class CacheEntry: class MessageCache: - window_size: int history_size: int @@ -91,8 +97,9 @@ class MessageCache: return mids def shift(self) -> None: - """Shift the window over by 1 position, dropping the last element of - the history.""" + """ + Shift the window over by 1 position, dropping the last element of the history. + """ last_entries: List[CacheEntry] = self.history[len(self.history) - 1] for entry in last_entries: diff --git a/libp2p/pubsub/pb/rpc_pb2.py b/libp2p/pubsub/pb/rpc_pb2.py index cc3e0724..d51f9f5d 100644 --- a/libp2p/pubsub/pb/rpc_pb2.py +++ b/libp2p/pubsub/pb/rpc_pb2.py @@ -1,636 +1,943 @@ -# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/pubsub/pb/rpc.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/pubsub/pb/rpc.proto', - package='pubsub.pb', - syntax='proto2', - serialized_options=None, - serialized_pb=_b('\n\x1alibp2p/pubsub/pb/rpc.proto\x12\tpubsub.pb\"\xb4\x01\n\x03RPC\x12-\n\rsubscriptions\x18\x01 \x03(\x0b\x32\x16.pubsub.pb.RPC.SubOpts\x12#\n\x07publish\x18\x02 \x03(\x0b\x32\x12.pubsub.pb.Message\x12*\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x19.pubsub.pb.ControlMessage\x1a-\n\x07SubOpts\x12\x11\n\tsubscribe\x18\x01 \x01(\x08\x12\x0f\n\x07topicid\x18\x02 \x01(\t\"i\n\x07Message\x12\x0f\n\x07\x66rom_id\x18\x01 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\r\n\x05seqno\x18\x03 \x01(\x0c\x12\x10\n\x08topicIDs\x18\x04 \x03(\t\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x12\x0b\n\x03key\x18\x06 \x01(\x0c\"\xb0\x01\n\x0e\x43ontrolMessage\x12&\n\x05ihave\x18\x01 \x03(\x0b\x32\x17.pubsub.pb.ControlIHave\x12&\n\x05iwant\x18\x02 \x03(\x0b\x32\x17.pubsub.pb.ControlIWant\x12&\n\x05graft\x18\x03 \x03(\x0b\x32\x17.pubsub.pb.ControlGraft\x12&\n\x05prune\x18\x04 \x03(\x0b\x32\x17.pubsub.pb.ControlPrune\"3\n\x0c\x43ontrolIHave\x12\x0f\n\x07topicID\x18\x01 \x01(\t\x12\x12\n\nmessageIDs\x18\x02 \x03(\t\"\"\n\x0c\x43ontrolIWant\x12\x12\n\nmessageIDs\x18\x01 \x03(\t\"\x1f\n\x0c\x43ontrolGraft\x12\x0f\n\x07topicID\x18\x01 \x01(\t\"\x1f\n\x0c\x43ontrolPrune\x12\x0f\n\x07topicID\x18\x01 \x01(\t\"\x87\x03\n\x0fTopicDescriptor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04\x61uth\x18\x02 \x01(\x0b\x32#.pubsub.pb.TopicDescriptor.AuthOpts\x12/\n\x03\x65nc\x18\x03 \x01(\x0b\x32\".pubsub.pb.TopicDescriptor.EncOpts\x1a|\n\x08\x41uthOpts\x12:\n\x04mode\x18\x01 \x01(\x0e\x32,.pubsub.pb.TopicDescriptor.AuthOpts.AuthMode\x12\x0c\n\x04keys\x18\x02 \x03(\x0c\"&\n\x08\x41uthMode\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x83\x01\n\x07\x45ncOpts\x12\x38\n\x04mode\x18\x01 \x01(\x0e\x32*.pubsub.pb.TopicDescriptor.EncOpts.EncMode\x12\x11\n\tkeyHashes\x18\x02 \x03(\x0c\"+\n\x07\x45ncMode\x12\x08\n\x04NONE\x10\x00\x12\r\n\tSHAREDKEY\x10\x01\x12\x07\n\x03WOT\x10\x02') + name="libp2p/pubsub/pb/rpc.proto", + package="pubsub.pb", + syntax="proto2", + serialized_options=None, + serialized_pb=_b( + '\n\x1alibp2p/pubsub/pb/rpc.proto\x12\tpubsub.pb"\xb4\x01\n\x03RPC\x12-\n\rsubscriptions\x18\x01 \x03(\x0b\x32\x16.pubsub.pb.RPC.SubOpts\x12#\n\x07publish\x18\x02 \x03(\x0b\x32\x12.pubsub.pb.Message\x12*\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x19.pubsub.pb.ControlMessage\x1a-\n\x07SubOpts\x12\x11\n\tsubscribe\x18\x01 \x01(\x08\x12\x0f\n\x07topicid\x18\x02 \x01(\t"i\n\x07Message\x12\x0f\n\x07\x66rom_id\x18\x01 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\r\n\x05seqno\x18\x03 \x01(\x0c\x12\x10\n\x08topicIDs\x18\x04 \x03(\t\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x12\x0b\n\x03key\x18\x06 \x01(\x0c"\xb0\x01\n\x0e\x43ontrolMessage\x12&\n\x05ihave\x18\x01 \x03(\x0b\x32\x17.pubsub.pb.ControlIHave\x12&\n\x05iwant\x18\x02 \x03(\x0b\x32\x17.pubsub.pb.ControlIWant\x12&\n\x05graft\x18\x03 \x03(\x0b\x32\x17.pubsub.pb.ControlGraft\x12&\n\x05prune\x18\x04 \x03(\x0b\x32\x17.pubsub.pb.ControlPrune"3\n\x0c\x43ontrolIHave\x12\x0f\n\x07topicID\x18\x01 \x01(\t\x12\x12\n\nmessageIDs\x18\x02 \x03(\t""\n\x0c\x43ontrolIWant\x12\x12\n\nmessageIDs\x18\x01 \x03(\t"\x1f\n\x0c\x43ontrolGraft\x12\x0f\n\x07topicID\x18\x01 \x01(\t"\x1f\n\x0c\x43ontrolPrune\x12\x0f\n\x07topicID\x18\x01 \x01(\t"\x87\x03\n\x0fTopicDescriptor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04\x61uth\x18\x02 \x01(\x0b\x32#.pubsub.pb.TopicDescriptor.AuthOpts\x12/\n\x03\x65nc\x18\x03 \x01(\x0b\x32".pubsub.pb.TopicDescriptor.EncOpts\x1a|\n\x08\x41uthOpts\x12:\n\x04mode\x18\x01 \x01(\x0e\x32,.pubsub.pb.TopicDescriptor.AuthOpts.AuthMode\x12\x0c\n\x04keys\x18\x02 \x03(\x0c"&\n\x08\x41uthMode\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x83\x01\n\x07\x45ncOpts\x12\x38\n\x04mode\x18\x01 \x01(\x0e\x32*.pubsub.pb.TopicDescriptor.EncOpts.EncMode\x12\x11\n\tkeyHashes\x18\x02 \x03(\x0c"+\n\x07\x45ncMode\x12\x08\n\x04NONE\x10\x00\x12\r\n\tSHAREDKEY\x10\x01\x12\x07\n\x03WOT\x10\x02' + ), ) - _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE = _descriptor.EnumDescriptor( - name='AuthMode', - full_name='pubsub.pb.TopicDescriptor.AuthOpts.AuthMode', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='NONE', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='KEY', index=1, number=1, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WOT', index=2, number=2, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=885, - serialized_end=923, + name="AuthMode", + full_name="pubsub.pb.TopicDescriptor.AuthOpts.AuthMode", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="NONE", index=0, number=0, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="KEY", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="WOT", index=2, number=2, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=885, + serialized_end=923, ) _sym_db.RegisterEnumDescriptor(_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE) _TOPICDESCRIPTOR_ENCOPTS_ENCMODE = _descriptor.EnumDescriptor( - name='EncMode', - full_name='pubsub.pb.TopicDescriptor.EncOpts.EncMode', - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name='NONE', index=0, number=0, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='SHAREDKEY', index=1, number=1, - serialized_options=None, - type=None), - _descriptor.EnumValueDescriptor( - name='WOT', index=2, number=2, - serialized_options=None, - type=None), - ], - containing_type=None, - serialized_options=None, - serialized_start=1014, - serialized_end=1057, + name="EncMode", + full_name="pubsub.pb.TopicDescriptor.EncOpts.EncMode", + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name="NONE", index=0, number=0, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="SHAREDKEY", index=1, number=1, serialized_options=None, type=None + ), + _descriptor.EnumValueDescriptor( + name="WOT", index=2, number=2, serialized_options=None, type=None + ), + ], + containing_type=None, + serialized_options=None, + serialized_start=1014, + serialized_end=1057, ) _sym_db.RegisterEnumDescriptor(_TOPICDESCRIPTOR_ENCOPTS_ENCMODE) _RPC_SUBOPTS = _descriptor.Descriptor( - name='SubOpts', - full_name='pubsub.pb.RPC.SubOpts', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='subscribe', full_name='pubsub.pb.RPC.SubOpts.subscribe', index=0, - number=1, type=8, cpp_type=7, label=1, - has_default_value=False, default_value=False, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='topicid', full_name='pubsub.pb.RPC.SubOpts.topicid', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=177, - serialized_end=222, + name="SubOpts", + full_name="pubsub.pb.RPC.SubOpts", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="subscribe", + full_name="pubsub.pb.RPC.SubOpts.subscribe", + index=0, + number=1, + type=8, + cpp_type=7, + label=1, + has_default_value=False, + default_value=False, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="topicid", + full_name="pubsub.pb.RPC.SubOpts.topicid", + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=177, + serialized_end=222, ) _RPC = _descriptor.Descriptor( - name='RPC', - full_name='pubsub.pb.RPC', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='subscriptions', full_name='pubsub.pb.RPC.subscriptions', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='publish', full_name='pubsub.pb.RPC.publish', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='control', full_name='pubsub.pb.RPC.control', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[_RPC_SUBOPTS, ], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=42, - serialized_end=222, + name="RPC", + full_name="pubsub.pb.RPC", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="subscriptions", + full_name="pubsub.pb.RPC.subscriptions", + index=0, + number=1, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="publish", + full_name="pubsub.pb.RPC.publish", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="control", + full_name="pubsub.pb.RPC.control", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[ + _RPC_SUBOPTS, + ], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=42, + serialized_end=222, ) _MESSAGE = _descriptor.Descriptor( - name='Message', - full_name='pubsub.pb.Message', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='from_id', full_name='pubsub.pb.Message.from_id', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='data', full_name='pubsub.pb.Message.data', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='seqno', full_name='pubsub.pb.Message.seqno', index=2, - number=3, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='topicIDs', full_name='pubsub.pb.Message.topicIDs', index=3, - number=4, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='signature', full_name='pubsub.pb.Message.signature', index=4, - number=5, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='key', full_name='pubsub.pb.Message.key', index=5, - number=6, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=224, - serialized_end=329, + name="Message", + full_name="pubsub.pb.Message", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="from_id", + full_name="pubsub.pb.Message.from_id", + index=0, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data", + full_name="pubsub.pb.Message.data", + index=1, + number=2, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="seqno", + full_name="pubsub.pb.Message.seqno", + index=2, + number=3, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="topicIDs", + full_name="pubsub.pb.Message.topicIDs", + index=3, + number=4, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="signature", + full_name="pubsub.pb.Message.signature", + index=4, + number=5, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="key", + full_name="pubsub.pb.Message.key", + index=5, + number=6, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=224, + serialized_end=329, ) _CONTROLMESSAGE = _descriptor.Descriptor( - name='ControlMessage', - full_name='pubsub.pb.ControlMessage', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='ihave', full_name='pubsub.pb.ControlMessage.ihave', index=0, - number=1, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='iwant', full_name='pubsub.pb.ControlMessage.iwant', index=1, - number=2, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='graft', full_name='pubsub.pb.ControlMessage.graft', index=2, - number=3, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='prune', full_name='pubsub.pb.ControlMessage.prune', index=3, - number=4, type=11, cpp_type=10, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=332, - serialized_end=508, + name="ControlMessage", + full_name="pubsub.pb.ControlMessage", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="ihave", + full_name="pubsub.pb.ControlMessage.ihave", + index=0, + number=1, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="iwant", + full_name="pubsub.pb.ControlMessage.iwant", + index=1, + number=2, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="graft", + full_name="pubsub.pb.ControlMessage.graft", + index=2, + number=3, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="prune", + full_name="pubsub.pb.ControlMessage.prune", + index=3, + number=4, + type=11, + cpp_type=10, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=332, + serialized_end=508, ) _CONTROLIHAVE = _descriptor.Descriptor( - name='ControlIHave', - full_name='pubsub.pb.ControlIHave', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='topicID', full_name='pubsub.pb.ControlIHave.topicID', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='messageIDs', full_name='pubsub.pb.ControlIHave.messageIDs', index=1, - number=2, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=510, - serialized_end=561, + name="ControlIHave", + full_name="pubsub.pb.ControlIHave", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="topicID", + full_name="pubsub.pb.ControlIHave.topicID", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="messageIDs", + full_name="pubsub.pb.ControlIHave.messageIDs", + index=1, + number=2, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=510, + serialized_end=561, ) _CONTROLIWANT = _descriptor.Descriptor( - name='ControlIWant', - full_name='pubsub.pb.ControlIWant', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='messageIDs', full_name='pubsub.pb.ControlIWant.messageIDs', index=0, - number=1, type=9, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=563, - serialized_end=597, + name="ControlIWant", + full_name="pubsub.pb.ControlIWant", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="messageIDs", + full_name="pubsub.pb.ControlIWant.messageIDs", + index=0, + number=1, + type=9, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=563, + serialized_end=597, ) _CONTROLGRAFT = _descriptor.Descriptor( - name='ControlGraft', - full_name='pubsub.pb.ControlGraft', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='topicID', full_name='pubsub.pb.ControlGraft.topicID', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=599, - serialized_end=630, + name="ControlGraft", + full_name="pubsub.pb.ControlGraft", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="topicID", + full_name="pubsub.pb.ControlGraft.topicID", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=599, + serialized_end=630, ) _CONTROLPRUNE = _descriptor.Descriptor( - name='ControlPrune', - full_name='pubsub.pb.ControlPrune', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='topicID', full_name='pubsub.pb.ControlPrune.topicID', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=632, - serialized_end=663, + name="ControlPrune", + full_name="pubsub.pb.ControlPrune", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="topicID", + full_name="pubsub.pb.ControlPrune.topicID", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=632, + serialized_end=663, ) _TOPICDESCRIPTOR_AUTHOPTS = _descriptor.Descriptor( - name='AuthOpts', - full_name='pubsub.pb.TopicDescriptor.AuthOpts', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mode', full_name='pubsub.pb.TopicDescriptor.AuthOpts.mode', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='keys', full_name='pubsub.pb.TopicDescriptor.AuthOpts.keys', index=1, - number=2, type=12, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE, - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=799, - serialized_end=923, + name="AuthOpts", + full_name="pubsub.pb.TopicDescriptor.AuthOpts", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="mode", + full_name="pubsub.pb.TopicDescriptor.AuthOpts.mode", + index=0, + number=1, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="keys", + full_name="pubsub.pb.TopicDescriptor.AuthOpts.keys", + index=1, + number=2, + type=12, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[ + _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE, + ], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=799, + serialized_end=923, ) _TOPICDESCRIPTOR_ENCOPTS = _descriptor.Descriptor( - name='EncOpts', - full_name='pubsub.pb.TopicDescriptor.EncOpts', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='mode', full_name='pubsub.pb.TopicDescriptor.EncOpts.mode', index=0, - number=1, type=14, cpp_type=8, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='keyHashes', full_name='pubsub.pb.TopicDescriptor.EncOpts.keyHashes', index=1, - number=2, type=12, cpp_type=9, label=3, - has_default_value=False, default_value=[], - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - _TOPICDESCRIPTOR_ENCOPTS_ENCMODE, - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=926, - serialized_end=1057, + name="EncOpts", + full_name="pubsub.pb.TopicDescriptor.EncOpts", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="mode", + full_name="pubsub.pb.TopicDescriptor.EncOpts.mode", + index=0, + number=1, + type=14, + cpp_type=8, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="keyHashes", + full_name="pubsub.pb.TopicDescriptor.EncOpts.keyHashes", + index=1, + number=2, + type=12, + cpp_type=9, + label=3, + has_default_value=False, + default_value=[], + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[ + _TOPICDESCRIPTOR_ENCOPTS_ENCMODE, + ], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=926, + serialized_end=1057, ) _TOPICDESCRIPTOR = _descriptor.Descriptor( - name='TopicDescriptor', - full_name='pubsub.pb.TopicDescriptor', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='name', full_name='pubsub.pb.TopicDescriptor.name', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='auth', full_name='pubsub.pb.TopicDescriptor.auth', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='enc', full_name='pubsub.pb.TopicDescriptor.enc', index=2, - number=3, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[_TOPICDESCRIPTOR_AUTHOPTS, _TOPICDESCRIPTOR_ENCOPTS, ], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=666, - serialized_end=1057, + name="TopicDescriptor", + full_name="pubsub.pb.TopicDescriptor", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="name", + full_name="pubsub.pb.TopicDescriptor.name", + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="auth", + full_name="pubsub.pb.TopicDescriptor.auth", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="enc", + full_name="pubsub.pb.TopicDescriptor.enc", + index=2, + number=3, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[ + _TOPICDESCRIPTOR_AUTHOPTS, + _TOPICDESCRIPTOR_ENCOPTS, + ], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=666, + serialized_end=1057, ) _RPC_SUBOPTS.containing_type = _RPC -_RPC.fields_by_name['subscriptions'].message_type = _RPC_SUBOPTS -_RPC.fields_by_name['publish'].message_type = _MESSAGE -_RPC.fields_by_name['control'].message_type = _CONTROLMESSAGE -_CONTROLMESSAGE.fields_by_name['ihave'].message_type = _CONTROLIHAVE -_CONTROLMESSAGE.fields_by_name['iwant'].message_type = _CONTROLIWANT -_CONTROLMESSAGE.fields_by_name['graft'].message_type = _CONTROLGRAFT -_CONTROLMESSAGE.fields_by_name['prune'].message_type = _CONTROLPRUNE -_TOPICDESCRIPTOR_AUTHOPTS.fields_by_name['mode'].enum_type = _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE +_RPC.fields_by_name["subscriptions"].message_type = _RPC_SUBOPTS +_RPC.fields_by_name["publish"].message_type = _MESSAGE +_RPC.fields_by_name["control"].message_type = _CONTROLMESSAGE +_CONTROLMESSAGE.fields_by_name["ihave"].message_type = _CONTROLIHAVE +_CONTROLMESSAGE.fields_by_name["iwant"].message_type = _CONTROLIWANT +_CONTROLMESSAGE.fields_by_name["graft"].message_type = _CONTROLGRAFT +_CONTROLMESSAGE.fields_by_name["prune"].message_type = _CONTROLPRUNE +_TOPICDESCRIPTOR_AUTHOPTS.fields_by_name[ + "mode" +].enum_type = _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE _TOPICDESCRIPTOR_AUTHOPTS.containing_type = _TOPICDESCRIPTOR _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE.containing_type = _TOPICDESCRIPTOR_AUTHOPTS -_TOPICDESCRIPTOR_ENCOPTS.fields_by_name['mode'].enum_type = _TOPICDESCRIPTOR_ENCOPTS_ENCMODE +_TOPICDESCRIPTOR_ENCOPTS.fields_by_name[ + "mode" +].enum_type = _TOPICDESCRIPTOR_ENCOPTS_ENCMODE _TOPICDESCRIPTOR_ENCOPTS.containing_type = _TOPICDESCRIPTOR _TOPICDESCRIPTOR_ENCOPTS_ENCMODE.containing_type = _TOPICDESCRIPTOR_ENCOPTS -_TOPICDESCRIPTOR.fields_by_name['auth'].message_type = _TOPICDESCRIPTOR_AUTHOPTS -_TOPICDESCRIPTOR.fields_by_name['enc'].message_type = _TOPICDESCRIPTOR_ENCOPTS -DESCRIPTOR.message_types_by_name['RPC'] = _RPC -DESCRIPTOR.message_types_by_name['Message'] = _MESSAGE -DESCRIPTOR.message_types_by_name['ControlMessage'] = _CONTROLMESSAGE -DESCRIPTOR.message_types_by_name['ControlIHave'] = _CONTROLIHAVE -DESCRIPTOR.message_types_by_name['ControlIWant'] = _CONTROLIWANT -DESCRIPTOR.message_types_by_name['ControlGraft'] = _CONTROLGRAFT -DESCRIPTOR.message_types_by_name['ControlPrune'] = _CONTROLPRUNE -DESCRIPTOR.message_types_by_name['TopicDescriptor'] = _TOPICDESCRIPTOR +_TOPICDESCRIPTOR.fields_by_name["auth"].message_type = _TOPICDESCRIPTOR_AUTHOPTS +_TOPICDESCRIPTOR.fields_by_name["enc"].message_type = _TOPICDESCRIPTOR_ENCOPTS +DESCRIPTOR.message_types_by_name["RPC"] = _RPC +DESCRIPTOR.message_types_by_name["Message"] = _MESSAGE +DESCRIPTOR.message_types_by_name["ControlMessage"] = _CONTROLMESSAGE +DESCRIPTOR.message_types_by_name["ControlIHave"] = _CONTROLIHAVE +DESCRIPTOR.message_types_by_name["ControlIWant"] = _CONTROLIWANT +DESCRIPTOR.message_types_by_name["ControlGraft"] = _CONTROLGRAFT +DESCRIPTOR.message_types_by_name["ControlPrune"] = _CONTROLPRUNE +DESCRIPTOR.message_types_by_name["TopicDescriptor"] = _TOPICDESCRIPTOR _sym_db.RegisterFileDescriptor(DESCRIPTOR) -RPC = _reflection.GeneratedProtocolMessageType('RPC', (_message.Message,), { - - 'SubOpts' : _reflection.GeneratedProtocolMessageType('SubOpts', (_message.Message,), { - 'DESCRIPTOR' : _RPC_SUBOPTS, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.RPC.SubOpts) - }) - , - 'DESCRIPTOR' : _RPC, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.RPC) - }) +RPC = _reflection.GeneratedProtocolMessageType( + "RPC", + (_message.Message,), + { + "SubOpts": _reflection.GeneratedProtocolMessageType( + "SubOpts", + (_message.Message,), + { + "DESCRIPTOR": _RPC_SUBOPTS, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.RPC.SubOpts) + }, + ), + "DESCRIPTOR": _RPC, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.RPC) + }, +) _sym_db.RegisterMessage(RPC) _sym_db.RegisterMessage(RPC.SubOpts) -Message = _reflection.GeneratedProtocolMessageType('Message', (_message.Message,), { - 'DESCRIPTOR' : _MESSAGE, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.Message) - }) +Message = _reflection.GeneratedProtocolMessageType( + "Message", + (_message.Message,), + { + "DESCRIPTOR": _MESSAGE, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.Message) + }, +) _sym_db.RegisterMessage(Message) -ControlMessage = _reflection.GeneratedProtocolMessageType('ControlMessage', (_message.Message,), { - 'DESCRIPTOR' : _CONTROLMESSAGE, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlMessage) - }) +ControlMessage = _reflection.GeneratedProtocolMessageType( + "ControlMessage", + (_message.Message,), + { + "DESCRIPTOR": _CONTROLMESSAGE, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.ControlMessage) + }, +) _sym_db.RegisterMessage(ControlMessage) -ControlIHave = _reflection.GeneratedProtocolMessageType('ControlIHave', (_message.Message,), { - 'DESCRIPTOR' : _CONTROLIHAVE, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIHave) - }) +ControlIHave = _reflection.GeneratedProtocolMessageType( + "ControlIHave", + (_message.Message,), + { + "DESCRIPTOR": _CONTROLIHAVE, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIHave) + }, +) _sym_db.RegisterMessage(ControlIHave) -ControlIWant = _reflection.GeneratedProtocolMessageType('ControlIWant', (_message.Message,), { - 'DESCRIPTOR' : _CONTROLIWANT, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIWant) - }) +ControlIWant = _reflection.GeneratedProtocolMessageType( + "ControlIWant", + (_message.Message,), + { + "DESCRIPTOR": _CONTROLIWANT, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIWant) + }, +) _sym_db.RegisterMessage(ControlIWant) -ControlGraft = _reflection.GeneratedProtocolMessageType('ControlGraft', (_message.Message,), { - 'DESCRIPTOR' : _CONTROLGRAFT, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlGraft) - }) +ControlGraft = _reflection.GeneratedProtocolMessageType( + "ControlGraft", + (_message.Message,), + { + "DESCRIPTOR": _CONTROLGRAFT, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.ControlGraft) + }, +) _sym_db.RegisterMessage(ControlGraft) -ControlPrune = _reflection.GeneratedProtocolMessageType('ControlPrune', (_message.Message,), { - 'DESCRIPTOR' : _CONTROLPRUNE, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlPrune) - }) +ControlPrune = _reflection.GeneratedProtocolMessageType( + "ControlPrune", + (_message.Message,), + { + "DESCRIPTOR": _CONTROLPRUNE, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.ControlPrune) + }, +) _sym_db.RegisterMessage(ControlPrune) -TopicDescriptor = _reflection.GeneratedProtocolMessageType('TopicDescriptor', (_message.Message,), { - - 'AuthOpts' : _reflection.GeneratedProtocolMessageType('AuthOpts', (_message.Message,), { - 'DESCRIPTOR' : _TOPICDESCRIPTOR_AUTHOPTS, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.AuthOpts) - }) - , - - 'EncOpts' : _reflection.GeneratedProtocolMessageType('EncOpts', (_message.Message,), { - 'DESCRIPTOR' : _TOPICDESCRIPTOR_ENCOPTS, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.EncOpts) - }) - , - 'DESCRIPTOR' : _TOPICDESCRIPTOR, - '__module__' : 'libp2p.pubsub.pb.rpc_pb2' - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor) - }) +TopicDescriptor = _reflection.GeneratedProtocolMessageType( + "TopicDescriptor", + (_message.Message,), + { + "AuthOpts": _reflection.GeneratedProtocolMessageType( + "AuthOpts", + (_message.Message,), + { + "DESCRIPTOR": _TOPICDESCRIPTOR_AUTHOPTS, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.AuthOpts) + }, + ), + "EncOpts": _reflection.GeneratedProtocolMessageType( + "EncOpts", + (_message.Message,), + { + "DESCRIPTOR": _TOPICDESCRIPTOR_ENCOPTS, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.EncOpts) + }, + ), + "DESCRIPTOR": _TOPICDESCRIPTOR, + "__module__": "libp2p.pubsub.pb.rpc_pb2" + # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor) + }, +) _sym_db.RegisterMessage(TopicDescriptor) _sym_db.RegisterMessage(TopicDescriptor.AuthOpts) _sym_db.RegisterMessage(TopicDescriptor.EncOpts) diff --git a/libp2p/pubsub/pb/rpc_pb2.pyi b/libp2p/pubsub/pb/rpc_pb2.pyi index 75c7c1e8..e19179dc 100644 --- a/libp2p/pubsub/pb/rpc_pb2.pyi +++ b/libp2p/pubsub/pb/rpc_pb2.pyi @@ -27,197 +27,352 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class RPC(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + class SubOpts(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - subscribe = ... # type: bool - topicid = ... # type: typing___Text + subscribe = ... # type: bool + topicid = ... # type: typing___Text - def __init__(self, + def __init__( + self, *, - subscribe : typing___Optional[bool] = None, - topicid : typing___Optional[typing___Text] = None, - ) -> None: ... + subscribe: typing___Optional[bool] = None, + topicid: typing___Optional[typing___Text] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> RPC.SubOpts: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... + def MergeFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... + def CopyFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"subscribe",u"topicid"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"subscribe",u"topicid"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["subscribe", "topicid"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["subscribe", "topicid"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"subscribe",b"subscribe",u"topicid",b"topicid"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"subscribe",b"subscribe",u"topicid",b"topicid"]) -> None: ... - + def HasField( + self, + field_name: typing_extensions___Literal[ + "subscribe", b"subscribe", "topicid", b"topicid" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "subscribe", b"subscribe", "topicid", b"topicid" + ], + ) -> None: ... @property - def subscriptions(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[RPC.SubOpts]: ... - + def subscriptions( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + RPC.SubOpts + ]: ... @property - def publish(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[Message]: ... - + def publish( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + Message + ]: ... @property def control(self) -> ControlMessage: ... - - def __init__(self, + def __init__( + self, *, - subscriptions : typing___Optional[typing___Iterable[RPC.SubOpts]] = None, - publish : typing___Optional[typing___Iterable[Message]] = None, - control : typing___Optional[ControlMessage] = None, - ) -> None: ... + subscriptions: typing___Optional[typing___Iterable[RPC.SubOpts]] = None, + publish: typing___Optional[typing___Iterable[Message]] = None, + control: typing___Optional[ControlMessage] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> RPC: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"control"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"control",u"publish",u"subscriptions"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["control"] + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "control", "publish", "subscriptions" + ], + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"control",b"control"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"control",b"control",u"publish",b"publish",u"subscriptions",b"subscriptions"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["control", b"control"] + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "control", + b"control", + "publish", + b"publish", + "subscriptions", + b"subscriptions", + ], + ) -> None: ... class Message(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - from_id = ... # type: bytes - data = ... # type: bytes - seqno = ... # type: bytes - topicIDs = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] - signature = ... # type: bytes - key = ... # type: bytes + from_id = ... # type: bytes + data = ... # type: bytes + seqno = ... # type: bytes + topicIDs = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] + signature = ... # type: bytes + key = ... # type: bytes - def __init__(self, + def __init__( + self, *, - from_id : typing___Optional[bytes] = None, - data : typing___Optional[bytes] = None, - seqno : typing___Optional[bytes] = None, - topicIDs : typing___Optional[typing___Iterable[typing___Text]] = None, - signature : typing___Optional[bytes] = None, - key : typing___Optional[bytes] = None, - ) -> None: ... + from_id: typing___Optional[bytes] = None, + data: typing___Optional[bytes] = None, + seqno: typing___Optional[bytes] = None, + topicIDs: typing___Optional[typing___Iterable[typing___Text]] = None, + signature: typing___Optional[bytes] = None, + key: typing___Optional[bytes] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> Message: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"data",u"from_id",u"key",u"seqno",u"signature"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",u"from_id",u"key",u"seqno",u"signature",u"topicIDs"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "data", "from_id", "key", "seqno", "signature" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", "from_id", "key", "seqno", "signature", "topicIDs" + ], + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"data",b"data",u"from_id",b"from_id",u"key",b"key",u"seqno",b"seqno",u"signature",b"signature"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"from_id",b"from_id",u"key",b"key",u"seqno",b"seqno",u"signature",b"signature",u"topicIDs",b"topicIDs"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "data", + b"data", + "from_id", + b"from_id", + "key", + b"key", + "seqno", + b"seqno", + "signature", + b"signature", + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", + b"data", + "from_id", + b"from_id", + "key", + b"key", + "seqno", + b"seqno", + "signature", + b"signature", + "topicIDs", + b"topicIDs", + ], + ) -> None: ... class ControlMessage(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... @property - def ihave(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ControlIHave]: ... - + def ihave( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + ControlIHave + ]: ... @property - def iwant(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ControlIWant]: ... - + def iwant( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + ControlIWant + ]: ... @property - def graft(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ControlGraft]: ... - + def graft( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + ControlGraft + ]: ... @property - def prune(self) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ControlPrune]: ... - - def __init__(self, + def prune( + self, + ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ + ControlPrune + ]: ... + def __init__( + self, *, - ihave : typing___Optional[typing___Iterable[ControlIHave]] = None, - iwant : typing___Optional[typing___Iterable[ControlIWant]] = None, - graft : typing___Optional[typing___Iterable[ControlGraft]] = None, - prune : typing___Optional[typing___Iterable[ControlPrune]] = None, - ) -> None: ... + ihave: typing___Optional[typing___Iterable[ControlIHave]] = None, + iwant: typing___Optional[typing___Iterable[ControlIWant]] = None, + graft: typing___Optional[typing___Iterable[ControlGraft]] = None, + prune: typing___Optional[typing___Iterable[ControlPrune]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> ControlMessage: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def ClearField(self, field_name: typing_extensions___Literal[u"graft",u"ihave",u"iwant",u"prune"]) -> None: ... + def ClearField( + self, + field_name: typing_extensions___Literal["graft", "ihave", "iwant", "prune"], + ) -> None: ... else: - def ClearField(self, field_name: typing_extensions___Literal[u"graft",b"graft",u"ihave",b"ihave",u"iwant",b"iwant",u"prune",b"prune"]) -> None: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "graft", + b"graft", + "ihave", + b"ihave", + "iwant", + b"iwant", + "prune", + b"prune", + ], + ) -> None: ... class ControlIHave(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text - messageIDs = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] + topicID = ... # type: typing___Text + messageIDs = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] - def __init__(self, + def __init__( + self, *, - topicID : typing___Optional[typing___Text] = None, - messageIDs : typing___Optional[typing___Iterable[typing___Text]] = None, - ) -> None: ... + topicID: typing___Optional[typing___Text] = None, + messageIDs: typing___Optional[typing___Iterable[typing___Text]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> ControlIHave: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"messageIDs",u"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["messageIDs", "topicID"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"topicID",b"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"messageIDs",b"messageIDs",u"topicID",b"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID", b"topicID"] + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "messageIDs", b"messageIDs", "topicID", b"topicID" + ], + ) -> None: ... class ControlIWant(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - messageIDs = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] + messageIDs = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] - def __init__(self, + def __init__( + self, *, - messageIDs : typing___Optional[typing___Iterable[typing___Text]] = None, - ) -> None: ... + messageIDs: typing___Optional[typing___Iterable[typing___Text]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> ControlIWant: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def ClearField(self, field_name: typing_extensions___Literal[u"messageIDs"]) -> None: ... + def ClearField( + self, field_name: typing_extensions___Literal["messageIDs"] + ) -> None: ... else: - def ClearField(self, field_name: typing_extensions___Literal[u"messageIDs",b"messageIDs"]) -> None: ... + def ClearField( + self, field_name: typing_extensions___Literal["messageIDs", b"messageIDs"] + ) -> None: ... class ControlGraft(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text + topicID = ... # type: typing___Text - def __init__(self, + def __init__( + self, *, - topicID : typing___Optional[typing___Text] = None, - ) -> None: ... + topicID: typing___Optional[typing___Text] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> ControlGraft: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["topicID"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"topicID",b"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"topicID",b"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID", b"topicID"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["topicID", b"topicID"] + ) -> None: ... class ControlPrune(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text + topicID = ... # type: typing___Text - def __init__(self, + def __init__( + self, *, - topicID : typing___Optional[typing___Text] = None, - ) -> None: ... + topicID: typing___Optional[typing___Text] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> ControlPrune: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["topicID"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"topicID",b"topicID"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"topicID",b"topicID"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["topicID", b"topicID"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["topicID", b"topicID"] + ) -> None: ... class TopicDescriptor(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + class AuthOpts(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + class AuthMode(int): DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... @classmethod @@ -229,7 +384,11 @@ class TopicDescriptor(google___protobuf___message___Message): @classmethod def values(cls) -> typing___List[TopicDescriptor.AuthOpts.AuthMode]: ... @classmethod - def items(cls) -> typing___List[typing___Tuple[str, TopicDescriptor.AuthOpts.AuthMode]]: ... + def items( + cls, + ) -> typing___List[ + typing___Tuple[str, TopicDescriptor.AuthOpts.AuthMode] + ]: ... NONE = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 0) KEY = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 1) WOT = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 2) @@ -237,27 +396,46 @@ class TopicDescriptor(google___protobuf___message___Message): KEY = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 1) WOT = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 2) - mode = ... # type: TopicDescriptor.AuthOpts.AuthMode - keys = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] + mode = ... # type: TopicDescriptor.AuthOpts.AuthMode + keys = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] - def __init__(self, + def __init__( + self, *, - mode : typing___Optional[TopicDescriptor.AuthOpts.AuthMode] = None, - keys : typing___Optional[typing___Iterable[bytes]] = None, - ) -> None: ... + mode: typing___Optional[TopicDescriptor.AuthOpts.AuthMode] = None, + keys: typing___Optional[typing___Iterable[bytes]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> TopicDescriptor.AuthOpts: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... + def MergeFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... + def CopyFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"mode"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"keys",u"mode"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["mode"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["keys", "mode"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"mode",b"mode"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"keys",b"keys",u"mode",b"mode"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["mode", b"mode"] + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "keys", b"keys", "mode", b"mode" + ], + ) -> None: ... class EncOpts(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + class EncMode(int): DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... @classmethod @@ -269,7 +447,11 @@ class TopicDescriptor(google___protobuf___message___Message): @classmethod def values(cls) -> typing___List[TopicDescriptor.EncOpts.EncMode]: ... @classmethod - def items(cls) -> typing___List[typing___Tuple[str, TopicDescriptor.EncOpts.EncMode]]: ... + def items( + cls, + ) -> typing___List[ + typing___Tuple[str, TopicDescriptor.EncOpts.EncMode] + ]: ... NONE = typing___cast(TopicDescriptor.EncOpts.EncMode, 0) SHAREDKEY = typing___cast(TopicDescriptor.EncOpts.EncMode, 1) WOT = typing___cast(TopicDescriptor.EncOpts.EncMode, 2) @@ -277,46 +459,77 @@ class TopicDescriptor(google___protobuf___message___Message): SHAREDKEY = typing___cast(TopicDescriptor.EncOpts.EncMode, 1) WOT = typing___cast(TopicDescriptor.EncOpts.EncMode, 2) - mode = ... # type: TopicDescriptor.EncOpts.EncMode - keyHashes = ... # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] + mode = ... # type: TopicDescriptor.EncOpts.EncMode + keyHashes = ( + ... + ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] - def __init__(self, + def __init__( + self, *, - mode : typing___Optional[TopicDescriptor.EncOpts.EncMode] = None, - keyHashes : typing___Optional[typing___Iterable[bytes]] = None, - ) -> None: ... + mode: typing___Optional[TopicDescriptor.EncOpts.EncMode] = None, + keyHashes: typing___Optional[typing___Iterable[bytes]] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> TopicDescriptor.EncOpts: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... + def MergeFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... + def CopyFrom( + self, other_msg: google___protobuf___message___Message + ) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"mode"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"keyHashes",u"mode"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["mode"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["keyHashes", "mode"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"mode",b"mode"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"keyHashes",b"keyHashes",u"mode",b"mode"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["mode", b"mode"] + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "keyHashes", b"keyHashes", "mode", b"mode" + ], + ) -> None: ... - name = ... # type: typing___Text + name = ... # type: typing___Text @property def auth(self) -> TopicDescriptor.AuthOpts: ... - @property def enc(self) -> TopicDescriptor.EncOpts: ... - - def __init__(self, + def __init__( + self, *, - name : typing___Optional[typing___Text] = None, - auth : typing___Optional[TopicDescriptor.AuthOpts] = None, - enc : typing___Optional[TopicDescriptor.EncOpts] = None, - ) -> None: ... + name: typing___Optional[typing___Text] = None, + auth: typing___Optional[TopicDescriptor.AuthOpts] = None, + enc: typing___Optional[TopicDescriptor.EncOpts] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> TopicDescriptor: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"auth",u"enc",u"name"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"auth",u"enc",u"name"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["auth", "enc", "name"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["auth", "enc", "name"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"auth",b"auth",u"enc",b"enc",u"name",b"name"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"auth",b"auth",u"enc",b"enc",u"name",b"name"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "auth", b"auth", "enc", b"enc", "name", b"name" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "auth", b"auth", "enc", b"enc", "name", b"name" + ], + ) -> None: ... diff --git a/libp2p/pubsub/pubsub.py b/libp2p/pubsub/pubsub.py index 965fc580..dd7bd52f 100644 --- a/libp2p/pubsub/pubsub.py +++ b/libp2p/pubsub/pubsub.py @@ -15,33 +15,78 @@ from typing import ( cast, ) -from async_service import Service +from async_service import ( + Service, +) import base58 -from lru import LRU +from lru import ( + LRU, +) import trio -from libp2p.crypto.keys import PrivateKey -from libp2p.exceptions import ParseError, ValidationError -from libp2p.host.host_interface import IHost -from libp2p.io.exceptions import IncompleteReadError -from libp2p.network.exceptions import SwarmException -from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.peer.id import ID -from libp2p.typing import TProtocol -from libp2p.utils import encode_varint_prefixed, read_varint_prefixed_bytes +from libp2p.crypto.keys import ( + PrivateKey, +) +from libp2p.exceptions import ( + ParseError, + ValidationError, +) +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.io.exceptions import ( + IncompleteReadError, +) +from libp2p.network.exceptions import ( + SwarmException, +) +from libp2p.network.stream.exceptions import ( + StreamClosed, + StreamEOF, + StreamReset, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.typing import ( + TProtocol, +) +from libp2p.utils import ( + encode_varint_prefixed, + read_varint_prefixed_bytes, +) -from .abc import IPubsub, ISubscriptionAPI -from .pb import rpc_pb2 -from .pubsub_notifee import PubsubNotifee -from .subscription import TrioSubscriptionAPI -from .typing import AsyncValidatorFn, SyncValidatorFn, ValidatorFn -from .validators import PUBSUB_SIGNING_PREFIX, signature_validator +from .abc import ( + IPubsub, + ISubscriptionAPI, +) +from .pb import ( + rpc_pb2, +) +from .pubsub_notifee import ( + PubsubNotifee, +) +from .subscription import ( + TrioSubscriptionAPI, +) +from .typing import ( + AsyncValidatorFn, + SyncValidatorFn, + ValidatorFn, +) +from .validators import ( + PUBSUB_SIGNING_PREFIX, + signature_validator, +) if TYPE_CHECKING: - from .abc import IPubsubRouter # noqa: F401 from typing import Any # noqa: F401 + from .abc import IPubsubRouter # noqa: F401 + # Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/40e1c94708658b155f30cf99e4574f384756d83c/topic.go#L97 # noqa: E501 SUBSCRIPTION_CHANNEL_SIZE = 32 @@ -64,7 +109,6 @@ class TopicValidator(NamedTuple): class Pubsub(Service, IPubsub): - host: IHost router: "IPubsubRouter" @@ -186,8 +230,10 @@ class Pubsub(Service, IPubsub): return self.subscribed_topics_receive.keys() def get_hello_packet(self) -> rpc_pb2.RPC: - """Generate subscription message with all topics we are subscribed to - only send hello packet if we have subscribed topics.""" + """ + Generate subscription message with all topics we are subscribed to + only send hello packet if we have subscribed topics. + """ packet = rpc_pb2.RPC() for topic_id in self.topic_ids: packet.subscriptions.extend( @@ -254,7 +300,7 @@ class Pubsub(Service, IPubsub): :param topic: the topic to register validator under :param validator: the validator used to validate messages published to the topic :param is_async_validator: indicate if the validator is an asynchronous validator - """ + """ # noqa: E501 self.topic_validators[topic] = TopicValidator(validator, is_async_validator) def remove_topic_validator(self, topic: str) -> None: @@ -341,9 +387,11 @@ class Pubsub(Service, IPubsub): logger.debug("removed dead peer %s", peer_id) async def handle_peer_queue(self) -> None: - """Continuously read from peer queue and each time a new peer is found, + """ + Continuously read from peer queue and each time a new peer is found, open a stream to the peer using a supported pubsub protocol pubsub - protocols we support.""" + protocols we support. + """ async with self.peer_receive_channel: self.event_handle_peer_queue_started.set() async for peer_id in self.peer_receive_channel: @@ -351,9 +399,10 @@ class Pubsub(Service, IPubsub): self.manager.run_task(self._handle_new_peer, peer_id) async def handle_dead_peer_queue(self) -> None: - """Continuously read from dead peer channel and close the stream - between that peer and remove peer info from pubsub and pubsub - router.""" + """ + Continuously read from dead peer channel and close the stream + between that peer and remove peer info from pubsub and pubsub router. + """ async with self.dead_peer_receive_channel: self.event_handle_dead_peer_queue_started.set() async for peer_id in self.dead_peer_receive_channel: @@ -373,7 +422,7 @@ class Pubsub(Service, IPubsub): """ if sub_message.subscribe: if sub_message.topicid not in self.peer_topics: - self.peer_topics[sub_message.topicid] = set([origin_id]) + self.peer_topics[sub_message.topicid] = {origin_id} elif origin_id not in self.peer_topics[sub_message.topicid]: # Add peer to topic self.peer_topics[sub_message.topicid].add(origin_id) @@ -388,7 +437,6 @@ class Pubsub(Service, IPubsub): :param publish_message: RPC.Message format """ - # Check if this message has any topics that we are subscribed to for topic in publish_message.topicIDs: if topic in self.topic_ids: @@ -409,7 +457,6 @@ class Pubsub(Service, IPubsub): :param topic_id: topic_id to subscribe to """ - logger.debug("subscribing to topic %s", topic_id) # Already subscribed @@ -448,7 +495,6 @@ class Pubsub(Service, IPubsub): :param topic_id: topic_id to unsubscribe from """ - logger.debug("unsubscribing from topic %s", topic_id) # Return if we already unsubscribed from the topic @@ -479,7 +525,6 @@ class Pubsub(Service, IPubsub): :param raw_msg: raw contents of the message to broadcast """ - # Broadcast message for stream in self.peers.values(): # Write message to stream @@ -571,7 +616,7 @@ class Pubsub(Service, IPubsub): # TODO: Check if the `from` is in the blacklist. If yes, reject. - # If the message is processed before, return(i.e., don't further process the message). + # If the message is processed before, return(i.e., don't further process the message) # noqa: E501 if self._is_msg_seen(msg): return @@ -588,7 +633,7 @@ class Pubsub(Service, IPubsub): await self.validate_msg(msg_forwarder, msg) except ValidationError: logger.debug( - "Topic validation failed: sender %s sent data %s under topic IDs: %s %s:%s", + "Topic validation failed: sender %s sent data %s under topic IDs: %s %s:%s", # noqa: E501 msg_forwarder, msg.data.hex(), msg.topicIDs, @@ -612,8 +657,8 @@ class Pubsub(Service, IPubsub): def _mark_msg_seen(self, msg: rpc_pb2.Message) -> None: msg_id = self._msg_id_constructor(msg) - # FIXME: Mapping `msg_id` to `1` is quite awkward. Should investigate if there is a - # more appropriate way. + # FIXME: Mapping `msg_id` to `1` is quite awkward. Should investigate if there + # is a more appropriate way. self.seen_messages[msg_id] = 1 def _is_subscribed_to_msg(self, msg: rpc_pb2.Message) -> bool: diff --git a/libp2p/pubsub/pubsub_notifee.py b/libp2p/pubsub/pubsub_notifee.py index 3c96e120..ae54d137 100644 --- a/libp2p/pubsub/pubsub_notifee.py +++ b/libp2p/pubsub/pubsub_notifee.py @@ -1,19 +1,30 @@ -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import trio -from libp2p.network.connection.net_connection_interface import INetConn -from libp2p.network.network_interface import INetwork -from libp2p.network.notifee_interface import INotifee -from libp2p.network.stream.net_stream_interface import INetStream +from libp2p.network.connection.net_connection_interface import ( + INetConn, +) +from libp2p.network.network_interface import ( + INetwork, +) +from libp2p.network.notifee_interface import ( + INotifee, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) if TYPE_CHECKING: from libp2p.peer.id import ID # noqa: F401 class PubsubNotifee(INotifee): - initiator_peers_queue: "trio.MemorySendChannel[ID]" dead_peers_queue: "trio.MemorySendChannel[ID]" diff --git a/libp2p/pubsub/subscription.py b/libp2p/pubsub/subscription.py index 09dffdec..27aae289 100644 --- a/libp2p/pubsub/subscription.py +++ b/libp2p/pubsub/subscription.py @@ -1,11 +1,23 @@ -from types import TracebackType -from typing import AsyncIterator, Optional, Type +from types import ( + TracebackType, +) +from typing import ( + AsyncIterator, + Optional, + Type, +) import trio -from .abc import ISubscriptionAPI -from .pb import rpc_pb2 -from .typing import UnsubscribeFn +from .abc import ( + ISubscriptionAPI, +) +from .pb import ( + rpc_pb2, +) +from .typing import ( + UnsubscribeFn, +) class BaseSubscriptionAPI(ISubscriptionAPI): @@ -32,11 +44,11 @@ class TrioSubscriptionAPI(BaseSubscriptionAPI): unsubscribe_fn: UnsubscribeFn, ) -> None: self.receive_channel = receive_channel - # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 + # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 # noqa: E501 self.unsubscribe_fn = unsubscribe_fn # type: ignore async def unsubscribe(self) -> None: - # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 + # Ignore type here since mypy complains: https://github.com/python/mypy/issues/2427 # noqa: E501 await self.unsubscribe_fn() # type: ignore def __aiter__(self) -> AsyncIterator[rpc_pb2.Message]: diff --git a/libp2p/pubsub/typing.py b/libp2p/pubsub/typing.py index 33297a9f..0683d0ae 100644 --- a/libp2p/pubsub/typing.py +++ b/libp2p/pubsub/typing.py @@ -1,8 +1,16 @@ -from typing import Awaitable, Callable, Union +from typing import ( + Awaitable, + Callable, + Union, +) -from libp2p.peer.id import ID +from libp2p.peer.id import ( + ID, +) -from .pb import rpc_pb2 +from .pb import ( + rpc_pb2, +) SyncValidatorFn = Callable[[ID, rpc_pb2.Message], bool] AsyncValidatorFn = Callable[[ID, rpc_pb2.Message], Awaitable[bool]] diff --git a/libp2p/pubsub/validators.py b/libp2p/pubsub/validators.py index 22f6579a..21c7e9c8 100644 --- a/libp2p/pubsub/validators.py +++ b/libp2p/pubsub/validators.py @@ -1,9 +1,15 @@ import logging -from libp2p.crypto.serialization import deserialize_public_key -from libp2p.peer.id import ID +from libp2p.crypto.serialization import ( + deserialize_public_key, +) +from libp2p.peer.id import ( + ID, +) -from .pb import rpc_pb2 +from .pb import ( + rpc_pb2, +) logger = logging.getLogger("libp2p.pubsub") diff --git a/libp2p/routing/interfaces.py b/libp2p/routing/interfaces.py index 24cad7e1..037a486b 100644 --- a/libp2p/routing/interfaces.py +++ b/libp2p/routing/interfaces.py @@ -1,8 +1,17 @@ -from abc import ABC, abstractmethod -from typing import Iterable +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Iterable, +) -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) class IContentRouting(ABC): @@ -18,12 +27,16 @@ class IContentRouting(ABC): @abstractmethod def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]: - """Search for peers who are able to provide a given key returns an - iterator of peer.PeerInfo.""" + """ + Search for peers who are able to provide a given key returns an + iterator of peer.PeerInfo. + """ class IPeerRouting(ABC): @abstractmethod async def find_peer(self, peer_id: ID) -> PeerInfo: - """Find specific Peer FindPeer searches for a peer with given peer_id, - returns a peer.PeerInfo with relevant addresses.""" + """ + Find specific Peer FindPeer searches for a peer with given peer_id, + returns a peer.PeerInfo with relevant addresses. + """ diff --git a/libp2p/security/base_session.py b/libp2p/security/base_session.py index abc3abb6..07ed74fc 100644 --- a/libp2p/security/base_session.py +++ b/libp2p/security/base_session.py @@ -1,13 +1,24 @@ -from typing import Optional +from typing import ( + Optional, +) -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) class BaseSession(ISecureConn): - """``BaseSession`` is not fully instantiated from its abstract classes as - it is only meant to be used in clases that derive from it.""" + """ + ``BaseSession`` is not fully instantiated from its abstract classes as + it is only meant to be used in clases that derive from it. + """ local_peer: ID local_private_key: PrivateKey diff --git a/libp2p/security/base_transport.py b/libp2p/security/base_transport.py index 916ccce8..5d055c2f 100644 --- a/libp2p/security/base_transport.py +++ b/libp2p/security/base_transport.py @@ -1,9 +1,17 @@ import secrets -from typing import Callable +from typing import ( + Callable, +) -from libp2p.crypto.keys import KeyPair -from libp2p.peer.id import ID -from libp2p.security.secure_transport_interface import ISecureTransport +from libp2p.crypto.keys import ( + KeyPair, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_transport_interface import ( + ISecureTransport, +) def default_secure_bytes_provider(n: int) -> bytes: diff --git a/libp2p/security/exceptions.py b/libp2p/security/exceptions.py index 269b2cbd..bff09d93 100644 --- a/libp2p/security/exceptions.py +++ b/libp2p/security/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class HandshakeFailure(BaseLibp2pError): diff --git a/libp2p/security/insecure/pb/plaintext_pb2.py b/libp2p/security/insecure/pb/plaintext_pb2.py index 72b27400..eabb6e49 100644 --- a/libp2p/security/insecure/pb/plaintext_pb2.py +++ b/libp2p/security/insecure/pb/plaintext_pb2.py @@ -2,12 +2,13 @@ # source: libp2p/security/insecure/pb/plaintext.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -17,62 +18,89 @@ from libp2p.crypto.pb import crypto_pb2 as libp2p_dot_crypto_dot_pb_dot_crypto__ DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/security/insecure/pb/plaintext.proto', - package='plaintext.pb', - syntax='proto2', - serialized_pb=_b('\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto\"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey') - , - dependencies=[libp2p_dot_crypto_dot_pb_dot_crypto__pb2.DESCRIPTOR,]) - - + name="libp2p/security/insecure/pb/plaintext.proto", + package="plaintext.pb", + syntax="proto2", + serialized_pb=_b( + '\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey' + ), + dependencies=[ + libp2p_dot_crypto_dot_pb_dot_crypto__pb2.DESCRIPTOR, + ], +) _EXCHANGE = _descriptor.Descriptor( - name='Exchange', - full_name='plaintext.pb.Exchange', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='id', full_name='plaintext.pb.Exchange.id', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='pubkey', full_name='plaintext.pb.Exchange.pubkey', index=1, - number=2, type=11, cpp_type=10, label=1, - has_default_value=False, default_value=None, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=92, - serialized_end=152, + name="Exchange", + full_name="plaintext.pb.Exchange", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="id", + full_name="plaintext.pb.Exchange.id", + index=0, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="pubkey", + full_name="plaintext.pb.Exchange.pubkey", + index=1, + number=2, + type=11, + cpp_type=10, + label=1, + has_default_value=False, + default_value=None, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=92, + serialized_end=152, ) -_EXCHANGE.fields_by_name['pubkey'].message_type = libp2p_dot_crypto_dot_pb_dot_crypto__pb2._PUBLICKEY -DESCRIPTOR.message_types_by_name['Exchange'] = _EXCHANGE +_EXCHANGE.fields_by_name[ + "pubkey" +].message_type = libp2p_dot_crypto_dot_pb_dot_crypto__pb2._PUBLICKEY +DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE _sym_db.RegisterFileDescriptor(DESCRIPTOR) -Exchange = _reflection.GeneratedProtocolMessageType('Exchange', (_message.Message,), dict( - DESCRIPTOR = _EXCHANGE, - __module__ = 'libp2p.security.insecure.pb.plaintext_pb2' - # @@protoc_insertion_point(class_scope:plaintext.pb.Exchange) - )) +Exchange = _reflection.GeneratedProtocolMessageType( + "Exchange", + (_message.Message,), + dict( + DESCRIPTOR=_EXCHANGE, + __module__="libp2p.security.insecure.pb.plaintext_pb2" + # @@protoc_insertion_point(class_scope:plaintext.pb.Exchange) + ), +) _sym_db.RegisterMessage(Exchange) diff --git a/libp2p/security/insecure/pb/plaintext_pb2.pyi b/libp2p/security/insecure/pb/plaintext_pb2.pyi index 641bd9a4..d5f7a3d6 100644 --- a/libp2p/security/insecure/pb/plaintext_pb2.pyi +++ b/libp2p/security/insecure/pb/plaintext_pb2.pyi @@ -20,26 +20,35 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class Exchange(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - id = ... # type: bytes + id = ... # type: bytes @property def pubkey(self) -> libp2p___crypto___pb___crypto_pb2___PublicKey: ... - - def __init__(self, + def __init__( + self, *, - id : typing___Optional[bytes] = None, - pubkey : typing___Optional[libp2p___crypto___pb___crypto_pb2___PublicKey] = None, - ) -> None: ... + id: typing___Optional[bytes] = None, + pubkey: typing___Optional[libp2p___crypto___pb___crypto_pb2___PublicKey] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> Exchange: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"id",u"pubkey"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"id",u"pubkey"]) -> None: ... + def HasField( + self, field_name: typing_extensions___Literal["id", "pubkey"] + ) -> bool: ... + def ClearField( + self, field_name: typing_extensions___Literal["id", "pubkey"] + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"id",b"id",u"pubkey",b"pubkey"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"id",b"id",u"pubkey",b"pubkey"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"], + ) -> None: ... diff --git a/libp2p/security/insecure/transport.py b/libp2p/security/insecure/transport.py index 8211944c..06610c5b 100644 --- a/libp2p/security/insecure/transport.py +++ b/libp2p/security/insecure/transport.py @@ -1,21 +1,52 @@ -from libp2p.crypto.exceptions import MissingDeserializerError -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.crypto.pb import crypto_pb2 -from libp2p.crypto.serialization import deserialize_public_key -from libp2p.io.abc import ReadWriteCloser -from libp2p.io.msgio import VarIntLengthMsgReadWriter -from libp2p.network.connection.exceptions import RawConnError -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.security.base_session import BaseSession -from libp2p.security.base_transport import BaseSecureTransport -from libp2p.security.exceptions import HandshakeFailure -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.typing import TProtocol +from libp2p.crypto.exceptions import ( + MissingDeserializerError, +) +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.crypto.pb import ( + crypto_pb2, +) +from libp2p.crypto.serialization import ( + deserialize_public_key, +) +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.io.msgio import ( + VarIntLengthMsgReadWriter, +) +from libp2p.network.connection.exceptions import ( + RawConnError, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.base_session import ( + BaseSession, +) +from libp2p.security.base_transport import ( + BaseSecureTransport, +) +from libp2p.security.exceptions import ( + HandshakeFailure, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.typing import ( + TProtocol, +) -from .pb import plaintext_pb2 +from .pb import ( + plaintext_pb2, +) -# Reference: https://github.com/libp2p/go-libp2p-core/blob/master/sec/insecure/insecure.go +# Reference: https://github.com/libp2p/go-libp2p-core/blob/master/sec/insecure/insecure.go # noqa: E501 PLAINTEXT_PROTOCOL_ID = TProtocol("/plaintext/2.0.0") @@ -120,9 +151,10 @@ async def run_handshake( class InsecureTransport(BaseSecureTransport): - """``InsecureTransport`` provides the "identity" upgrader for a - ``IRawConnection``, i.e. the upgraded transport does not add any additional - security.""" + """ + Provides the "identity" upgrader for a ``IRawConnection``, i.e. the upgraded + transport does not add any additional security. + """ async def secure_inbound(self, conn: IRawConnection) -> ISecureConn: """ diff --git a/libp2p/security/noise/exceptions.py b/libp2p/security/noise/exceptions.py index 85cf3f29..e392e7b0 100644 --- a/libp2p/security/noise/exceptions.py +++ b/libp2p/security/noise/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.security.exceptions import HandshakeFailure +from libp2p.security.exceptions import ( + HandshakeFailure, +) class NoiseFailure(HandshakeFailure): @@ -14,8 +16,10 @@ class InvalidSignature(NoiseFailure): class NoiseStateError(NoiseFailure): - """Raised when anything goes wrong in the noise state in `noiseprotocol` - package.""" + """ + Raised when anything goes wrong in the noise state in `noiseprotocol` + package. + """ class PeerIDMismatchesPubkey(NoiseFailure): diff --git a/libp2p/security/noise/io.py b/libp2p/security/noise/io.py index c6d48e48..327a5400 100644 --- a/libp2p/security/noise/io.py +++ b/libp2p/security/noise/io.py @@ -1,10 +1,20 @@ -from typing import cast +from typing import ( + cast, +) from noise.connection import NoiseConnection as NoiseState -from libp2p.io.abc import EncryptedMsgReadWriter, MsgReadWriteCloser, ReadWriteCloser -from libp2p.io.msgio import FixedSizeLenMsgReadWriter -from libp2p.network.connection.raw_connection_interface import IRawConnection +from libp2p.io.abc import ( + EncryptedMsgReadWriter, + MsgReadWriteCloser, + ReadWriteCloser, +) +from libp2p.io.msgio import ( + FixedSizeLenMsgReadWriter, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) SIZE_NOISE_MESSAGE_LEN = 2 MAX_NOISE_MESSAGE_LEN = 2 ** (8 * SIZE_NOISE_MESSAGE_LEN) - 1 diff --git a/libp2p/security/noise/messages.py b/libp2p/security/noise/messages.py index feb27666..cea5f166 100644 --- a/libp2p/security/noise/messages.py +++ b/libp2p/security/noise/messages.py @@ -1,7 +1,14 @@ -from dataclasses import dataclass +from dataclasses import ( + dataclass, +) -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.crypto.serialization import deserialize_public_key +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.crypto.serialization import ( + deserialize_public_key, +) from .pb import noise_pb2 as noise_pb diff --git a/libp2p/security/noise/patterns.py b/libp2p/security/noise/patterns.py index 69195080..0803060e 100644 --- a/libp2p/security/noise/patterns.py +++ b/libp2p/security/noise/patterns.py @@ -1,16 +1,34 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) -from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives import ( + serialization, +) from noise.backends.default.keypairs import KeyPair as NoiseKeyPair from noise.connection import Keypair as NoiseKeypairEnum from noise.connection import NoiseConnection as NoiseState -from libp2p.crypto.ed25519 import Ed25519PublicKey -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_session import SecureSession +from libp2p.crypto.ed25519 import ( + Ed25519PublicKey, +) +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.secure_session import ( + SecureSession, +) from .exceptions import ( HandshakeHasNotFinished, @@ -18,7 +36,10 @@ from .exceptions import ( NoiseStateError, PeerIDMismatchesPubkey, ) -from .io import NoiseHandshakeReadWriter, NoiseTransportReadWriter +from .io import ( + NoiseHandshakeReadWriter, + NoiseTransportReadWriter, +) from .messages import ( NoiseHandshakePayload, make_handshake_payload_sig, @@ -95,8 +116,8 @@ class PatternXX(BasePattern): if handshake_state.rs is None: raise NoiseStateError( "something is wrong in the underlying noise `handshake_state`: " - "we received and consumed msg#3, which should have included the" - " remote static public key, but it is not present in the handshake_state" + "we received and consumed msg#3, which should have included the " + "remote static public key, but it is not present in the handshake_state" ) remote_pubkey = self._get_pubkey_from_noise_keypair(handshake_state.rs) @@ -139,8 +160,8 @@ class PatternXX(BasePattern): if handshake_state.rs is None: raise NoiseStateError( "something is wrong in the underlying noise `handshake_state`: " - "we received and consumed msg#3, which should have included the" - " remote static public key, but it is not present in the handshake_state" + "we received and consumed msg#3, which should have included the " + "remote static public key, but it is not present in the handshake_state" ) remote_pubkey = self._get_pubkey_from_noise_keypair(handshake_state.rs) diff --git a/libp2p/security/noise/pb/noise_pb2.py b/libp2p/security/noise/pb/noise_pb2.py index 63320daf..273d3d32 100644 --- a/libp2p/security/noise/pb/noise_pb2.py +++ b/libp2p/security/noise/pb/noise_pb2.py @@ -2,81 +2,114 @@ # source: libp2p/security/noise/pb/noise.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database -from google.protobuf import descriptor_pb2 + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/security/noise/pb/noise.proto', - package='pb', - syntax='proto3', - serialized_pb=_b('\n$libp2p/security/noise/pb/noise.proto\x12\x02pb\"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3') + name="libp2p/security/noise/pb/noise.proto", + package="pb", + syntax="proto3", + serialized_pb=_b( + '\n$libp2p/security/noise/pb/noise.proto\x12\x02pb"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3' + ), ) - - _NOISEHANDSHAKEPAYLOAD = _descriptor.Descriptor( - name='NoiseHandshakePayload', - full_name='pb.NoiseHandshakePayload', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='identity_key', full_name='pb.NoiseHandshakePayload.identity_key', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='identity_sig', full_name='pb.NoiseHandshakePayload.identity_sig', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='data', full_name='pb.NoiseHandshakePayload.data', index=2, - number=3, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - syntax='proto3', - extension_ranges=[], - oneofs=[ - ], - serialized_start=44, - serialized_end=125, + name="NoiseHandshakePayload", + full_name="pb.NoiseHandshakePayload", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="identity_key", + full_name="pb.NoiseHandshakePayload.identity_key", + index=0, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="identity_sig", + full_name="pb.NoiseHandshakePayload.identity_sig", + index=1, + number=2, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="data", + full_name="pb.NoiseHandshakePayload.data", + index=2, + number=3, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + options=None, + is_extendable=False, + syntax="proto3", + extension_ranges=[], + oneofs=[], + serialized_start=44, + serialized_end=125, ) -DESCRIPTOR.message_types_by_name['NoiseHandshakePayload'] = _NOISEHANDSHAKEPAYLOAD +DESCRIPTOR.message_types_by_name["NoiseHandshakePayload"] = _NOISEHANDSHAKEPAYLOAD _sym_db.RegisterFileDescriptor(DESCRIPTOR) -NoiseHandshakePayload = _reflection.GeneratedProtocolMessageType('NoiseHandshakePayload', (_message.Message,), dict( - DESCRIPTOR = _NOISEHANDSHAKEPAYLOAD, - __module__ = 'libp2p.security.noise.pb.noise_pb2' - # @@protoc_insertion_point(class_scope:pb.NoiseHandshakePayload) - )) +NoiseHandshakePayload = _reflection.GeneratedProtocolMessageType( + "NoiseHandshakePayload", + (_message.Message,), + dict( + DESCRIPTOR=_NOISEHANDSHAKEPAYLOAD, + __module__="libp2p.security.noise.pb.noise_pb2" + # @@protoc_insertion_point(class_scope:pb.NoiseHandshakePayload) + ), +) _sym_db.RegisterMessage(NoiseHandshakePayload) diff --git a/libp2p/security/noise/pb/noise_pb2.pyi b/libp2p/security/noise/pb/noise_pb2.pyi index a4bcf5b1..16b6772a 100644 --- a/libp2p/security/noise/pb/noise_pb2.pyi +++ b/libp2p/security/noise/pb/noise_pb2.pyi @@ -16,24 +16,39 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class NoiseHandshakePayload(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - identity_key = ... # type: bytes - identity_sig = ... # type: bytes - data = ... # type: bytes + identity_key = ... # type: bytes + identity_sig = ... # type: bytes + data = ... # type: bytes - def __init__(self, + def __init__( + self, *, - identity_key : typing___Optional[bytes] = None, - identity_sig : typing___Optional[bytes] = None, - data : typing___Optional[bytes] = None, - ) -> None: ... + identity_key: typing___Optional[bytes] = None, + identity_sig: typing___Optional[bytes] = None, + data: typing___Optional[bytes] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> NoiseHandshakePayload: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def ClearField(self, field_name: typing_extensions___Literal[u"data",u"identity_key",u"identity_sig"]) -> None: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", "identity_key", "identity_sig" + ], + ) -> None: ... else: - def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"identity_key",b"identity_key",u"identity_sig",b"identity_sig"]) -> None: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "data", + b"data", + "identity_key", + b"identity_key", + "identity_sig", + b"identity_sig", + ], + ) -> None: ... diff --git a/libp2p/security/noise/transport.py b/libp2p/security/noise/transport.py index 80bb6ee1..ffe927ca 100644 --- a/libp2p/security/noise/transport.py +++ b/libp2p/security/noise/transport.py @@ -1,11 +1,27 @@ -from libp2p.crypto.keys import KeyPair, PrivateKey -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_transport_interface import ISecureTransport -from libp2p.typing import TProtocol +from libp2p.crypto.keys import ( + KeyPair, + PrivateKey, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.secure_transport_interface import ( + ISecureTransport, +) +from libp2p.typing import ( + TProtocol, +) -from .patterns import IPattern, PatternXX +from .patterns import ( + IPattern, + PatternXX, +) PROTOCOL_ID = TProtocol("/noise") diff --git a/libp2p/security/secio/exceptions.py b/libp2p/security/secio/exceptions.py index ca6d37fa..bd4a0451 100644 --- a/libp2p/security/secio/exceptions.py +++ b/libp2p/security/secio/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.security.exceptions import HandshakeFailure +from libp2p.security.exceptions import ( + HandshakeFailure, +) class SecioException(HandshakeFailure): @@ -6,10 +8,10 @@ class SecioException(HandshakeFailure): class SelfEncryption(SecioException): - """Raised to indicate that a host is attempting to encrypt communications - with itself.""" - - pass + """ + Raised to indicate that a host is attempting to encrypt communications + with itself. + """ class PeerMismatchException(SecioException): diff --git a/libp2p/security/secio/pb/spipe.proto b/libp2p/security/secio/pb/spipe.proto index 942a9a5f..3e8f573a 100644 --- a/libp2p/security/secio/pb/spipe.proto +++ b/libp2p/security/secio/pb/spipe.proto @@ -13,4 +13,4 @@ message Propose { message Exchange { optional bytes ephemeral_public_key = 1; optional bytes signature = 2; -} \ No newline at end of file +} diff --git a/libp2p/security/secio/pb/spipe_pb2.py b/libp2p/security/secio/pb/spipe_pb2.py index d684b95d..f0ad7872 100644 --- a/libp2p/security/secio/pb/spipe_pb2.py +++ b/libp2p/security/secio/pb/spipe_pb2.py @@ -1,143 +1,221 @@ -# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/security/secio/pb/spipe.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) + +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database + # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() - - DESCRIPTOR = _descriptor.FileDescriptor( - name='libp2p/security/secio/pb/spipe.proto', - package='spipe.pb', - syntax='proto2', - serialized_options=None, - serialized_pb=_b('\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb\"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t\";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c') + name="libp2p/security/secio/pb/spipe.proto", + package="spipe.pb", + syntax="proto2", + serialized_options=None, + serialized_pb=_b( + '\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c' + ), ) - - _PROPOSE = _descriptor.Descriptor( - name='Propose', - full_name='spipe.pb.Propose', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='rand', full_name='spipe.pb.Propose.rand', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='public_key', full_name='spipe.pb.Propose.public_key', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='exchanges', full_name='spipe.pb.Propose.exchanges', index=2, - number=3, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='ciphers', full_name='spipe.pb.Propose.ciphers', index=3, - number=4, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='hashes', full_name='spipe.pb.Propose.hashes', index=4, - number=5, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=50, - serialized_end=145, + name="Propose", + full_name="spipe.pb.Propose", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="rand", + full_name="spipe.pb.Propose.rand", + index=0, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="public_key", + full_name="spipe.pb.Propose.public_key", + index=1, + number=2, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="exchanges", + full_name="spipe.pb.Propose.exchanges", + index=2, + number=3, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="ciphers", + full_name="spipe.pb.Propose.ciphers", + index=3, + number=4, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="hashes", + full_name="spipe.pb.Propose.hashes", + index=4, + number=5, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode("utf-8"), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=50, + serialized_end=145, ) _EXCHANGE = _descriptor.Descriptor( - name='Exchange', - full_name='spipe.pb.Exchange', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='ephemeral_public_key', full_name='spipe.pb.Exchange.ephemeral_public_key', index=0, - number=1, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - _descriptor.FieldDescriptor( - name='signature', full_name='spipe.pb.Exchange.signature', index=1, - number=2, type=12, cpp_type=9, label=1, - has_default_value=False, default_value=_b(""), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - serialized_options=None, file=DESCRIPTOR), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - serialized_options=None, - is_extendable=False, - syntax='proto2', - extension_ranges=[], - oneofs=[ - ], - serialized_start=147, - serialized_end=206, + name="Exchange", + full_name="spipe.pb.Exchange", + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name="ephemeral_public_key", + full_name="spipe.pb.Exchange.ephemeral_public_key", + index=0, + number=1, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + _descriptor.FieldDescriptor( + name="signature", + full_name="spipe.pb.Exchange.signature", + index=1, + number=2, + type=12, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b(""), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + serialized_options=None, + file=DESCRIPTOR, + ), + ], + extensions=[], + nested_types=[], + enum_types=[], + serialized_options=None, + is_extendable=False, + syntax="proto2", + extension_ranges=[], + oneofs=[], + serialized_start=147, + serialized_end=206, ) -DESCRIPTOR.message_types_by_name['Propose'] = _PROPOSE -DESCRIPTOR.message_types_by_name['Exchange'] = _EXCHANGE +DESCRIPTOR.message_types_by_name["Propose"] = _PROPOSE +DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE _sym_db.RegisterFileDescriptor(DESCRIPTOR) -Propose = _reflection.GeneratedProtocolMessageType('Propose', (_message.Message,), { - 'DESCRIPTOR' : _PROPOSE, - '__module__' : 'libp2p.security.secio.pb.spipe_pb2' - # @@protoc_insertion_point(class_scope:spipe.pb.Propose) - }) +Propose = _reflection.GeneratedProtocolMessageType( + "Propose", + (_message.Message,), + { + "DESCRIPTOR": _PROPOSE, + "__module__": "libp2p.security.secio.pb.spipe_pb2" + # @@protoc_insertion_point(class_scope:spipe.pb.Propose) + }, +) _sym_db.RegisterMessage(Propose) -Exchange = _reflection.GeneratedProtocolMessageType('Exchange', (_message.Message,), { - 'DESCRIPTOR' : _EXCHANGE, - '__module__' : 'libp2p.security.secio.pb.spipe_pb2' - # @@protoc_insertion_point(class_scope:spipe.pb.Exchange) - }) +Exchange = _reflection.GeneratedProtocolMessageType( + "Exchange", + (_message.Message,), + { + "DESCRIPTOR": _EXCHANGE, + "__module__": "libp2p.security.secio.pb.spipe_pb2" + # @@protoc_insertion_point(class_scope:spipe.pb.Exchange) + }, +) _sym_db.RegisterMessage(Exchange) diff --git a/libp2p/security/secio/pb/spipe_pb2.pyi b/libp2p/security/secio/pb/spipe_pb2.pyi index 2025ff13..5319942e 100644 --- a/libp2p/security/secio/pb/spipe_pb2.pyi +++ b/libp2p/security/secio/pb/spipe_pb2.pyi @@ -17,51 +17,116 @@ from typing_extensions import ( Literal as typing_extensions___Literal, ) - class Propose(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - rand = ... # type: bytes - public_key = ... # type: bytes - exchanges = ... # type: typing___Text - ciphers = ... # type: typing___Text - hashes = ... # type: typing___Text + rand = ... # type: bytes + public_key = ... # type: bytes + exchanges = ... # type: typing___Text + ciphers = ... # type: typing___Text + hashes = ... # type: typing___Text - def __init__(self, + def __init__( + self, *, - rand : typing___Optional[bytes] = None, - public_key : typing___Optional[bytes] = None, - exchanges : typing___Optional[typing___Text] = None, - ciphers : typing___Optional[typing___Text] = None, - hashes : typing___Optional[typing___Text] = None, - ) -> None: ... + rand: typing___Optional[bytes] = None, + public_key: typing___Optional[bytes] = None, + exchanges: typing___Optional[typing___Text] = None, + ciphers: typing___Optional[typing___Text] = None, + hashes: typing___Optional[typing___Text] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> Propose: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"ciphers",u"exchanges",u"hashes",u"public_key",u"rand"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"ciphers",u"exchanges",u"hashes",u"public_key",u"rand"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "ciphers", "exchanges", "hashes", "public_key", "rand" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "ciphers", "exchanges", "hashes", "public_key", "rand" + ], + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"ciphers",b"ciphers",u"exchanges",b"exchanges",u"hashes",b"hashes",u"public_key",b"public_key",u"rand",b"rand"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"ciphers",b"ciphers",u"exchanges",b"exchanges",u"hashes",b"hashes",u"public_key",b"public_key",u"rand",b"rand"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "ciphers", + b"ciphers", + "exchanges", + b"exchanges", + "hashes", + b"hashes", + "public_key", + b"public_key", + "rand", + b"rand", + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "ciphers", + b"ciphers", + "exchanges", + b"exchanges", + "hashes", + b"hashes", + "public_key", + b"public_key", + "rand", + b"rand", + ], + ) -> None: ... class Exchange(google___protobuf___message___Message): DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - ephemeral_public_key = ... # type: bytes - signature = ... # type: bytes + ephemeral_public_key = ... # type: bytes + signature = ... # type: bytes - def __init__(self, + def __init__( + self, *, - ephemeral_public_key : typing___Optional[bytes] = None, - signature : typing___Optional[bytes] = None, - ) -> None: ... + ephemeral_public_key: typing___Optional[bytes] = None, + signature: typing___Optional[bytes] = None, + ) -> None: ... @classmethod def FromString(cls, s: bytes) -> Exchange: ... def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... if sys.version_info >= (3,): - def HasField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",u"signature"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",u"signature"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "ephemeral_public_key", "signature" + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "ephemeral_public_key", "signature" + ], + ) -> None: ... else: - def HasField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",b"ephemeral_public_key",u"signature",b"signature"]) -> bool: ... - def ClearField(self, field_name: typing_extensions___Literal[u"ephemeral_public_key",b"ephemeral_public_key",u"signature",b"signature"]) -> None: ... + def HasField( + self, + field_name: typing_extensions___Literal[ + "ephemeral_public_key", + b"ephemeral_public_key", + "signature", + b"signature", + ], + ) -> bool: ... + def ClearField( + self, + field_name: typing_extensions___Literal[ + "ephemeral_public_key", + b"ephemeral_public_key", + "signature", + b"signature", + ], + ) -> None: ... diff --git a/libp2p/security/secio/transport.py b/libp2p/security/secio/transport.py index 46f5c2d7..482a4005 100644 --- a/libp2p/security/secio/transport.py +++ b/libp2p/security/secio/transport.py @@ -1,31 +1,66 @@ -from dataclasses import dataclass +from dataclasses import ( + dataclass, +) import itertools -from typing import Optional, Tuple +from typing import ( + Optional, + Tuple, +) import multihash from libp2p.crypto.authenticated_encryption import ( EncryptionParameters as AuthenticatedEncryptionParameters, ) +from libp2p.crypto.authenticated_encryption import ( + InvalidMACException, +) from libp2p.crypto.authenticated_encryption import ( initialize_pair as initialize_pair_for_encryption, ) -from libp2p.crypto.authenticated_encryption import InvalidMACException from libp2p.crypto.authenticated_encryption import MacAndCipher as Encrypter -from libp2p.crypto.ecc import ECCPublicKey -from libp2p.crypto.exceptions import MissingDeserializerError -from libp2p.crypto.key_exchange import create_ephemeral_key_pair -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.crypto.serialization import deserialize_public_key -from libp2p.io.abc import EncryptedMsgReadWriter -from libp2p.io.exceptions import DecryptionFailedException, IOException -from libp2p.io.msgio import FixedSizeLenMsgReadWriter -from libp2p.network.connection.raw_connection_interface import IRawConnection +from libp2p.crypto.ecc import ( + ECCPublicKey, +) +from libp2p.crypto.exceptions import ( + MissingDeserializerError, +) +from libp2p.crypto.key_exchange import ( + create_ephemeral_key_pair, +) +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.crypto.serialization import ( + deserialize_public_key, +) +from libp2p.io.abc import ( + EncryptedMsgReadWriter, +) +from libp2p.io.exceptions import ( + DecryptionFailedException, + IOException, +) +from libp2p.io.msgio import ( + FixedSizeLenMsgReadWriter, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) from libp2p.peer.id import ID as PeerID -from libp2p.security.base_transport import BaseSecureTransport -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_session import SecureSession -from libp2p.typing import TProtocol +from libp2p.security.base_transport import ( + BaseSecureTransport, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.secure_session import ( + SecureSession, +) +from libp2p.typing import ( + TProtocol, +) from .exceptions import ( IncompatibleChoices, @@ -36,7 +71,10 @@ from .exceptions import ( SedesException, SelfEncryption, ) -from .pb.spipe_pb2 import Exchange, Propose +from .pb.spipe_pb2 import ( + Exchange, + Propose, +) ID = TProtocol("/secio/1.0.0") @@ -101,8 +139,10 @@ class SecioMsgReadWriter(EncryptedMsgReadWriter): @dataclass(frozen=True) class Proposal: - """A ``Proposal`` represents the set of session parameters one peer in a - pair of peers attempting to negotiate a `secio` channel prefers.""" + """ + Represents the set of session parameters one peer in a + pair of peers attempting to negotiate a `secio` channel prefers. + """ nonce: bytes public_key: PublicKey @@ -401,8 +441,10 @@ async def create_secure_session( class Transport(BaseSecureTransport): - """``Transport`` provides a security upgrader for a ``IRawConnection``, - following the `secio` protocol defined in the libp2p specs.""" + """ + Provide a security upgrader for a ``IRawConnection``, + following the `secio` protocol defined in the libp2p specs. + """ def get_nonce(self) -> bytes: return self.secure_bytes_provider(NONCE_SIZE) diff --git a/libp2p/security/secure_conn_interface.py b/libp2p/security/secure_conn_interface.py index ab69a6d0..245b5f58 100644 --- a/libp2p/security/secure_conn_interface.py +++ b/libp2p/security/secure_conn_interface.py @@ -1,13 +1,22 @@ -from abc import ABC, abstractmethod - -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID +from abc import ( + ABC, + abstractmethod, +) +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) """ -Represents a secured connection object, which includes a connection and details about the security -involved in the secured connection +Represents a secured connection object, which includes a connection and details about +the security involved in the secured connection Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go """ diff --git a/libp2p/security/secure_session.py b/libp2p/security/secure_session.py index dbabd1a7..7c727619 100644 --- a/libp2p/security/secure_session.py +++ b/libp2p/security/secure_session.py @@ -1,9 +1,18 @@ import io -from libp2p.crypto.keys import PrivateKey, PublicKey -from libp2p.io.abc import EncryptedMsgReadWriter -from libp2p.peer.id import ID -from libp2p.security.base_session import BaseSession +from libp2p.crypto.keys import ( + PrivateKey, + PublicKey, +) +from libp2p.io.abc import ( + EncryptedMsgReadWriter, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.base_session import ( + BaseSession, +) class SecureSession(BaseSession): @@ -39,7 +48,7 @@ class SecureSession(BaseSession): def _drain(self, n: int) -> bytes: if self.low_watermark == self.high_watermark: - return bytes() + return b"" data = self.buf.getbuffer()[self.low_watermark : self.high_watermark] @@ -61,7 +70,7 @@ class SecureSession(BaseSession): async def read(self, n: int = None) -> bytes: if n == 0: - return bytes() + return b"" data_from_buffer = self._drain(n) if len(data_from_buffer) > 0: diff --git a/libp2p/security/secure_transport_interface.py b/libp2p/security/secure_transport_interface.py index 678b9c67..5fcf2732 100644 --- a/libp2p/security/secure_transport_interface.py +++ b/libp2p/security/secure_transport_interface.py @@ -1,9 +1,17 @@ -from abc import ABC, abstractmethod - -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn +from abc import ( + ABC, + abstractmethod, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) """ Transport that is used to secure a connection. This transport is diff --git a/libp2p/security/security_multistream.py b/libp2p/security/security_multistream.py index c83a2aa4..046846ca 100644 --- a/libp2p/security/security_multistream.py +++ b/libp2p/security/security_multistream.py @@ -1,20 +1,41 @@ -from abc import ABC -from collections import OrderedDict - -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.protocol_muxer.multiselect import Multiselect -from libp2p.protocol_muxer.multiselect_client import MultiselectClient -from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_transport_interface import ISecureTransport -from libp2p.transport.typing import TSecurityOptions -from libp2p.typing import TProtocol +from abc import ( + ABC, +) +from collections import ( + OrderedDict, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.protocol_muxer.multiselect import ( + Multiselect, +) +from libp2p.protocol_muxer.multiselect_client import ( + MultiselectClient, +) +from libp2p.protocol_muxer.multiselect_communicator import ( + MultiselectCommunicator, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.secure_transport_interface import ( + ISecureTransport, +) +from libp2p.transport.typing import ( + TSecurityOptions, +) +from libp2p.typing import ( + TProtocol, +) """ -Represents a secured connection object, which includes a connection and details about the security -involved in the secured connection +Represents a secured connection object, which includes a connection and details about +the security involved in the secured connection Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go """ diff --git a/libp2p/stream_muxer/abc.py b/libp2p/stream_muxer/abc.py index 82140ff4..a054bef6 100644 --- a/libp2p/stream_muxer/abc.py +++ b/libp2p/stream_muxer/abc.py @@ -1,10 +1,19 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) import trio -from libp2p.io.abc import ReadWriteCloser -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) class IMuxedConn(ABC): @@ -18,7 +27,7 @@ class IMuxedConn(ABC): @abstractmethod def __init__(self, conn: ISecureConn, peer_id: ID) -> None: """ - create a new muxed connection. + Create a new muxed connection. :param conn: an instance of secured connection for new muxed streams @@ -28,21 +37,21 @@ class IMuxedConn(ABC): @property @abstractmethod def is_initiator(self) -> bool: - """if this connection is the initiator.""" + """If this connection is the initiator.""" @abstractmethod async def start(self) -> None: - """start the multiplexer.""" + """Start the multiplexer.""" @abstractmethod async def close(self) -> None: - """close connection.""" + """Close connection.""" @property @abstractmethod def is_closed(self) -> bool: """ - check connection is fully closed. + Check connection is fully closed. :return: true if successful """ @@ -50,28 +59,27 @@ class IMuxedConn(ABC): @abstractmethod async def open_stream(self) -> "IMuxedStream": """ - creates a new muxed_stream. + Create a new muxed_stream. :return: a new ``IMuxedStream`` stream """ @abstractmethod async def accept_stream(self) -> "IMuxedStream": - """accepts a muxed stream opened by the other end.""" + """Accept a muxed stream opened by the other end.""" class IMuxedStream(ReadWriteCloser): - muxed_conn: IMuxedConn @abstractmethod async def reset(self) -> None: - """closes both ends of the stream tells this remote side to hang up.""" + """Close both ends of the stream tells this remote side to hang up.""" @abstractmethod def set_deadline(self, ttl: int) -> bool: """ - set deadline for muxed stream. + Set deadline for muxed stream. :return: a new stream """ diff --git a/libp2p/stream_muxer/exceptions.py b/libp2p/stream_muxer/exceptions.py index ce0f92e3..46cb4fcc 100644 --- a/libp2p/stream_muxer/exceptions.py +++ b/libp2p/stream_muxer/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class MuxedConnError(BaseLibp2pError): diff --git a/libp2p/stream_muxer/mplex/constants.py b/libp2p/stream_muxer/mplex/constants.py index 8989e763..c8a625a5 100644 --- a/libp2p/stream_muxer/mplex/constants.py +++ b/libp2p/stream_muxer/mplex/constants.py @@ -1,4 +1,6 @@ -from enum import Enum +from enum import ( + Enum, +) class HeaderTags(Enum): diff --git a/libp2p/stream_muxer/mplex/datastructures.py b/libp2p/stream_muxer/mplex/datastructures.py index 28a4b41a..0fc8164e 100644 --- a/libp2p/stream_muxer/mplex/datastructures.py +++ b/libp2p/stream_muxer/mplex/datastructures.py @@ -1,4 +1,6 @@ -from typing import NamedTuple +from typing import ( + NamedTuple, +) class StreamID(NamedTuple): diff --git a/libp2p/stream_muxer/mplex/mplex.py b/libp2p/stream_muxer/mplex/mplex.py index defe0b8d..89d364c4 100644 --- a/libp2p/stream_muxer/mplex/mplex.py +++ b/libp2p/stream_muxer/mplex/mplex.py @@ -1,15 +1,34 @@ import logging -from typing import Dict, Optional, Tuple +from typing import ( + Dict, + Optional, + Tuple, +) import trio -from libp2p.exceptions import ParseError -from libp2p.io.exceptions import IncompleteReadError -from libp2p.network.connection.exceptions import RawConnError -from libp2p.peer.id import ID -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.stream_muxer.abc import IMuxedConn, IMuxedStream -from libp2p.typing import TProtocol +from libp2p.exceptions import ( + ParseError, +) +from libp2p.io.exceptions import ( + IncompleteReadError, +) +from libp2p.network.connection.exceptions import ( + RawConnError, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, + IMuxedStream, +) +from libp2p.typing import ( + TProtocol, +) from libp2p.utils import ( decode_uvarint_from_stream, encode_uvarint, @@ -17,10 +36,18 @@ from libp2p.utils import ( read_varint_prefixed_bytes, ) -from .constants import HeaderTags -from .datastructures import StreamID -from .exceptions import MplexUnavailable -from .mplex_stream import MplexStream +from .constants import ( + HeaderTags, +) +from .datastructures import ( + StreamID, +) +from .exceptions import ( + MplexUnavailable, +) +from .mplex_stream import ( + MplexStream, +) MPLEX_PROTOCOL_ID = TProtocol("/mplex/6.7.0") # Ref: https://github.com/libp2p/go-mplex/blob/414db61813d9ad3e6f4a7db5c1b1612de343ace9/multiplex.go#L115 # noqa: E501 @@ -49,7 +76,7 @@ class Mplex(IMuxedConn): def __init__(self, secured_conn: ISecureConn, peer_id: ID) -> None: """ - create a new muxed connection. + Create a new muxed connection. :param secured_conn: an instance of ``ISecureConn`` :param generic_protocol_handler: generic protocol handler @@ -81,7 +108,9 @@ class Mplex(IMuxedConn): return self.secured_conn.is_initiator async def close(self) -> None: - """close the stream muxer and underlying secured connection.""" + """ + Close the stream muxer and underlying secured connection. + """ if self.event_shutting_down.is_set(): return # Set the `event_shutting_down`, to allow graceful shutdown. @@ -93,7 +122,7 @@ class Mplex(IMuxedConn): @property def is_closed(self) -> bool: """ - check connection is fully closed. + Check connection is fully closed. :return: true if successful """ @@ -121,7 +150,7 @@ class Mplex(IMuxedConn): async def open_stream(self) -> IMuxedStream: """ - creates a new muxed_stream. + Create a new muxed_stream. :return: a new ``MplexStream`` """ @@ -134,7 +163,9 @@ class Mplex(IMuxedConn): return stream async def accept_stream(self) -> IMuxedStream: - """accepts a muxed stream opened by the other end.""" + """ + Accept a muxed stream opened by the other end. + """ try: return await self.new_stream_receive_channel.receive() except trio.EndOfChannel: @@ -144,7 +175,7 @@ class Mplex(IMuxedConn): self, flag: HeaderTags, data: Optional[bytes], stream_id: StreamID ) -> int: """ - sends a message over the connection. + Send a message over the connection. :param flag: header to use :param data: data to send in the message @@ -162,7 +193,7 @@ class Mplex(IMuxedConn): async def write_to_stream(self, _bytes: bytes) -> None: """ - writes a byte array to a secured connection. + Write a byte array to a secured connection. :param _bytes: byte array to write :return: length written @@ -175,8 +206,10 @@ class Mplex(IMuxedConn): ) from e async def handle_incoming(self) -> None: - """Read a message off of the secured connection and add it to the - corresponding message buffer.""" + """ + Read a message off of the secured connection and add it to the + corresponding message buffer. + """ self.event_started.set() while True: try: @@ -194,19 +227,19 @@ class Mplex(IMuxedConn): :return: stream_id, flag, message contents """ - try: header = await decode_uvarint_from_stream(self.secured_conn) except (ParseError, RawConnError, IncompleteReadError) as error: raise MplexUnavailable( - f"failed to read the header correctly from the underlying connection: {error}" + "failed to read the header correctly from the underlying connection: " + f"{error}" ) try: message = await read_varint_prefixed_bytes(self.secured_conn) except (ParseError, RawConnError, IncompleteReadError) as error: raise MplexUnavailable( - "failed to read the message body correctly from the underlying connection: " - f"{error}" + "failed to read the message body correctly from the underlying " + f"connection: {error}" ) flag = header & 0x07 diff --git a/libp2p/stream_muxer/mplex/mplex_stream.py b/libp2p/stream_muxer/mplex/mplex_stream.py index 9c724cc7..6714604c 100644 --- a/libp2p/stream_muxer/mplex/mplex_stream.py +++ b/libp2p/stream_muxer/mplex/mplex_stream.py @@ -1,16 +1,32 @@ -from typing import TYPE_CHECKING +from typing import ( + TYPE_CHECKING, +) import trio -from libp2p.stream_muxer.abc import IMuxedStream -from libp2p.stream_muxer.exceptions import MuxedConnUnavailable +from libp2p.stream_muxer.abc import ( + IMuxedStream, +) +from libp2p.stream_muxer.exceptions import ( + MuxedConnUnavailable, +) -from .constants import HeaderTags -from .datastructures import StreamID -from .exceptions import MplexStreamClosed, MplexStreamEOF, MplexStreamReset +from .constants import ( + HeaderTags, +) +from .datastructures import ( + StreamID, +) +from .exceptions import ( + MplexStreamClosed, + MplexStreamEOF, + MplexStreamReset, +) if TYPE_CHECKING: - from libp2p.stream_muxer.mplex.mplex import Mplex + from libp2p.stream_muxer.mplex.mplex import ( + Mplex, + ) class MplexStream(IMuxedStream): @@ -44,7 +60,7 @@ class MplexStream(IMuxedStream): incoming_data_channel: "trio.MemoryReceiveChannel[bytes]", ) -> None: """ - create new MuxedStream in muxer. + Create new MuxedStream in muxer. :param stream_id: stream id of this stream :param muxed_conn: muxed connection of this muxed_stream @@ -93,8 +109,8 @@ class MplexStream(IMuxedStream): """ if n is not None and n < 0: raise ValueError( - f"the number of bytes to read `n` must be non-negative or " - "`None` to indicate read until EOF" + "the number of bytes to read `n` must be non-negative or " + f"`None` to indicate read until EOF, got n={n}" ) if self.event_reset.is_set(): raise MplexStreamReset @@ -102,16 +118,16 @@ class MplexStream(IMuxedStream): return await self._read_until_eof() if len(self._buf) == 0: data: bytes - # Peek whether there is data available. If yes, we just read until there is no data, - # and then return. + # Peek whether there is data available. If yes, we just read until there is + # no data, then return. try: data = self.incoming_data_channel.receive_nowait() self._buf.extend(data) except trio.EndOfChannel: raise MplexStreamEOF except trio.WouldBlock: - # We know `receive` will be blocked here. Wait for data here with `receive` and - # catch all kinds of errors here. + # We know `receive` will be blocked here. Wait for data here with + # `receive` and catch all kinds of errors here. try: data = await self.incoming_data_channel.receive() self._buf.extend(data) @@ -121,8 +137,8 @@ class MplexStream(IMuxedStream): if self.event_remote_closed.is_set(): raise MplexStreamEOF except trio.ClosedResourceError as error: - # Probably `incoming_data_channel` is closed in `reset` when we are waiting - # for `receive`. + # Probably `incoming_data_channel` is closed in `reset` when we are + # waiting for `receive`. if self.event_reset.is_set(): raise MplexStreamReset raise Exception( @@ -136,7 +152,7 @@ class MplexStream(IMuxedStream): async def write(self, data: bytes) -> None: """ - write to stream. + Write to stream. :return: number of bytes written """ @@ -150,8 +166,10 @@ class MplexStream(IMuxedStream): await self.muxed_conn.send_message(flag, data, self.stream_id) async def close(self) -> None: - """Closing a stream closes it for writing and closes the remote end for - reading but allows writing in the other direction.""" + """ + Closing a stream closes it for writing and closes the remote end for + reading but allows writing in the other direction. + """ # TODO error handling with timeout async with self.close_lock: @@ -175,7 +193,7 @@ class MplexStream(IMuxedStream): self.muxed_conn.streams.pop(self.stream_id, None) async def reset(self) -> None: - """closes both ends of the stream tells this remote side to hang up.""" + """Close both ends of the stream tells this remote side to hang up.""" async with self.close_lock: # Both sides have been closed. No need to event_reset. if self.event_remote_closed.is_set() and self.event_local_closed.is_set(): @@ -190,7 +208,8 @@ class MplexStream(IMuxedStream): if self.is_initiator else HeaderTags.ResetReceiver ) - # Try to send reset message to the other side. Ignore if there is anything wrong. + # Try to send reset message to the other side. + # Ignore if there is anything wrong. try: await self.muxed_conn.send_message(flag, None, self.stream_id) except MuxedConnUnavailable: @@ -208,7 +227,7 @@ class MplexStream(IMuxedStream): # TODO deadline not in use def set_deadline(self, ttl: int) -> bool: """ - set deadline for muxed stream. + Set deadline for muxed stream. :return: True if successful """ @@ -218,7 +237,7 @@ class MplexStream(IMuxedStream): def set_read_deadline(self, ttl: int) -> bool: """ - set read deadline for muxed stream. + Set read deadline for muxed stream. :return: True if successful """ @@ -227,7 +246,7 @@ class MplexStream(IMuxedStream): def set_write_deadline(self, ttl: int) -> bool: """ - set write deadline for muxed stream. + Set write deadline for muxed stream. :return: True if successful """ diff --git a/libp2p/stream_muxer/muxer_multistream.py b/libp2p/stream_muxer/muxer_multistream.py index d83869f0..5cadc568 100644 --- a/libp2p/stream_muxer/muxer_multistream.py +++ b/libp2p/stream_muxer/muxer_multistream.py @@ -1,15 +1,36 @@ -from collections import OrderedDict +from collections import ( + OrderedDict, +) -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.protocol_muxer.multiselect import Multiselect -from libp2p.protocol_muxer.multiselect_client import MultiselectClient -from libp2p.protocol_muxer.multiselect_communicator import MultiselectCommunicator -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.transport.typing import TMuxerClass, TMuxerOptions -from libp2p.typing import TProtocol +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.protocol_muxer.multiselect import ( + Multiselect, +) +from libp2p.protocol_muxer.multiselect_client import ( + MultiselectClient, +) +from libp2p.protocol_muxer.multiselect_communicator import ( + MultiselectCommunicator, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.transport.typing import ( + TMuxerClass, + TMuxerOptions, +) +from libp2p.typing import ( + TProtocol, +) -from .abc import IMuxedConn +from .abc import ( + IMuxedConn, +) # FIXME: add negotiate timeout to `MuxerMultistream` DEFAULT_NEGOTIATE_TIMEOUT = 60 diff --git a/libp2p/tools/constants.py b/libp2p/tools/constants.py index b1ad2652..9306b066 100644 --- a/libp2p/tools/constants.py +++ b/libp2p/tools/constants.py @@ -1,8 +1,13 @@ -from typing import NamedTuple +from typing import ( + NamedTuple, +) import multiaddr -from libp2p.pubsub import floodsub, gossipsub +from libp2p.pubsub import ( + floodsub, + gossipsub, +) # Just a arbitrary large number. # It is used when calling `MplexStream.read(MAX_READ_LEN)`, diff --git a/libp2p/tools/factories.py b/libp2p/tools/factories.py index d9b2f4e6..35ed1cfb 100644 --- a/libp2p/tools/factories.py +++ b/libp2p/tools/factories.py @@ -1,35 +1,96 @@ -from typing import Any, AsyncIterator, Callable, Dict, List, Sequence, Tuple, cast +from typing import ( + Any, + AsyncIterator, + Callable, + Dict, + List, + Sequence, + Tuple, + cast, +) -from async_exit_stack import AsyncExitStack -from async_generator import asynccontextmanager -from async_service import background_trio_service +from async_exit_stack import ( + AsyncExitStack, +) +from async_generator import ( + asynccontextmanager, +) +from async_service import ( + background_trio_service, +) import factory -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import trio -from libp2p import generate_new_rsa_identity, generate_peer_id_from +from libp2p import ( + generate_new_rsa_identity, + generate_peer_id_from, +) from libp2p.crypto.ed25519 import create_new_key_pair as create_ed25519_key_pair -from libp2p.crypto.keys import KeyPair, PrivateKey +from libp2p.crypto.keys import ( + KeyPair, + PrivateKey, +) from libp2p.crypto.secp256k1 import create_new_key_pair as create_secp256k1_key_pair -from libp2p.host.basic_host import BasicHost -from libp2p.host.host_interface import IHost -from libp2p.host.routed_host import RoutedHost -from libp2p.io.abc import ReadWriteCloser -from libp2p.network.connection.raw_connection import RawConnection -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.network.connection.swarm_connection import SwarmConn -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.network.swarm import Swarm -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo -from libp2p.peer.peerstore import PeerStore -from libp2p.pubsub.abc import IPubsubRouter -from libp2p.pubsub.floodsub import FloodSub -from libp2p.pubsub.gossipsub import GossipSub +from libp2p.host.basic_host import ( + BasicHost, +) +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.host.routed_host import ( + RoutedHost, +) +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.network.connection.raw_connection import ( + RawConnection, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.network.connection.swarm_connection import ( + SwarmConn, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.network.swarm import ( + Swarm, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) +from libp2p.peer.peerstore import ( + PeerStore, +) +from libp2p.pubsub.abc import ( + IPubsubRouter, +) +from libp2p.pubsub.floodsub import ( + FloodSub, +) +from libp2p.pubsub.gossipsub import ( + GossipSub, +) import libp2p.pubsub.pb.rpc_pb2 as rpc_pb2 -from libp2p.pubsub.pubsub import Pubsub, get_peer_and_seqno_msg_id -from libp2p.routing.interfaces import IPeerRouting -from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID, InsecureTransport +from libp2p.pubsub.pubsub import ( + Pubsub, + get_peer_and_seqno_msg_id, +) +from libp2p.routing.interfaces import ( + IPeerRouting, +) +from libp2p.security.insecure.transport import ( + PLAINTEXT_PROTOCOL_ID, + InsecureTransport, +) from libp2p.security.noise.messages import ( NoiseHandshakePayload, make_handshake_payload_sig, @@ -37,18 +98,45 @@ from libp2p.security.noise.messages import ( from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID from libp2p.security.noise.transport import Transport as NoiseTransport import libp2p.security.secio.transport as secio -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.secure_transport_interface import ISecureTransport -from libp2p.stream_muxer.mplex.mplex import MPLEX_PROTOCOL_ID, Mplex -from libp2p.stream_muxer.mplex.mplex_stream import MplexStream -from libp2p.tools.constants import GOSSIPSUB_PARAMS -from libp2p.transport.tcp.tcp import TCP -from libp2p.transport.typing import TMuxerOptions, TSecurityOptions -from libp2p.transport.upgrader import TransportUpgrader -from libp2p.typing import TProtocol +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.secure_transport_interface import ( + ISecureTransport, +) +from libp2p.stream_muxer.mplex.mplex import ( + MPLEX_PROTOCOL_ID, + Mplex, +) +from libp2p.stream_muxer.mplex.mplex_stream import ( + MplexStream, +) +from libp2p.tools.constants import ( + GOSSIPSUB_PARAMS, +) +from libp2p.transport.tcp.tcp import ( + TCP, +) +from libp2p.transport.typing import ( + TMuxerOptions, + TSecurityOptions, +) +from libp2p.transport.upgrader import ( + TransportUpgrader, +) +from libp2p.typing import ( + TProtocol, +) -from .constants import FLOODSUB_PROTOCOL_ID, GOSSIPSUB_PROTOCOL_ID, LISTEN_MADDR -from .utils import connect, connect_swarm +from .constants import ( + FLOODSUB_PROTOCOL_ID, + GOSSIPSUB_PROTOCOL_ID, + LISTEN_MADDR, +) +from .utils import ( + connect, + connect_swarm, +) DEFAULT_SECURITY_PROTOCOL_ID = PLAINTEXT_PROTOCOL_ID @@ -105,7 +193,7 @@ def noise_transport_factory(key_pair: KeyPair) -> ISecureTransport: def security_options_factory_factory( - protocol_id: TProtocol = None + protocol_id: TProtocol = None, ) -> Callable[[KeyPair], TSecurityOptions]: if protocol_id is None: protocol_id = DEFAULT_SECURITY_PROTOCOL_ID @@ -135,7 +223,7 @@ def default_muxer_transport_factory() -> TMuxerOptions: @asynccontextmanager async def raw_conn_factory( - nursery: trio.Nursery + nursery: trio.Nursery, ) -> AsyncIterator[Tuple[IRawConnection, IRawConnection]]: conn_0 = None conn_1 = None @@ -158,7 +246,7 @@ async def raw_conn_factory( @asynccontextmanager async def noise_conn_factory( - nursery: trio.Nursery + nursery: trio.Nursery, ) -> AsyncIterator[Tuple[ISecureConn, ISecureConn]]: local_transport = cast( NoiseTransport, noise_transport_factory(create_secp256k1_key_pair()) @@ -188,7 +276,8 @@ async def noise_conn_factory( if local_secure_conn is None or remote_secure_conn is None: raise Exception( "local or remote secure conn has not been successfully upgraded" - f"local_secure_conn={local_secure_conn}, remote_secure_conn={remote_secure_conn}" + f"local_secure_conn={local_secure_conn}, " + f"remote_secure_conn={remote_secure_conn}" ) yield local_secure_conn, remote_secure_conn @@ -223,8 +312,8 @@ class SwarmFactory(factory.Factory): muxer_opt: TMuxerOptions = None, ) -> AsyncIterator[Swarm]: # `factory.Factory.__init__` does *not* prepare a *default value* if we pass - # an argument explicitly with `None`. If an argument is `None`, we don't pass it to - # `factory.Factory.__init__`, in order to let the function initialize it. + # an argument explicitly with `None`. If an argument is `None`, we don't pass it + # to `factory.Factory.__init__`, in order to let the function initialize it. optional_kwargs: Dict[str, Any] = {} if key_pair is not None: optional_kwargs["key_pair"] = key_pair @@ -541,7 +630,7 @@ async def swarm_conn_pair_factory( @asynccontextmanager async def mplex_conn_pair_factory( - security_protocol: TProtocol = None + security_protocol: TProtocol = None, ) -> AsyncIterator[Tuple[Mplex, Mplex]]: async with swarm_conn_pair_factory( security_protocol=security_protocol, muxer_opt=default_muxer_transport_factory() @@ -554,7 +643,7 @@ async def mplex_conn_pair_factory( @asynccontextmanager async def mplex_stream_pair_factory( - security_protocol: TProtocol = None + security_protocol: TProtocol = None, ) -> AsyncIterator[Tuple[MplexStream, MplexStream]]: async with mplex_conn_pair_factory( security_protocol=security_protocol diff --git a/libp2p/tools/interop/daemon.py b/libp2p/tools/interop/daemon.py index a440324f..a7a69cec 100644 --- a/libp2p/tools/interop/daemon.py +++ b/libp2p/tools/interop/daemon.py @@ -1,20 +1,41 @@ -from typing import AsyncIterator +from typing import ( + AsyncIterator, +) -from async_generator import asynccontextmanager +from async_generator import ( + asynccontextmanager, +) import multiaddr -from multiaddr import Multiaddr -from p2pclient import Client +from multiaddr import ( + Multiaddr, +) +from p2pclient import ( + Client, +) import trio -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, + info_from_p2p_addr, +) from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID from libp2p.security.secio.transport import ID as SECIO_PROTOCOL_ID -from libp2p.typing import TProtocol +from libp2p.typing import ( + TProtocol, +) -from .constants import LOCALHOST_IP -from .envs import GO_BIN_PATH -from .process import BaseInteractiveProcess +from .constants import ( + LOCALHOST_IP, +) +from .envs import ( + GO_BIN_PATH, +) +from .process import ( + BaseInteractiveProcess, +) P2PD_PATH = GO_BIN_PATH / "p2pd" @@ -47,7 +68,7 @@ class P2PDProcess(BaseInteractiveProcess): # NOTE: # Two other params are possibly what we want to configure: # - gossipsubHeartbeatInterval: GossipSubHeartbeatInitialDelay = 100 * time.Millisecond # noqa: E501 - # - gossipsubHeartbeatInitialDelay: GossipSubHeartbeatInterval = 1 * time.Second + # - gossipsubHeartbeatInitialDelay: GossipSubHeartbeatInterval = 1 * time.Second # noqa: E501 # Referece: https://github.com/libp2p/go-libp2p-daemon/blob/b95e77dbfcd186ccf817f51e95f73f9fd5982600/p2pd/main.go#L348-L353 # noqa: E501 self.proc = None self.cmd = str(P2PD_PATH) diff --git a/libp2p/tools/interop/process.py b/libp2p/tools/interop/process.py index 0c17e51b..7cdf8729 100644 --- a/libp2p/tools/interop/process.py +++ b/libp2p/tools/interop/process.py @@ -1,6 +1,12 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) import subprocess -from typing import Iterable, List +from typing import ( + Iterable, + List, +) import trio @@ -54,7 +60,7 @@ class BaseInteractiveProcess(AbstractInterativeProcess): self.proc = await trio.open_process( # type: ignore [self.cmd] + self.args, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, # Redirect stderr to stdout, which makes parsing easier + stderr=subprocess.STDOUT, # Redirect stderr to stdout, which makes parsing easier # noqa: E501 bufsize=0, ) await self.wait_until_ready() diff --git a/libp2p/tools/interop/utils.py b/libp2p/tools/interop/utils.py index ce05c8fb..fe0997a0 100644 --- a/libp2p/tools/interop/utils.py +++ b/libp2p/tools/interop/utils.py @@ -1,13 +1,25 @@ -from typing import Union +from typing import ( + Union, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import trio -from libp2p.host.host_interface import IHost -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import PeerInfo +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) -from .daemon import Daemon +from .daemon import ( + Daemon, +) TDaemonOrHost = Union[IHost, Daemon] diff --git a/libp2p/tools/pubsub/dummy_account_node.py b/libp2p/tools/pubsub/dummy_account_node.py index 32f78851..bef47553 100644 --- a/libp2p/tools/pubsub/dummy_account_node.py +++ b/libp2p/tools/pubsub/dummy_account_node.py @@ -1,12 +1,29 @@ -from typing import AsyncIterator, Dict, Tuple +from typing import ( + AsyncIterator, + Dict, + Tuple, +) -from async_exit_stack import AsyncExitStack -from async_generator import asynccontextmanager -from async_service import Service, background_trio_service +from async_exit_stack import ( + AsyncExitStack, +) +from async_generator import ( + asynccontextmanager, +) +from async_service import ( + Service, + background_trio_service, +) -from libp2p.host.host_interface import IHost -from libp2p.pubsub.pubsub import Pubsub -from libp2p.tools.factories import PubsubFactory +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.pubsub.pubsub import ( + Pubsub, +) +from libp2p.tools.factories import ( + PubsubFactory, +) CRYPTO_TOPIC = "ethereum" diff --git a/libp2p/tools/pubsub/floodsub_integration_test_settings.py b/libp2p/tools/pubsub/floodsub_integration_test_settings.py index 8b3df73c..ab895d71 100644 --- a/libp2p/tools/pubsub/floodsub_integration_test_settings.py +++ b/libp2p/tools/pubsub/floodsub_integration_test_settings.py @@ -1,11 +1,16 @@ # type: ignore -# To add typing to this module, it's better to do it after refactoring test cases into classes +# To add typing to this module, it's better to do it after refactoring test cases +# into classes import pytest import trio -from libp2p.tools.constants import FLOODSUB_PROTOCOL_ID -from libp2p.tools.utils import connect +from libp2p.tools.constants import ( + FLOODSUB_PROTOCOL_ID, +) +from libp2p.tools.utils import ( + connect, +) SUPPORTED_PROTOCOLS = [FLOODSUB_PROTOCOL_ID] @@ -181,8 +186,7 @@ async def perform_test_from_obj(obj, pubsub_factory) -> None: In adj_list, for any neighbors A and B, only list B as a neighbor of A or B as a neighbor of A once. Do NOT list both A: ["B"] and B:["A"] as the behavior is undefined (even if it may work) - """ - + """ # noqa: E501 # Step 1) Create graph adj_list = obj["adj_list"] node_list = obj["nodes"] @@ -242,7 +246,8 @@ async def perform_test_from_obj(obj, pubsub_factory) -> None: for topic in topics: await pubsub_map[node_id].publish(topic, data) - # For each topic in topics, add (topic, node_id, data) tuple to ordered test list + # For each topic in topics, add (topic, node_id, data) tuple to + # ordered test list for topic in topics: topics_in_msgs_ordered.append((topic, node_id, data)) # Allow time for publishing before continuing diff --git a/libp2p/tools/pubsub/utils.py b/libp2p/tools/pubsub/utils.py index eba1bc7b..cd631e2a 100644 --- a/libp2p/tools/pubsub/utils.py +++ b/libp2p/tools/pubsub/utils.py @@ -1,9 +1,19 @@ -from typing import Sequence +from typing import ( + Sequence, +) -from libp2p.host.host_interface import IHost -from libp2p.peer.id import ID -from libp2p.pubsub.pb import rpc_pb2 -from libp2p.tools.utils import connect +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.pubsub.pb import ( + rpc_pb2, +) +from libp2p.tools.utils import ( + connect, +) def make_pubsub_msg( diff --git a/libp2p/tools/utils.py b/libp2p/tools/utils.py index 5a262b3b..37764c4e 100644 --- a/libp2p/tools/utils.py +++ b/libp2p/tools/utils.py @@ -1,12 +1,27 @@ -from typing import Awaitable, Callable +from typing import ( + Awaitable, + Callable, +) -from libp2p.host.host_interface import IHost -from libp2p.network.stream.exceptions import StreamError -from libp2p.network.stream.net_stream_interface import INetStream -from libp2p.network.swarm import Swarm -from libp2p.peer.peerinfo import info_from_p2p_addr +from libp2p.host.host_interface import ( + IHost, +) +from libp2p.network.stream.exceptions import ( + StreamError, +) +from libp2p.network.stream.net_stream_interface import ( + INetStream, +) +from libp2p.network.swarm import ( + Swarm, +) +from libp2p.peer.peerinfo import ( + info_from_p2p_addr, +) -from .constants import MAX_READ_LEN +from .constants import ( + MAX_READ_LEN, +) async def connect_swarm(swarm_0: Swarm, swarm_1: Swarm) -> None: @@ -30,7 +45,7 @@ async def connect(node1: IHost, node2: IHost) -> None: def create_echo_stream_handler( - ack_prefix: str + ack_prefix: str, ) -> Callable[[INetStream], Awaitable[None]]: async def echo_stream_handler(stream: INetStream) -> None: while True: diff --git a/libp2p/transport/exceptions.py b/libp2p/transport/exceptions.py index d935b3a0..8e370de9 100644 --- a/libp2p/transport/exceptions.py +++ b/libp2p/transport/exceptions.py @@ -1,4 +1,6 @@ -from libp2p.exceptions import BaseLibp2pError +from libp2p.exceptions import ( + BaseLibp2pError, +) class OpenConnectionError(BaseLibp2pError): diff --git a/libp2p/transport/listener_interface.py b/libp2p/transport/listener_interface.py index d170d1de..63a742be 100644 --- a/libp2p/transport/listener_interface.py +++ b/libp2p/transport/listener_interface.py @@ -1,7 +1,14 @@ -from abc import ABC, abstractmethod -from typing import Tuple +from abc import ( + ABC, + abstractmethod, +) +from typing import ( + Tuple, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import trio @@ -9,7 +16,7 @@ class IListener(ABC): @abstractmethod async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> bool: """ - put listener in listening mode and wait for incoming connections. + Put listener in listening mode and wait for incoming connections. :param maddr: multiaddr of peer :return: return True if successful @@ -18,7 +25,7 @@ class IListener(ABC): @abstractmethod def get_addrs(self) -> Tuple[Multiaddr, ...]: """ - retrieve list of addresses the listener is listening on. + Retrieve list of addresses the listener is listening on. :return: return list of addrs """ diff --git a/libp2p/transport/tcp/tcp.py b/libp2p/transport/tcp/tcp.py index 8edaca8f..3b1c66d5 100644 --- a/libp2p/transport/tcp/tcp.py +++ b/libp2p/transport/tcp/tcp.py @@ -1,17 +1,41 @@ import logging -from typing import Awaitable, Callable, List, Sequence, Tuple +from typing import ( + Awaitable, + Callable, + List, + Sequence, + Tuple, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import trio -from trio_typing import TaskStatus +from trio_typing import ( + TaskStatus, +) -from libp2p.io.trio import TrioTCPStream -from libp2p.network.connection.raw_connection import RawConnection -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.transport.exceptions import OpenConnectionError -from libp2p.transport.listener_interface import IListener -from libp2p.transport.transport_interface import ITransport -from libp2p.transport.typing import THandler +from libp2p.io.trio import ( + TrioTCPStream, +) +from libp2p.network.connection.raw_connection import ( + RawConnection, +) +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.transport.exceptions import ( + OpenConnectionError, +) +from libp2p.transport.listener_interface import ( + IListener, +) +from libp2p.transport.transport_interface import ( + ITransport, +) +from libp2p.transport.typing import ( + THandler, +) logger = logging.getLogger("libp2p.transport.tcp") @@ -26,7 +50,7 @@ class TCPListener(IListener): # TODO: Get rid of `nursery`? async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> None: """ - put listener in listening mode and wait for incoming connections. + Put listener in listening mode and wait for incoming connections. :param maddr: maddr of peer :return: return True if successful @@ -56,7 +80,7 @@ class TCPListener(IListener): def get_addrs(self) -> Tuple[Multiaddr, ...]: """ - retrieve list of addresses the listener is listening on. + Retrieve list of addresses the listener is listening on. :return: return list of addrs """ @@ -73,7 +97,7 @@ class TCPListener(IListener): class TCP(ITransport): async def dial(self, maddr: Multiaddr) -> IRawConnection: """ - dial a transport to peer listening on multiaddr. + Dial a transport to peer listening on multiaddr. :param maddr: multiaddr of peer :return: `RawConnection` if successful @@ -92,7 +116,7 @@ class TCP(ITransport): def create_listener(self, handler_function: THandler) -> TCPListener: """ - create listener on transport. + Create listener on transport. :param handler_function: a function called when a new connection is received that takes a connection as argument which implements interface-connection diff --git a/libp2p/transport/transport_interface.py b/libp2p/transport/transport_interface.py index 402162bc..32feab4a 100644 --- a/libp2p/transport/transport_interface.py +++ b/libp2p/transport/transport_interface.py @@ -1,18 +1,29 @@ -from abc import ABC, abstractmethod +from abc import ( + ABC, + abstractmethod, +) -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) -from libp2p.network.connection.raw_connection_interface import IRawConnection +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) -from .listener_interface import IListener -from .typing import THandler +from .listener_interface import ( + IListener, +) +from .typing import ( + THandler, +) class ITransport(ABC): @abstractmethod async def dial(self, maddr: Multiaddr) -> IRawConnection: """ - dial a transport to peer listening on multiaddr. + Dial a transport to peer listening on multiaddr. :param multiaddr: multiaddr of peer :param self_id: peer_id of the dialer (to send to receiver) @@ -22,7 +33,7 @@ class ITransport(ABC): @abstractmethod def create_listener(self, handler_function: THandler) -> IListener: """ - create listener on transport. + Create listener on transport. :param handler_function: a function called when a new conntion is received that takes a connection as argument which implements interface-connection diff --git a/libp2p/transport/typing.py b/libp2p/transport/typing.py index d68a8aa4..b406a20c 100644 --- a/libp2p/transport/typing.py +++ b/libp2p/transport/typing.py @@ -1,9 +1,22 @@ -from typing import Awaitable, Callable, Mapping, Type +from typing import ( + Awaitable, + Callable, + Mapping, + Type, +) -from libp2p.io.abc import ReadWriteCloser -from libp2p.security.secure_transport_interface import ISecureTransport -from libp2p.stream_muxer.abc import IMuxedConn -from libp2p.typing import TProtocol +from libp2p.io.abc import ( + ReadWriteCloser, +) +from libp2p.security.secure_transport_interface import ( + ISecureTransport, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, +) +from libp2p.typing import ( + TProtocol, +) THandler = Callable[[ReadWriteCloser], Awaitable[None]] TSecurityOptions = Mapping[TProtocol, ISecureTransport] diff --git a/libp2p/transport/upgrader.py b/libp2p/transport/upgrader.py index cd8c26da..4203b718 100644 --- a/libp2p/transport/upgrader.py +++ b/libp2p/transport/upgrader.py @@ -1,16 +1,43 @@ -from libp2p.network.connection.raw_connection_interface import IRawConnection -from libp2p.peer.id import ID -from libp2p.protocol_muxer.exceptions import MultiselectClientError, MultiselectError -from libp2p.security.exceptions import HandshakeFailure -from libp2p.security.secure_conn_interface import ISecureConn -from libp2p.security.security_multistream import SecurityMultistream -from libp2p.stream_muxer.abc import IMuxedConn -from libp2p.stream_muxer.muxer_multistream import MuxerMultistream -from libp2p.transport.exceptions import MuxerUpgradeFailure, SecurityUpgradeFailure -from libp2p.transport.typing import TMuxerOptions, TSecurityOptions +from libp2p.network.connection.raw_connection_interface import ( + IRawConnection, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.protocol_muxer.exceptions import ( + MultiselectClientError, + MultiselectError, +) +from libp2p.security.exceptions import ( + HandshakeFailure, +) +from libp2p.security.secure_conn_interface import ( + ISecureConn, +) +from libp2p.security.security_multistream import ( + SecurityMultistream, +) +from libp2p.stream_muxer.abc import ( + IMuxedConn, +) +from libp2p.stream_muxer.muxer_multistream import ( + MuxerMultistream, +) +from libp2p.transport.exceptions import ( + MuxerUpgradeFailure, + SecurityUpgradeFailure, +) +from libp2p.transport.typing import ( + TMuxerOptions, + TSecurityOptions, +) -from .listener_interface import IListener -from .transport_interface import ITransport +from .listener_interface import ( + IListener, +) +from .transport_interface import ( + ITransport, +) class TransportUpgrader: @@ -28,7 +55,6 @@ class TransportUpgrader: def upgrade_listener(self, transport: ITransport, listeners: IListener) -> None: """Upgrade multiaddr listeners to libp2p-transport listeners.""" # TODO: Figure out what to do with this function. - pass async def upgrade_security( self, raw_conn: IRawConnection, peer_id: ID, is_initiator: bool diff --git a/libp2p/typing.py b/libp2p/typing.py index be0b584e..7c21f6df 100644 --- a/libp2p/typing.py +++ b/libp2p/typing.py @@ -1,4 +1,9 @@ -from typing import TYPE_CHECKING, Awaitable, Callable, NewType +from typing import ( + TYPE_CHECKING, + Awaitable, + Callable, + NewType, +) if TYPE_CHECKING: from libp2p.network.stream.net_stream_interface import INetStream # noqa: F401 diff --git a/libp2p/utils.py b/libp2p/utils.py index 64937829..45111c23 100644 --- a/libp2p/utils.py +++ b/libp2p/utils.py @@ -1,16 +1,22 @@ import itertools import math -from libp2p.exceptions import ParseError -from libp2p.io.abc import Reader +from libp2p.exceptions import ( + ParseError, +) +from libp2p.io.abc import ( + Reader, +) -from .io.utils import read_exactly +from .io.utils import ( + read_exactly, +) # Unsigned LEB128(varint codec) # Reference: https://github.com/ethereum/py-wasm/blob/master/wasm/parsers/leb128.py -LOW_MASK = 2 ** 7 - 1 -HIGH_MASK = 2 ** 7 +LOW_MASK = 2**7 - 1 +HIGH_MASK = 2**7 # The maximum shift width for a 64 bit integer. We shouldn't have to decode @@ -72,7 +78,7 @@ def encode_delim(msg: bytes) -> bytes: async def read_delim(reader: Reader) -> bytes: msg_bytes = await read_varint_prefixed_bytes(reader) if len(msg_bytes) == 0: - raise ParseError(f"`len(msg_bytes)` should not be 0") + raise ParseError("`len(msg_bytes)` should not be 0") if msg_bytes[-1:] != b"\n": raise ParseError( f'`msg_bytes` is not delimited by b"\\n": `msg_bytes`={msg_bytes!r}' diff --git a/scripts/release/test_package.py b/scripts/release/test_package.py index 89ef36a4..cc16c8e9 100644 --- a/scripts/release/test_package.py +++ b/scripts/release/test_package.py @@ -1,22 +1,29 @@ -from pathlib import Path +from pathlib import ( + Path, +) import subprocess -from tempfile import TemporaryDirectory +from tempfile import ( + TemporaryDirectory, +) import venv def create_venv(parent_path): - venv_path = parent_path / 'package-smoke-test' + venv_path = parent_path / "package-smoke-test" venv.create(venv_path, with_pip=True) - subprocess.run([venv_path / 'bin' / 'pip', 'install', '-U', 'pip', 'setuptools'], check=True) + subprocess.run( + [venv_path / "bin" / "pip", "install", "-U", "pip", "setuptools"], check=True + ) return venv_path def find_wheel(project_path): - wheels = list(project_path.glob('dist/*.whl')) + wheels = list(project_path.glob("dist/*.whl")) if len(wheels) != 1: raise Exception( - f"Expected one wheel. Instead found: {wheels} in project {project_path.absolute()}" + f"Expected one wheel. Instead found: {wheels} in project " + f"{project_path.absolute()}" ) return wheels[0] @@ -29,11 +36,7 @@ def install_wheel(venv_path, wheel_path, extras=()): extra_suffix = "" subprocess.run( - [ - venv_path / 'bin' / 'pip', - 'install', - f"{wheel_path}{extra_suffix}" - ], + [venv_path / "bin" / "pip", "install", f"{wheel_path}{extra_suffix}"], check=True, ) @@ -41,12 +44,12 @@ def install_wheel(venv_path, wheel_path, extras=()): def test_install_local_wheel(): with TemporaryDirectory() as tmpdir: venv_path = create_venv(Path(tmpdir)) - wheel_path = find_wheel(Path('.')) + wheel_path = find_wheel(Path(".")) install_wheel(venv_path, wheel_path) print("Installed", wheel_path.absolute(), "to", venv_path) print(f"Activate with `source {venv_path}/bin/activate`") input("Press enter when the test has completed. The directory will be deleted.") -if __name__ == '__main__': +if __name__ == "__main__": test_install_local_wheel() diff --git a/setup.py b/setup.py index 1ed91f39..e6d910c4 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- import os from setuptools import ( diff --git a/tests/conftest.py b/tests/conftest.py index c1a2b132..8b34953a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,8 @@ import pytest -from libp2p.tools.factories import HostFactory +from libp2p.tools.factories import ( + HostFactory, +) @pytest.fixture diff --git a/tests/core/test_import_and_version.py b/tests/core/test_import_and_version.py index b9e96e4c..b5ba01d6 100644 --- a/tests/core/test_import_and_version.py +++ b/tests/core/test_import_and_version.py @@ -1,4 +1,4 @@ def test_import_and_version(): import libp2p - + assert isinstance(libp2p.__version__, str) diff --git a/tests/crypto/test_ed25519.py b/tests/crypto/test_ed25519.py index 89c446f9..92c8216d 100644 --- a/tests/crypto/test_ed25519.py +++ b/tests/crypto/test_ed25519.py @@ -1,5 +1,10 @@ -from libp2p.crypto.ed25519 import create_new_key_pair -from libp2p.crypto.serialization import deserialize_private_key, deserialize_public_key +from libp2p.crypto.ed25519 import ( + create_new_key_pair, +) +from libp2p.crypto.serialization import ( + deserialize_private_key, + deserialize_public_key, +) def test_public_key_serialize_deserialize_round_trip(): diff --git a/tests/crypto/test_secp256k1.py b/tests/crypto/test_secp256k1.py index 81e9eb23..d2bb0327 100644 --- a/tests/crypto/test_secp256k1.py +++ b/tests/crypto/test_secp256k1.py @@ -1,5 +1,10 @@ -from libp2p.crypto.secp256k1 import create_new_key_pair -from libp2p.crypto.serialization import deserialize_private_key, deserialize_public_key +from libp2p.crypto.secp256k1 import ( + create_new_key_pair, +) +from libp2p.crypto.serialization import ( + deserialize_private_key, + deserialize_public_key, +) def test_public_key_serialize_deserialize_round_trip(): diff --git a/tests/examples/test_examples.py b/tests/examples/test_examples.py index df59bd24..56997bad 100644 --- a/tests/examples/test_examples.py +++ b/tests/examples/test_examples.py @@ -1,10 +1,18 @@ import pytest import trio -from libp2p.host.exceptions import StreamFailure -from libp2p.peer.peerinfo import info_from_p2p_addr -from libp2p.tools.factories import HostFactory -from libp2p.tools.utils import MAX_READ_LEN +from libp2p.host.exceptions import ( + StreamFailure, +) +from libp2p.peer.peerinfo import ( + info_from_p2p_addr, +) +from libp2p.tools.factories import ( + HostFactory, +) +from libp2p.tools.utils import ( + MAX_READ_LEN, +) PROTOCOL_ID = "/chat/1.0.0" diff --git a/tests/host/test_basic_host.py b/tests/host/test_basic_host.py index 55605ed5..ed21ad80 100644 --- a/tests/host/test_basic_host.py +++ b/tests/host/test_basic_host.py @@ -1,7 +1,15 @@ -from libp2p import new_swarm -from libp2p.crypto.rsa import create_new_key_pair -from libp2p.host.basic_host import BasicHost -from libp2p.host.defaults import get_default_protocols +from libp2p import ( + new_swarm, +) +from libp2p.crypto.rsa import ( + create_new_key_pair, +) +from libp2p.host.basic_host import ( + BasicHost, +) +from libp2p.host.defaults import ( + get_default_protocols, +) def test_default_protocols(): @@ -11,6 +19,6 @@ def test_default_protocols(): mux = host.get_mux() handlers = mux.handlers - # NOTE: comparing keys for equality as handlers may be closures that do not compare in the way - # this test is concerned with + # NOTE: comparing keys for equality as handlers may be closures that do not compare + # in the way this test is concerned with assert handlers.keys() == get_default_protocols(host).keys() diff --git a/tests/host/test_ping.py b/tests/host/test_ping.py index 79285bc8..77387b8f 100644 --- a/tests/host/test_ping.py +++ b/tests/host/test_ping.py @@ -3,8 +3,13 @@ import secrets import pytest import trio -from libp2p.host.ping import ID, PING_LENGTH -from libp2p.tools.factories import host_pair_factory +from libp2p.host.ping import ( + ID, + PING_LENGTH, +) +from libp2p.tools.factories import ( + host_pair_factory, +) @pytest.mark.trio diff --git a/tests/host/test_routed_host.py b/tests/host/test_routed_host.py index 7dfa8e7f..d7ccde0d 100644 --- a/tests/host/test_routed_host.py +++ b/tests/host/test_routed_host.py @@ -1,8 +1,15 @@ import pytest -from libp2p.host.exceptions import ConnectionFailure -from libp2p.peer.peerinfo import PeerInfo -from libp2p.tools.factories import HostFactory, RoutedHostFactory +from libp2p.host.exceptions import ( + ConnectionFailure, +) +from libp2p.peer.peerinfo import ( + PeerInfo, +) +from libp2p.tools.factories import ( + HostFactory, + RoutedHostFactory, +) @pytest.mark.trio diff --git a/tests/identity/identify/test_protocol.py b/tests/identity/identify/test_protocol.py index 0d398ff9..58592d70 100644 --- a/tests/identity/identify/test_protocol.py +++ b/tests/identity/identify/test_protocol.py @@ -1,8 +1,15 @@ import pytest -from libp2p.identity.identify.pb.identify_pb2 import Identify -from libp2p.identity.identify.protocol import ID, _mk_identify_protobuf -from libp2p.tools.factories import host_pair_factory +from libp2p.identity.identify.pb.identify_pb2 import ( + Identify, +) +from libp2p.identity.identify.protocol import ( + ID, + _mk_identify_protobuf, +) +from libp2p.tools.factories import ( + host_pair_factory, +) @pytest.mark.trio diff --git a/tests/libp2p/test_libp2p.py b/tests/libp2p/test_libp2p.py index 8cf8e069..7fa7bbdc 100644 --- a/tests/libp2p/test_libp2p.py +++ b/tests/libp2p/test_libp2p.py @@ -1,11 +1,22 @@ import multiaddr import pytest -from libp2p.network.stream.exceptions import StreamError -from libp2p.tools.constants import MAX_READ_LEN -from libp2p.tools.factories import HostFactory -from libp2p.tools.utils import connect, create_echo_stream_handler -from libp2p.typing import TProtocol +from libp2p.network.stream.exceptions import ( + StreamError, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) +from libp2p.tools.factories import ( + HostFactory, +) +from libp2p.tools.utils import ( + connect, + create_echo_stream_handler, +) +from libp2p.typing import ( + TProtocol, +) PROTOCOL_ID_0 = TProtocol("/echo/0") PROTOCOL_ID_1 = TProtocol("/echo/1") @@ -84,7 +95,8 @@ async def test_double_response(security_protocol): @pytest.mark.trio async def test_multiple_streams(security_protocol): # hosts[0] should be able to open a stream with hosts[1] and then vice versa. - # Stream IDs should be generated uniquely so that the stream state is not overwritten + # Stream IDs should be generated uniquely so that the stream state is not + # overwritten async with HostFactory.create_batch_and_listen( 2, security_protocol=security_protocol @@ -125,7 +137,6 @@ async def test_multiple_streams_same_initiator_different_protocols(security_prot async with HostFactory.create_batch_and_listen( 2, security_protocol=security_protocol ) as hosts: - hosts[1].set_stream_handler( PROTOCOL_ID_0, create_echo_stream_handler(ACK_STR_0) ) @@ -231,7 +242,6 @@ async def test_triangle_nodes_connection(security_protocol): async with HostFactory.create_batch_and_listen( 3, security_protocol=security_protocol ) as hosts: - hosts[0].set_stream_handler( PROTOCOL_ID_0, create_echo_stream_handler(ACK_STR_0) ) diff --git a/tests/network/test_net_stream.py b/tests/network/test_net_stream.py index b558f1dd..2f913515 100644 --- a/tests/network/test_net_stream.py +++ b/tests/network/test_net_stream.py @@ -1,8 +1,14 @@ import pytest import trio -from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset -from libp2p.tools.constants import MAX_READ_LEN +from libp2p.network.stream.exceptions import ( + StreamClosed, + StreamEOF, + StreamReset, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) DATA = b"data_123" diff --git a/tests/network/test_notify.py b/tests/network/test_notify.py index 5be4c082..b01a34a3 100644 --- a/tests/network/test_notify.py +++ b/tests/network/test_notify.py @@ -10,14 +10,24 @@ features are implemented in swarm """ import enum -from async_service import background_trio_service +from async_service import ( + background_trio_service, +) import pytest import trio -from libp2p.network.notifee_interface import INotifee -from libp2p.tools.constants import LISTEN_MADDR -from libp2p.tools.factories import SwarmFactory -from libp2p.tools.utils import connect_swarm +from libp2p.network.notifee_interface import ( + INotifee, +) +from libp2p.tools.constants import ( + LISTEN_MADDR, +) +from libp2p.tools.factories import ( + SwarmFactory, +) +from libp2p.tools.utils import ( + connect_swarm, +) class Event(enum.Enum): @@ -63,8 +73,8 @@ async def test_notify(security_protocol): events_0_without_listen = [] # Run swarms. async with background_trio_service(swarms[0]), background_trio_service(swarms[1]): - # Register events before listening, to allow `MyNotifee` is notified with the event - # `listen`. + # Register events before listening, to allow `MyNotifee` is notified with the + # event `listen`. swarms[0].register_notifee(MyNotifee(events_0_0)) swarms[1].register_notifee(MyNotifee(events_1_0)) diff --git a/tests/network/test_swarm.py b/tests/network/test_swarm.py index 42b7db1c..ae2b46d0 100644 --- a/tests/network/test_swarm.py +++ b/tests/network/test_swarm.py @@ -1,11 +1,21 @@ -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import pytest import trio -from trio.testing import wait_all_tasks_blocked +from trio.testing import ( + wait_all_tasks_blocked, +) -from libp2p.network.exceptions import SwarmException -from libp2p.tools.factories import SwarmFactory -from libp2p.tools.utils import connect_swarm +from libp2p.network.exceptions import ( + SwarmException, +) +from libp2p.tools.factories import ( + SwarmFactory, +) +from libp2p.tools.utils import ( + connect_swarm, +) @pytest.mark.trio diff --git a/tests/network/test_swarm_conn.py b/tests/network/test_swarm_conn.py index dc692f44..ebd66cfb 100644 --- a/tests/network/test_swarm_conn.py +++ b/tests/network/test_swarm_conn.py @@ -1,6 +1,8 @@ import pytest import trio -from trio.testing import wait_all_tasks_blocked +from trio.testing import ( + wait_all_tasks_blocked, +) @pytest.mark.trio diff --git a/tests/peer/test_addrbook.py b/tests/peer/test_addrbook.py index 1cc273d6..55240659 100644 --- a/tests/peer/test_addrbook.py +++ b/tests/peer/test_addrbook.py @@ -1,6 +1,9 @@ import pytest -from libp2p.peer.peerstore import PeerStore, PeerStoreError +from libp2p.peer.peerstore import ( + PeerStore, + PeerStoreError, +) # Testing methods from IAddrBook base class. @@ -51,8 +54,8 @@ def test_peers_with_addrs(): store.add_addrs("peer2", ["/foo"], 10) store.add_addrs("peer3", ["/bar"], 10) - assert set(store.peers_with_addrs()) == set(["peer2", "peer3"]) + assert set(store.peers_with_addrs()) == {"peer2", "peer3"} store.clear_addrs("peer2") - assert set(store.peers_with_addrs()) == set(["peer3"]) + assert set(store.peers_with_addrs()) == {"peer3"} diff --git a/tests/peer/test_interop.py b/tests/peer/test_interop.py index 17dcb4ce..cda571f9 100644 --- a/tests/peer/test_interop.py +++ b/tests/peer/test_interop.py @@ -3,8 +3,12 @@ import base64 import Crypto.PublicKey.RSA as RSA from libp2p.crypto.pb import crypto_pb2 as pb -from libp2p.crypto.rsa import RSAPrivateKey -from libp2p.peer.id import ID +from libp2p.crypto.rsa import ( + RSAPrivateKey, +) +from libp2p.peer.id import ( + ID, +) # ``PRIVATE_KEY_PROTOBUF_SERIALIZATION`` is a protobuf holding an RSA private key. PRIVATE_KEY_PROTOBUF_SERIALIZATION = """ diff --git a/tests/peer/test_peerid.py b/tests/peer/test_peerid.py index e808a3b6..b2201c09 100644 --- a/tests/peer/test_peerid.py +++ b/tests/peer/test_peerid.py @@ -3,9 +3,13 @@ import random import base58 import multihash -from libp2p.crypto.rsa import create_new_key_pair +from libp2p.crypto.rsa import ( + create_new_key_pair, +) import libp2p.peer.id as PeerID -from libp2p.peer.id import ID +from libp2p.peer.id import ( + ID, +) ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" diff --git a/tests/peer/test_peerinfo.py b/tests/peer/test_peerinfo.py index deb760d4..cc3f79a0 100644 --- a/tests/peer/test_peerinfo.py +++ b/tests/peer/test_peerinfo.py @@ -3,8 +3,14 @@ import random import multiaddr import pytest -from libp2p.peer.id import ID -from libp2p.peer.peerinfo import InvalidAddrError, PeerInfo, info_from_p2p_addr +from libp2p.peer.id import ( + ID, +) +from libp2p.peer.peerinfo import ( + InvalidAddrError, + PeerInfo, + info_from_p2p_addr, +) ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501 diff --git a/tests/peer/test_peermetadata.py b/tests/peer/test_peermetadata.py index 412a1511..0ee56f2d 100644 --- a/tests/peer/test_peermetadata.py +++ b/tests/peer/test_peermetadata.py @@ -1,6 +1,9 @@ import pytest -from libp2p.peer.peerstore import PeerStore, PeerStoreError +from libp2p.peer.peerstore import ( + PeerStore, + PeerStoreError, +) # Testing methods from IPeerMetadata base class. diff --git a/tests/peer/test_peerstore.py b/tests/peer/test_peerstore.py index 4a45651e..42137b3c 100644 --- a/tests/peer/test_peerstore.py +++ b/tests/peer/test_peerstore.py @@ -1,6 +1,9 @@ import pytest -from libp2p.peer.peerstore import PeerStore, PeerStoreError +from libp2p.peer.peerstore import ( + PeerStore, + PeerStoreError, +) # Testing methods from IPeerStore base class. @@ -25,8 +28,8 @@ def test_add_get_protocols_basic(): store.add_protocols("peer1", ["p1", "p2"]) store.add_protocols("peer2", ["p3"]) - assert set(store.get_protocols("peer1")) == set(["p1", "p2"]) - assert set(store.get_protocols("peer2")) == set(["p3"]) + assert set(store.get_protocols("peer1")) == {"p1", "p2"} + assert set(store.get_protocols("peer2")) == {"p3"} def test_add_get_protocols_extend(): @@ -34,7 +37,7 @@ def test_add_get_protocols_extend(): store.add_protocols("peer1", ["p1", "p2"]) store.add_protocols("peer1", ["p3"]) - assert set(store.get_protocols("peer1")) == set(["p1", "p2", "p3"]) + assert set(store.get_protocols("peer1")) == {"p1", "p2", "p3"} def test_set_protocols(): @@ -45,8 +48,8 @@ def test_set_protocols(): store.set_protocols("peer1", ["p4"]) store.set_protocols("peer2", []) - assert set(store.get_protocols("peer1")) == set(["p4"]) - assert set(store.get_protocols("peer2")) == set([]) + assert set(store.get_protocols("peer1")) == {"p4"} + assert set(store.get_protocols("peer2")) == set() # Test with methods from other Peer interfaces. @@ -56,4 +59,4 @@ def test_peers(): store.put("peer2", "key", "val") store.add_addr("peer3", "/foo", 10) - assert set(store.peer_ids()) == set(["peer1", "peer2", "peer3"]) + assert set(store.peer_ids()) == {"peer1", "peer2", "peer3"} diff --git a/tests/protocol_muxer/test_protocol_muxer.py b/tests/protocol_muxer/test_protocol_muxer.py index 0537c4ea..ce6be7ac 100644 --- a/tests/protocol_muxer/test_protocol_muxer.py +++ b/tests/protocol_muxer/test_protocol_muxer.py @@ -1,8 +1,14 @@ import pytest -from libp2p.host.exceptions import StreamFailure -from libp2p.tools.factories import HostFactory -from libp2p.tools.utils import create_echo_stream_handler +from libp2p.host.exceptions import ( + StreamFailure, +) +from libp2p.tools.factories import ( + HostFactory, +) +from libp2p.tools.utils import ( + create_echo_stream_handler, +) PROTOCOL_ECHO = "/echo/1.0.0" PROTOCOL_POTATO = "/potato/1.0.0" diff --git a/tests/pubsub/test_dummyaccount_demo.py b/tests/pubsub/test_dummyaccount_demo.py index 24d5bd41..ab8278b3 100644 --- a/tests/pubsub/test_dummyaccount_demo.py +++ b/tests/pubsub/test_dummyaccount_demo.py @@ -1,8 +1,12 @@ import pytest import trio -from libp2p.tools.pubsub.dummy_account_node import DummyAccountNode -from libp2p.tools.utils import connect +from libp2p.tools.pubsub.dummy_account_node import ( + DummyAccountNode, +) +from libp2p.tools.utils import ( + connect, +) async def perform_test(num_nodes, adjacency_map, action_func, assertion_func): diff --git a/tests/pubsub/test_floodsub.py b/tests/pubsub/test_floodsub.py index fe9f9cfd..11400197 100644 --- a/tests/pubsub/test_floodsub.py +++ b/tests/pubsub/test_floodsub.py @@ -3,13 +3,19 @@ import functools import pytest import trio -from libp2p.peer.id import ID -from libp2p.tools.factories import PubsubFactory +from libp2p.peer.id import ( + ID, +) +from libp2p.tools.factories import ( + PubsubFactory, +) from libp2p.tools.pubsub.floodsub_integration_test_settings import ( floodsub_protocol_pytest_params, perform_test_from_obj, ) -from libp2p.tools.utils import connect +from libp2p.tools.utils import ( + connect, +) @pytest.mark.trio diff --git a/tests/pubsub/test_gossipsub.py b/tests/pubsub/test_gossipsub.py index 20611300..8dc1b575 100644 --- a/tests/pubsub/test_gossipsub.py +++ b/tests/pubsub/test_gossipsub.py @@ -3,10 +3,20 @@ import random import pytest import trio -from libp2p.pubsub.gossipsub import PROTOCOL_ID -from libp2p.tools.factories import IDFactory, PubsubFactory -from libp2p.tools.pubsub.utils import dense_connect, one_to_all_connect -from libp2p.tools.utils import connect +from libp2p.pubsub.gossipsub import ( + PROTOCOL_ID, +) +from libp2p.tools.factories import ( + IDFactory, + PubsubFactory, +) +from libp2p.tools.pubsub.utils import ( + dense_connect, + one_to_all_connect, +) +from libp2p.tools.utils import ( + connect, +) @pytest.mark.trio @@ -353,11 +363,11 @@ async def test_mesh_heartbeat(initial_mesh_peer_count, monkeypatch): 1, heartbeat_initial_delay=100 ) as pubsubs_gsub: # It's difficult to set up the initial peer subscription condition. - # Ideally I would like to have initial mesh peer count that's below ``GossipSubDegree`` - # so I can test if `mesh_heartbeat` return correct peers to GRAFT. - # The problem is that I can not set it up so that we have peers subscribe to the topic - # but not being part of our mesh peers (as these peers are the peers to GRAFT). - # So I monkeypatch the peer subscriptions and our mesh peers. + # Ideally I would like to have initial mesh peer count that's below + # ``GossipSubDegree`` so I can test if `mesh_heartbeat` return correct peers to + # GRAFT. The problem is that I can not set it up so that we have peers subscribe + # to the topic but not being part of our mesh peers (as these peers are the + # peers to GRAFT). So I monkeypatch the peer subscriptions and our mesh peers. total_peer_count = 14 topic = "TEST_MESH_HEARTBEAT" @@ -408,9 +418,9 @@ async def test_gossip_heartbeat(initial_peer_count, monkeypatch): async with PubsubFactory.create_batch_with_gossipsub( 1, heartbeat_initial_delay=100 ) as pubsubs_gsub: - # The problem is that I can not set it up so that we have peers subscribe to the topic - # but not being part of our mesh peers (as these peers are the peers to GRAFT). - # So I monkeypatch the peer subscriptions and our mesh peers. + # The problem is that I can not set it up so that we have peers subscribe to the + # topic but not being part of our mesh peers (as these peers are the peers to + # GRAFT). So I monkeypatch the peer subscriptions and our mesh peers. total_peer_count = 28 topic_mesh = "TEST_GOSSIP_HEARTBEAT_1" topic_fanout = "TEST_GOSSIP_HEARTBEAT_2" @@ -455,8 +465,8 @@ async def test_gossip_heartbeat(initial_peer_count, monkeypatch): monkeypatch.setattr(pubsubs_gsub[0].router.mcache, "window", window) peers_to_gossip = pubsubs_gsub[0].router.gossip_heartbeat() - # If our mesh peer count is less than `GossipSubDegree`, we should gossip to up to - # `GossipSubDegree` peers (exclude mesh peers). + # If our mesh peer count is less than `GossipSubDegree`, we should gossip to up + # to `GossipSubDegree` peers (exclude mesh peers). if topic_mesh_peer_count - initial_peer_count < pubsubs_gsub[0].router.degree: # The same goes for fanout so it's two times the number of peers to gossip. assert len(peers_to_gossip) == 2 * ( diff --git a/tests/pubsub/test_gossipsub_backward_compatibility.py b/tests/pubsub/test_gossipsub_backward_compatibility.py index 08f0284b..09c40579 100644 --- a/tests/pubsub/test_gossipsub_backward_compatibility.py +++ b/tests/pubsub/test_gossipsub_backward_compatibility.py @@ -2,8 +2,12 @@ import functools import pytest -from libp2p.tools.constants import FLOODSUB_PROTOCOL_ID -from libp2p.tools.factories import PubsubFactory +from libp2p.tools.constants import ( + FLOODSUB_PROTOCOL_ID, +) +from libp2p.tools.factories import ( + PubsubFactory, +) from libp2p.tools.pubsub.floodsub_integration_test_settings import ( floodsub_protocol_pytest_params, perform_test_from_obj, diff --git a/tests/pubsub/test_mcache.py b/tests/pubsub/test_mcache.py index fb764b31..7a494259 100644 --- a/tests/pubsub/test_mcache.py +++ b/tests/pubsub/test_mcache.py @@ -1,4 +1,6 @@ -from libp2p.pubsub.mcache import MessageCache +from libp2p.pubsub.mcache import ( + MessageCache, +) class Msg: diff --git a/tests/pubsub/test_pubsub.py b/tests/pubsub/test_pubsub.py index 2209413e..26f725ce 100644 --- a/tests/pubsub/test_pubsub.py +++ b/tests/pubsub/test_pubsub.py @@ -1,17 +1,40 @@ -from contextlib import contextmanager -from typing import NamedTuple +from contextlib import ( + contextmanager, +) +from typing import ( + NamedTuple, +) import pytest import trio -from libp2p.exceptions import ValidationError -from libp2p.pubsub.pb import rpc_pb2 -from libp2p.pubsub.pubsub import PUBSUB_SIGNING_PREFIX, SUBSCRIPTION_CHANNEL_SIZE -from libp2p.tools.constants import MAX_READ_LEN -from libp2p.tools.factories import IDFactory, PubsubFactory, net_stream_pair_factory -from libp2p.tools.pubsub.utils import make_pubsub_msg -from libp2p.tools.utils import connect -from libp2p.utils import encode_varint_prefixed +from libp2p.exceptions import ( + ValidationError, +) +from libp2p.pubsub.pb import ( + rpc_pb2, +) +from libp2p.pubsub.pubsub import ( + PUBSUB_SIGNING_PREFIX, + SUBSCRIPTION_CHANNEL_SIZE, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) +from libp2p.tools.factories import ( + IDFactory, + PubsubFactory, + net_stream_pair_factory, +) +from libp2p.tools.pubsub.utils import ( + make_pubsub_msg, +) +from libp2p.tools.utils import ( + connect, +) +from libp2p.utils import ( + encode_varint_prefixed, +) TESTING_TOPIC = "TEST_SUBSCRIBE" TESTING_DATA = b"data" @@ -77,7 +100,8 @@ async def test_get_hello_packet(): packet = pubsubs_fsub[0].get_hello_packet() return tuple(sub.topicid for sub in packet.subscriptions) - # Test: No subscription, so there should not be any topic ids in the hello packet. + # Test: No subscription, so there should not be any topic ids in the + # hello packet. assert len(_get_hello_packet_topic_ids()) == 0 # Test: After subscriptions, topic ids should be in the hello packet. @@ -469,7 +493,8 @@ async def test_subscribe_and_publish_full_channel(): for data in list_data: await pubsub.publish(TESTING_TOPIC, data) - # Publish `extra_data_0` which should be dropped since the channel is already full. + # Publish `extra_data_0` which should be dropped since the channel is + # already full. await pubsub.publish(TESTING_TOPIC, extra_data_0) # Consume a message and there is an empty slot in the channel. assert (await subscription.get()).data == expected_list_data.pop(0) @@ -520,7 +545,6 @@ async def test_push_msg(monkeypatch): @contextmanager def mock_router_publish(): - event = trio.Event() async def router_publish(*args, **kwargs): diff --git a/tests/pubsub/test_subscription.py b/tests/pubsub/test_subscription.py index a0a6c10c..4564531a 100644 --- a/tests/pubsub/test_subscription.py +++ b/tests/pubsub/test_subscription.py @@ -3,8 +3,12 @@ import math import pytest import trio -from libp2p.pubsub.pb import rpc_pb2 -from libp2p.pubsub.subscription import TrioSubscriptionAPI +from libp2p.pubsub.pb import ( + rpc_pb2, +) +from libp2p.pubsub.subscription import ( + TrioSubscriptionAPI, +) GET_TIMEOUT = 0.001 diff --git a/tests/security/noise/test_msg_read_writer.py b/tests/security/noise/test_msg_read_writer.py index 47e9afac..a356f657 100644 --- a/tests/security/noise/test_msg_read_writer.py +++ b/tests/security/noise/test_msg_read_writer.py @@ -1,7 +1,12 @@ import pytest -from libp2p.security.noise.io import MAX_NOISE_MESSAGE_LEN, NoisePacketReadWriter -from libp2p.tools.factories import raw_conn_factory +from libp2p.security.noise.io import ( + MAX_NOISE_MESSAGE_LEN, + NoisePacketReadWriter, +) +from libp2p.tools.factories import ( + raw_conn_factory, +) @pytest.mark.parametrize( diff --git a/tests/security/noise/test_noise.py b/tests/security/noise/test_noise.py index f1d208ca..ba15622b 100644 --- a/tests/security/noise/test_noise.py +++ b/tests/security/noise/test_noise.py @@ -1,7 +1,12 @@ import pytest -from libp2p.security.noise.messages import NoiseHandshakePayload -from libp2p.tools.factories import noise_conn_factory, noise_handshake_payload_factory +from libp2p.security.noise.messages import ( + NoiseHandshakePayload, +) +from libp2p.tools.factories import ( + noise_conn_factory, + noise_handshake_payload_factory, +) DATA_0 = b"data_0" DATA_1 = b"1" * 1000 diff --git a/tests/security/test_secio.py b/tests/security/test_secio.py index d009a738..e2fd75b4 100644 --- a/tests/security/test_secio.py +++ b/tests/security/test_secio.py @@ -1,11 +1,22 @@ import pytest import trio -from libp2p.crypto.secp256k1 import create_new_key_pair -from libp2p.peer.id import ID -from libp2p.security.secio.transport import NONCE_SIZE, create_secure_session -from libp2p.tools.constants import MAX_READ_LEN -from libp2p.tools.factories import raw_conn_factory +from libp2p.crypto.secp256k1 import ( + create_new_key_pair, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.security.secio.transport import ( + NONCE_SIZE, + create_secure_session, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) +from libp2p.tools.factories import ( + raw_conn_factory, +) @pytest.mark.trio diff --git a/tests/security/test_security_multistream.py b/tests/security/test_security_multistream.py index 32534cfb..38727f9b 100644 --- a/tests/security/test_security_multistream.py +++ b/tests/security/test_security_multistream.py @@ -1,11 +1,20 @@ import pytest -from libp2p.crypto.rsa import create_new_key_pair -from libp2p.security.insecure.transport import PLAINTEXT_PROTOCOL_ID, InsecureSession +from libp2p.crypto.rsa import ( + create_new_key_pair, +) +from libp2p.security.insecure.transport import ( + PLAINTEXT_PROTOCOL_ID, + InsecureSession, +) from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID from libp2p.security.secio.transport import ID as SECIO_PROTOCOL_ID -from libp2p.security.secure_session import SecureSession -from libp2p.tools.factories import host_pair_factory +from libp2p.security.secure_session import ( + SecureSession, +) +from libp2p.tools.factories import ( + host_pair_factory, +) initiator_key_pair = create_new_key_pair() diff --git a/tests/stream_muxer/conftest.py b/tests/stream_muxer/conftest.py index 44606d59..8d9625e9 100644 --- a/tests/stream_muxer/conftest.py +++ b/tests/stream_muxer/conftest.py @@ -1,6 +1,9 @@ import pytest -from libp2p.tools.factories import mplex_conn_pair_factory, mplex_stream_pair_factory +from libp2p.tools.factories import ( + mplex_conn_pair_factory, + mplex_stream_pair_factory, +) @pytest.fixture diff --git a/tests/stream_muxer/test_mplex_stream.py b/tests/stream_muxer/test_mplex_stream.py index 3bc8bc1c..62d384c2 100644 --- a/tests/stream_muxer/test_mplex_stream.py +++ b/tests/stream_muxer/test_mplex_stream.py @@ -1,14 +1,20 @@ import pytest import trio -from trio.testing import wait_all_tasks_blocked +from trio.testing import ( + wait_all_tasks_blocked, +) from libp2p.stream_muxer.mplex.exceptions import ( MplexStreamClosed, MplexStreamEOF, MplexStreamReset, ) -from libp2p.stream_muxer.mplex.mplex import MPLEX_MESSAGE_CHANNEL_SIZE -from libp2p.tools.constants import MAX_READ_LEN +from libp2p.stream_muxer.mplex.mplex import ( + MPLEX_MESSAGE_CHANNEL_SIZE, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) DATA = b"data_123" diff --git a/tests/transport/test_tcp.py b/tests/transport/test_tcp.py index 130b3cc4..8d011f4f 100644 --- a/tests/transport/test_tcp.py +++ b/tests/transport/test_tcp.py @@ -1,11 +1,21 @@ -from multiaddr import Multiaddr +from multiaddr import ( + Multiaddr, +) import pytest import trio -from libp2p.network.connection.raw_connection import RawConnection -from libp2p.tools.constants import LISTEN_MADDR -from libp2p.transport.exceptions import OpenConnectionError -from libp2p.transport.tcp.tcp import TCP +from libp2p.network.connection.raw_connection import ( + RawConnection, +) +from libp2p.tools.constants import ( + LISTEN_MADDR, +) +from libp2p.transport.exceptions import ( + OpenConnectionError, +) +from libp2p.transport.tcp.tcp import ( + TCP, +) @pytest.mark.trio diff --git a/tests_interop/conftest.py b/tests_interop/conftest.py index 952140d0..5bf9f2ff 100644 --- a/tests_interop/conftest.py +++ b/tests_interop/conftest.py @@ -1,16 +1,31 @@ import anyio -from async_exit_stack import AsyncExitStack -from p2pclient.datastructures import StreamInfo -from p2pclient.utils import get_unused_tcp_port +from async_exit_stack import ( + AsyncExitStack, +) +from p2pclient.datastructures import ( + StreamInfo, +) +from p2pclient.utils import ( + get_unused_tcp_port, +) import pytest import trio -from libp2p.io.abc import ReadWriteCloser +from libp2p.io.abc import ( + ReadWriteCloser, +) from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID from libp2p.security.secio.transport import ID as SECIO_PROTOCOL_ID -from libp2p.tools.factories import HostFactory, PubsubFactory -from libp2p.tools.interop.daemon import make_p2pd -from libp2p.tools.interop.utils import connect +from libp2p.tools.factories import ( + HostFactory, + PubsubFactory, +) +from libp2p.tools.interop.daemon import ( + make_p2pd, +) +from libp2p.tools.interop.utils import ( + connect, +) @pytest.fixture(params=[NOISE_PROTOCOL_ID, SECIO_PROTOCOL_ID]) @@ -130,12 +145,13 @@ async def py_to_daemon_stream_pair(p2pds, security_protocol, is_to_fail_daemon_s if is_to_fail_daemon_stream: # FIXME: This is a workaround to make daemon reset the stream. - # We intentionally close the listener on the python side, it makes the connection from - # daemon to us fail, and therefore the daemon resets the opened stream on their side. + # We intentionally close the listener on the python side, it makes the + # connection from daemon to us fail, and therefore the daemon resets the + # opened stream on their side. # Reference: https://github.com/libp2p/go-libp2p-daemon/blob/b95e77dbfcd186ccf817f51e95f73f9fd5982600/stream.go#L47-L50 # noqa: E501 - # We need it because we want to test against `stream_py` after the remote side(daemon) - # is reset. This should be removed after the API `stream.reset` is exposed in daemon - # some day. + # We need it because we want to test against `stream_py` after the remote + # side(daemon) is reset. This should be removed after the API + # `stream.reset` is exposed in daemon some day. await p2pds[0].control.control.close() stream_py = await host.new_stream(p2pd.peer_id, [protocol_id]) if not is_to_fail_daemon_stream: diff --git a/tests_interop/test_bindings.py b/tests_interop/test_bindings.py index d7a169cb..4fbc309e 100644 --- a/tests_interop/test_bindings.py +++ b/tests_interop/test_bindings.py @@ -1,8 +1,12 @@ import pytest import trio -from libp2p.tools.factories import HostFactory -from libp2p.tools.interop.utils import connect +from libp2p.tools.factories import ( + HostFactory, +) +from libp2p.tools.interop.utils import ( + connect, +) @pytest.mark.trio diff --git a/tests_interop/test_echo.py b/tests_interop/test_echo.py index d1bae0e9..623b4085 100644 --- a/tests_interop/test_echo.py +++ b/tests_interop/test_echo.py @@ -1,15 +1,30 @@ import re -from multiaddr import Multiaddr -from p2pclient.utils import get_unused_tcp_port +from multiaddr import ( + Multiaddr, +) +from p2pclient.utils import ( + get_unused_tcp_port, +) import pytest import trio -from libp2p.peer.peerinfo import PeerInfo, info_from_p2p_addr -from libp2p.tools.factories import HostFactory -from libp2p.tools.interop.envs import GO_BIN_PATH -from libp2p.tools.interop.process import BaseInteractiveProcess -from libp2p.typing import TProtocol +from libp2p.peer.peerinfo import ( + PeerInfo, + info_from_p2p_addr, +) +from libp2p.tools.factories import ( + HostFactory, +) +from libp2p.tools.interop.envs import ( + GO_BIN_PATH, +) +from libp2p.tools.interop.process import ( + BaseInteractiveProcess, +) +from libp2p.typing import ( + TProtocol, +) ECHO_PATH = GO_BIN_PATH / "echo" ECHO_PROTOCOL_ID = TProtocol("/echo/1.0.0") @@ -38,7 +53,7 @@ class EchoProcess(BaseInteractiveProcess): self.port = port self._peer_info = None - self.regex_pat = re.compile(br"I am ([\w\./]+)") + self.regex_pat = re.compile(rb"I am ([\w\./]+)") @property def peer_info(self) -> None: @@ -47,8 +62,8 @@ class EchoProcess(BaseInteractiveProcess): if not self.event_ready.is_set(): raise Exception("process is not ready yet. failed to parse the peer info") # Example: - # b"I am /ip4/127.0.0.1/tcp/56171/ipfs/QmU41TRPs34WWqa1brJEojBLYZKrrBcJq9nyNfVvSrbZUJ\n" - m = re.search(br"I am ([\w\./]+)", self.bytes_read) + # b"I am /ip4/127.0.0.1/tcp/56171/ipfs/QmU41TRPs34WWqa1brJEojBLYZKrrBcJq9nyNfVvSrbZUJ\n" # noqa: E501 + m = re.search(rb"I am ([\w\./]+)", self.bytes_read) if m is None: raise Exception("failed to find the pattern for the listening multiaddr") maddr_bytes_str_ipfs = m.group(1) diff --git a/tests_interop/test_net_stream.py b/tests_interop/test_net_stream.py index 573786c0..dfaef6c5 100644 --- a/tests_interop/test_net_stream.py +++ b/tests_interop/test_net_stream.py @@ -1,8 +1,14 @@ import pytest import trio -from libp2p.network.stream.exceptions import StreamClosed, StreamEOF, StreamReset -from libp2p.tools.constants import MAX_READ_LEN +from libp2p.network.stream.exceptions import ( + StreamClosed, + StreamEOF, + StreamReset, +) +from libp2p.tools.constants import ( + MAX_READ_LEN, +) DATA = b"data" diff --git a/tests_interop/test_pubsub.py b/tests_interop/test_pubsub.py index cc7fa0dd..471f0dea 100644 --- a/tests_interop/test_pubsub.py +++ b/tests_interop/test_pubsub.py @@ -1,17 +1,33 @@ import functools import math -from p2pclient.pb import p2pd_pb2 +from p2pclient.pb import ( + p2pd_pb2, +) import pytest import trio -from libp2p.io.trio import TrioTCPStream -from libp2p.peer.id import ID -from libp2p.pubsub.pb import rpc_pb2 -from libp2p.pubsub.subscription import TrioSubscriptionAPI -from libp2p.tools.factories import PubsubFactory -from libp2p.tools.interop.utils import connect -from libp2p.utils import read_varint_prefixed_bytes +from libp2p.io.trio import ( + TrioTCPStream, +) +from libp2p.peer.id import ( + ID, +) +from libp2p.pubsub.pb import ( + rpc_pb2, +) +from libp2p.pubsub.subscription import ( + TrioSubscriptionAPI, +) +from libp2p.tools.factories import ( + PubsubFactory, +) +from libp2p.tools.interop.utils import ( + connect, +) +from libp2p.utils import ( + read_varint_prefixed_bytes, +) TOPIC_0 = "ABALA" TOPIC_1 = "YOOOO" diff --git a/tox.ini b/tox.ini index 6e3cf447..2847f71e 100644 --- a/tox.ini +++ b/tox.ini @@ -33,7 +33,7 @@ allowlist_externals=make,pre-commit [testenv:py{38,39,310,311,312}-lint] deps=pre-commit commands= - pre-commit install + pre-commit install pre-commit run --all-files --show-diff-on-failure [testenv:py{38,39,310,311,312}-wheel] From 755fb21e1cb86ea87897693c4ac8f41ed4e73338 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Tue, 20 Feb 2024 09:17:01 -0700 Subject: [PATCH 096/102] turn off windows wheel builds --- .circleci/config.yml | 4 ++-- setup.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 079315ad..af41e526 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -242,5 +242,5 @@ workflows: - py310-wheel - py311-wheel - py312-wheel - - py311-windows-wheel - - py312-windows-wheel + # - py311-windows-wheel + # - py312-windows-wheel diff --git a/setup.py b/setup.py index e6d910c4..4e07bd6e 100644 --- a/setup.py +++ b/setup.py @@ -61,7 +61,6 @@ install_requires = [ "protobuf>=3.10.0,<4.0.0", "coincurve>=10.0.0,<11.0.0", "pynacl==1.3.0", - "dataclasses>=0.7, <1;python_version<'3.7'", "async_generator==1.10", "trio>=0.15.0", "async-service>=0.1.0a6", From 7c3a122b5e9bcb52fa9286c7ae11269c24864f8a Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:33:49 -0700 Subject: [PATCH 097/102] do not lint protobuf-generated files --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 38caecd8..504c1a8d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: '.project-template|docs/conf.py|.bumpversion.cfg' +exclude: '.project-template|docs/conf.py|.bumpversion.cfg|.*pb2\..*' repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 From 51291cee9544759436270e255886f670ef8941f1 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:34:44 -0700 Subject: [PATCH 098/102] drop upper pins --- setup.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 4e07bd6e..83d62240 100644 --- a/setup.py +++ b/setup.py @@ -52,20 +52,20 @@ with open("./README.md") as readme: install_requires = [ - "pycryptodome>=3.9.2,<4.0.0", - "base58>=1.0.3,<2.0.0", + "pycryptodome>=3.9.2", + "base58>=1.0.3", "pymultihash>=0.8.2", - "multiaddr>=0.0.9,<0.1.0", - "rpcudp>=3.0.0,<4.0.0", + "multiaddr>=0.0.9", + "rpcudp>=3.0.0", "lru-dict>=1.1.6", - "protobuf>=3.10.0,<4.0.0", - "coincurve>=10.0.0,<11.0.0", + "protobuf>=3.10.0", + "coincurve>=10.0.0", "pynacl==1.3.0", "async_generator==1.10", "trio>=0.15.0", "async-service>=0.1.0a6", "async-exit-stack==1.0.1", - "noiseprotocol>=0.3.0,<0.4.0", + "noiseprotocol>=0.3.0", ] From 318ce66ef51a134bcafcdbd3424ac24e3a6ad16b Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:36:16 -0700 Subject: [PATCH 099/102] add missing deps --- setup.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup.py b/setup.py index 83d62240..aed39a65 100644 --- a/setup.py +++ b/setup.py @@ -66,6 +66,10 @@ install_requires = [ "async-service>=0.1.0a6", "async-exit-stack==1.0.1", "noiseprotocol>=0.3.0", + # added during debugging + "anyio", + "p2pclient", + "mypy-protobuf", ] From ee4e9c4645a0daf6f74b7335066ae6e1b88ac49d Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:10:05 -0700 Subject: [PATCH 100/102] rename libp2p test dir and rebuild protobufs --- libp2p/__init__.py | 5 + libp2p/crypto/pb/crypto_pb2.py | 208 +--- libp2p/crypto/pb/crypto_pb2.pyi | 152 +-- libp2p/identity/identify/pb/identify_pb2.py | 171 +-- libp2p/identity/identify/pb/identify_pb2.pyi | 132 +-- libp2p/pubsub/pb/rpc_pb2.py | 970 +----------------- libp2p/pubsub/pb/rpc_pb2.pyi | 673 ++++-------- libp2p/security/insecure/pb/plaintext_pb2.py | 106 +- libp2p/security/insecure/pb/plaintext_pb2.pyi | 70 +- libp2p/security/noise/pb/noise_pb2.py | 116 +-- libp2p/security/noise/pb/noise_pb2.pyi | 72 +- libp2p/security/secio/pb/spipe_pb2.py | 224 +--- libp2p/security/secio/pb/spipe_pb2.pyi | 164 +-- tests/{libp2p => test_libp2p}/test_libp2p.py | 0 14 files changed, 526 insertions(+), 2537 deletions(-) rename tests/{libp2p => test_libp2p}/test_libp2p.py (100%) diff --git a/libp2p/__init__.py b/libp2p/__init__.py index 9afbf6a2..73912d4f 100644 --- a/libp2p/__init__.py +++ b/libp2p/__init__.py @@ -1,3 +1,5 @@ +from importlib.metadata import version as __version + from libp2p.crypto.keys import ( KeyPair, ) @@ -132,3 +134,6 @@ def new_host( else: host = BasicHost(swarm) return host + + +__version__ = __version("libp2p") diff --git a/libp2p/crypto/pb/crypto_pb2.py b/libp2p/crypto/pb/crypto_pb2.py index fda8fa41..04435d4a 100644 --- a/libp2p/crypto/pb/crypto_pb2.py +++ b/libp2p/crypto/pb/crypto_pb2.py @@ -1,204 +1,30 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/crypto/pb/crypto.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) -from google.protobuf.internal import enum_type_wrapper +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/crypto/pb/crypto.proto", - package="crypto.pb", - syntax="proto2", - serialized_options=None, - serialized_pb=_b( - '\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03' - ), -) - -_KEYTYPE = _descriptor.EnumDescriptor( - name="KeyType", - full_name="crypto.pb.KeyType", - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name="RSA", index=0, number=0, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="Ed25519", index=1, number=1, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="Secp256k1", index=2, number=2, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="ECDSA", index=3, number=3, serialized_options=None, type=None - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=175, - serialized_end=232, -) -_sym_db.RegisterEnumDescriptor(_KEYTYPE) - -KeyType = enum_type_wrapper.EnumTypeWrapper(_KEYTYPE) -RSA = 0 -Ed25519 = 1 -Secp256k1 = 2 -ECDSA = 3 -_PUBLICKEY = _descriptor.Descriptor( - name="PublicKey", - full_name="crypto.pb.PublicKey", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="key_type", - full_name="crypto.pb.PublicKey.key_type", - index=0, - number=1, - type=14, - cpp_type=8, - label=2, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="data", - full_name="crypto.pb.PublicKey.data", - index=1, - number=2, - type=12, - cpp_type=9, - label=2, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=44, - serialized_end=107, -) - - -_PRIVATEKEY = _descriptor.Descriptor( - name="PrivateKey", - full_name="crypto.pb.PrivateKey", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="key_type", - full_name="crypto.pb.PrivateKey.key_type", - index=0, - number=1, - type=14, - cpp_type=8, - label=2, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="data", - full_name="crypto.pb.PrivateKey.data", - index=1, - number=2, - type=12, - cpp_type=9, - label=2, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=109, - serialized_end=173, -) - -_PUBLICKEY.fields_by_name["key_type"].enum_type = _KEYTYPE -_PRIVATEKEY.fields_by_name["key_type"].enum_type = _KEYTYPE -DESCRIPTOR.message_types_by_name["PublicKey"] = _PUBLICKEY -DESCRIPTOR.message_types_by_name["PrivateKey"] = _PRIVATEKEY -DESCRIPTOR.enum_types_by_name["KeyType"] = _KEYTYPE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -PublicKey = _reflection.GeneratedProtocolMessageType( - "PublicKey", - (_message.Message,), - { - "DESCRIPTOR": _PUBLICKEY, - "__module__": "libp2p.crypto.pb.crypto_pb2" - # @@protoc_insertion_point(class_scope:crypto.pb.PublicKey) - }, -) -_sym_db.RegisterMessage(PublicKey) - -PrivateKey = _reflection.GeneratedProtocolMessageType( - "PrivateKey", - (_message.Message,), - { - "DESCRIPTOR": _PRIVATEKEY, - "__module__": "libp2p.crypto.pb.crypto_pb2" - # @@protoc_insertion_point(class_scope:crypto.pb.PrivateKey) - }, -) -_sym_db.RegisterMessage(PrivateKey) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb\"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c\"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.crypto.pb.crypto_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_KEYTYPE']._serialized_start=175 + _globals['_KEYTYPE']._serialized_end=232 + _globals['_PUBLICKEY']._serialized_start=44 + _globals['_PUBLICKEY']._serialized_end=107 + _globals['_PRIVATEKEY']._serialized_start=109 + _globals['_PRIVATEKEY']._serialized_end=173 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/crypto/pb/crypto_pb2.pyi b/libp2p/crypto/pb/crypto_pb2.pyi index 08656f0a..777fcbd2 100644 --- a/libp2p/crypto/pb/crypto_pb2.pyi +++ b/libp2p/crypto/pb/crypto_pb2.pyi @@ -1,114 +1,74 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.internal.enum_type_wrapper +import google.protobuf.message import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, - EnumDescriptor as google___protobuf___descriptor___EnumDescriptor, -) +import typing -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +if sys.version_info >= (3, 10): + import typing as typing_extensions +else: + import typing_extensions -from typing import ( - List as typing___List, - Tuple as typing___Tuple, - cast as typing___cast, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing_extensions import ( - Literal as typing_extensions___Literal, -) +class _KeyType: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType -class KeyType(int): - DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... - @classmethod - def Name(cls, number: int) -> str: ... - @classmethod - def Value(cls, name: str) -> KeyType: ... - @classmethod - def keys(cls) -> typing___List[str]: ... - @classmethod - def values(cls) -> typing___List[KeyType]: ... - @classmethod - def items(cls) -> typing___List[typing___Tuple[str, KeyType]]: ... - RSA = typing___cast(KeyType, 0) - Ed25519 = typing___cast(KeyType, 1) - Secp256k1 = typing___cast(KeyType, 2) - ECDSA = typing___cast(KeyType, 3) +class _KeyTypeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_KeyType.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + RSA: _KeyType.ValueType # 0 + Ed25519: _KeyType.ValueType # 1 + Secp256k1: _KeyType.ValueType # 2 + ECDSA: _KeyType.ValueType # 3 -RSA = typing___cast(KeyType, 0) -Ed25519 = typing___cast(KeyType, 1) -Secp256k1 = typing___cast(KeyType, 2) -ECDSA = typing___cast(KeyType, 3) +class KeyType(_KeyType, metaclass=_KeyTypeEnumTypeWrapper): ... -class PublicKey(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - key_type = ... # type: KeyType - data = ... # type: bytes +RSA: KeyType.ValueType # 0 +Ed25519: KeyType.ValueType # 1 +Secp256k1: KeyType.ValueType # 2 +ECDSA: KeyType.ValueType # 3 +global___KeyType = KeyType +@typing_extensions.final +class PublicKey(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + KEY_TYPE_FIELD_NUMBER: builtins.int + DATA_FIELD_NUMBER: builtins.int + key_type: global___KeyType.ValueType + data: builtins.bytes def __init__( self, *, - key_type: KeyType, - data: bytes, + key_type: global___KeyType.ValueType | None = ..., + data: builtins.bytes | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> PublicKey: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["data", "key_type"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["data", "key_type"] - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "data", b"data", "key_type", b"key_type" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", b"data", "key_type", b"key_type" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["data", b"data", "key_type", b"key_type"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["data", b"data", "key_type", b"key_type"]) -> None: ... -class PrivateKey(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - key_type = ... # type: KeyType - data = ... # type: bytes +global___PublicKey = PublicKey +@typing_extensions.final +class PrivateKey(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + KEY_TYPE_FIELD_NUMBER: builtins.int + DATA_FIELD_NUMBER: builtins.int + key_type: global___KeyType.ValueType + data: builtins.bytes def __init__( self, *, - key_type: KeyType, - data: bytes, + key_type: global___KeyType.ValueType | None = ..., + data: builtins.bytes | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> PrivateKey: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["data", "key_type"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["data", "key_type"] - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "data", b"data", "key_type", b"key_type" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", b"data", "key_type", b"key_type" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["data", b"data", "key_type", b"key_type"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["data", b"data", "key_type", b"key_type"]) -> None: ... + +global___PrivateKey = PrivateKey diff --git a/libp2p/identity/identify/pb/identify_pb2.py b/libp2p/identity/identify/pb/identify_pb2.py index 87ff9ccf..67248619 100644 --- a/libp2p/identity/identify/pb/identify_pb2.py +++ b/libp2p/identity/identify/pb/identify_pb2.py @@ -1,171 +1,26 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/identity/identify/pb/identify.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/identity/identify/pb/identify.proto", - package="identify.pb", - syntax="proto2", - serialized_options=None, - serialized_pb=_b( - '\n*libp2p/identity/identify/pb/identify.proto\x12\x0bidentify.pb"\x8f\x01\n\x08Identify\x12\x18\n\x10protocol_version\x18\x05 \x01(\t\x12\x15\n\ragent_version\x18\x06 \x01(\t\x12\x12\n\npublic_key\x18\x01 \x01(\x0c\x12\x14\n\x0clisten_addrs\x18\x02 \x03(\x0c\x12\x15\n\robserved_addr\x18\x04 \x01(\x0c\x12\x11\n\tprotocols\x18\x03 \x03(\t' - ), -) -_IDENTIFY = _descriptor.Descriptor( - name="Identify", - full_name="identify.pb.Identify", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="protocol_version", - full_name="identify.pb.Identify.protocol_version", - index=0, - number=5, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="agent_version", - full_name="identify.pb.Identify.agent_version", - index=1, - number=6, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="public_key", - full_name="identify.pb.Identify.public_key", - index=2, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="listen_addrs", - full_name="identify.pb.Identify.listen_addrs", - index=3, - number=2, - type=12, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="observed_addr", - full_name="identify.pb.Identify.observed_addr", - index=4, - number=4, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="protocols", - full_name="identify.pb.Identify.protocols", - index=5, - number=3, - type=9, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=60, - serialized_end=203, -) - -DESCRIPTOR.message_types_by_name["Identify"] = _IDENTIFY -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Identify = _reflection.GeneratedProtocolMessageType( - "Identify", - (_message.Message,), - { - "DESCRIPTOR": _IDENTIFY, - "__module__": "libp2p.identity.identify.pb.identify_pb2" - # @@protoc_insertion_point(class_scope:identify.pb.Identify) - }, -) -_sym_db.RegisterMessage(Identify) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n*libp2p/identity/identify/pb/identify.proto\x12\x0bidentify.pb\"\x8f\x01\n\x08Identify\x12\x18\n\x10protocol_version\x18\x05 \x01(\t\x12\x15\n\ragent_version\x18\x06 \x01(\t\x12\x12\n\npublic_key\x18\x01 \x01(\x0c\x12\x14\n\x0clisten_addrs\x18\x02 \x03(\x0c\x12\x15\n\robserved_addr\x18\x04 \x01(\x0c\x12\x11\n\tprotocols\x18\x03 \x03(\t') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.identity.identify.pb.identify_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_IDENTIFY']._serialized_start=60 + _globals['_IDENTIFY']._serialized_end=203 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/identity/identify/pb/identify_pb2.pyi b/libp2p/identity/identify/pb/identify_pb2.pyi index d548a3a7..aa9668f4 100644 --- a/libp2p/identity/identify/pb/identify_pb2.pyi +++ b/libp2p/identity/identify/pb/identify_pb2.pyi @@ -1,100 +1,50 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import collections.abc +import google.protobuf.descriptor +import google.protobuf.internal.containers +import google.protobuf.message import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, -) -from google.protobuf.internal.containers import ( - RepeatedScalarFieldContainer as google___protobuf___internal___containers___RepeatedScalarFieldContainer, -) +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing import ( - Iterable as typing___Iterable, - Optional as typing___Optional, - Text as typing___Text, -) - -from typing_extensions import ( - Literal as typing_extensions___Literal, -) - -class Identify(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - protocol_version = ... # type: typing___Text - agent_version = ... # type: typing___Text - public_key = ... # type: bytes - listen_addrs = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] - observed_addr = ... # type: bytes - protocols = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] +@typing_extensions.final +class Identify(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + PROTOCOL_VERSION_FIELD_NUMBER: builtins.int + AGENT_VERSION_FIELD_NUMBER: builtins.int + PUBLIC_KEY_FIELD_NUMBER: builtins.int + LISTEN_ADDRS_FIELD_NUMBER: builtins.int + OBSERVED_ADDR_FIELD_NUMBER: builtins.int + PROTOCOLS_FIELD_NUMBER: builtins.int + protocol_version: builtins.str + agent_version: builtins.str + public_key: builtins.bytes + @property + def listen_addrs(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.bytes]: ... + observed_addr: builtins.bytes + @property + def protocols(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... def __init__( self, *, - protocol_version: typing___Optional[typing___Text] = None, - agent_version: typing___Optional[typing___Text] = None, - public_key: typing___Optional[bytes] = None, - listen_addrs: typing___Optional[typing___Iterable[bytes]] = None, - observed_addr: typing___Optional[bytes] = None, - protocols: typing___Optional[typing___Iterable[typing___Text]] = None, + protocol_version: builtins.str | None = ..., + agent_version: builtins.str | None = ..., + public_key: builtins.bytes | None = ..., + listen_addrs: collections.abc.Iterable[builtins.bytes] | None = ..., + observed_addr: builtins.bytes | None = ..., + protocols: collections.abc.Iterable[builtins.str] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> Identify: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, - field_name: typing_extensions___Literal[ - "agent_version", "observed_addr", "protocol_version", "public_key" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "agent_version", - "listen_addrs", - "observed_addr", - "protocol_version", - "protocols", - "public_key", - ], - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "agent_version", - b"agent_version", - "observed_addr", - b"observed_addr", - "protocol_version", - b"protocol_version", - "public_key", - b"public_key", - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "agent_version", - b"agent_version", - "listen_addrs", - b"listen_addrs", - "observed_addr", - b"observed_addr", - "protocol_version", - b"protocol_version", - "protocols", - b"protocols", - "public_key", - b"public_key", - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["agent_version", b"agent_version", "observed_addr", b"observed_addr", "protocol_version", b"protocol_version", "public_key", b"public_key"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["agent_version", b"agent_version", "listen_addrs", b"listen_addrs", "observed_addr", b"observed_addr", "protocol_version", b"protocol_version", "protocols", b"protocols", "public_key", b"public_key"]) -> None: ... + +global___Identify = Identify diff --git a/libp2p/pubsub/pb/rpc_pb2.py b/libp2p/pubsub/pb/rpc_pb2.py index d51f9f5d..397edf87 100644 --- a/libp2p/pubsub/pb/rpc_pb2.py +++ b/libp2p/pubsub/pb/rpc_pb2.py @@ -1,946 +1,50 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/pubsub/pb/rpc.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/pubsub/pb/rpc.proto", - package="pubsub.pb", - syntax="proto2", - serialized_options=None, - serialized_pb=_b( - '\n\x1alibp2p/pubsub/pb/rpc.proto\x12\tpubsub.pb"\xb4\x01\n\x03RPC\x12-\n\rsubscriptions\x18\x01 \x03(\x0b\x32\x16.pubsub.pb.RPC.SubOpts\x12#\n\x07publish\x18\x02 \x03(\x0b\x32\x12.pubsub.pb.Message\x12*\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x19.pubsub.pb.ControlMessage\x1a-\n\x07SubOpts\x12\x11\n\tsubscribe\x18\x01 \x01(\x08\x12\x0f\n\x07topicid\x18\x02 \x01(\t"i\n\x07Message\x12\x0f\n\x07\x66rom_id\x18\x01 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\r\n\x05seqno\x18\x03 \x01(\x0c\x12\x10\n\x08topicIDs\x18\x04 \x03(\t\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x12\x0b\n\x03key\x18\x06 \x01(\x0c"\xb0\x01\n\x0e\x43ontrolMessage\x12&\n\x05ihave\x18\x01 \x03(\x0b\x32\x17.pubsub.pb.ControlIHave\x12&\n\x05iwant\x18\x02 \x03(\x0b\x32\x17.pubsub.pb.ControlIWant\x12&\n\x05graft\x18\x03 \x03(\x0b\x32\x17.pubsub.pb.ControlGraft\x12&\n\x05prune\x18\x04 \x03(\x0b\x32\x17.pubsub.pb.ControlPrune"3\n\x0c\x43ontrolIHave\x12\x0f\n\x07topicID\x18\x01 \x01(\t\x12\x12\n\nmessageIDs\x18\x02 \x03(\t""\n\x0c\x43ontrolIWant\x12\x12\n\nmessageIDs\x18\x01 \x03(\t"\x1f\n\x0c\x43ontrolGraft\x12\x0f\n\x07topicID\x18\x01 \x01(\t"\x1f\n\x0c\x43ontrolPrune\x12\x0f\n\x07topicID\x18\x01 \x01(\t"\x87\x03\n\x0fTopicDescriptor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04\x61uth\x18\x02 \x01(\x0b\x32#.pubsub.pb.TopicDescriptor.AuthOpts\x12/\n\x03\x65nc\x18\x03 \x01(\x0b\x32".pubsub.pb.TopicDescriptor.EncOpts\x1a|\n\x08\x41uthOpts\x12:\n\x04mode\x18\x01 \x01(\x0e\x32,.pubsub.pb.TopicDescriptor.AuthOpts.AuthMode\x12\x0c\n\x04keys\x18\x02 \x03(\x0c"&\n\x08\x41uthMode\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x83\x01\n\x07\x45ncOpts\x12\x38\n\x04mode\x18\x01 \x01(\x0e\x32*.pubsub.pb.TopicDescriptor.EncOpts.EncMode\x12\x11\n\tkeyHashes\x18\x02 \x03(\x0c"+\n\x07\x45ncMode\x12\x08\n\x04NONE\x10\x00\x12\r\n\tSHAREDKEY\x10\x01\x12\x07\n\x03WOT\x10\x02' - ), -) -_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE = _descriptor.EnumDescriptor( - name="AuthMode", - full_name="pubsub.pb.TopicDescriptor.AuthOpts.AuthMode", - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name="NONE", index=0, number=0, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="KEY", index=1, number=1, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="WOT", index=2, number=2, serialized_options=None, type=None - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=885, - serialized_end=923, -) -_sym_db.RegisterEnumDescriptor(_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE) - -_TOPICDESCRIPTOR_ENCOPTS_ENCMODE = _descriptor.EnumDescriptor( - name="EncMode", - full_name="pubsub.pb.TopicDescriptor.EncOpts.EncMode", - filename=None, - file=DESCRIPTOR, - values=[ - _descriptor.EnumValueDescriptor( - name="NONE", index=0, number=0, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="SHAREDKEY", index=1, number=1, serialized_options=None, type=None - ), - _descriptor.EnumValueDescriptor( - name="WOT", index=2, number=2, serialized_options=None, type=None - ), - ], - containing_type=None, - serialized_options=None, - serialized_start=1014, - serialized_end=1057, -) -_sym_db.RegisterEnumDescriptor(_TOPICDESCRIPTOR_ENCOPTS_ENCMODE) - - -_RPC_SUBOPTS = _descriptor.Descriptor( - name="SubOpts", - full_name="pubsub.pb.RPC.SubOpts", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="subscribe", - full_name="pubsub.pb.RPC.SubOpts.subscribe", - index=0, - number=1, - type=8, - cpp_type=7, - label=1, - has_default_value=False, - default_value=False, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="topicid", - full_name="pubsub.pb.RPC.SubOpts.topicid", - index=1, - number=2, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=177, - serialized_end=222, -) - -_RPC = _descriptor.Descriptor( - name="RPC", - full_name="pubsub.pb.RPC", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="subscriptions", - full_name="pubsub.pb.RPC.subscriptions", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="publish", - full_name="pubsub.pb.RPC.publish", - index=1, - number=2, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="control", - full_name="pubsub.pb.RPC.control", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[ - _RPC_SUBOPTS, - ], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=42, - serialized_end=222, -) - - -_MESSAGE = _descriptor.Descriptor( - name="Message", - full_name="pubsub.pb.Message", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="from_id", - full_name="pubsub.pb.Message.from_id", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="data", - full_name="pubsub.pb.Message.data", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="seqno", - full_name="pubsub.pb.Message.seqno", - index=2, - number=3, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="topicIDs", - full_name="pubsub.pb.Message.topicIDs", - index=3, - number=4, - type=9, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="signature", - full_name="pubsub.pb.Message.signature", - index=4, - number=5, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="key", - full_name="pubsub.pb.Message.key", - index=5, - number=6, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=224, - serialized_end=329, -) - - -_CONTROLMESSAGE = _descriptor.Descriptor( - name="ControlMessage", - full_name="pubsub.pb.ControlMessage", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="ihave", - full_name="pubsub.pb.ControlMessage.ihave", - index=0, - number=1, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="iwant", - full_name="pubsub.pb.ControlMessage.iwant", - index=1, - number=2, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="graft", - full_name="pubsub.pb.ControlMessage.graft", - index=2, - number=3, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="prune", - full_name="pubsub.pb.ControlMessage.prune", - index=3, - number=4, - type=11, - cpp_type=10, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=332, - serialized_end=508, -) - - -_CONTROLIHAVE = _descriptor.Descriptor( - name="ControlIHave", - full_name="pubsub.pb.ControlIHave", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="topicID", - full_name="pubsub.pb.ControlIHave.topicID", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="messageIDs", - full_name="pubsub.pb.ControlIHave.messageIDs", - index=1, - number=2, - type=9, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=510, - serialized_end=561, -) - - -_CONTROLIWANT = _descriptor.Descriptor( - name="ControlIWant", - full_name="pubsub.pb.ControlIWant", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="messageIDs", - full_name="pubsub.pb.ControlIWant.messageIDs", - index=0, - number=1, - type=9, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=563, - serialized_end=597, -) - - -_CONTROLGRAFT = _descriptor.Descriptor( - name="ControlGraft", - full_name="pubsub.pb.ControlGraft", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="topicID", - full_name="pubsub.pb.ControlGraft.topicID", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=599, - serialized_end=630, -) - - -_CONTROLPRUNE = _descriptor.Descriptor( - name="ControlPrune", - full_name="pubsub.pb.ControlPrune", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="topicID", - full_name="pubsub.pb.ControlPrune.topicID", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=632, - serialized_end=663, -) - - -_TOPICDESCRIPTOR_AUTHOPTS = _descriptor.Descriptor( - name="AuthOpts", - full_name="pubsub.pb.TopicDescriptor.AuthOpts", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="mode", - full_name="pubsub.pb.TopicDescriptor.AuthOpts.mode", - index=0, - number=1, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="keys", - full_name="pubsub.pb.TopicDescriptor.AuthOpts.keys", - index=1, - number=2, - type=12, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[ - _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE, - ], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=799, - serialized_end=923, -) - -_TOPICDESCRIPTOR_ENCOPTS = _descriptor.Descriptor( - name="EncOpts", - full_name="pubsub.pb.TopicDescriptor.EncOpts", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="mode", - full_name="pubsub.pb.TopicDescriptor.EncOpts.mode", - index=0, - number=1, - type=14, - cpp_type=8, - label=1, - has_default_value=False, - default_value=0, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="keyHashes", - full_name="pubsub.pb.TopicDescriptor.EncOpts.keyHashes", - index=1, - number=2, - type=12, - cpp_type=9, - label=3, - has_default_value=False, - default_value=[], - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[ - _TOPICDESCRIPTOR_ENCOPTS_ENCMODE, - ], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=926, - serialized_end=1057, -) - -_TOPICDESCRIPTOR = _descriptor.Descriptor( - name="TopicDescriptor", - full_name="pubsub.pb.TopicDescriptor", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="name", - full_name="pubsub.pb.TopicDescriptor.name", - index=0, - number=1, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="auth", - full_name="pubsub.pb.TopicDescriptor.auth", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="enc", - full_name="pubsub.pb.TopicDescriptor.enc", - index=2, - number=3, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[ - _TOPICDESCRIPTOR_AUTHOPTS, - _TOPICDESCRIPTOR_ENCOPTS, - ], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=666, - serialized_end=1057, -) - -_RPC_SUBOPTS.containing_type = _RPC -_RPC.fields_by_name["subscriptions"].message_type = _RPC_SUBOPTS -_RPC.fields_by_name["publish"].message_type = _MESSAGE -_RPC.fields_by_name["control"].message_type = _CONTROLMESSAGE -_CONTROLMESSAGE.fields_by_name["ihave"].message_type = _CONTROLIHAVE -_CONTROLMESSAGE.fields_by_name["iwant"].message_type = _CONTROLIWANT -_CONTROLMESSAGE.fields_by_name["graft"].message_type = _CONTROLGRAFT -_CONTROLMESSAGE.fields_by_name["prune"].message_type = _CONTROLPRUNE -_TOPICDESCRIPTOR_AUTHOPTS.fields_by_name[ - "mode" -].enum_type = _TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE -_TOPICDESCRIPTOR_AUTHOPTS.containing_type = _TOPICDESCRIPTOR -_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE.containing_type = _TOPICDESCRIPTOR_AUTHOPTS -_TOPICDESCRIPTOR_ENCOPTS.fields_by_name[ - "mode" -].enum_type = _TOPICDESCRIPTOR_ENCOPTS_ENCMODE -_TOPICDESCRIPTOR_ENCOPTS.containing_type = _TOPICDESCRIPTOR -_TOPICDESCRIPTOR_ENCOPTS_ENCMODE.containing_type = _TOPICDESCRIPTOR_ENCOPTS -_TOPICDESCRIPTOR.fields_by_name["auth"].message_type = _TOPICDESCRIPTOR_AUTHOPTS -_TOPICDESCRIPTOR.fields_by_name["enc"].message_type = _TOPICDESCRIPTOR_ENCOPTS -DESCRIPTOR.message_types_by_name["RPC"] = _RPC -DESCRIPTOR.message_types_by_name["Message"] = _MESSAGE -DESCRIPTOR.message_types_by_name["ControlMessage"] = _CONTROLMESSAGE -DESCRIPTOR.message_types_by_name["ControlIHave"] = _CONTROLIHAVE -DESCRIPTOR.message_types_by_name["ControlIWant"] = _CONTROLIWANT -DESCRIPTOR.message_types_by_name["ControlGraft"] = _CONTROLGRAFT -DESCRIPTOR.message_types_by_name["ControlPrune"] = _CONTROLPRUNE -DESCRIPTOR.message_types_by_name["TopicDescriptor"] = _TOPICDESCRIPTOR -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -RPC = _reflection.GeneratedProtocolMessageType( - "RPC", - (_message.Message,), - { - "SubOpts": _reflection.GeneratedProtocolMessageType( - "SubOpts", - (_message.Message,), - { - "DESCRIPTOR": _RPC_SUBOPTS, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.RPC.SubOpts) - }, - ), - "DESCRIPTOR": _RPC, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.RPC) - }, -) -_sym_db.RegisterMessage(RPC) -_sym_db.RegisterMessage(RPC.SubOpts) - -Message = _reflection.GeneratedProtocolMessageType( - "Message", - (_message.Message,), - { - "DESCRIPTOR": _MESSAGE, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.Message) - }, -) -_sym_db.RegisterMessage(Message) - -ControlMessage = _reflection.GeneratedProtocolMessageType( - "ControlMessage", - (_message.Message,), - { - "DESCRIPTOR": _CONTROLMESSAGE, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlMessage) - }, -) -_sym_db.RegisterMessage(ControlMessage) - -ControlIHave = _reflection.GeneratedProtocolMessageType( - "ControlIHave", - (_message.Message,), - { - "DESCRIPTOR": _CONTROLIHAVE, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIHave) - }, -) -_sym_db.RegisterMessage(ControlIHave) - -ControlIWant = _reflection.GeneratedProtocolMessageType( - "ControlIWant", - (_message.Message,), - { - "DESCRIPTOR": _CONTROLIWANT, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlIWant) - }, -) -_sym_db.RegisterMessage(ControlIWant) - -ControlGraft = _reflection.GeneratedProtocolMessageType( - "ControlGraft", - (_message.Message,), - { - "DESCRIPTOR": _CONTROLGRAFT, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlGraft) - }, -) -_sym_db.RegisterMessage(ControlGraft) - -ControlPrune = _reflection.GeneratedProtocolMessageType( - "ControlPrune", - (_message.Message,), - { - "DESCRIPTOR": _CONTROLPRUNE, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.ControlPrune) - }, -) -_sym_db.RegisterMessage(ControlPrune) - -TopicDescriptor = _reflection.GeneratedProtocolMessageType( - "TopicDescriptor", - (_message.Message,), - { - "AuthOpts": _reflection.GeneratedProtocolMessageType( - "AuthOpts", - (_message.Message,), - { - "DESCRIPTOR": _TOPICDESCRIPTOR_AUTHOPTS, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.AuthOpts) - }, - ), - "EncOpts": _reflection.GeneratedProtocolMessageType( - "EncOpts", - (_message.Message,), - { - "DESCRIPTOR": _TOPICDESCRIPTOR_ENCOPTS, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor.EncOpts) - }, - ), - "DESCRIPTOR": _TOPICDESCRIPTOR, - "__module__": "libp2p.pubsub.pb.rpc_pb2" - # @@protoc_insertion_point(class_scope:pubsub.pb.TopicDescriptor) - }, -) -_sym_db.RegisterMessage(TopicDescriptor) -_sym_db.RegisterMessage(TopicDescriptor.AuthOpts) -_sym_db.RegisterMessage(TopicDescriptor.EncOpts) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x1alibp2p/pubsub/pb/rpc.proto\x12\tpubsub.pb\"\xb4\x01\n\x03RPC\x12-\n\rsubscriptions\x18\x01 \x03(\x0b\x32\x16.pubsub.pb.RPC.SubOpts\x12#\n\x07publish\x18\x02 \x03(\x0b\x32\x12.pubsub.pb.Message\x12*\n\x07\x63ontrol\x18\x03 \x01(\x0b\x32\x19.pubsub.pb.ControlMessage\x1a-\n\x07SubOpts\x12\x11\n\tsubscribe\x18\x01 \x01(\x08\x12\x0f\n\x07topicid\x18\x02 \x01(\t\"i\n\x07Message\x12\x0f\n\x07\x66rom_id\x18\x01 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x02 \x01(\x0c\x12\r\n\x05seqno\x18\x03 \x01(\x0c\x12\x10\n\x08topicIDs\x18\x04 \x03(\t\x12\x11\n\tsignature\x18\x05 \x01(\x0c\x12\x0b\n\x03key\x18\x06 \x01(\x0c\"\xb0\x01\n\x0e\x43ontrolMessage\x12&\n\x05ihave\x18\x01 \x03(\x0b\x32\x17.pubsub.pb.ControlIHave\x12&\n\x05iwant\x18\x02 \x03(\x0b\x32\x17.pubsub.pb.ControlIWant\x12&\n\x05graft\x18\x03 \x03(\x0b\x32\x17.pubsub.pb.ControlGraft\x12&\n\x05prune\x18\x04 \x03(\x0b\x32\x17.pubsub.pb.ControlPrune\"3\n\x0c\x43ontrolIHave\x12\x0f\n\x07topicID\x18\x01 \x01(\t\x12\x12\n\nmessageIDs\x18\x02 \x03(\t\"\"\n\x0c\x43ontrolIWant\x12\x12\n\nmessageIDs\x18\x01 \x03(\t\"\x1f\n\x0c\x43ontrolGraft\x12\x0f\n\x07topicID\x18\x01 \x01(\t\"\x1f\n\x0c\x43ontrolPrune\x12\x0f\n\x07topicID\x18\x01 \x01(\t\"\x87\x03\n\x0fTopicDescriptor\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x31\n\x04\x61uth\x18\x02 \x01(\x0b\x32#.pubsub.pb.TopicDescriptor.AuthOpts\x12/\n\x03\x65nc\x18\x03 \x01(\x0b\x32\".pubsub.pb.TopicDescriptor.EncOpts\x1a|\n\x08\x41uthOpts\x12:\n\x04mode\x18\x01 \x01(\x0e\x32,.pubsub.pb.TopicDescriptor.AuthOpts.AuthMode\x12\x0c\n\x04keys\x18\x02 \x03(\x0c\"&\n\x08\x41uthMode\x12\x08\n\x04NONE\x10\x00\x12\x07\n\x03KEY\x10\x01\x12\x07\n\x03WOT\x10\x02\x1a\x83\x01\n\x07\x45ncOpts\x12\x38\n\x04mode\x18\x01 \x01(\x0e\x32*.pubsub.pb.TopicDescriptor.EncOpts.EncMode\x12\x11\n\tkeyHashes\x18\x02 \x03(\x0c\"+\n\x07\x45ncMode\x12\x08\n\x04NONE\x10\x00\x12\r\n\tSHAREDKEY\x10\x01\x12\x07\n\x03WOT\x10\x02') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.pubsub.pb.rpc_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_RPC']._serialized_start=42 + _globals['_RPC']._serialized_end=222 + _globals['_RPC_SUBOPTS']._serialized_start=177 + _globals['_RPC_SUBOPTS']._serialized_end=222 + _globals['_MESSAGE']._serialized_start=224 + _globals['_MESSAGE']._serialized_end=329 + _globals['_CONTROLMESSAGE']._serialized_start=332 + _globals['_CONTROLMESSAGE']._serialized_end=508 + _globals['_CONTROLIHAVE']._serialized_start=510 + _globals['_CONTROLIHAVE']._serialized_end=561 + _globals['_CONTROLIWANT']._serialized_start=563 + _globals['_CONTROLIWANT']._serialized_end=597 + _globals['_CONTROLGRAFT']._serialized_start=599 + _globals['_CONTROLGRAFT']._serialized_end=630 + _globals['_CONTROLPRUNE']._serialized_start=632 + _globals['_CONTROLPRUNE']._serialized_end=663 + _globals['_TOPICDESCRIPTOR']._serialized_start=666 + _globals['_TOPICDESCRIPTOR']._serialized_end=1057 + _globals['_TOPICDESCRIPTOR_AUTHOPTS']._serialized_start=799 + _globals['_TOPICDESCRIPTOR_AUTHOPTS']._serialized_end=923 + _globals['_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE']._serialized_start=885 + _globals['_TOPICDESCRIPTOR_AUTHOPTS_AUTHMODE']._serialized_end=923 + _globals['_TOPICDESCRIPTOR_ENCOPTS']._serialized_start=926 + _globals['_TOPICDESCRIPTOR_ENCOPTS']._serialized_end=1057 + _globals['_TOPICDESCRIPTOR_ENCOPTS_ENCMODE']._serialized_start=1014 + _globals['_TOPICDESCRIPTOR_ENCOPTS_ENCMODE']._serialized_end=1057 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/pubsub/pb/rpc_pb2.pyi b/libp2p/pubsub/pb/rpc_pb2.pyi index e19179dc..bc4db367 100644 --- a/libp2p/pubsub/pb/rpc_pb2.pyi +++ b/libp2p/pubsub/pb/rpc_pb2.pyi @@ -1,535 +1,294 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +Modified from https://github.com/libp2p/go-libp2p-pubsub/blob/master/pb/rpc.proto""" +import builtins +import collections.abc +import google.protobuf.descriptor +import google.protobuf.internal.containers +import google.protobuf.internal.enum_type_wrapper +import google.protobuf.message import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, - EnumDescriptor as google___protobuf___descriptor___EnumDescriptor, -) +import typing -from google.protobuf.internal.containers import ( - RepeatedCompositeFieldContainer as google___protobuf___internal___containers___RepeatedCompositeFieldContainer, - RepeatedScalarFieldContainer as google___protobuf___internal___containers___RepeatedScalarFieldContainer, -) +if sys.version_info >= (3, 10): + import typing as typing_extensions +else: + import typing_extensions -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing import ( - Iterable as typing___Iterable, - List as typing___List, - Optional as typing___Optional, - Text as typing___Text, - Tuple as typing___Tuple, - cast as typing___cast, -) +@typing_extensions.final +class RPC(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor -from typing_extensions import ( - Literal as typing_extensions___Literal, -) - -class RPC(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - - class SubOpts(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - subscribe = ... # type: bool - topicid = ... # type: typing___Text + @typing_extensions.final + class SubOpts(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + SUBSCRIBE_FIELD_NUMBER: builtins.int + TOPICID_FIELD_NUMBER: builtins.int + subscribe: builtins.bool + """subscribe or unsubscribe""" + topicid: builtins.str def __init__( self, *, - subscribe: typing___Optional[bool] = None, - topicid: typing___Optional[typing___Text] = None, + subscribe: builtins.bool | None = ..., + topicid: builtins.str | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> RPC.SubOpts: ... - def MergeFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - def CopyFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["subscribe", "topicid"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["subscribe", "topicid"] - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "subscribe", b"subscribe", "topicid", b"topicid" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "subscribe", b"subscribe", "topicid", b"topicid" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["subscribe", b"subscribe", "topicid", b"topicid"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["subscribe", b"subscribe", "topicid", b"topicid"]) -> None: ... + SUBSCRIPTIONS_FIELD_NUMBER: builtins.int + PUBLISH_FIELD_NUMBER: builtins.int + CONTROL_FIELD_NUMBER: builtins.int @property - def subscriptions( - self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - RPC.SubOpts - ]: ... + def subscriptions(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___RPC.SubOpts]: ... @property - def publish( - self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - Message - ]: ... + def publish(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___Message]: ... @property - def control(self) -> ControlMessage: ... + def control(self) -> global___ControlMessage: ... def __init__( self, *, - subscriptions: typing___Optional[typing___Iterable[RPC.SubOpts]] = None, - publish: typing___Optional[typing___Iterable[Message]] = None, - control: typing___Optional[ControlMessage] = None, + subscriptions: collections.abc.Iterable[global___RPC.SubOpts] | None = ..., + publish: collections.abc.Iterable[global___Message] | None = ..., + control: global___ControlMessage | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> RPC: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["control"] - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "control", "publish", "subscriptions" - ], - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["control", b"control"] - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "control", - b"control", - "publish", - b"publish", - "subscriptions", - b"subscriptions", - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["control", b"control"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["control", b"control", "publish", b"publish", "subscriptions", b"subscriptions"]) -> None: ... -class Message(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - from_id = ... # type: bytes - data = ... # type: bytes - seqno = ... # type: bytes - topicIDs = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] - signature = ... # type: bytes - key = ... # type: bytes +global___RPC = RPC - def __init__( - self, - *, - from_id: typing___Optional[bytes] = None, - data: typing___Optional[bytes] = None, - seqno: typing___Optional[bytes] = None, - topicIDs: typing___Optional[typing___Iterable[typing___Text]] = None, - signature: typing___Optional[bytes] = None, - key: typing___Optional[bytes] = None, - ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> Message: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, - field_name: typing_extensions___Literal[ - "data", "from_id", "key", "seqno", "signature" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", "from_id", "key", "seqno", "signature", "topicIDs" - ], - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "data", - b"data", - "from_id", - b"from_id", - "key", - b"key", - "seqno", - b"seqno", - "signature", - b"signature", - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", - b"data", - "from_id", - b"from_id", - "key", - b"key", - "seqno", - b"seqno", - "signature", - b"signature", - "topicIDs", - b"topicIDs", - ], - ) -> None: ... - -class ControlMessage(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... +@typing_extensions.final +class Message(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + FROM_ID_FIELD_NUMBER: builtins.int + DATA_FIELD_NUMBER: builtins.int + SEQNO_FIELD_NUMBER: builtins.int + TOPICIDS_FIELD_NUMBER: builtins.int + SIGNATURE_FIELD_NUMBER: builtins.int + KEY_FIELD_NUMBER: builtins.int + from_id: builtins.bytes + data: builtins.bytes + seqno: builtins.bytes @property - def ihave( + def topicIDs(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... + signature: builtins.bytes + key: builtins.bytes + def __init__( self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - ControlIHave - ]: ... + *, + from_id: builtins.bytes | None = ..., + data: builtins.bytes | None = ..., + seqno: builtins.bytes | None = ..., + topicIDs: collections.abc.Iterable[builtins.str] | None = ..., + signature: builtins.bytes | None = ..., + key: builtins.bytes | None = ..., + ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["data", b"data", "from_id", b"from_id", "key", b"key", "seqno", b"seqno", "signature", b"signature"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["data", b"data", "from_id", b"from_id", "key", b"key", "seqno", b"seqno", "signature", b"signature", "topicIDs", b"topicIDs"]) -> None: ... + +global___Message = Message + +@typing_extensions.final +class ControlMessage(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + IHAVE_FIELD_NUMBER: builtins.int + IWANT_FIELD_NUMBER: builtins.int + GRAFT_FIELD_NUMBER: builtins.int + PRUNE_FIELD_NUMBER: builtins.int @property - def iwant( - self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - ControlIWant - ]: ... + def ihave(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___ControlIHave]: ... @property - def graft( - self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - ControlGraft - ]: ... + def iwant(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___ControlIWant]: ... @property - def prune( - self, - ) -> google___protobuf___internal___containers___RepeatedCompositeFieldContainer[ - ControlPrune - ]: ... + def graft(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___ControlGraft]: ... + @property + def prune(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___ControlPrune]: ... def __init__( self, *, - ihave: typing___Optional[typing___Iterable[ControlIHave]] = None, - iwant: typing___Optional[typing___Iterable[ControlIWant]] = None, - graft: typing___Optional[typing___Iterable[ControlGraft]] = None, - prune: typing___Optional[typing___Iterable[ControlPrune]] = None, + ihave: collections.abc.Iterable[global___ControlIHave] | None = ..., + iwant: collections.abc.Iterable[global___ControlIWant] | None = ..., + graft: collections.abc.Iterable[global___ControlGraft] | None = ..., + prune: collections.abc.Iterable[global___ControlPrune] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> ControlMessage: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def ClearField( - self, - field_name: typing_extensions___Literal["graft", "ihave", "iwant", "prune"], - ) -> None: ... - else: - def ClearField( - self, - field_name: typing_extensions___Literal[ - "graft", - b"graft", - "ihave", - b"ihave", - "iwant", - b"iwant", - "prune", - b"prune", - ], - ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["graft", b"graft", "ihave", b"ihave", "iwant", b"iwant", "prune", b"prune"]) -> None: ... -class ControlIHave(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text - messageIDs = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] +global___ControlMessage = ControlMessage +@typing_extensions.final +class ControlIHave(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + TOPICID_FIELD_NUMBER: builtins.int + MESSAGEIDS_FIELD_NUMBER: builtins.int + topicID: builtins.str + @property + def messageIDs(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... def __init__( self, *, - topicID: typing___Optional[typing___Text] = None, - messageIDs: typing___Optional[typing___Iterable[typing___Text]] = None, + topicID: builtins.str | None = ..., + messageIDs: collections.abc.Iterable[builtins.str] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> ControlIHave: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["topicID"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["messageIDs", "topicID"] - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["topicID", b"topicID"] - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "messageIDs", b"messageIDs", "topicID", b"topicID" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["topicID", b"topicID"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["messageIDs", b"messageIDs", "topicID", b"topicID"]) -> None: ... -class ControlIWant(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - messageIDs = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[typing___Text] +global___ControlIHave = ControlIHave +@typing_extensions.final +class ControlIWant(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + MESSAGEIDS_FIELD_NUMBER: builtins.int + @property + def messageIDs(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.str]: ... def __init__( self, *, - messageIDs: typing___Optional[typing___Iterable[typing___Text]] = None, + messageIDs: collections.abc.Iterable[builtins.str] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> ControlIWant: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def ClearField( - self, field_name: typing_extensions___Literal["messageIDs"] - ) -> None: ... - else: - def ClearField( - self, field_name: typing_extensions___Literal["messageIDs", b"messageIDs"] - ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["messageIDs", b"messageIDs"]) -> None: ... -class ControlGraft(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text +global___ControlIWant = ControlIWant +@typing_extensions.final +class ControlGraft(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + TOPICID_FIELD_NUMBER: builtins.int + topicID: builtins.str def __init__( self, *, - topicID: typing___Optional[typing___Text] = None, + topicID: builtins.str | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> ControlGraft: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["topicID"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["topicID"] - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["topicID", b"topicID"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["topicID", b"topicID"] - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["topicID", b"topicID"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["topicID", b"topicID"]) -> None: ... -class ControlPrune(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - topicID = ... # type: typing___Text +global___ControlGraft = ControlGraft +@typing_extensions.final +class ControlPrune(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + TOPICID_FIELD_NUMBER: builtins.int + topicID: builtins.str def __init__( self, *, - topicID: typing___Optional[typing___Text] = None, + topicID: builtins.str | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> ControlPrune: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["topicID"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["topicID"] - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["topicID", b"topicID"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["topicID", b"topicID"] - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["topicID", b"topicID"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["topicID", b"topicID"]) -> None: ... -class TopicDescriptor(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... +global___ControlPrune = ControlPrune - class AuthOpts(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... +@typing_extensions.final +class TopicDescriptor(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor - class AuthMode(int): - DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... - @classmethod - def Name(cls, number: int) -> str: ... - @classmethod - def Value(cls, name: str) -> TopicDescriptor.AuthOpts.AuthMode: ... - @classmethod - def keys(cls) -> typing___List[str]: ... - @classmethod - def values(cls) -> typing___List[TopicDescriptor.AuthOpts.AuthMode]: ... - @classmethod - def items( - cls, - ) -> typing___List[ - typing___Tuple[str, TopicDescriptor.AuthOpts.AuthMode] - ]: ... - NONE = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 0) - KEY = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 1) - WOT = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 2) - NONE = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 0) - KEY = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 1) - WOT = typing___cast(TopicDescriptor.AuthOpts.AuthMode, 2) + @typing_extensions.final + class AuthOpts(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor - mode = ... # type: TopicDescriptor.AuthOpts.AuthMode - keys = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] + class _AuthMode: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + class _AuthModeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[TopicDescriptor.AuthOpts._AuthMode.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + NONE: TopicDescriptor.AuthOpts._AuthMode.ValueType # 0 + """no authentication, anyone can publish""" + KEY: TopicDescriptor.AuthOpts._AuthMode.ValueType # 1 + """only messages signed by keys in the topic descriptor are accepted""" + WOT: TopicDescriptor.AuthOpts._AuthMode.ValueType # 2 + """web of trust, certificates can allow publisher set to grow""" + + class AuthMode(_AuthMode, metaclass=_AuthModeEnumTypeWrapper): ... + NONE: TopicDescriptor.AuthOpts.AuthMode.ValueType # 0 + """no authentication, anyone can publish""" + KEY: TopicDescriptor.AuthOpts.AuthMode.ValueType # 1 + """only messages signed by keys in the topic descriptor are accepted""" + WOT: TopicDescriptor.AuthOpts.AuthMode.ValueType # 2 + """web of trust, certificates can allow publisher set to grow""" + + MODE_FIELD_NUMBER: builtins.int + KEYS_FIELD_NUMBER: builtins.int + mode: global___TopicDescriptor.AuthOpts.AuthMode.ValueType + @property + def keys(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.bytes]: + """root keys to trust""" def __init__( self, *, - mode: typing___Optional[TopicDescriptor.AuthOpts.AuthMode] = None, - keys: typing___Optional[typing___Iterable[bytes]] = None, + mode: global___TopicDescriptor.AuthOpts.AuthMode.ValueType | None = ..., + keys: collections.abc.Iterable[builtins.bytes] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> TopicDescriptor.AuthOpts: ... - def MergeFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - def CopyFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["mode"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["keys", "mode"] - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["mode", b"mode"] - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "keys", b"keys", "mode", b"mode" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["mode", b"mode"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["keys", b"keys", "mode", b"mode"]) -> None: ... - class EncOpts(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... + @typing_extensions.final + class EncOpts(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor - class EncMode(int): - DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ... - @classmethod - def Name(cls, number: int) -> str: ... - @classmethod - def Value(cls, name: str) -> TopicDescriptor.EncOpts.EncMode: ... - @classmethod - def keys(cls) -> typing___List[str]: ... - @classmethod - def values(cls) -> typing___List[TopicDescriptor.EncOpts.EncMode]: ... - @classmethod - def items( - cls, - ) -> typing___List[ - typing___Tuple[str, TopicDescriptor.EncOpts.EncMode] - ]: ... - NONE = typing___cast(TopicDescriptor.EncOpts.EncMode, 0) - SHAREDKEY = typing___cast(TopicDescriptor.EncOpts.EncMode, 1) - WOT = typing___cast(TopicDescriptor.EncOpts.EncMode, 2) - NONE = typing___cast(TopicDescriptor.EncOpts.EncMode, 0) - SHAREDKEY = typing___cast(TopicDescriptor.EncOpts.EncMode, 1) - WOT = typing___cast(TopicDescriptor.EncOpts.EncMode, 2) + class _EncMode: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType - mode = ... # type: TopicDescriptor.EncOpts.EncMode - keyHashes = ( - ... - ) # type: google___protobuf___internal___containers___RepeatedScalarFieldContainer[bytes] + class _EncModeEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[TopicDescriptor.EncOpts._EncMode.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + NONE: TopicDescriptor.EncOpts._EncMode.ValueType # 0 + """no encryption, anyone can read""" + SHAREDKEY: TopicDescriptor.EncOpts._EncMode.ValueType # 1 + """messages are encrypted with shared key""" + WOT: TopicDescriptor.EncOpts._EncMode.ValueType # 2 + """web of trust, certificates can allow publisher set to grow""" + class EncMode(_EncMode, metaclass=_EncModeEnumTypeWrapper): ... + NONE: TopicDescriptor.EncOpts.EncMode.ValueType # 0 + """no encryption, anyone can read""" + SHAREDKEY: TopicDescriptor.EncOpts.EncMode.ValueType # 1 + """messages are encrypted with shared key""" + WOT: TopicDescriptor.EncOpts.EncMode.ValueType # 2 + """web of trust, certificates can allow publisher set to grow""" + + MODE_FIELD_NUMBER: builtins.int + KEYHASHES_FIELD_NUMBER: builtins.int + mode: global___TopicDescriptor.EncOpts.EncMode.ValueType + @property + def keyHashes(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.bytes]: + """the hashes of the shared keys used (salted)""" def __init__( self, *, - mode: typing___Optional[TopicDescriptor.EncOpts.EncMode] = None, - keyHashes: typing___Optional[typing___Iterable[bytes]] = None, + mode: global___TopicDescriptor.EncOpts.EncMode.ValueType | None = ..., + keyHashes: collections.abc.Iterable[builtins.bytes] | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> TopicDescriptor.EncOpts: ... - def MergeFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - def CopyFrom( - self, other_msg: google___protobuf___message___Message - ) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["mode"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["keyHashes", "mode"] - ) -> None: ... - else: - def HasField( - self, field_name: typing_extensions___Literal["mode", b"mode"] - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "keyHashes", b"keyHashes", "mode", b"mode" - ], - ) -> None: ... - - name = ... # type: typing___Text + def HasField(self, field_name: typing_extensions.Literal["mode", b"mode"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["keyHashes", b"keyHashes", "mode", b"mode"]) -> None: ... + NAME_FIELD_NUMBER: builtins.int + AUTH_FIELD_NUMBER: builtins.int + ENC_FIELD_NUMBER: builtins.int + name: builtins.str @property - def auth(self) -> TopicDescriptor.AuthOpts: ... + def auth(self) -> global___TopicDescriptor.AuthOpts: ... @property - def enc(self) -> TopicDescriptor.EncOpts: ... + def enc(self) -> global___TopicDescriptor.EncOpts: ... def __init__( self, *, - name: typing___Optional[typing___Text] = None, - auth: typing___Optional[TopicDescriptor.AuthOpts] = None, - enc: typing___Optional[TopicDescriptor.EncOpts] = None, + name: builtins.str | None = ..., + auth: global___TopicDescriptor.AuthOpts | None = ..., + enc: global___TopicDescriptor.EncOpts | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> TopicDescriptor: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["auth", "enc", "name"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["auth", "enc", "name"] - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "auth", b"auth", "enc", b"enc", "name", b"name" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "auth", b"auth", "enc", b"enc", "name", b"name" - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["auth", b"auth", "enc", b"enc", "name", b"name"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["auth", b"auth", "enc", b"enc", "name", b"name"]) -> None: ... + +global___TopicDescriptor = TopicDescriptor diff --git a/libp2p/security/insecure/pb/plaintext_pb2.py b/libp2p/security/insecure/pb/plaintext_pb2.py index eabb6e49..c04fc603 100644 --- a/libp2p/security/insecure/pb/plaintext_pb2.py +++ b/libp2p/security/insecure/pb/plaintext_pb2.py @@ -1,14 +1,12 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/security/insecure/pb/plaintext.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() @@ -17,91 +15,13 @@ _sym_db = _symbol_database.Default() from libp2p.crypto.pb import crypto_pb2 as libp2p_dot_crypto_dot_pb_dot_crypto__pb2 -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/security/insecure/pb/plaintext.proto", - package="plaintext.pb", - syntax="proto2", - serialized_pb=_b( - '\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey' - ), - dependencies=[ - libp2p_dot_crypto_dot_pb_dot_crypto__pb2.DESCRIPTOR, - ], -) - - -_EXCHANGE = _descriptor.Descriptor( - name="Exchange", - full_name="plaintext.pb.Exchange", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="id", - full_name="plaintext.pb.Exchange.id", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="pubkey", - full_name="plaintext.pb.Exchange.pubkey", - index=1, - number=2, - type=11, - cpp_type=10, - label=1, - has_default_value=False, - default_value=None, - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=92, - serialized_end=152, -) - -_EXCHANGE.fields_by_name[ - "pubkey" -].message_type = libp2p_dot_crypto_dot_pb_dot_crypto__pb2._PUBLICKEY -DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Exchange = _reflection.GeneratedProtocolMessageType( - "Exchange", - (_message.Message,), - dict( - DESCRIPTOR=_EXCHANGE, - __module__="libp2p.security.insecure.pb.plaintext_pb2" - # @@protoc_insertion_point(class_scope:plaintext.pb.Exchange) - ), -) -_sym_db.RegisterMessage(Exchange) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n+libp2p/security/insecure/pb/plaintext.proto\x12\x0cplaintext.pb\x1a\x1dlibp2p/crypto/pb/crypto.proto\"<\n\x08\x45xchange\x12\n\n\x02id\x18\x01 \x01(\x0c\x12$\n\x06pubkey\x18\x02 \x01(\x0b\x32\x14.crypto.pb.PublicKey') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.security.insecure.pb.plaintext_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_EXCHANGE']._serialized_start=92 + _globals['_EXCHANGE']._serialized_end=152 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/security/insecure/pb/plaintext_pb2.pyi b/libp2p/security/insecure/pb/plaintext_pb2.pyi index d5f7a3d6..e97aa0d9 100644 --- a/libp2p/security/insecure/pb/plaintext_pb2.pyi +++ b/libp2p/security/insecure/pb/plaintext_pb2.pyi @@ -1,54 +1,36 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.message +import libp2p.crypto.pb.crypto_pb2 import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, -) -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions -from libp2p.crypto.pb.crypto_pb2 import ( - PublicKey as libp2p___crypto___pb___crypto_pb2___PublicKey, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing import ( - Optional as typing___Optional, -) - -from typing_extensions import ( - Literal as typing_extensions___Literal, -) - -class Exchange(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - id = ... # type: bytes +@typing_extensions.final +class Exchange(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + ID_FIELD_NUMBER: builtins.int + PUBKEY_FIELD_NUMBER: builtins.int + id: builtins.bytes @property - def pubkey(self) -> libp2p___crypto___pb___crypto_pb2___PublicKey: ... + def pubkey(self) -> libp2p.crypto.pb.crypto_pb2.PublicKey: ... def __init__( self, *, - id: typing___Optional[bytes] = None, - pubkey: typing___Optional[libp2p___crypto___pb___crypto_pb2___PublicKey] = None, + id: builtins.bytes | None = ..., + pubkey: libp2p.crypto.pb.crypto_pb2.PublicKey | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> Exchange: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, field_name: typing_extensions___Literal["id", "pubkey"] - ) -> bool: ... - def ClearField( - self, field_name: typing_extensions___Literal["id", "pubkey"] - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal["id", b"id", "pubkey", b"pubkey"], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["id", b"id", "pubkey", b"pubkey"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["id", b"id", "pubkey", b"pubkey"]) -> None: ... + +global___Exchange = Exchange diff --git a/libp2p/security/noise/pb/noise_pb2.py b/libp2p/security/noise/pb/noise_pb2.py index 273d3d32..45e3d6c0 100644 --- a/libp2p/security/noise/pb/noise_pb2.py +++ b/libp2p/security/noise/pb/noise_pb2.py @@ -1,116 +1,26 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/security/noise/pb/noise.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/security/noise/pb/noise.proto", - package="pb", - syntax="proto3", - serialized_pb=_b( - '\n$libp2p/security/noise/pb/noise.proto\x12\x02pb"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3' - ), -) -_NOISEHANDSHAKEPAYLOAD = _descriptor.Descriptor( - name="NoiseHandshakePayload", - full_name="pb.NoiseHandshakePayload", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="identity_key", - full_name="pb.NoiseHandshakePayload.identity_key", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="identity_sig", - full_name="pb.NoiseHandshakePayload.identity_sig", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="data", - full_name="pb.NoiseHandshakePayload.data", - index=2, - number=3, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - options=None, - is_extendable=False, - syntax="proto3", - extension_ranges=[], - oneofs=[], - serialized_start=44, - serialized_end=125, -) - -DESCRIPTOR.message_types_by_name["NoiseHandshakePayload"] = _NOISEHANDSHAKEPAYLOAD -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -NoiseHandshakePayload = _reflection.GeneratedProtocolMessageType( - "NoiseHandshakePayload", - (_message.Message,), - dict( - DESCRIPTOR=_NOISEHANDSHAKEPAYLOAD, - __module__="libp2p.security.noise.pb.noise_pb2" - # @@protoc_insertion_point(class_scope:pb.NoiseHandshakePayload) - ), -) -_sym_db.RegisterMessage(NoiseHandshakePayload) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$libp2p/security/noise/pb/noise.proto\x12\x02pb\"Q\n\x15NoiseHandshakePayload\x12\x14\n\x0cidentity_key\x18\x01 \x01(\x0c\x12\x14\n\x0cidentity_sig\x18\x02 \x01(\x0c\x12\x0c\n\x04\x64\x61ta\x18\x03 \x01(\x0c\x62\x06proto3') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.security.noise.pb.noise_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_NOISEHANDSHAKEPAYLOAD']._serialized_start=44 + _globals['_NOISEHANDSHAKEPAYLOAD']._serialized_end=125 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/security/noise/pb/noise_pb2.pyi b/libp2p/security/noise/pb/noise_pb2.pyi index 16b6772a..d3cd4d24 100644 --- a/libp2p/security/noise/pb/noise_pb2.pyi +++ b/libp2p/security/noise/pb/noise_pb2.pyi @@ -1,54 +1,36 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.message import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, -) -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions -from typing import ( - Optional as typing___Optional, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing_extensions import ( - Literal as typing_extensions___Literal, -) - -class NoiseHandshakePayload(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - identity_key = ... # type: bytes - identity_sig = ... # type: bytes - data = ... # type: bytes +@typing_extensions.final +class NoiseHandshakePayload(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + IDENTITY_KEY_FIELD_NUMBER: builtins.int + IDENTITY_SIG_FIELD_NUMBER: builtins.int + DATA_FIELD_NUMBER: builtins.int + identity_key: builtins.bytes + identity_sig: builtins.bytes + data: builtins.bytes def __init__( self, *, - identity_key: typing___Optional[bytes] = None, - identity_sig: typing___Optional[bytes] = None, - data: typing___Optional[bytes] = None, + identity_key: builtins.bytes = ..., + identity_sig: builtins.bytes = ..., + data: builtins.bytes = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> NoiseHandshakePayload: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", "identity_key", "identity_sig" - ], - ) -> None: ... - else: - def ClearField( - self, - field_name: typing_extensions___Literal[ - "data", - b"data", - "identity_key", - b"identity_key", - "identity_sig", - b"identity_sig", - ], - ) -> None: ... + def ClearField(self, field_name: typing_extensions.Literal["data", b"data", "identity_key", b"identity_key", "identity_sig", b"identity_sig"]) -> None: ... + +global___NoiseHandshakePayload = NoiseHandshakePayload diff --git a/libp2p/security/secio/pb/spipe_pb2.py b/libp2p/security/secio/pb/spipe_pb2.py index f0ad7872..32636112 100644 --- a/libp2p/security/secio/pb/spipe_pb2.py +++ b/libp2p/security/secio/pb/spipe_pb2.py @@ -1,222 +1,28 @@ +# -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: libp2p/security/secio/pb/spipe.proto - -import sys - -_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1")) +# Protobuf Python Version: 4.25.3 +"""Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection +from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database - +from google.protobuf.internal import builder as _builder # @@protoc_insertion_point(imports) _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor.FileDescriptor( - name="libp2p/security/secio/pb/spipe.proto", - package="spipe.pb", - syntax="proto2", - serialized_options=None, - serialized_pb=_b( - '\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c' - ), -) -_PROPOSE = _descriptor.Descriptor( - name="Propose", - full_name="spipe.pb.Propose", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="rand", - full_name="spipe.pb.Propose.rand", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="public_key", - full_name="spipe.pb.Propose.public_key", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="exchanges", - full_name="spipe.pb.Propose.exchanges", - index=2, - number=3, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="ciphers", - full_name="spipe.pb.Propose.ciphers", - index=3, - number=4, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="hashes", - full_name="spipe.pb.Propose.hashes", - index=4, - number=5, - type=9, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b("").decode("utf-8"), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=50, - serialized_end=145, -) - - -_EXCHANGE = _descriptor.Descriptor( - name="Exchange", - full_name="spipe.pb.Exchange", - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name="ephemeral_public_key", - full_name="spipe.pb.Exchange.ephemeral_public_key", - index=0, - number=1, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - _descriptor.FieldDescriptor( - name="signature", - full_name="spipe.pb.Exchange.signature", - index=1, - number=2, - type=12, - cpp_type=9, - label=1, - has_default_value=False, - default_value=_b(""), - message_type=None, - enum_type=None, - containing_type=None, - is_extension=False, - extension_scope=None, - serialized_options=None, - file=DESCRIPTOR, - ), - ], - extensions=[], - nested_types=[], - enum_types=[], - serialized_options=None, - is_extendable=False, - syntax="proto2", - extension_ranges=[], - oneofs=[], - serialized_start=147, - serialized_end=206, -) - -DESCRIPTOR.message_types_by_name["Propose"] = _PROPOSE -DESCRIPTOR.message_types_by_name["Exchange"] = _EXCHANGE -_sym_db.RegisterFileDescriptor(DESCRIPTOR) - -Propose = _reflection.GeneratedProtocolMessageType( - "Propose", - (_message.Message,), - { - "DESCRIPTOR": _PROPOSE, - "__module__": "libp2p.security.secio.pb.spipe_pb2" - # @@protoc_insertion_point(class_scope:spipe.pb.Propose) - }, -) -_sym_db.RegisterMessage(Propose) - -Exchange = _reflection.GeneratedProtocolMessageType( - "Exchange", - (_message.Message,), - { - "DESCRIPTOR": _EXCHANGE, - "__module__": "libp2p.security.secio.pb.spipe_pb2" - # @@protoc_insertion_point(class_scope:spipe.pb.Exchange) - }, -) -_sym_db.RegisterMessage(Exchange) - +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n$libp2p/security/secio/pb/spipe.proto\x12\x08spipe.pb\"_\n\x07Propose\x12\x0c\n\x04rand\x18\x01 \x01(\x0c\x12\x12\n\npublic_key\x18\x02 \x01(\x0c\x12\x11\n\texchanges\x18\x03 \x01(\t\x12\x0f\n\x07\x63iphers\x18\x04 \x01(\t\x12\x0e\n\x06hashes\x18\x05 \x01(\t\";\n\x08\x45xchange\x12\x1c\n\x14\x65phemeral_public_key\x18\x01 \x01(\x0c\x12\x11\n\tsignature\x18\x02 \x01(\x0c') +_globals = globals() +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'libp2p.security.secio.pb.spipe_pb2', _globals) +if _descriptor._USE_C_DESCRIPTORS == False: + DESCRIPTOR._options = None + _globals['_PROPOSE']._serialized_start=50 + _globals['_PROPOSE']._serialized_end=145 + _globals['_EXCHANGE']._serialized_start=147 + _globals['_EXCHANGE']._serialized_end=206 # @@protoc_insertion_point(module_scope) diff --git a/libp2p/security/secio/pb/spipe_pb2.pyi b/libp2p/security/secio/pb/spipe_pb2.pyi index 5319942e..afb44b7a 100644 --- a/libp2p/security/secio/pb/spipe_pb2.pyi +++ b/libp2p/security/secio/pb/spipe_pb2.pyi @@ -1,132 +1,62 @@ -# @generated by generate_proto_mypy_stubs.py. Do not edit! +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +""" +import builtins +import google.protobuf.descriptor +import google.protobuf.message import sys -from google.protobuf.descriptor import ( - Descriptor as google___protobuf___descriptor___Descriptor, -) -from google.protobuf.message import ( - Message as google___protobuf___message___Message, -) +if sys.version_info >= (3, 8): + import typing as typing_extensions +else: + import typing_extensions -from typing import ( - Optional as typing___Optional, - Text as typing___Text, -) +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor -from typing_extensions import ( - Literal as typing_extensions___Literal, -) - -class Propose(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - rand = ... # type: bytes - public_key = ... # type: bytes - exchanges = ... # type: typing___Text - ciphers = ... # type: typing___Text - hashes = ... # type: typing___Text +@typing_extensions.final +class Propose(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + RAND_FIELD_NUMBER: builtins.int + PUBLIC_KEY_FIELD_NUMBER: builtins.int + EXCHANGES_FIELD_NUMBER: builtins.int + CIPHERS_FIELD_NUMBER: builtins.int + HASHES_FIELD_NUMBER: builtins.int + rand: builtins.bytes + public_key: builtins.bytes + exchanges: builtins.str + ciphers: builtins.str + hashes: builtins.str def __init__( self, *, - rand: typing___Optional[bytes] = None, - public_key: typing___Optional[bytes] = None, - exchanges: typing___Optional[typing___Text] = None, - ciphers: typing___Optional[typing___Text] = None, - hashes: typing___Optional[typing___Text] = None, + rand: builtins.bytes | None = ..., + public_key: builtins.bytes | None = ..., + exchanges: builtins.str | None = ..., + ciphers: builtins.str | None = ..., + hashes: builtins.str | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> Propose: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, - field_name: typing_extensions___Literal[ - "ciphers", "exchanges", "hashes", "public_key", "rand" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "ciphers", "exchanges", "hashes", "public_key", "rand" - ], - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "ciphers", - b"ciphers", - "exchanges", - b"exchanges", - "hashes", - b"hashes", - "public_key", - b"public_key", - "rand", - b"rand", - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "ciphers", - b"ciphers", - "exchanges", - b"exchanges", - "hashes", - b"hashes", - "public_key", - b"public_key", - "rand", - b"rand", - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["ciphers", b"ciphers", "exchanges", b"exchanges", "hashes", b"hashes", "public_key", b"public_key", "rand", b"rand"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["ciphers", b"ciphers", "exchanges", b"exchanges", "hashes", b"hashes", "public_key", b"public_key", "rand", b"rand"]) -> None: ... -class Exchange(google___protobuf___message___Message): - DESCRIPTOR: google___protobuf___descriptor___Descriptor = ... - ephemeral_public_key = ... # type: bytes - signature = ... # type: bytes +global___Propose = Propose +@typing_extensions.final +class Exchange(google.protobuf.message.Message): + DESCRIPTOR: google.protobuf.descriptor.Descriptor + + EPHEMERAL_PUBLIC_KEY_FIELD_NUMBER: builtins.int + SIGNATURE_FIELD_NUMBER: builtins.int + ephemeral_public_key: builtins.bytes + signature: builtins.bytes def __init__( self, *, - ephemeral_public_key: typing___Optional[bytes] = None, - signature: typing___Optional[bytes] = None, + ephemeral_public_key: builtins.bytes | None = ..., + signature: builtins.bytes | None = ..., ) -> None: ... - @classmethod - def FromString(cls, s: bytes) -> Exchange: ... - def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ... - if sys.version_info >= (3,): - def HasField( - self, - field_name: typing_extensions___Literal[ - "ephemeral_public_key", "signature" - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "ephemeral_public_key", "signature" - ], - ) -> None: ... - else: - def HasField( - self, - field_name: typing_extensions___Literal[ - "ephemeral_public_key", - b"ephemeral_public_key", - "signature", - b"signature", - ], - ) -> bool: ... - def ClearField( - self, - field_name: typing_extensions___Literal[ - "ephemeral_public_key", - b"ephemeral_public_key", - "signature", - b"signature", - ], - ) -> None: ... + def HasField(self, field_name: typing_extensions.Literal["ephemeral_public_key", b"ephemeral_public_key", "signature", b"signature"]) -> builtins.bool: ... + def ClearField(self, field_name: typing_extensions.Literal["ephemeral_public_key", b"ephemeral_public_key", "signature", b"signature"]) -> None: ... + +global___Exchange = Exchange diff --git a/tests/libp2p/test_libp2p.py b/tests/test_libp2p/test_libp2p.py similarity index 100% rename from tests/libp2p/test_libp2p.py rename to tests/test_libp2p/test_libp2p.py From 121c1d0afc04bebace1a841ec49f48e4969e04d5 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Sat, 2 Mar 2024 11:47:59 -0700 Subject: [PATCH 101/102] add interop tests, but not turned on --- .circleci/config.yml | 52 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 44 +++++++++---------------------------- tox.ini | 1 + 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index af41e526..b5a0d13c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -95,6 +95,22 @@ docs: &docs sudo apt-get update sudo apt-get install latexmk tex-gyre texlive-fonts-extra +interop: &interop + docker: + - image: common + steps: + - run: + name: install interop test dependencies + command: | + sudo apt-get update + sudo apt-get install latexmk tex-gyre texlive-fonts-extra + wget https://dl.google.com/go/$GOBINPKG + sudo tar -C /usr/local -xzf $GOBINPKG + export GOPATH=$HOME/go + export GOROOT=/usr/local/go + export PATH=$GOROOT/bin:$GOPATH/bin:$PATH + ./tests_interop/go_pkgs/install_interop_go_pkgs.sh + jobs: docs: <<: *docs @@ -222,6 +238,37 @@ jobs: - <<: *run-tox-step - <<: *save-cache-step + py38-interop: + <<: *interop + docker: + - image: cimg/python:3.8 + environment: + TOXENV: py38-interop + py39-interop: + <<: *interop + docker: + - image: cimg/python:3.9 + environment: + TOXENV: py39-interop + py310-interop: + <<: *interop + docker: + - image: cimg/python:3.10 + environment: + TOXENV: py310-interop + py311-interop: + <<: *interop + docker: + - image: cimg/python:3.11 + environment: + TOXENV: py311-interop + py312-interop: + <<: *interop + docker: + - image: cimg/python:3.12 + environment: + TOXENV: py312-interop + workflows: version: 2 test: @@ -244,3 +291,8 @@ workflows: - py312-wheel # - py311-windows-wheel # - py312-windows-wheel + # - py38-interop + # - py39-interop + # - py310-interop + # - py311-interop + # - py312-interop diff --git a/README.md b/README.md index 31c9669d..d343c7d6 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ ## WARNING -py-libp2p is an experimental and work-in-progress repo under heavy development. We do not yet recommend using py-libp2p in production environments. +py-libp2p is an experimental and work-in-progress repo under development. We do not yet recommend using py-libp2p in production environments. +Right now, `tests_interop` are turned off for CI, and a number of `tests` are failing. The Python implementation of the libp2p networking stack @@ -27,50 +28,25 @@ This project is graciously sponsored by the Ethereum Foundation through [Wave 5 ## Maintainers -The py-libp2p team consists of: +Currently maintained by [@pacrob](https://github.com/pacrob), looking for assistance! + +The py-libp2p team previously consisted of: [@zixuanzh](https://github.com/zixuanzh) [@alexh](https://github.com/alexh) [@stuckinaboot](https://github.com/stuckinaboot) [@robzajac](https://github.com/robzajac) [@carver](https://github.com/carver) ## Development -py-libp2p requires Python 3.7 and the best way to guarantee a clean Python 3.7 environment is with [`virtualenv`](https://virtualenv.pypa.io/en/stable/) +py-libp2p requires Python 3.8+ and the best way to guarantee a clean Python environment is with [`virtualenv`](https://virtualenv.pypa.io/en/stable/) ```sh git clone git@github.com:libp2p/py-libp2p.git cd py-libp2p -virtualenv -p python3.7 venv +virtualenv -p python venv . venv/bin/activate -pip install -e .[dev] +python -m pip install -e .[dev] ``` -### Testing Setup - -During development, you might like to have tests run on every file save. - -Show flake8 errors on file change: - -```sh -# Test flake8 -when-changed -v -s -r -1 libp2p/ tests/ -c "clear; flake8 libp2p tests && echo 'flake8 success' || echo 'error'" -``` - -Run multi-process tests in one command, but without color: - -```sh -# in the project root: -pytest --numprocesses=4 --looponfail --maxfail=1 -# the same thing, succinctly: -pytest -n 4 -f --maxfail=1 -``` - -Run in one thread, with color and desktop notifications: - -```sh -cd venv -ptw --onfail "notify-send -t 5000 'Test failure ⚠⚠⚠⚠⚠' 'python 3 test on py-libp2p failed'" ../tests ../libp2p -``` - -Note that tests/libp2p/test_libp2p.py contains an end-to-end messaging test between two libp2p hosts, which is the bulk of our proof of concept. +Note that tests/test_libp2p/test_libp2p.py contains an end-to-end messaging test between two libp2p hosts, which is the bulk of our proof of concept. ### Release setup @@ -85,7 +61,7 @@ To release a new version: > > > > > > > template -The protobuf description in this repository was generated by `protoc` at version `3.7.1`. +The protobuf description in this repository was generated by `protoc` at version `25.3`. ## Feature Breakdown diff --git a/tox.ini b/tox.ini index 2847f71e..401cbff4 100644 --- a/tox.ini +++ b/tox.ini @@ -5,6 +5,7 @@ envlist= py{38,39,310,311,312}-wheel windows-wheel docs + py{38,39,310,311,312}-interop [flake8] exclude=venv*,.tox,docs,build,*_pb2*.py From 6099b7c5db6d17ad99bb3a40f06c13c5923afb49 Mon Sep 17 00:00:00 2001 From: pacrob <5199899+pacrob@users.noreply.github.com> Date: Sat, 2 Mar 2024 12:05:27 -0700 Subject: [PATCH 102/102] newsfragments --- newsfragments/447.breaking.rst | 1 + newsfragments/447.feature.rst | 1 + newsfragments/447.internal.rst | 1 + 3 files changed, 3 insertions(+) create mode 100644 newsfragments/447.breaking.rst create mode 100644 newsfragments/447.feature.rst create mode 100644 newsfragments/447.internal.rst diff --git a/newsfragments/447.breaking.rst b/newsfragments/447.breaking.rst new file mode 100644 index 00000000..89a9b6a5 --- /dev/null +++ b/newsfragments/447.breaking.rst @@ -0,0 +1 @@ +Drop support for ``python<3.8`` diff --git a/newsfragments/447.feature.rst b/newsfragments/447.feature.rst new file mode 100644 index 00000000..99445953 --- /dev/null +++ b/newsfragments/447.feature.rst @@ -0,0 +1 @@ +Add basic support for ``python3.8, 3.9, 3.10, 3.11, 3.12`` diff --git a/newsfragments/447.internal.rst b/newsfragments/447.internal.rst new file mode 100644 index 00000000..dd381fe4 --- /dev/null +++ b/newsfragments/447.internal.rst @@ -0,0 +1 @@ +Merge updates from ethereum python project template, including using ``pre-commit`` for linting, change name of ``master`` branch to ``main``, lots of linting changes