Skip to content

Commit bdadec7

Browse files
arcinstonacul71kaneki003sukhman-sukhvarun-r-mallya
authored
ft. modernise py-libp2p (#618)
* fix pyproject.toml , add ruff * rm lock * make progress * add poetry lock ignore * fix type issues * fix tcp type errors * fix text example - type error - wrong args * add setuptools to dev * test ci * fix docs build * fix type issues for new_swarm & new_host * fix types in gossipsub * fix type issues in noise * wip: factories * revert factories * fix more type issues * more type fixes * fix: add null checks for noise protocol initialization and key handling * corrected argument-errors in peerId and Multiaddr in peer tests * fix: Noice - remove redundant type casts in BaseNoiseMsgReadWriter * fix: update test_notify.py to use SwarmFactory.create_batch_and_listen, fix type hints, and comment out ClosedStream assertions * Fix type checks for pubsub module Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com> * Fix type checks for pubsub module-tests Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com> * noise: add checks for uninitialized protocol and key states in PatternXX Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> * pubsub: add None checks for optional fields in FloodSub and Pubsub Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> * Fix type hints and improve testing Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> * remove redundant checks Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> * fix build issues * add optional to trio service * fix types * fix type errors * Fix type errors Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> * fixed more-type checks in crypto and peer_data files * wip: factories * replaced union with optional * fix: type-error in interp-utils and peerinfo * replace pyright with pyrefly * add pyrefly.toml * wip: fix multiselect issues * try typecheck * base check * mcache test fixes , typecheck ci update * fix ci * will this work * minor fix * use poetry * fix wokflow * use cache,fix err * fix pyrefly.toml * fix pyrefly.toml * fix cache in ci * deploy commit * add main baseline * update to v5 * improve typecheck ci (#14) * fix typo * remove holepunching code (#16) * fix gossipsub typeerrors (#17) * fix: ensure initiator user includes remote peer id in handshake (#15) * fix ci (#19) * typefix: custom_types | core/peerinfo/test_peer_info | io/abc | pubsub/floodsub | protocol_muxer/multiselect (#18) * fix: Typefixes in PeerInfo (#21) * fix minor type issue (#22) * fix type errors in pubsub (#24) * fix: Minor typefixes in tests (#23) * Fix failing tests for type-fixed test/pubsub (#8) * move pyrefly & ruff to pyproject.toml & rm .project-template (#28) * move the async_context file to tests/core * move crypto test to crypto folder * fix: some typefixes (#25) * fix type errors * fix type issues * fix: update gRPC API usage in autonat_pb2_grpc.py (#31) * md: typecheck ci * rm comments * clean up : from review suggestions * use | None over Optional as per new python standards * drop supporto for py3.9 * newsfragments --------- Signed-off-by: sukhman <sukhmansinghsaluja@gmail.com> Signed-off-by: varun-r-mallya <varunrmallya@gmail.com> Co-authored-by: acul71 <luca.pisani@birdo.net> Co-authored-by: kaneki003 <sakshamchauhan707@gmail.com> Co-authored-by: sukhman <sukhmansinghsaluja@gmail.com> Co-authored-by: varun-r-mallya <varunrmallya@gmail.com> Co-authored-by: varunrmallya <100590632+varun-r-mallya@users.noreply.github.com> Co-authored-by: lla-dane <abhinavagarwalla6@gmail.com> Co-authored-by: Collins <ArtemisfowlX@protonmail.com> Co-authored-by: Abhinav Agarwalla <120122716+lla-dane@users.noreply.github.com> Co-authored-by: guha-rahul <52607971+guha-rahul@users.noreply.github.com> Co-authored-by: Sukhman Singh <63765293+sukhman-sukh@users.noreply.github.com> Co-authored-by: acul71 <34693171+acul71@users.noreply.github.com> Co-authored-by: pacrob <5199899+pacrob@users.noreply.github.com>
1 parent d020bbc commit bdadec7

File tree

111 files changed

+1552
-1416
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+1552
-1416
lines changed

.github/workflows/tox.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717
strategy:
1818
matrix:
19-
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
19+
python: ["3.10", "3.11", "3.12", "3.13"]
2020
toxenv: [core, interop, lint, wheel, demos]
2121
include:
22-
- python: '3.10'
22+
- python: "3.10"
2323
toxenv: docs
2424
fail-fast: false
2525
steps:
@@ -46,7 +46,7 @@ jobs:
4646
runs-on: windows-latest
4747
strategy:
4848
matrix:
49-
python-version: ['3.11', '3.12', '3.13']
49+
python-version: ["3.11", "3.12", "3.13"]
5050
toxenv: [core, wheel]
5151
fail-fast: false
5252
steps:

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ instance/
146146
# PyBuilder
147147
target/
148148

149+
# PyRight Config
150+
pyrightconfig.json
151+
149152
# Jupyter Notebook
150153
.ipynb_checkpoints
151154

@@ -171,3 +174,7 @@ env.bak/
171174

172175
# mkdocs documentation
173176
/site
177+
178+
#lockfiles
179+
uv.lock
180+
poetry.lock

.pre-commit-config.yaml

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,49 @@
11
exclude: '.project-template|docs/conf.py|.*pb2\..*'
22
repos:
3-
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v5.0.0
55
hooks:
6-
- id: check-yaml
7-
- id: check-toml
8-
- id: end-of-file-fixer
9-
- id: trailing-whitespace
10-
- repo: https://github.com/asottile/pyupgrade
11-
rev: v3.15.0
12-
hooks:
13-
- id: pyupgrade
14-
args: [--py39-plus]
15-
- repo: https://github.com/psf/black
16-
rev: 23.9.1
17-
hooks:
18-
- id: black
19-
- repo: https://github.com/PyCQA/flake8
20-
rev: 6.1.0
21-
hooks:
22-
- id: flake8
23-
additional_dependencies:
24-
- flake8-bugbear==23.9.16
25-
exclude: setup.py
26-
- repo: https://github.com/PyCQA/autoflake
27-
rev: v2.2.1
28-
hooks:
29-
- id: autoflake
30-
- repo: https://github.com/pycqa/isort
31-
rev: 5.12.0
32-
hooks:
33-
- id: isort
34-
- repo: https://github.com/pycqa/pydocstyle
35-
rev: 6.3.0
36-
hooks:
37-
- id: pydocstyle
38-
additional_dependencies:
39-
- tomli # required until >= python311
40-
- repo: https://github.com/executablebooks/mdformat
6+
- id: check-yaml
7+
- id: check-toml
8+
- id: end-of-file-fixer
9+
- id: trailing-whitespace
10+
- repo: https://github.com/asottile/pyupgrade
11+
rev: v3.20.0
12+
hooks:
13+
- id: pyupgrade
14+
args: [--py310-plus]
15+
- repo: https://github.com/astral-sh/ruff-pre-commit
16+
rev: v0.11.10
17+
hooks:
18+
- id: ruff
19+
args: [--fix, --exit-non-zero-on-fix]
20+
- id: ruff-format
21+
- repo: https://github.com/executablebooks/mdformat
4122
rev: 0.7.22
4223
hooks:
43-
- id: mdformat
24+
- id: mdformat
4425
additional_dependencies:
45-
- mdformat-gfm
46-
- repo: local
26+
- mdformat-gfm
27+
- repo: local
4728
hooks:
48-
- id: mypy-local
29+
- id: mypy-local
4930
name: run mypy with all dev dependencies present
50-
entry: python -m mypy -p libp2p
31+
entry: mypy -p libp2p
32+
language: system
33+
always_run: true
34+
pass_filenames: false
35+
- repo: local
36+
hooks:
37+
- id: pyrefly-local
38+
name: run pyrefly typecheck locally
39+
entry: pyrefly check
5140
language: system
5241
always_run: true
5342
pass_filenames: false
54-
- repo: local
43+
44+
- repo: local
5545
hooks:
56-
- id: check-rst-files
46+
- id: check-rst-files
5747
name: Check for .rst files in the top-level directory
5848
entry: python -c "import glob, sys; rst_files = glob.glob('*.rst'); sys.exit(1) if rst_files else sys.exit(0)"
5949
language: system

.project-template/fill_template_vars.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

.project-template/refill_template_vars.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

.project-template/template_vars.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ help:
77
@echo "clean-pyc - remove Python file artifacts"
88
@echo "clean - run clean-build and clean-pyc"
99
@echo "dist - build package and cat contents of the dist directory"
10+
@echo "fix - fix formatting & linting issues with ruff"
1011
@echo "lint - fix linting issues with pre-commit"
1112
@echo "test - run tests quickly with the default Python"
1213
@echo "docs - generate docs and open in browser (linux-docs for version on linux)"
@@ -37,8 +38,14 @@ lint:
3738
&& pre-commit run --all-files --show-diff-on-failure \
3839
)
3940

41+
fix:
42+
python -m ruff check --fix
43+
44+
typecheck:
45+
pre-commit run mypy-local --all-files && pre-commit run pyrefly-local --all-files
46+
4047
test:
41-
python -m pytest tests
48+
python -m pytest tests -n auto
4249

4350
# protobufs management
4451

docs/conf.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,24 @@
1515
# documentation root, use os.path.abspath to make it absolute, like shown here.
1616
# sys.path.insert(0, os.path.abspath('.'))
1717

18+
import doctest
1819
import os
20+
import sys
21+
from unittest.mock import MagicMock
22+
23+
try:
24+
import tomllib
25+
except ModuleNotFoundError:
26+
# For Python < 3.11
27+
import tomli as tomllib # type: ignore (In case of >3.11 Pyrefly doesnt find tomli , which is right but a false flag)
28+
29+
# Path to pyproject.toml (assuming conf.py is in a 'docs' subdirectory)
30+
pyproject_path = os.path.join(os.path.dirname(__file__), "..", "pyproject.toml")
1931

20-
DIR = os.path.dirname(__file__)
21-
with open(os.path.join(DIR, "../setup.py"), "r") as f:
22-
for line in f:
23-
if "version=" in line:
24-
setup_version = line.split('"')[1]
25-
break
32+
with open(pyproject_path, "rb") as f:
33+
pyproject_data = tomllib.load(f)
34+
35+
setup_version = pyproject_data["project"]["version"]
2636

2737
# -- General configuration ------------------------------------------------
2838

@@ -302,7 +312,6 @@
302312

303313
# -- Doctest configuration ----------------------------------------
304314

305-
import doctest
306315

307316
doctest_default_flags = (
308317
0
@@ -317,10 +326,9 @@
317326
# Mock out dependencies that are unbuildable on readthedocs, as recommended here:
318327
# https://docs.readthedocs.io/en/rel/faq.html#i-get-import-errors-on-libraries-that-depend-on-c-modules
319328

320-
import sys
321-
from unittest.mock import MagicMock
322329

323-
# Add new modules to mock here (it should be the same list as those excluded in setup.py)
330+
# Add new modules to mock here (it should be the same list
331+
# as those excluded in pyproject.toml)
324332
MOCK_MODULES = [
325333
"fastecdsa",
326334
"fastecdsa.encoding",
@@ -338,4 +346,4 @@
338346

339347
# Allow duplicate object descriptions
340348
nitpicky = False
341-
nitpick_ignore = [("py:class", "type")]
349+
nitpick_ignore = [("py:class", "type")]

examples/doc-examples/example_encryption_insecure.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ async def main():
2424
insecure_transport = InsecureTransport(
2525
# local_key_pair: The key pair used for libp2p identity
2626
local_key_pair=key_pair,
27-
# secure_bytes_provider: Optional function to generate secure random bytes
28-
# (defaults to secrets.token_bytes)
29-
secure_bytes_provider=None, # Use default implementation
3027
)
3128

3229
# Create a security options dictionary mapping protocol ID to transport

examples/doc-examples/example_encryption_noise.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
from libp2p.crypto.secp256k1 import (
1010
create_new_key_pair,
1111
)
12-
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
13-
from libp2p.security.noise.transport import Transport as NoiseTransport
12+
from libp2p.security.noise.transport import (
13+
PROTOCOL_ID as NOISE_PROTOCOL_ID,
14+
Transport as NoiseTransport,
15+
)
1416

1517

1618
async def main():

0 commit comments

Comments
 (0)