Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff with pre-commit #49

Merged
merged 12 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v2
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.4
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: install, run-demo, ruff, help

install:
poetry install
pre-commit install

run-demo:
python3 examples/demo.py

ruff:
ruff format
ruff check

help:
@echo "Available commands:"
@echo " install - Install dependencies and set up pre-commit hooks"
@echo " ruff - Format code and fix linting issues using ruff"
@echo " run-demo - Run /examples/demo.py file"
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<a name="readme-top"></a>

___
---

<br />
<div align="center">
Expand Down Expand Up @@ -51,7 +51,7 @@ ___
</ol>
</details>

___
---

<br/>

Expand All @@ -61,6 +61,7 @@ ___
<summary>

### **What is the Decentralized Knowledge Graph?**

</summary>

<br/>
Expand All @@ -70,31 +71,35 @@ ___
</div>

OriginTrail Decentralized Knowledge Graph (DKG), hosted on the OriginTrail Decentralized Network (ODN) as trusted knowledge infrastructure, is shared global Knowledge Graph of Knowledge Assets. Running on the basis of the permissionless multi-chain OriginTrail protocol, it combines blockchains and knowledge graph technology to enable trusted AI applications based on key W3C standards.

</details>

<details open>
<summary>

### **The OriginTrail DKG Architecture**

</summary>

<br/>

The OriginTrail tech stack is a three layer structure, consisting of the multi-chain consensus layer (OriginTrail layer 1, running on multiple blockchains), the Decentralized Knowledge Graph layer (OriginTrail Layer 2, hosted on the ODN) and Trusted Knowledge applications in the application layer.
The OriginTrail tech stack is a three layer structure, consisting of the multi-chain consensus layer (OriginTrail layer 1, running on multiple blockchains), the Decentralized Knowledge Graph layer (OriginTrail Layer 2, hosted on the ODN) and Trusted Knowledge applications in the application layer.

<div align="center">
<img src="images/dkg-architecture.png" alt="DKG Architecture" width="400">
</div>

Further, the architecture differentiates between **the public, replicated knowledge graph** shared by all network nodes according to the protocol, and **private Knowledge graphs** hosted separately by each of the OriginTrail nodes.

