diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 281da2da..efe86d6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,6 +89,16 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.12 + # pre-commit or ruff as example + - uses: pre-commit/action@v3.0.1 + - 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 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 00000000..18e74986 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -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/action@v3.0.1 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..e3ee3458 --- /dev/null +++ b/.pre-commit-config.yaml @@ -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 \ No newline at end of file diff --git a/python/main.py b/python/main.py index 75281453..6be7c15d 100644 --- a/python/main.py +++ b/python/main.py @@ -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()