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

Antonyjin upgrade pydantic version #293

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ dynamic = [ "version" ]
dependencies = [
"aiodns==3.2",
"aiohttp==3.10.6",
"aleph-message>=0.5",
"aleph-sdk-python>=1.2,<2",
"base58==2.1.1", # Needed now as default with _load_account changement
"py-sr25519-bindings==0.2", # Needed for DOT signatures
"aleph-message @ git+https://github.com/aleph-im/aleph-message@108-upgrade-pydantic-version#egg=aleph-message", # Change the version after the release
"aleph-sdk-python @ git+https://github.com/aleph-im/aleph-sdk-python@177-upgrade-pydantic-version#egg=aleph-sdk-python", # Change the version after the release
"base58==2.1.1", # Needed now as default with _load_account changement
"py-sr25519-bindings==0.2", # Needed for DOT signatures
"pygments==2.18",
"pynacl==1.5", # Needed now as default with _load_account changement
"pynacl==1.5", # Needed now as default with _load_account changement
"python-magic==0.4.27",
"rich==13.9.3",
"setuptools>=65.5",
"substrate-interface==1.7.11", # Needed for DOT signatures
"substrate-interface==1.7.11", # Needed for DOT signatures
"textual==0.73",
"typer==0.12.5",
]
Expand Down Expand Up @@ -83,7 +83,7 @@ dependencies = [
"pytest-cov==5.0.0",
"mypy==1.10.0",
"base58==2.1.1",
"fastapi==0.98.0",
"fastapi==0.100.0",
"httpx==0.27.0",
"types-requests==2.32.0.20240602",
"types-setuptools==70.0.0.20240524",
Expand All @@ -99,7 +99,7 @@ dependencies = [
"pytest-cov==5.0.0",
"mypy==1.10.0",
"base58==2.1.1",
"fastapi==0.98.0",
"fastapi==0.100.0",
"httpx==0.27.0",
]
[tool.hatch.envs.testing.scripts]
Expand All @@ -122,7 +122,7 @@ dependencies = [
"mypy==1.10.0",
"ruff==0.4.9",
"isort==5.13.2",
"yamlfix==1.16.1",
"yamlfix==1.17.0",
"pyproject-fmt==2.2.1",

"types-requests==2.32.0.20240602",
Expand Down
2 changes: 1 addition & 1 deletion src/aleph_client/commands/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def sign_bytes(

coroutine = account.sign_raw(message.encode())
signature = asyncio.run(coroutine)
typer.echo("\nSignature: " + signature.hex())
typer.echo("\nSignature: " + f"0x{signature.hex()}")


@app.command()
Expand Down
2 changes: 1 addition & 1 deletion src/aleph_client/commands/aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
inline=inline,
address=address,
)
log_message = json.dumps(message.dict(), indent=4, default=extended_json_encoder)
log_message = json.dumps(message.model_dump(), indent=4, default=extended_json_encoder)

Check warning on line 84 in src/aleph_client/commands/aggregate.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/aggregate.py#L84

Added line #L84 was not covered by tests
typer.echo(log_message)


Expand Down
8 changes: 4 additions & 4 deletions src/aleph_client/commands/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
ref=ref,
)
logger.debug("Upload finished")
typer.echo(f"{result.json(indent=4)}")
typer.echo(f"{result.model_dump_json(indent=4)}")

Check warning on line 55 in src/aleph_client/commands/files.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/files.py#L55

Added line #L55 was not covered by tests


@app.command()
Expand Down Expand Up @@ -91,7 +91,7 @@
ref=ref,
)
logger.debug("Upload finished")
typer.echo(f"{result.json(indent=4)}")
typer.echo(f"{result.model_dump_json(indent=4)}")


@app.command()
Expand Down Expand Up @@ -142,7 +142,7 @@

async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
value = await client.forget(hashes=[ItemHash(item_hash)], reason=reason, channel=channel)
typer.echo(f"{value[0].json(indent=4)}")
typer.echo(f"{value[0].model_dump_json(indent=4)}")

Check warning on line 145 in src/aleph_client/commands/files.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/files.py#L145

Added line #L145 was not covered by tests


class GetAccountFilesQueryParams(BaseModel):
Expand Down Expand Up @@ -229,7 +229,7 @@