**Anyone can run an OriginTrail node and become part of the ODN, contributing to the network capacity and hosting the OriginTrail DKG. The OriginTrail node is the ultimate data service for data and knowledge intensive Web3 applications and is used as the key backbone for trusted AI applications (see https://chatdkg.ai)**
**Anyone can run an OriginTrail node and become part of the ODN, contributing to the network capacity and hosting the OriginTrail DKG. The OriginTrail node is the ultimate data service for data and knowledge intensive Web3 applications and is used as the key backbone for trusted AI applications (see https://chatdkg.ai)**

</details>

<details open>
<summary>

### **What is a Knowledge Asset?**

</summary>

<br/>
Expand All @@ -106,15 +111,16 @@ Further, the architecture differentiates between **the public, replicated knowle
**Knowledge Asset is the new, AI‑ready resource for the Internet**

Knowledge Assets are verifiable containers of structured knowledge that live on the OriginTrail DKG and provide:

- **Discoverability - UAL is the new URL**. Uniform Asset Locators (UALs, based on the W3C Decentralized Identifiers) are a new Web3 knowledge identifier (extensions of the Uniform Resource Locators - URLs) which identify a specific piece of knowledge and make it easy to find and connect with other Knowledge Assets.
- **Ownership - NFTs enable ownership**. Each Knowledge Asset contains an NFT token that enables ownership, knowledge asset administration and market mechanisms.
- **Verifiability - On-chain information origin and verifiable trail**. The blockchain tech increases trust, security, transparency, and the traceability of information.


By their nature, Knowledge Assets are semantic resources (following the W3C Semantic Web set of standards), and through their symbolic representations inherently AI ready. See more at https://chatdkg.ai
<br/>

**Discover Knowledge Assets with the DKG Explorer:**

<div align="center">
<table>
<tr>
Expand Down Expand Up @@ -146,48 +152,50 @@ By their nature, Knowledge Assets are semantic resources (following the W3C Sema
</table>
</div>


</details>

<p align="right">(<a href="#readme-top">back to top</a>)</p>
<br/>

## 🚀 Getting Started

___
---

### Prerequisites

* python `>=3.10`
* poetry `>=1.5.1`

- python `>=3.10`
- poetry `>=1.5.1`

In order to use in the local environment, make sure to [run the local DKG network](https://github.com/OriginTrail/ot-node?tab=readme-ov-file#local-network-setup).

___
---

<br/>

### Installation


Create virtual environment (you can choose any existing folder this command will create configurations and virtual env for python):

```bash
python3 -m venv /path/to/folder
```

Inside of previously generated folder you will find activate script in bin folder and run it:

```bash
source /path/to/folder/bin/activate
```

Install dependencies:
Install dependencies and configure pre-commit hooks:

```bash
poetry install
make install
```

Now you can run a demo example file (you need to have the local DKG network running):

```bash
python3 examples/demo.py
make run-demo
```

<br/>
Expand Down Expand Up @@ -228,7 +236,6 @@ Don't forget to give the project a star! Thanks again!

- [web3.py](https://github.com/ethereum/web3.py): Basis for this project


<br/>
<p align="right">(<a href="#readme-top">back to top</a>)</p>

Expand Down Expand Up @@ -263,4 +270,4 @@ Don't forget to give the project a star! Thanks again!
</a>
</div>

___
---
22 changes: 11 additions & 11 deletions dkg/types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from .general import (
AutoStrEnum,
AutoStrEnumCapitalize,
AutoStrEnumUpperCase,
) # NOQA: F401
AutoStrEnum, # NOQA: F401
AutoStrEnumCapitalize, # NOQA: F401
AutoStrEnumUpperCase, # NOQA: F401
)
from .blockchain import (
ABI,
ABIElement,
ABIError,
ABI, # NOQA: F401
ABIElement, # NOQA: F401
ABIError, # NOQA: F401
ABIEvent, # NOQA: F401
ABIFunction,
ABIParameter,
AgreementData,
Environment,
ABIFunction, # NOQA: F401
ABIParameter, # NOQA: F401
AgreementData, # NOQA: F401
Environment, # NOQA: F401
)
from .dkg_node import UAL # NOQA: F401
from .encoding import BytesLike, DataHexStr, HexStr # NOQA: F401
Expand Down
9 changes: 4 additions & 5 deletions examples/curated_paranets_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@
# under the License.

import json
import time

from hexbytes import HexBytes

from dkg import DKG
from dkg.providers import BlockchainProvider, NodeHTTPProvider
from dkg.dataclasses import ParanetNodesAccessPolicy, ParanetMinersAccessPolicy

node_provider = NodeHTTPProvider("http://localhost:8900")
blockchain_provider = BlockchainProvider(
Expand Down Expand Up @@ -61,6 +59,7 @@
node2_identity_id = dkg.node.get_identity_id(dkg2.blockchain_provider.account.address)
node3_identity_id = dkg.node.get_identity_id(dkg3.blockchain_provider.account.address)


def divider():
print("==================================================")
print("==================================================")
Expand All @@ -73,7 +72,7 @@ def convert_hexbytes(data):
return {k: convert_hexbytes(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_hexbytes(i) for i in data]
elif isinstance(data, tuple) and hasattr(data, '_asdict'):
elif isinstance(data, tuple) and hasattr(data, "_asdict"):
return convert_hexbytes(data._asdict())
elif isinstance(data, bytes):
return data.decode("utf-8")
Expand Down Expand Up @@ -211,7 +210,7 @@ def convert_hexbytes(data):

# divider()

paranet_ual = 'did:dkg:hardhat2:31337/0x8aafc28174bb6c3bdc7be92f18c2f134e876c05e/1'
paranet_ual = "did:dkg:hardhat2:31337/0x8aafc28174bb6c3bdc7be92f18c2f134e876c05e/1"

local_store_first_asset_result = dkg3.asset.local_store(
paranet_data,
Expand Down Expand Up @@ -241,4 +240,4 @@ def convert_hexbytes(data):
)
print(local_store_second_asset_result)

divider()
divider()
3 changes: 2 additions & 1 deletion examples/paranets_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

dkg = DKG(node_provider, blockchain_provider)


def divider():
print("==================================================")
print("==================================================")
Expand Down Expand Up @@ -77,7 +78,7 @@ def convert_hexbytes(data):
"TestParanet",
"TestParanetDescription",
ParanetNodesAccessPolicy.OPEN,
ParanetMinersAccessPolicy.OPEN
ParanetMinersAccessPolicy.OPEN,
)

print("======================== PARANET CREATED")
Expand Down
Loading
Loading