Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ htmlcov/
.coverage
.coverage.*
.cache
.idea
nosetests.xml
coverage.xml
*.cover
Expand Down
2 changes: 1 addition & 1 deletion .idea/anchorpy.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 45 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[project]
name = "anchorpy"
version = "0.21.0"
description = "The Python Anchor client."
authors = [{ name = "kevinheavey", email = "kevinheavey123@gmail.com" }]
requires-python = "~=3.9"
readme = "README.md"
dependencies = [
"construct-typing>=0.5.1,<0.6",
"solana>=0.36.1,<1.0",
Expand All @@ -13,10 +7,25 @@ dependencies = [
"toolz>=0.11.2,<0.12",
"pyheck>=0.1.4,<0.2",
"based58>=0.1.1,<0.2",
"anchorpy-core>=0.2.0,<0.3",
"toml>=0.10.2,<0.11",
"typer>=0.16.0",
"ipython>=9.4.0",
"pytest-asyncio>=1.1.0",
"pytest-xprocess>=1.0.2",
"autoflake>=2.3.1",
"black>=25.1.0",
"genpy>=2022.1",
"anchorpy-idl @ file:///Users/ttt/code/pysrc/anchorpy-idl2",
]
# "anchorpy-idl @ file:////Users/ttt/code/pysrc/anchorpy-idl2",
name = "anchorpy"
version = "0.21.0"
description = "The Python Anchor client."
authors = [{ name = "kevinheavey", email = "kevinheavey123@gmail.com" }]
requires-python = "~=3.9"
readme = "README.md"

#"anchorpy-core>=0.2.0,<0.3",
[project.optional-dependencies]
cli = [
"typer==0.4.1",
Expand All @@ -26,7 +35,6 @@ cli = [
"autoflake~=1.4",
]
pytest = [
"pytest>=7.2.0,<8",
"py>=1.11.0,<2",
"pytest-xprocess>=0.18.1,<0.19",
"pytest-asyncio>=0.21.0,<0.22",
Expand Down Expand Up @@ -122,5 +130,33 @@ convention = "google"
"tests/client_gen/token/**/*.py" = ["C417", "I001", "F401"]
"src/anchorpy/cli.py" = ["B008"]

#[tool.pyright]
#reportMissingModuleSource = false
[tool.ty.rules]
index-out-of-bounds = "ignore"

[tool.pyright]
reportMissingModuleSource = false
venvPath = "."
venv = ".venv"
#pythonVersion = "3.13"
typeCheckingMode = "basic"
include = ["src"]
exclude = [".venv"]

[tool.rye]
managed = true
dev-dependencies = [
"pytest>=8.4.1",
"pytest-xprocess>=1.0.2",
]

[tool.hatch.metadata]
allow-direct-references = true

[tool.pytest.ini_options]
asyncio_mode = "auto"
asyncio_default_test_loop_scope = "session"
testpaths = ["tests"]



2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ markers =
unit: mark a test as a unit test.
addopts = -x
asyncio_mode=strict
testpaths =
tests
2 changes: 1 addition & 1 deletion src/anchorpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""The Python Anchor client."""
from contextlib import suppress as __suppress

from anchorpy_core.idl import Idl
from anchorpy_idl import Idl

from anchorpy import error, utils
from anchorpy.coder.coder import AccountsCoder, Coder, EventCoder, InstructionCoder
Expand Down
3 changes: 2 additions & 1 deletion src/anchorpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Optional, cast

import typer
from anchorpy_core.idl import Idl
from anchorpy_idl import Idl
from IPython import embed

from anchorpy import create_workspace
Expand Down Expand Up @@ -106,6 +106,7 @@ def client_gen(
),
):
"""Generate Python client code from the specified anchor IDL."""

idl_obj = Idl.from_json(idl.read_text())
if program_id is None:
idl_metadata = idl_obj.metadata
Expand Down
18 changes: 11 additions & 7 deletions src/anchorpy/clientgen/accounts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from typing import cast

from anchorpy_core.idl import (
from anchorpy_idl import (
Idl,
IdlField,
IdlTypeDefinition,
IdlTypeDefinitionTyStruct,
IdlTypeDef,
IdlTypeDefStruct,
#IdlTypeDefTyStruct,
)
from autoflake import fix_code
from black import FileMode, format_str
Expand Down Expand Up @@ -47,6 +48,7 @@
TypedParam,
)
from anchorpy.coder.accounts import _account_discriminator
from anchorpy.coder.idl import find_type_by_name


def gen_accounts(idl: Idl, root: Path) -> None:
Expand Down Expand Up @@ -92,7 +94,7 @@ def gen_accounts_code(idl: Idl, accounts_dir: Path) -> dict[Path, str]:
return res


def gen_account_code(acc: IdlTypeDefinition, idl: Idl) -> str:
def gen_account_code(acc: IdlTypeDef, idl: Idl) -> str:
base_imports = [
Import("typing"),
FromImport("dataclasses", ["dataclass"]),
Expand All @@ -114,8 +116,10 @@ def gen_account_code(acc: IdlTypeDefinition, idl: Idl) -> str:
)
fields_interface_params: list[TypedParam] = []
json_interface_params: list[TypedParam] = []
ty = cast(IdlTypeDefinitionTyStruct, acc.ty)
fields = ty.fields
accType = find_type_by_name(acc.name,idl.types)

ty = cast(IdlTypeDefStruct, accType.ty)
fields = ty.fields.fields
name = _sanitize(acc.name)
json_interface_name = _json_interface_name(name)
layout_items: list[str] = []
Expand Down Expand Up @@ -155,7 +159,7 @@ def gen_account_code(acc: IdlTypeDefinition, idl: Idl) -> str:
field_name,
_field_from_decoded(
idl=idl,
ty=IdlField(name=snake(field.name), docs=None, ty=field.ty),
ty=IdlField(name=snake(field.name), docs=[], ty=field.ty),
types_relative_imports=False,
val_prefix="dec.",
),
Expand Down
Loading