merge template, fill vars, lint

This commit is contained in:
pacrob
2025-01-25 14:40:18 -07:00
21 changed files with 114 additions and 102 deletions

View File

@ -9,8 +9,8 @@ Summary of approach.
### To-Do ### To-Do
- [ ] Clean up commit history - [ ] Clean up commit history
- [ ] Add or update documentation related to these changes
* [ ] 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 #### Cute Animal Picture

View File

@ -4,7 +4,7 @@ on:
pull_request: pull_request:
push: push:
branches: branches:
- master - main
- github-actions - github-actions
defaults: defaults:
@ -16,10 +16,10 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
python: ['3.8', '3.9', '3.10', '3.11', '3.12'] python: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
toxenv: [core, lint, wheel] toxenv: [core, lint, wheel]
include: include:
- python: '3.9' - python: '3.10'
toxenv: docs toxenv: docs
fail-fast: false fail-fast: false
steps: steps:

27
.gitignore vendored
View File

@ -95,31 +95,8 @@ logs
# vs-code # vs-code
.vscode .vscode
### JetBrains template # jupyter notebook files
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm *.ipynb
# 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
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# For a more precise, explicit template, see: # For a more precise, explicit template, see:

View File

@ -1,4 +1,4 @@
exclude: '.project-template|docs/conf.py|.bumpversion.cfg|.*pb2\..*' exclude: '.project-template|docs/conf.py|.*pb2\..*'
repos: repos:
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0 rev: v4.5.0

View File

@ -3,7 +3,7 @@ version: 2
build: build:
os: ubuntu-22.04 os: ubuntu-22.04
tools: tools:
python: "3.9" python: "3.10"
sphinx: sphinx:
configuration: docs/conf.py configuration: docs/conf.py

View File