uri = f"{settings.API_HOST}/api/v0/addresses/{address}/files"
async with aiohttp.ClientSession() as session:
response = await session.get(uri, params=query_params.dict())
response = await session.get(uri, params=query_params.model_dump())

Check warning on line 232 in src/aleph_client/commands/files.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/files.py#L232

Added line #L232 was not covered by tests
if response.status == 200:
files_data = await response.json()
formatted_files_data = json_lib.dumps(files_data, indent=4)
Expand Down
6 changes: 3 additions & 3 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@
)
raise typer.Exit(code=1)
if print_messages:
echo(f"{message.json(indent=4)}")
echo(f"{message.model_dump_json(indent=4)}")

Check warning on line 410 in src/aleph_client/commands/instance/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/instance/__init__.py#L410

Added line #L410 was not covered by tests

item_hash: ItemHash = message.item_hash
item_hash_text = Text(item_hash, style="bright_cyan")
Expand Down Expand Up @@ -584,7 +584,7 @@

message, status = await client.forget(hashes=[ItemHash(item_hash)], reason=reason)
if print_message:
echo(f"{message.json(indent=4)}")
echo(f"{message.model_dump_json(indent=4)}")
echo(f"Instance {item_hash} has been deleted.")


Expand Down Expand Up @@ -761,7 +761,7 @@
echo(f"Address: {address}\n\nNo instance found\n")
raise typer.Exit(code=1)
if json:
echo(messages.json(indent=4))
echo(messages.model_dump_json(indent=4))

Check warning on line 764 in src/aleph_client/commands/instance/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/instance/__init__.py#L764

Added line #L764 was not covered by tests
else:
# Since we filtered on message type, we can safely cast as InstanceMessage.
messages = cast(List[InstanceMessage], messages)
Expand Down
4 changes: 2 additions & 2 deletions src/aleph_client/commands/instance/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from aleph_message.models import InstanceMessage
from aleph_message.models.execution.base import PaymentType
from aleph_message.models.item_hash import ItemHash
from pydantic import ValidationError
from pydantic import ValidationError, field_validator

from aleph_client.commands import help_strings
from aleph_client.commands.node import NodeInfo, _fetch_nodes
Expand Down Expand Up @@ -49,7 +49,7 @@ async def fetch_crn_info(node_url: str) -> dict | None:
async with session.get(url) as resp:
resp.raise_for_status()
system: dict = await resp.json()
info["machine_usage"] = MachineUsage.parse_obj(system)
info["machine_usage"] = MachineUsage.model_validate(system)
return info
except aiohttp.InvalidURL as e:
logger.debug(f"Invalid CRN URL: {url}: {e}")
Expand Down
21 changes: 12 additions & 9 deletions src/aleph_client/commands/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import tempfile
import time
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Optional

Expand All @@ -18,7 +19,7 @@
from aleph.sdk.query.responses import MessagesResponse
from aleph.sdk.types import AccountFromPrivateKey, StorageEnum
from aleph.sdk.utils import extended_json_encoder
from aleph_message.models import AlephMessage, ProgramMessage
from aleph_message.models import AlephMessage, ProgramMessage, StoreMessage
from aleph_message.models.base import MessageType
from aleph_message.models.item_hash import ItemHash
from aleph_message.status import MessageStatus
Expand Down Expand Up @@ -46,9 +47,9 @@
typer.echo(f"Message Status: {colorized_status(status)}")
if status == MessageStatus.REJECTED:
reason = await client.get_message_error(item_hash=ItemHash(item_hash))
typer.echo(colorful_json(json.dumps(reason, indent=4)))
typer.echo(colorful_json(json.dumps(reason, indent=4, default=extended_json_encoder)))

Check warning on line 50 in src/aleph_client/commands/message.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/message.py#L50

Added line #L50 was not covered by tests
else:
typer.echo(colorful_message_json(message))
typer.echo(colorful_json(json.dumps(message, indent=4, default=extended_json_encoder)))


@app.command()
Expand Down Expand Up @@ -102,7 +103,9 @@
),
ignore_invalid_messages=ignore_invalid_messages,
)
typer.echo(colorful_json(response.json(sort_keys=True, indent=4)))
typer.echo(
colorful_json(json.dumps(response.model_dump(), sort_keys=True, indent=4, default=extended_json_encoder))
)


