Skip to content

Commit 604408e

Browse files
committed
ffi: add python package
1 parent 42a5aa6 commit 604408e

File tree

12 files changed

+151
-0
lines changed

12 files changed

+151
-0
lines changed

negentropy-ffi/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ffi/

negentropy-ffi/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
python:
2+
rm -rf bindings-python/dist
3+
pip install -r bindings-python/requirements.txt --break-system-packages
4+
cargo build --release
5+
cargo run --features=uniffi/cli --bin uniffi-bindgen generate src/negentropy.udl --language python --no-format -o bindings-python/src/negentropy/
6+
cp ../target/release/libnegentropy_ffi.so bindings-python/src/negentropy/ | true
7+
cp ../target/release/libnegentropy_ffi.dylib bindings-python/src/negentropy/ | true
8+
cd bindings-python && python setup.py --verbose bdist_wheel
9+
pip install ./bindings-python/dist/negentropy*.whl --force-reinstall --break-system-packages

negentropy-ffi/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Negentropy FFI
2+
3+
## Build
4+
5+
### Python
6+
7+
For most users, we recommend using our official Python package: TODO.
8+
9+
If you want to compile from source or need more options, read on.
10+
11+
### Wheel
12+
13+
#### Unix
14+
15+
```
16+
make python
17+
```
18+
19+
## License
20+
21+
This project is distributed under the MIT software license - see the [LICENSE](../../LICENSE) file for details
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.tox/
2+
dist/
3+
negentropy.egg-info/
4+
__pycache__/
5+
libnegentropy_ffi.dylib
6+
.idea/
7+
.DS_Store
8+
9+
*.swp
10+
11+
src/negentropy/negentropy.py
12+
src/negentropy/*.so
13+
*.whl
14+
build/
15+
16+
testing-setup-py-simple-example.py
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Yuki Kishimoto
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include ./src/negentropy/libnegentropy_ffi.dylib
2+
include ./src/negentropy/libnegentropy_ffi.so
3+
include ./src/negentropy/negentropy_ffi.dll
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Negentropy - Python Package
2+
3+
The Python language bindings for [negentropy](https://github.com/yukibtc/rust-negentropy).
4+
5+
## Getting started
6+
7+
```shell
8+
pip install negentropy
9+
```
10+
11+
## License
12+
13+
This project is distributed under the MIT software license - see the [LICENSE](https://github.com/yukibtc/rust-negentropy/tree/master/LICENSE) file for details
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from negentropy import Negentropy, Bytes
2+
3+
# Client init
4+
client = Negentropy(16, None)
5+
client.add_item(0, Bytes.from_hex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
6+
client.add_item(1, Bytes.from_hex("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
7+
client.seal()
8+
init_output = client.initiate()
9+
print(f"Initiator Output: {init_output.as_hex()}")
10+
11+
# Relay
12+
relay = Negentropy(16, None)
13+
relay.add_item(0, Bytes.from_hex("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
14+
relay.add_item(2, Bytes.from_hex("cccccccccccccccccccccccccccccccc"))
15+
relay.add_item(3, Bytes.from_hex("11111111111111111111111111111111"))
16+
relay.add_item(5, Bytes.from_hex("22222222222222222222222222222222"))
17+
relay.add_item(10, Bytes.from_hex("33333333333333333333333333333333"))
18+
relay.seal()
19+
reconcile_output = relay.reconcile(init_output)
20+
print(f"Reconcile Output: {reconcile_output.as_hex()}")
21+
22+
# Client reconcile
23+
reconcile_output_with_ids = client.reconcile_with_ids(reconcile_output)
24+
print(f"Reconcile Output with IDs: {reconcile_output_with_ids.output}")
25+
26+
print("Have IDs:")
27+
for id in reconcile_output_with_ids.have_ids:
28+
print(f"- {id.as_hex()}")
29+
30+
print("Need IDs:")
31+
for id in reconcile_output_with_ids.need_ids:
32+
print(f"- {id.as_hex()}")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build-system]
2+
requires = ["setuptools", "wheel"]
3+
4+
[tool.pytest.ini_options]
5+
pythonpath = ["."]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
semantic-version==2.9.0
2+
typing_extensions==4.0.1
3+
setuptools==67.4.0
4+
wheel==0.38.4

0 commit comments

Comments
 (0)