Skip to content

Commit

Permalink
Fix Python Example main.py
Browse files Browse the repository at this point in the history
FIXME: Get Node ID
Add Pre-Commit and Ruff in Github Actions
  • Loading branch information
dasTholo committed Oct 14, 2024
1 parent 5eeec2f commit 112e43f
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 26 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: 3.12
# pre-commit or ruff as example
- uses: pre-commit/[email protected]
- uses: astral-sh/ruff-action@v1
with:
args: --check --fix ./python/
src: "./python"
- uses: astral-sh/ruff-action@v1
with:
args: "format --check"
src: "./python"
- name: Install virtualenv
run: pip install virtualenv
- name: Python tests
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_language_version:
python: python3.12
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- id: check-merge-conflict
- id: debug-statements
- id: check-toml
# All non-bat files should end with LF
- id: mixed-line-ending
name: Ensure LF endings on most files
args: [ "--fix=lf" ]
exclude: \.bat$
# Bat files should end with CRLF
- id: mixed-line-ending
name: Ensure CFLF endings on Windows files
args: [ "--fix=crlf" ]
files: \.bat$
- id: detect-private-key
- id: no-commit-to-branch
args: [ --branch, main, --branch, master ]
stages: [ commit-msg ]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [--fix --line-length=120]
- id: ruff-format
types_or: [ python, pyi ]
ci:
autofix_commit_msg: 🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
autoupdate_commit_msg: ⬆ [pre-commit.ci] pre-commit autoupdate
54 changes: 28 additions & 26 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,34 @@ async def main():

args = parser.parse_args()

if not args.ticket:
print("In example mode")
print("(To run the sync demo, please provide a ticket to join a document)")
print()

# create iroh node
node = await iroh.Iroh.memory()
node_id = await node.node().node_id()
print("Started Iroh node: {}".format(node_id))

# create doc
doc = await node.docs().create()
doc_id = doc.id()
print("Created doc: {}".format(doc_id))

doc = await node.docs().create()
doc_id = doc.id()
print("Created doc: {}".format(doc_id))

# list docs
docs = await node.docs().list()
print("List all {} docs:".format(len(docs)))
for doc in docs:
print("\t{}".format(doc))

exit()
# if not args.ticket:
# print("In example mode")
# print("(To run the sync demo, please provide a ticket to join a document)")
# print()
#
# # create iroh node
# options = iroh.NodeOptions()
# options.enable_docs = True
# node = await iroh.Iroh.memory_with_options(options)
# # FIXME: Get Node ID
# print(f"Started Iroh node")
#
# # create doc
# doc = await node.docs().create()
# doc_id = doc.id()
# print("Created doc: {}".format(doc_id))
#
# doc = await node.docs().create()
# doc_id = doc.id()
# print("Created doc: {}".format(doc_id))
#
# # list docs
# docs = await node.docs().list()
# print("List all {} docs:".format(len(docs)))
# for doc in docs:
# print("\t{}".format(doc))
#
# exit()

# create iroh node
node = await iroh.Iroh.memory()
Expand Down

0 comments on commit 112e43f

Please sign in to comment.