@app.command()
Expand Down Expand Up @@ -156,7 +159,7 @@
storage_engine=storage_engine,
)

typer.echo(json.dumps(result.dict(), indent=4, default=extended_json_encoder))
typer.echo(json.dumps(result.model_dump(), indent=4, default=extended_json_encoder))


@app.command()
Expand All @@ -178,7 +181,7 @@
editor: str = os.getenv("EDITOR", default="nano")
with tempfile.NamedTemporaryFile(suffix="json") as fd:
# Fill in message template
fd.write(existing_message.content.json(indent=4).encode())
fd.write(existing_message.content.model_dump_json(indent=4).encode())

Check warning on line 184 in src/aleph_client/commands/message.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/message.py#L184

Added line #L184 was not covered by tests
fd.seek(0)

# Launch editor
Expand All @@ -203,11 +206,11 @@
typer.echo(new_content)
async with AuthenticatedAlephHttpClient(account=account, api_server=settings.API_HOST) as client:
message, status, response = await client.submit(
content=new_content.dict(),
content=new_content.model_dump(),
message_type=existing_message.type,
channel=existing_message.channel,
)
typer.echo(f"{message.json(indent=4)}")
typer.echo(f"{message.model_dump_json(indent=4)}")

Check warning on line 213 in src/aleph_client/commands/message.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/message.py#L213

Added line #L213 was not covered by tests


@app.command()
Expand Down Expand Up @@ -245,7 +248,7 @@
async for message in client.watch_messages(
message_filter=MessageFilter(refs=[ref], addresses=[original.content.address])
):
typer.echo(f"{message.json(indent=indent)}")
typer.echo(f"{message.model_dump_json(indent=indent)}")

Check warning on line 251 in src/aleph_client/commands/message.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/message.py#L251

Added line #L251 was not covered by tests


@app.command()
Expand Down
8 changes: 4 additions & 4 deletions src/aleph_client/commands/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
)
logger.debug("Upload finished")
if print_messages or print_code_message:
typer.echo(f"{user_code.json(indent=4)}")
typer.echo(f"{user_code.model_dump_json(indent=4)}")

Check warning on line 127 in src/aleph_client/commands/program.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/program.py#L127

Added line #L127 was not covered by tests
program_ref = user_code.item_hash

# Register the program
Expand All @@ -144,7 +144,7 @@
)
logger.debug("Upload finished")
if print_messages or print_program_message:
typer.echo(f"{message.json(indent=4)}")
typer.echo(f"{message.model_dump_json(indent=4)}")

Check warning on line 147 in src/aleph_client/commands/program.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/program.py#L147

Added line #L147 was not covered by tests

item_hash: ItemHash = message.item_hash
hash_base32 = b32encode(b16decode(item_hash.upper())).strip(b"=").lower().decode()
Expand Down Expand Up @@ -212,7 +212,7 @@
)
logger.debug("Upload finished")
if print_message:
typer.echo(f"{message.json(indent=4)}")
typer.echo(f"{message.model_dump_json(indent=4)}")

Check warning on line 215 in src/aleph_client/commands/program.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/program.py#L215

Added line #L215 was not covered by tests


@app.command()
Expand Down Expand Up @@ -240,7 +240,7 @@
message_type=message.type,
channel=message.channel,
)
typer.echo(f"{message.json(indent=4)}")
typer.echo(f"{message.model_dump_json(indent=4)}")

Check warning on line 243 in src/aleph_client/commands/program.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/program.py#L243

Added line #L243 was not covered by tests


@app.command()
Expand Down
3 changes: 2 additions & 1 deletion src/aleph_client/commands/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import asyncio
import json
import logging
import os
import sys
Expand Down Expand Up @@ -50,7 +51,7 @@

def colorful_message_json(message: GenericMessage):
"""Render a message in JSON with colors."""
return colorful_json(message.json(sort_keys=True, indent=4))
return colorful_json(json.dumps(message.model_dump(), sort_keys=True, indent=4))

Check warning on line 54 in src/aleph_client/commands/utils.py

View check run for this annotation

Codecov / codecov/patch

src/aleph_client/commands/utils.py#L54

Added line #L54 was not covered by tests


def input_multiline() -> str:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_post.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{"hello": "world"}
{
"type": "POST",
"hello": "world"
}
Loading