Skip to content

Commit a8e817f

Browse files
committed
add pyproject,ruff and rm old setup.py
1 parent 512d286 commit a8e817f

29 files changed

+393
-354
lines changed

.bumpversion.cfg

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[bumpversion]
2+
current_version = 0.0.9
3+
commit = True
4+
tag = True
5+
6+
[bumpversion:file:pyproject.toml]
7+
search = version = "{current_version}"
8+
replace = version = "{new_version}"
9+
10+
[bumpversion:file:multiaddr/__init__.py]
11+
search = __version__ = '{current_version}'
12+
replace = __version__ = '{new_version}'

.editorconfig

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

.flake8

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

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ var/
2323
*.egg-info/
2424
.installed.cfg
2525
*.egg
26+
poetry.lock
27+
uv.lock
2628

2729
# PyInstaller
2830
# Usually these files are written by a python script from a template

.pre-commit-config.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
exclude: '.project-template|docs/conf.py|.*pb2\..*'
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: v5.0.0
5+
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/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/northisup/pyright-pretty
22+
rev: v0.1.0
23+
hooks:
24+
- id: pyright-pretty
25+
args: [--show-summary]
26+
- repo: local
27+
hooks:
28+
- id: check-rst-files
29+
name: Check for .rst files in the top-level directory
30+
entry: python -c "import glob, sys; rst_files = glob.glob('*.rst'); sys.exit(1) if rst_files else sys.exit(0)"
31+
language: system
32+
always_run: true
33+
pass_filenames: false

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ help:
1616
@echo "clean-build - remove build artifacts"
1717
@echo "clean-pyc - remove Python file artifacts"
1818
@echo "clean-test - remove test and coverage artifacts"
19-
@echo "lint - check style with flake8"
19+
@echo "lint - check style with ruff"
2020
@echo "test - run tests quickly with the default Python"
2121
@echo "test-all - run tests on every Python version with tox"
2222
@echo "coverage - check code coverage quickly with the default Python"
@@ -49,13 +49,13 @@ setup:
4949
pip install -r requirements_dev.txt
5050

