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

chore: restructure linting & formatting #252

Merged
merged 11 commits into from
Mar 6, 2024
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
16 changes: 7 additions & 9 deletions .github/workflows/ci-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
include:
- os: macos-latest
python-version: "3.10.10"
Expand Down Expand Up @@ -68,8 +68,8 @@ jobs:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- if: ${{
needs.check-if-files-changed.outputs.uagents == 'true' &&
steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
needs.check-if-files-changed.outputs.uagents == 'true' &&
steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
}}
name: Install dependencies
run: poetry install --no-interaction --no-root
Expand All @@ -92,7 +92,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10" ]
python-version: ["3.10"]

steps:
- if: ${{ needs.check-if-files-changed.outputs.uagents == 'true' }}
Expand All @@ -118,15 +118,13 @@ jobs:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- if: ${{
needs.check-if-files-changed.outputs.uagents == 'true' &&
steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
needs.check-if-files-changed.outputs.uagents == 'true' &&
steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
}}
name: Install dependencies
run: poetry install -E all --no-interaction --no-root

- if: ${{ needs.check-if-files-changed.outputs.uagents == 'true' }}
run: poetry install -E all --no-interaction
- if: ${{ needs.check-if-files-changed.outputs.uagents == 'true' }}
run: poetry run black --check .
- if: ${{ needs.check-if-files-changed.outputs.uagents == 'true' }}
run: poetry run pylint $(git ls-files '*.py')
run: poetry run ruff check .
30 changes: 14 additions & 16 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
## Development setup

