Skip to content

Commit 0b36f67

Browse files
authored
Api refactor (#27)
* hide internals behind a public api * disable loguru by default when imported * fix scripts and mypy config for new api * update readme organization * update contributing with scripts etc * fix scripts to use logging * bump major version (api is a breaking change)
1 parent a8e2566 commit 0b36f67

File tree

15 files changed

+106
-29
lines changed

15 files changed

+106
-29
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ open issue you want to work on, please leave a comment on it - assigned issues
55
are spearheaded by the assignee, if they need help they will coordinate on the
66
issue.
77

8-
## Development
8+
## Development Environment
99
This project uses `uv` and `pre-commit`.
1010
to install `uv`, you can use homebrew:
1111
```sh
@@ -19,3 +19,10 @@ Once `uv` is installed, clone this repo, then run the following:
1919
uv sync --locked --all-extras --dev # this installs all dev dependencies, without upgrading any.
2020
uv run pre-commit install # sets up pre-commit
2121
```
22+
23+
## Organization
24+
This project uses a `src` layout. all tests are in the `tests` directory, and can be
25+
run with `pytest` from root. the `scripts` directory contains useful scripts for
26+
debugging nodes, including a set of "auto" scripts (which runs normally and periodically
27+
prints the finger table), and "manual" scripts (which include a step function, to manually
28+
run one iteration of the daemon and print the result".

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,25 @@ Fall 2024.
1919

2020
`uv add chordnet`
2121

22-
## Development
23-
See `CONTRIBUTING.md`.
2422

2523
## Usage
2624
to stay consistent with the language from the original paper, we recommend
27-
importing this package as `ring`:
25+
naming your chordnet attribute `ring`:
2826
```python
29-
from chordnet import Node as ring
27+
from chordnet import ChordNet
28+
29+
ring = new ChordNet(...)
30+
ring.create()
31+
# or ring.join(...)
32+
#...
33+
ring.leave()
3034
```
3135
This fits with the concept of "joining" an existing ring network, or creating a
32-
new one, (`ring.join(...)`, `ring.create()`.
33-
Examples follow this practice.
36+
new one. Examples follow this practice.
37+
38+
## Development
39+
See `CONTRIBUTING.md`.
40+
41+
## Security
42+
If you discover a security issue, **please do not open a public issue**.
43+
See `SECURITY.md` for the full policy/reporting instructions.

pyproject.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "chordnet"
3-
version = "1.1.0"
3+
version = "2.0.0"
44
license = "MIT"
55
license-files = ["LICENSE"]
66
description = "Implementation of the chord peer-to-peer networking protocol, introduced by Stoica et al."
@@ -119,13 +119,11 @@ convention = "google"
119119
python_version = "3.10"
120120
warn_return_any = true
121121
warn_unused_configs = true
122+
mypy_path = "src"
122123
files = ["src", "tests", "scripts"]
123124
exclude = [
124125
'(^|.*/)__pycache__/', # matches __pycache__ at any depth
125126
'(^|.*/).ruff_cache/',
126127
'(^|.*/).mypy_cache/',
128+
'(^|.*/)dist/',
127129
]
128-
129-
[[tool.mypy.overrides]]
130-
module = ["bpython"]
131-
ignore_missing_imports = true

scripts/auto/anchor.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
import sys
33

44
import IPython
5+
from loguru import logger
56

6-
from chordnet import Node as ChordNode
7+
from chordnet._node import _Node as ChordNode
8+
9+
logger.enable("chordnet")
710

811

912
def main() -> None:

scripts/auto/joiner.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
import sys
33

44
import IPython
5+
from loguru import logger
56

6-
from chordnet import Node as ChordNode
7+
from chordnet._node import _Node as ChordNode
8+
9+
logger.enable("chordnet")
710

811

912
def main() -> None:

scripts/manual/anchor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import IPython
55
from step import step #type: ignore
66

7-
from chordnet import Node as ChordNode
7+
from chordnet._node import _Node as ChordNode
88

99

1010
def main() -> None:

scripts/manual/joiner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import IPython
55
from step import step #type: ignore
66

7-
from chordnet import Node as ChordNode
7+
from chordnet._node import _Node as ChordNode
88

99

1010
def main() -> None:

scripts/manual/step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""step.py: helper for manual scripts."""
22

3-
from chordnet import Node as ChordNode
3+
from chordnet._node import _Node as ChordNode
44

55

66
def step(node: ChordNode) -> None:

src/chordnet/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""init.py: defines importable classes."""
2-
from .address import Address
3-
from .net import _Net
4-
from .node import Node
2+
from loguru import logger
53

6-
__all__=['Node', 'Address', '_Net']
4+
from .chordnet import ChordNet
5+
6+
logger.disable("chordnet")
7+
8+
__all__=['ChordNet']
File renamed without changes.

0 commit comments

Comments
 (0)