@ -6,16 +6,18 @@ help:
@echo "clean-build - remove build artifacts" @echo "clean-build - remove build artifacts"
@echo "clean-pyc - remove Python file artifacts" @echo "clean-pyc - remove Python file artifacts"
@echo "clean - run clean-build and clean-pyc" @echo "clean - run clean-build and clean-pyc"
@echo "dist - build package and cat contents of the dist directory"
@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 "test - run tests quickly with the default Python"
@echo "docs - generate docs and open in browser (linux-docs for version on linux)" @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 "package-test - build package and install it in a venv for manual testing"
@echo "release - package and upload a release (does not run notes target)" @echo "notes - consume towncrier newsfragments and update release notes in docs - requires bump to be set"
@echo "dist - package" @echo "release - package and upload a release (does not run notes target) - requires bump to be set"
clean-build: clean-build:
rm -fr build/ rm -fr build/
rm -fr dist/ rm -fr dist/
rm -fr *.egg-info
clean-pyc: clean-pyc:
find . -name '*.pyc' -exec rm -f {} + find . -name '*.pyc' -exec rm -f {} +
@ -25,6 +27,10 @@ clean-pyc:
clean: clean-build clean-pyc clean: clean-build clean-pyc
dist: clean
python -m build
ls -l dist
lint: 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..." \ echo "\n\n\n * pre-commit should have fixed the errors above. Running again to make sure everything is good..." \
@ -32,7 +38,7 @@ lint:
) )
test: test:
pytest tests python -m pytest tests
# protobufs management # protobufs management
@ -73,13 +79,11 @@ validate-newsfragments:
check-docs: build-docs validate-newsfragments check-docs: build-docs validate-newsfragments
build-docs: build-docs:
sphinx-apidoc -o docs/ . setup.py "*conftest*" "libp2p/tools/interop*" sphinx-apidoc -o docs/ . setup.py "*conftest*"
$(MAKE) -C docs clean $(MAKE) -C docs clean
$(MAKE) -C docs html $(MAKE) -C docs html
$(MAKE) -C docs doctest $(MAKE) -C docs doctest
# docs helpers for CI, which requires extra dependencies
check-docs-ci: build-docs build-docs-ci validate-newsfragments check-docs-ci: build-docs build-docs-ci validate-newsfragments
build-docs-ci: build-docs-ci:
@ -93,14 +97,14 @@ package-test: clean
notes: check-bump validate-newsfragments notes: check-bump validate-newsfragments
# Let UPCOMING_VERSION be the version that is used for the current bump # Let UPCOMING_VERSION be the version that is used for the current bump
$(eval UPCOMING_VERSION=$(shell bump-my-version show --increment $(bump) new_version)) $(eval UPCOMING_VERSION=$(shell bump-my-version bump --dry-run $(bump) -v | awk -F"'" '/New version will be / {print $$2}'))
# Now generate the release notes to have them included in the release commit # Now generate the release notes to have them included in the release commit
towncrier build --yes --version $(UPCOMING_VERSION) towncrier build --yes --version $(UPCOMING_VERSION)
# Before we bump the version, make sure that the towncrier-generated docs will build # Before we bump the version, make sure that the towncrier-generated docs will build
make build-docs make build-docs
git commit -m "Compile release notes for v$(UPCOMING_VERSION)" git commit -m "Compile release notes for v$(UPCOMING_VERSION)"
release: check-bump clean release: check-bump check-git clean
# verify that notes command ran correctly # verify that notes command ran correctly
./newsfragments/validate_files.py is-empty ./newsfragments/validate_files.py is-empty
CURRENT_SIGN_SETTING=$(git config commit.gpgSign) CURRENT_SIGN_SETTING=$(git config commit.gpgSign)
@ -115,15 +119,10 @@ release: check-bump clean
check-bump: check-bump:
ifndef bump ifndef bump
$(error bump must be one of: major, minor, patch, stage, or devnum) $(error bump must be set, typically: major, minor, patch, or devnum)
endif endif
check-git: check-git:
# require that you be on a branch that's linked to upstream/main
@if ! git status -s -b | head -1 | grep -q "\.\.upstream/main"; then \
echo "Error: You must be on a branch that's linked to upstream/main"; \
exit 1; \
fi
# require that upstream is configured for ethereum/py-libp2p # require that upstream is configured for ethereum/py-libp2p
@if ! git remote -v | grep "upstream[[:space:]]git@github.com:ethereum/py-libp2p.git (push)\|upstream[[:space:]]https://github.com/ethereum/py-libp2p (push)"; then \ @if ! git remote -v | grep "upstream[[:space:]]git@github.com:ethereum/py-libp2p.git (push)\|upstream[[:space:]]https://github.com/ethereum/py-libp2p (push)"; then \
echo "Error: You must have a remote named 'upstream' that points to 'py-libp2p'"; \ echo "Error: You must have a remote named 'upstream' that points to 'py-libp2p'"; \

