Skip to content

Commit 7e377ed

Browse files
authored
Merge branch 'main' into feat/619-store-pubkey-peerid-peerstore
2 parents 30b5811 + 630aac7 commit 7e377ed

File tree

123 files changed

+2862
-1457
lines changed

Some content is hidden

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

123 files changed

+2862
-1457
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ 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)"
1314
@echo "package-test - build package and install it in a venv for manual testing"
1415
@echo "notes - consume towncrier newsfragments and update release notes in docs - requires bump to be set"
1516
@echo "release - package and upload a release (does not run notes target) - requires bump to be set"
17+
@echo "pr - run clean, fix, lint, typecheck, and test i.e basically everything you need to do before creating a PR"
1618

1719
clean-build:
1820
rm -fr build/
@@ -37,8 +39,16 @@ lint:
3739
&& pre-commit run --all-files --show-diff-on-failure \
3840
)
3941

42+
fix:
43+
python -m ruff check --fix
44+
45+
typecheck:
46+
pre-commit run mypy-local --all-files && pre-commit run pyrefly-local --all-files
47+
4048
test:
41-
python -m pytest tests
49+
python -m pytest tests -n auto
50+
51+
pr: clean fix lint typecheck test
4252

4353
# protobufs management
4454

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/chat/chat.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ async def write_data(stream: INetStream) -> None:
4040

4141

4242
async def run(port: int, destination: str) -> None:
43-
localhost_ip = "127.0.0.1"
4443
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
4544
host = new_host()
4645
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
@@ -54,8 +53,8 @@ async def stream_handler(stream: INetStream) -> None:
5453

5554
print(
5655
"Run this from the same folder in another console:\n\n"
57-
f"chat-demo -p {int(port) + 1} "
58-
f"-d /ip4/{localhost_ip}/tcp/{port}/p2p/{host.get_id().pretty()}\n"
56+
f"chat-demo "
57+
f"-d {host.get_addrs()[0]}\n"
5958
)
6059
print("Waiting for incoming connection...")
6160

@@ -87,9 +86,7 @@ def main() -> None:
8786
"/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q"
8887
)
8988
parser = argparse.ArgumentParser(description=description)
90-
parser.add_argument(
91-
"-p", "--port", default=8000, type=int, help="source port number"
92-
)
89+
parser.add_argument("-p", "--port", default=0, type=int, help="source port number")
9390
parser.add_argument(
9491
"-d",
9592
"--destination",
@@ -98,9 +95,6 @@ def main() -> None:
9895
)
9996
args = parser.parse_args()
10097

101-
if not args.port:
102-
raise RuntimeError("was not able to determine a local port")
103-
10498
try:
10599
trio.run(run, *(args.port, args.destination))
106100
except KeyboardInterrupt:

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)