The easiest way to get set up for development is to install Python (`3.8`, `3.9`, `3.10`, or `3.11`) and [poetry](https://pypi.org/project/poetry/), and then run the following from the top-level project directory:
The easiest way to get set up for development is to install Python (`3.9` to `3.12`) and [poetry](https://pypi.org/project/poetry/), and then run the following from the top-level project directory:

```bash
cd python
poetry install
poetry shell
pre-commit install
```

## Development commands

Following are some helpful commands for development:
When developing for `uAgents` make sure to have the poetry shell active. This ensures that linting and formatting will automatically be checked during `git commit`.

- To run the code formatter:
We are using [Ruff](https://github.com/astral-sh/ruff) with added rules for formatting and linting.
Please consider adding `ruff` to your IDE to speed up the development process and ensure you only commit clean code.

```bash
black .
```
Alternately you can invoke ruff by typing the following from within the `./python` folder

- To run lint checks:

```bash
pylint $(git ls-files '*.py')
```
```bash
ruff check --fix && ruff format
```

- To run tests:
### Testing

```bash
pytest
```
To run tests use the following command:

Before committing and opening a PR, use the above commands to run the checks locally. This saves CI hours and ensures you only commit clean code.
```bash
pytest
```
8 changes: 8 additions & 0 deletions python/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
files: ^python/
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
19 changes: 0 additions & 19 deletions python/.pylintrc

This file was deleted.

2 changes: 1 addition & 1 deletion python/examples/03-multiple-agents/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from uagents import Agent, Context, Bureau
from uagents import Agent, Bureau, Context

alice = Agent(name="alice")
bob = Agent(name="bob")
Expand Down
2 changes: 1 addition & 1 deletion python/examples/05-send-msg/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from uagents import Agent, Context, Bureau, Model
from uagents import Agent, Bureau, Context, Model


class Message(Model):
Expand Down
1 change: 1 addition & 0 deletions python/examples/07-msg-verification/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import hashlib

from uagents import Agent, Bureau, Context, Model
from uagents.crypto import Identity

Expand Down
1 change: 0 additions & 1 deletion python/examples/08-local-network-interaction/agent1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from uagents import Agent, Context, Model


# NOTE: Run agent1.py before running agent2.py


Expand Down
2 changes: 0 additions & 2 deletions python/examples/09-booking-protocol-demo/query.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import asyncio

from protocols.query import GetTotalQueries, TotalQueries

from uagents.contrib.protocols.protocol_query import ProtocolQuery, ProtocolResponse
from uagents.query import query


RESTAURANT_ADDRESS = "agent1qfpqn9jhvp9cg33f27q6jvmuv52dgyg9rfuu37rmxrletlqe7lewwjed5gy"


Expand Down
4 changes: 1 addition & 3 deletions python/examples/09-booking-protocol-demo/restaurant.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from protocols.book import book_proto
from protocols.query import query_proto, TableStatus

from protocols.query import TableStatus, query_proto
from uagents import Agent
from uagents.contrib.protocols.protocol_query import proto_query


restaurant = Agent(
name="restaurant",
port=8001,
Expand Down
2 changes: 0 additions & 2 deletions python/examples/09-booking-protocol-demo/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
QueryTableRequest,
QueryTableResponse,
)

from uagents import Agent, Context


RESTAURANT_ADDRESS = (
"test-agent://agent1qfpqn9jhvp9cg33f27q6jvmuv52dgyg9rfuu37rmxrletlqe7lewwjed5gy"
)
Expand Down
7 changes: 2 additions & 5 deletions python/examples/10-cleaning-demo/cleaner.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from datetime import datetime
from pytz import utc

from tortoise import Tortoise

from protocols.cleaning import cleaning_proto
from protocols.cleaning.models import Availability, Provider, Service, ServiceType

from pytz import utc
from tortoise import Tortoise
from uagents import Agent, Context


cleaner = Agent(
name="cleaner",
port=8001,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from datetime import datetime, timedelta
from typing import List

from geopy.geocoders import Nominatim
from geopy.distance import geodesic

from geopy.geocoders import Nominatim
from uagents import Context, Model, Protocol
from .models import Provider, Availability, User

from .models import Availability, Provider, User

PROTOCOL_NAME = "cleaning"
PROTOCOL_VERSION = "0.1.0"
Expand Down
5 changes: 2 additions & 3 deletions python/examples/10-cleaning-demo/user.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
from datetime import datetime, timedelta
from pytz import utc

from protocols.cleaning import (
ServiceBooking,
BookingResponse,
ServiceBooking,
ServiceRequest,
ServiceResponse,
)
from protocols.cleaning.models import ServiceType
from pytz import utc
from uagents import Agent, Context


CLEANER_ADDRESS = (
"test-agent://agent1qdfdx6952trs028fxyug7elgcktam9f896ays6u9art4uaf75hwy2j9m87w"
)
Expand Down
2 changes: 1 addition & 1 deletion python/examples/12-remote-agents/agent1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
- during the first run, the script will download the ngrok application
(no installation or registration required)
"""
from pyngrok import conf, ngrok

from pyngrok import conf, ngrok
from uagents import Agent, Context, Model


Expand Down
1 change: 1 addition & 0 deletions python/examples/12-remote-agents/agent2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Counterpart for the remote connection example in agent1.py.
"""

from uagents import Agent, Context, Model


Expand Down
4 changes: 1 addition & 3 deletions python/examples/13-agent-name-service/agent1.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from cosmpy.aerial.wallet import LocalWallet

from uagents.network import get_name_service_contract, get_faucet
from uagents import Agent, Context, Model

from uagents.network import get_faucet, get_name_service_contract

# NOTE: Run agent1.py before running agent2.py

Expand Down
1 change: 0 additions & 1 deletion python/examples/15-wallet-messaging/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from uagents import Agent, Bureau, Context
from uagents.wallet_messaging import WalletMessage


ALICE_SEED = "alice dorado recovery phrase"
BOB_SEED = "bob dorado recovery phrase"

Expand Down
1 change: 1 addition & 0 deletions python/examples/17-stateful-communication/agent1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Chit chat dialogue example"""

import json

from dialogues.chitchat import ChitChatDialogue
Expand Down
1 change: 1 addition & 0 deletions python/examples/17-stateful-communication/agent2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Chit chat dialogue example"""

from asyncio import sleep

from dialogues.chitchat import ChitChatDialogue
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Specific dialogue class for the chit-chat dialogue."""

from typing import Type

from uagents import Model
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Specific dialogue class for the chit-chat dialogue."""

from typing import Type

from uagents import Model
Expand Down
Loading
Loading