View File

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
#
# py-libp2p documentation build configuration file, created by # py-libp2p documentation build configuration file, created by
# sphinx-quickstart on Thu Oct 16 20:43:24 2014. # sphinx-quickstart on Thu Oct 16 20:43:24 2014.
# #
@ -19,7 +17,7 @@
import os import os
DIR = os.path.dirname("__file__") DIR = os.path.dirname(__file__)
with open(os.path.join(DIR, "../setup.py"), "r") as f: with open(os.path.join(DIR, "../setup.py"), "r") as f:
for line in f: for line in f:
if "version=" in line: if "version=" in line:
@ -200,6 +198,8 @@ htmlhelp_basename = "libp2pdocs"
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
latex_engine = "xelatex"
latex_elements = { latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper', #'papersize': 'letterpaper',

View File

@ -1,8 +1,12 @@
Contributing Contributing
------------ ------------
Development Thank you for your interest in contributing! We welcome all contributions no matter
~~~~~~~~~~~ their size. Please read along to learn how to get started. If you get stuck, feel free
to ask for help in `Ethereum Python Discord server <https://discord.gg/GHryRvPB84>`_.
Setting the stage
~~~~~~~~~~~~~~~~~
To get started, fork the repository to your own github account, then clone it to your To get started, fork the repository to your own github account, then clone it to your
development machine: development machine:
@ -11,8 +15,7 @@ development machine:
git clone git@github.com:your-github-username/py-libp2p.git git clone git@github.com:your-github-username/py-libp2p.git
Next, install the development dependencies. We recommend using a virtual environment,
then install the development dependencies. We recommend using a virtual environment,
such as `virtualenv <https://virtualenv.pypa.io/en/stable/>`_. such as `virtualenv <https://virtualenv.pypa.io/en/stable/>`_.
.. code:: sh .. code:: sh
@ -43,12 +46,16 @@ Requirements
The protobuf description in this repository was generated by ``protoc`` at version The protobuf description in this repository was generated by ``protoc`` at version
``27.2``. ``27.2``.
Testing Running the tests
~~~~~~~ ~~~~~~~~~~~~~~~~~
Running that tests is a great way to explore the codebase. A great way to explore the code base is to run the tests.
You can run all the tests with ``pytest tests``. We can run all tests with:
.. code:: sh
make test
At this time, the interop tests are not passing. You can run just the internal tests At this time, the interop tests are not passing. You can run just the internal tests
with ``pytest tests/core``. with ``pytest tests/core``.
@ -57,20 +64,47 @@ with ``pytest tests/core``.
Code Style Code Style
~~~~~~~~~~ ~~~~~~~~~~
We use `pre-commit <https://pre-commit.com/>`_ to maintain consistent code style. Once We use `pre-commit <https://pre-commit.com/>`_ to enforce a consistent code style across
installed, it will run automatically with every commit. You can also run it manually the library. This tool runs automatically with every commit, but you can also run it
with: manually with:
.. code:: sh .. code:: sh
make lint make lint
If you need to make a commit that skips the pre-commit checks, you can do so with If you need to make a commit that skips the ``pre-commit`` checks, you can do so with
``git commit --no-verify``. ``git commit --no-verify``.
This project uses ``mypy`` for static type checking, though it is not yet complete. This library uses type hints, which are enforced by the ``mypy`` tool (part of the
All new code should be fully typed, and we are working to add types to the existing ``pre-commit`` checks). All new code is required to land with type hints, with the
codebase. exception of code within the ``tests`` directory.
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 <https://github.com/ethereum/snake-charmers-tactical-manual/blob/main/documentation.md>`_.
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 <https://docs.github.com/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests>`_.
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 <https://github.com/ethereum/py-libp2p/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 Releasing
~~~~~~~~~ ~~~~~~~~~
@ -87,10 +121,8 @@ Before releasing a new version, build and test the package that will be released
.. code:: sh .. code:: sh
git checkout main && git pull git checkout main && git pull
make package-test make package-test
This will build the package and install it in a temporary virtual environment. Follow This will build the package and install it in a temporary virtual environment. Follow
the instructions to activate the venv and test whatever you think is important. the instructions to activate the venv and test whatever you think is important.
@ -100,7 +132,6 @@ You can also preview the release notes:
towncrier --draft towncrier --draft
Build the release notes Build the release notes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -112,7 +143,6 @@ release notes.
make notes bump=$$VERSION_PART_TO_BUMP$$ make notes bump=$$VERSION_PART_TO_BUMP$$
If there are any errors, be sure to re-run make notes until it works. If there are any errors, be sure to re-run make notes until it works.
Push the release to github & pypi Push the release to github & pypi
@ -124,7 +154,6 @@ After confirming that the release package looks okay, release a new version:
make release bump=$$VERSION_PART_TO_BUMP$$ make release bump=$$VERSION_PART_TO_BUMP$$
This command will: This command will:
- Bump the version number as specified in ``.pyproject.toml`` and ``setup.py``. - Bump the version number as specified in ``.pyproject.toml`` and ``setup.py``.

View File

@ -3,8 +3,13 @@ py-libp2p
The Python implementation of the libp2p networking stack The Python implementation of the libp2p networking stack
Contents Installation
-------- ------------
.. code-block:: bash
python -m pip install py-libp2p
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
@ -14,6 +19,9 @@ Contents
quickstart quickstart
release_notes release_notes
.. toctree::
:maxdepth: 1
:caption: Community
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1

View File

@ -0,0 +1 @@
Merge template, adding python 3.13 to CI checks.

View File

@ -7,11 +7,14 @@ combine_as_imports = false
extra_standard_library = "pytest" extra_standard_library = "pytest"
force_grid_wrap = 1 force_grid_wrap = 1
force_sort_within_sections = true force_sort_within_sections = true
force_to_top = "pytest"
honor_noqa = true
known_first_party = "libp2p" known_first_party = "libp2p"
known_third_party = "anyio,factory,lru,p2pclient,pytest,noise" known_third_party = "anyio,factory,lru,p2pclient,pytest,noise"
multi_line_output = 3 multi_line_output = 3
profile = "black" profile = "black"
skip_glob= "*_pb2*.py, *.pyi" skip_glob= "*_pb2*.py, *.pyi"
use_parentheses = true
[tool.mypy] [tool.mypy]
check_untyped_defs = true check_untyped_defs = true

View File

@ -5,9 +5,6 @@ import subprocess
from tempfile import ( from tempfile import (
TemporaryDirectory, TemporaryDirectory,
) )
from typing import (
Tuple,
)
import venv import venv
@ -25,23 +22,16 @@ def find_wheel(project_path: Path) -> Path:
if len(wheels) != 1: if len(wheels) != 1:
raise Exception( raise Exception(
f"Expected one wheel. Instead found: {wheels} in project " f"Expected one wheel. Instead found: {wheels} "
f"{project_path.absolute()}" f"in project {project_path.absolute()}"
) )
return wheels[0] return wheels[0]
def install_wheel( def install_wheel(venv_path: Path, wheel_path: Path) -> None:
venv_path: Path, wheel_path: Path, extras: Tuple[str, ...] = ()
) -> None:
if extras:
extra_suffix = f"[{','.join(extras)}]"
else:
extra_suffix = ""
subprocess.run( subprocess.run(
[venv_path / "bin" / "pip", "install", f"{wheel_path}{extra_suffix}"], [venv_path / "bin" / "pip", "install", f"{wheel_path}"],
check=True, check=True,
) )

View File

@ -9,7 +9,7 @@ from setuptools import (
extras_require = { extras_require = {
"dev": [ "dev": [
"build>=0.9.0", "build>=0.9.0",
"bump-my-version>=0.5.3", "bump_my_version>=0.19.0",
"ipython", "ipython",
"mypy==1.10.0", "mypy==1.10.0",
"pre-commit>=3.4.0", "pre-commit>=3.4.0",
@ -20,7 +20,7 @@ extras_require = {
"docs": [ "docs": [
"sphinx>=6.0.0", "sphinx>=6.0.0",
"sphinx_rtd_theme>=1.0.0", "sphinx_rtd_theme>=1.0.0",
"towncrier>=21,<22", "towncrier>=24,<25",
], ],
"test": [ "test": [
"pytest>=7.0.0", "pytest>=7.0.0",
@ -79,7 +79,7 @@ if not readthedocs_is_building:
setup( setup(
name="libp2p", name="libp2p",
# *IMPORTANT*: Don't manually change the version here. Use `make bump`, as described in readme # *IMPORTANT*: Don't manually change the version here. See Contributing docs for the release process.
version="0.2.1", version="0.2.1",
description="""libp2p: The Python implementation of the libp2p networking stack""", description="""libp2p: The Python implementation of the libp2p networking stack""",
long_description=long_description, long_description=long_description,
@ -109,6 +109,7 @@ setup(
"Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
], ],
platforms=["unix", "linux", "osx"], platforms=["unix", "linux", "osx"],
entry_points={ entry_points={

View File

@ -1,7 +1,7 @@
import pytest
from multiaddr import ( from multiaddr import (
Multiaddr, Multiaddr,
) )
import pytest
import trio import trio
from trio.testing import ( from trio.testing import (
wait_all_tasks_blocked, wait_all_tasks_blocked,

View File

@ -1,7 +1,7 @@
import random import random
import multiaddr
import pytest import pytest
import multiaddr
from libp2p.peer.id import ( from libp2p.peer.id import (
ID, ID,

View File

@ -1,5 +1,5 @@
import multiaddr
import pytest import pytest
import multiaddr
from libp2p.network.stream.exceptions import ( from libp2p.network.stream.exceptions import (
StreamError, StreamError,

View File

@ -1,7 +1,7 @@
import pytest
from multiaddr import ( from multiaddr import (
Multiaddr, Multiaddr,
) )
import pytest
import trio import trio
from libp2p.network.connection.raw_connection import ( from libp2p.network.connection.raw_connection import (

View File

@ -2,6 +2,7 @@ from contextlib import (
AsyncExitStack, AsyncExitStack,
) )
import pytest
import anyio import anyio
from p2pclient.datastructures import ( from p2pclient.datastructures import (
StreamInfo, StreamInfo,
@ -9,7 +10,6 @@ from p2pclient.datastructures import (
from p2pclient.utils import ( from p2pclient.utils import (
get_unused_tcp_port, get_unused_tcp_port,
) )
import pytest
import trio import trio
from libp2p.io.abc import ( from libp2p.io.abc import (

View File

@ -1,12 +1,12 @@
import re import re
import pytest
from multiaddr import ( from multiaddr import (
Multiaddr, Multiaddr,
) )
from p2pclient.utils import ( from p2pclient.utils import (
get_unused_tcp_port, get_unused_tcp_port,
) )
import pytest
import trio import trio
from libp2p.peer.peerinfo import ( from libp2p.peer.peerinfo import (

View File

@ -1,10 +1,10 @@
import functools import functools
import math import math
import pytest
from p2pclient.pb import ( from p2pclient.pb import (
p2pd_pb2, p2pd_pb2,
) )
import pytest
import trio import trio
from libp2p.io.trio import ( from libp2p.io.trio import (

16
tox.ini
View File

@ -1,9 +1,9 @@
[tox] [tox]
envlist= envlist=
py{38,39,310,311,312}-core py{38,39,310,311,312,313}-core
py{38,39,310,311,312}-lint py{38,39,310,311,312,313}-lint
py{38,39,310,311,312}-wheel py{38,39,310,311,312,313}-wheel
py{38,39,310,311,312}-interop py{38,39,310,311,312,313}-interop
windows-wheel windows-wheel
docs docs
@ -13,6 +13,9 @@ extend-ignore=E203
max-line-length=88 max-line-length=88
per-file-ignores=__init__.py:F401 per-file-ignores=__init__.py:F401
[blocklint]
max_issue_threshold=1
[testenv] [testenv]
usedevelop=True usedevelop=True
commands= commands=
@ -27,12 +30,13 @@ basepython=
py310: python3.10 py310: python3.10
py311: python3.11 py311: python3.11
py312: python3.12 py312: python3.12
py313: python3.13
extras= extras=
test test
docs docs
allowlist_externals=make,pre-commit allowlist_externals=make,pre-commit
[testenv:py{38,39,310,311,312}-lint] [testenv:py{38,39,310,311,312,313}-lint]
deps=pre-commit deps=pre-commit
extras= extras=
dev dev
@ -40,7 +44,7 @@ commands=
pre-commit install pre-commit install
pre-commit run --all-files --show-diff-on-failure pre-commit run --all-files --show-diff-on-failure
[testenv:py{38,39,310,311,312}-wheel] [testenv:py{38,39,310,311,312,313}-wheel]
deps= deps=
wheel wheel
build[virtualenv] build[virtualenv]