Skip to content

Commit 801ceec

Browse files
committed
Revert "merging main branch"
This reverts commit bd8b82b.
1 parent c85d757 commit 801ceec

File tree

123 files changed

+1522
-2694
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

+1522
-2694
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.10", "3.11", "3.12", "3.13"]
19+
python: ['3.9', '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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ instance/
146146
# PyBuilder
147147
target/
148148

149-
# PyRight Config
150-
pyrightconfig.json
151-
152149
# Jupyter Notebook
153150
.ipynb_checkpoints
154151

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

175172
# mkdocs documentation
176173
/site
177-
178-
#lockfiles
179-
uv.lock
180-
poetry.lock

.pre-commit-config.yaml

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,59 @@
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.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
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
2241
rev: 0.7.22
2342
hooks:
24-
- id: mdformat
43+
- id: mdformat
2544
additional_dependencies:
26-
- mdformat-gfm
27-
- repo: local
45+
- mdformat-gfm
46+
- repo: local
2847
hooks:
29-
- id: mypy-local
48+
- id: mypy-local
3049
name: run mypy with all dev dependencies present
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
50+
entry: python -m mypy -p libp2p
4051
language: system
4152
always_run: true
4253
pass_filenames: false
43-
44-
- repo: local
54+
- repo: local
4555
hooks:
46-
- id: check-rst-files
56+
- id: check-rst-files
4757
name: Check for .rst files in the top-level directory
4858
entry: python -c "import glob, sys; rst_files = glob.glob('*.rst'); sys.exit(1) if rst_files else sys.exit(0)"
4959
language: system
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import re
6+
from pathlib import Path
7+
8+
9+
def _find_files(project_root):
10+
path_exclude_pattern = r"\.git($|\/)|venv|_build"
11+
file_exclude_pattern = r"fill_template_vars\.py|\.swp$"
12+
filepaths = []
13+
for dir_path, _dir_names, file_names in os.walk(project_root):
14+
if not re.search(path_exclude_pattern, dir_path):
15+
for file in file_names:
16+
if not re.search(file_exclude_pattern, file):
17+
filepaths.append(str(Path(dir_path, file)))
18+
19+
return filepaths
20+
21+
22+
def _replace(pattern, replacement, project_root):
23+
print(f"Replacing values: {pattern}")
24+
for file in _find_files(project_root):
25+
try:
26+
with open(file) as f:
27+
content = f.read()
28+
content = re.sub(pattern, replacement, content)
29+
with open(file, "w") as f:
30+
f.write(content)
31+
except UnicodeDecodeError:
32+
pass
33+
34+
35+
def main():
36+
project_root = Path(os.path.realpath(sys.argv[0])).parent.parent
37+
38+
module_name = input("What is your python module name? ")
39+
40+
pypi_input = input(f"What is your pypi package name? (default: {module_name}) ")
41+
pypi_name = pypi_input or module_name
42+
43+
repo_input = input(f"What is your github project name? (default: {pypi_name}) ")
44+
repo_name = repo_input or pypi_name
45+
46+
rtd_input = input(
47+
f"What is your readthedocs.org project name? (default: {pypi_name}) "
48+
)
49+
rtd_name = rtd_input or pypi_name
50+
51+
project_input = input(
52+
f"What is your project name (ex: at the top of the README)? (default: {repo_name}) "
53+
)
54+
project_name = project_input or repo_name
55+
56+
short_description = input("What is a one-liner describing the project? ")
57+
58+
_replace("<MODULE_NAME>", module_name, project_root)
59+
_replace("<PYPI_NAME>", pypi_name, project_root)
60+
_replace("<REPO_NAME>", repo_name, project_root)
61+
_replace("<RTD_NAME>", rtd_name, project_root)
62+
_replace("<PROJECT_NAME>", project_name, project_root)
63+
_replace("<SHORT_DESCRIPTION>", short_description, project_root)
64+
65+
os.makedirs(project_root / module_name, exist_ok=True)
66+
Path(project_root / module_name / "__init__.py").touch()
67+
Path(project_root / module_name / "py.typed").touch()
68+
69+
70+
if __name__ == "__main__":
71+
main()
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
from pathlib import Path
6+
import subprocess
7+
8+
9+
def main():
10+
template_dir = Path(os.path.dirname(sys.argv[0]))
11+
template_vars_file = template_dir / "template_vars.txt"
12+
fill_template_vars_script = template_dir / "fill_template_vars.py"
13+
14+
with open(template_vars_file, "r") as input_file:
15+
content_lines = input_file.readlines()
16+
17+
process = subprocess.Popen(
18+
[sys.executable, str(fill_template_vars_script)],
19+
stdin=subprocess.PIPE,
20+
stdout=subprocess.PIPE,
21+
stderr=subprocess.PIPE,
22+
text=True,
23+
)
24+
25+
for line in content_lines:
26+
process.stdin.write(line)
27+
process.stdin.flush()
28+
29+
stdout, stderr = process.communicate()
30+
31+
if process.returncode != 0:
32+
print(f"Error occurred: {stderr}")
33+
sys.exit(1)
34+
35+
print(stdout)
36+
37+
38+
if __name__ == "__main__":
39+
main()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
libp2p
2+
libp2p
3+
py-libp2p
4+
py-libp2p
5+
py-libp2p
6+
The Python implementation of the libp2p networking stack

Makefile

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ 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"
1110
@echo "lint - fix linting issues with pre-commit"
1211
@echo "test - run tests quickly with the default Python"
1312
@echo "docs - generate docs and open in browser (linux-docs for version on linux)"
@@ -38,14 +37,8 @@ lint:
3837
&& pre-commit run --all-files --show-diff-on-failure \
3938
)
4039

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-
4740
test:
48-
python -m pytest tests -n auto
41+
python -m pytest tests
4942

5043
# protobufs management
5144

docs/conf.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,14 @@
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
1918
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")
3119

32-
with open(pyproject_path, "rb") as f:
33-
pyproject_data = tomllib.load(f)
34-
35-
setup_version = pyproject_data["project"]["version"]
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
3626

3727
# -- General configuration ------------------------------------------------
3828

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

313303
# -- Doctest configuration ----------------------------------------
314304

305+
import doctest
315306

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

320+
import sys
321+
from unittest.mock import MagicMock
329322

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

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

examples/chat/chat.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ 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"
4344
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/{port}")
4445
host = new_host()
4546
async with host.run(listen_addrs=[listen_addr]), trio.open_nursery() as nursery:
@@ -53,8 +54,8 @@ async def stream_handler(stream: INetStream) -> None:
5354

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

@@ -86,7 +87,9 @@ def main() -> None:
8687
"/ip4/127.0.0.1/tcp/8000/p2p/QmQn4SwGkDZKkUEpBRBvTmheQycxAHJUNmVEnjA2v1qe8Q"
8788
)
8889
parser = argparse.ArgumentParser(description=description)
89-
parser.add_argument("-p", "--port", default=0, type=int, help="source port number")
90+
parser.add_argument(
91+
"-p", "--port", default=8000, type=int, help="source port number"
92+
)
9093
parser.add_argument(
9194
"-d",
9295
"--destination",
@@ -95,6 +98,9 @@ def main() -> None:
9598
)
9699
args = parser.parse_args()
97100

101+
if not args.port:
102+
raise RuntimeError("was not able to determine a local port")
103+
98104
try:
99105
trio.run(run, *(args.port, args.destination))
100106
except KeyboardInterrupt:

examples/doc-examples/example_encryption_insecure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ 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
2730
)
2831

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

0 commit comments

Comments
 (0)