5151
lint:
52-
flake8 multiaddr/* tests/*
52+
python -m ruff check --fix
5353

5454
fix:
55-
python -m ruff check --fix .
55+
python -m ruff check --fix
5656

5757
typecheck:
58-
pre-commit run mypy-local --all-files && pre-commit run pyright-pretty --all-files
58+
pre-commit run pyright-pretty --all-files
5959

6060
test:
6161
python -m pytest tests

multiaddr/codecs/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import importlib
2-
from typing import Dict, Union, Any
3-
2+
from typing import Any, Dict, Union
43

54
# These are special sizes
65
LENGTH_PREFIXED_VAR_SIZE = -1
@@ -32,7 +31,7 @@ def to_bytes(self, proto: Any, string: str) -> bytes:
3231

3332

3433
def codec_by_name(name: Union[str, None]) -> CodecBase:
35-
if name is None: # Special "do nothing expect nothing" pseudo-codec
34+
if name is None: # Special "do nothing - expect nothing" pseudo-codec
3635
return NoneCodec()
3736
codec = CODEC_CACHE.get(name)
3837
if codec is None:

multiaddr/codecs/cid.py

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from typing import Dict, List
2+
13
import base58
24
import cid
3-
from typing import Dict, List
4-
from ..codecs import CodecBase
55

6+
from ..codecs import CodecBase
67
from . import LENGTH_PREFIXED_VAR_SIZE
78

89
SIZE = LENGTH_PREFIXED_VAR_SIZE
@@ -11,56 +12,55 @@
1112

1213
# Spec: https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#string-representation
1314
CIDv0_PREFIX_TO_LENGTH: Dict[str, List[int]] = {
14-
# base58btc prefixes for valid lengths 1 – 42 with the identity "hash" function
15-
'12': [5, 12, 19, 23, 30, 41, 52, 56],
16-
'13': [9, 16, 34, 45],
17-
'14': [27, 38, 49, 60],
18-
'15': [3, 6, 20],
19-
'16': [3, 6, 13, 20, 31, 42, 53],
20-
'17': [3, 13, 42],
21-
'18': [3],
22-
'19': [3, 24, 57],
23-
'1A': [24, 35, 46],
24-
'1B': [35],
25-
'1D': [17],
26-
'1E': [10, 17],
27-
'1F': [10],
28-
'1G': [10, 28, 50],
29-
'1H': [28, 39],
30-
'1P': [21],
31-
'1Q': [21],
32-
'1R': [21, 54],
33-
'1S': [54],
34-
'1T': [7, 32, 43],
35-
'1U': [7, 32, 43],
36-
'1V': [7],
37-
'1W': [7, 14],
38-
'1X': [7, 14],
39-
'1Y': [7, 14],
40-
'1Z': [7, 14],
41-
'1f': [4],
42-
'1g': [4, 58],
43-
'1h': [4, 25, 58],
44-
'1i': [4, 25],
45-
'1j': [4, 25],
46-
'1k': [4, 25, 47],
47-
'1m': [4, 36, 47],
48-
'1n': [4, 36],
49-
'1o': [4, 36],
50-
'1p': [4],
51-
'1q': [4],
52-
'1r': [4],
53-
'1s': [4],
54-
'1t': [4],
55-
'1u': [4],
56-
'1v': [4],
57-
'1w': [4],
58-
'1x': [4],
59-
'1y': [4],
60-
'1z': [4, 18],
61-
15+
# base58btc prefixes for valid lengths 1 - 42 with the identity "hash" function
16+
"12": [5, 12, 19, 23, 30, 41, 52, 56],
17+
"13": [9, 16, 34, 45],
18+
"14": [27, 38, 49, 60],
19+
"15": [3, 6, 20],
20+
"16": [3, 6, 13, 20, 31, 42, 53],
21+
"17": [3, 13, 42],
22+
"18": [3],
23+
"19": [3, 24, 57],
24+
"1A": [24, 35, 46],
25+
"1B": [35],
26+
"1D": [17],
27+
"1E": [10, 17],
28+
"1F": [10],
29+
"1G": [10, 28, 50],
30+
"1H": [28, 39],
31+
"1P": [21],
32+
"1Q": [21],
33+
"1R": [21, 54],
34+
"1S": [54],
35+
"1T": [7, 32, 43],
36+
"1U": [7, 32, 43],
37+
"1V": [7],
38+
"1W": [7, 14],
39+
"1X": [7, 14],
40+
"1Y": [7, 14],
41+
"1Z": [7, 14],
42+
"1f": [4],
43+
"1g": [4, 58],
44+
"1h": [4, 25, 58],
45+
"1i": [4, 25],
46+
"1j": [4, 25],
47+
"1k": [4, 25, 47],
48+
"1m": [4, 36, 47],
49+
"1n": [4, 36],
50+
"1o": [4, 36],
51+
"1p": [4],
52+
"1q": [4],
53+
"1r": [4],
54+
"1s": [4],
55+
"1t": [4],
56+
"1u": [4],
57+
"1v": [4],
58+
"1w": [4],
59+
"1x": [4],
60+
"1y": [4],
61+
"1z": [4, 18],
6262
# base58btc prefix for length 42 with the sha256 hash function
63-
'Qm': [46],
63+
"Qm": [46],
6464
}
6565

6666
PROTO_NAME_TO_CIDv1_CODEC: Dict[str, str] = {
@@ -104,7 +104,7 @@ def to_string(self, proto, buf):
104104
if _is_binary_cidv0_multihash(buf): # CIDv0
105105
if not expected_codec:
106106
# Simply encode as base58btc as there is nothing better to do
107-
return base58.b58encode(buf).decode('ascii')
107+
return base58.b58encode(buf).decode("ascii")
108108

109109
# "Implementations SHOULD display peer IDs using the first (raw
110110
# base58btc encoded multihash) format until the second format is

multiaddr/codecs/domain.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from ..codecs import CodecBase
44
from ..exceptions import BinaryParseError
55

6-
76
SIZE = -1
87
IS_PATH = False
98

multiaddr/codecs/fspath.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from ..codecs import CodecBase
22

3-
43
SIZE = -1
54
IS_PATH = True
65

0 commit comments

Comments
 (0)