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

feat: algokit-utils-py v3 implementation #119

Merged
merged 32 commits into from
Jan 29, 2025
Merged

Conversation

aorumbayev
Copy link
Contributor

@aorumbayev aorumbayev commented Oct 22, 2024

Proposed changes

This PR is to be used as a temporary dev branch for all feature parity prs as we gradually progress with the refactoring efforts.

Implementation plan

  • 1. Preparing codebase for breaking changes

  • Moving all v2 code into legacy_v2 folder inside src

  • Moving all v2 tests into legacy_v2_tests

  • Moving all beta abstractions related tests into tests - which will be expanding as refactoring progresses (some tests might be pulled back from legacy_v2_tests folder).

  • Keeping all individual .py files at the root of the algokit-utils to forward exports to ensure backwards compatibility

  • 2. Breaking down beta module into dedicated modules that will represent the refactored v3 of utils-py

The proposed new structure is as follows:

algokit_utils/
├── __init__.py # contains old v2 exports from _legacy_v2 + new abstractions (eventually old exports will be phased out)
├── _legacy_v2/ # contents of most of current v2 .py files
├── clients/
│   ├── __init__.py
|   ├── models.py # data models specific to clients namespace 
│   ├── client_manager.py
│   ├── dispenser_api_client.py # unchanged from v2 as there are no major breaking changes
│   └── algorand_client.py
├── accounts/
│   ├── __init__.py
|   ├── models.py # data models specific to accounts namespace 
│   └── account_manager.py
├── assets/
│   ├── __init__.py
|   ├── models.py # data models specific to assets namespace 
│   └── assets_manager.py
├── applications/
│   ├── __init__.py
|   ├── models.py # data models specific to applications namespace 
│   ├── app_manager.py
│   ├── app_deployer.py
│   ├── app_client.py
│   └── app_factory.py
├── transactions/
│   ├── __init__.py
|   ├── models.py # data models specific to transactions namespace 
│   ├── transaction_sender.py
│   └── transaction_creator.py
│   └── transaction_composer.py
├── models/
│   ├── __init__.py # currently exposes contents of old models.py which resides in _legacy_v2
│   └── common.py # Any number of common models reused in at least 2 different namespaces
├── _utils/ # marked as private module
│   ├── __init__.py
│   ├── debugging.py # previously was at the root as _debugging.py, instead it will now reside in a private _utils namespace, this is partly to also avoid awkward `from algokit_utils.utils` statements, all utils exposed to end user in _utils would need to be explicitly exported via `__all__` dunder in root `__init__.py`
│   └── ... any other misc # of .py files for commonly used methods
├── errors/
│   ├── __init__.py
│   ├── ... # any other custom errors which may benefit from extracting into separate module
│   └── logic_error.py
├── config.py # unchanged from v2 as there are no major breaking changes
└── ... `account.py` `application_client.py` and other legacy files all re exporting contents from `_legacy_v2` folder which contains the v2 abstractions -> required to insure backwards compatibility after users upgrade to this version AND to establish clear boundary between old vs new abstractions
  • New abstractions are significantly more type heavy, the v2 of utils-py contained a module named models at the root represented as a file, its turned into a folder now and re exposes the old legacy models, however the intent is to reuse it and later add more granular files inside for various abstractions (assets, apps, and etc)

  • Note that some files from legacy_v2 and/or root .py files that expose the contents of legacy_v2 for backwards compatibility will be resurrected and repurposed (if it will make sense, similar to what was done with models.py -> models folder)

  • 3. Implement TransactionComposer (previously AlgoKitComposer) and any dependant abstractions

Implemented in: #120

  • 4. Implementing AppFactory, AppClient and AppDeployer abstractions

Implemented and refined in: #127

  • 5. Initial documentation

Implemented in: #128

  • 6. Refined documentation and deprecation warning instructions

Work in progress

  • 7. Addressing final batch of suggestions/feedback

Work in progress

@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch 3 times, most recently from 39a8844 to f569a20 Compare October 22, 2024 17:38
Copy link

github-actions bot commented Oct 22, 2024

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/algokit_utils
   _debugging.py1411887%21, 40–42, 45, 54, 62, 81, 87, 96, 110–114, 133, 141–143
   account.py330%1–12
   algorand.py981585%62–63, 74–75, 95–96, 108–110, 119–120, 214, 234, 247, 263
   application_client.py330%1–11
   application_specification.py770%1–39
   config.py891880%26–28, 41, 53, 84–85, 100, 105, 110, 118–123, 153, 155, 157
   deploy.py330%1–10
   logic_error.py330%1–10
src/algokit_utils/_legacy_v2
   _ensure_funded.py71199%100
   _transfer.py70396%14, 75–76
   account.py931386%15–18, 70–74, 109, 126, 156, 159, 203
   application_client.py5367786%56–57, 175, 180, 209, 321, 326–327, 329, 331, 800, 815, 833–836, 930, 970, 982, 995, 1037, 1097–1103, 1107–1112, 1114, 1150, 1157, 1270, 1306, 1320, 1358–1360, 1362, 1372–1429, 1440–1445, 1465–1468
   asset.py80495%24–27
   common.py13192%13
   deploy.py4072295%32–35, 170, 174–175, 193, 249, 339–340, 361, 395, 406–414, 429, 437, 593–594, 618
   network_clients.py73593%77–78, 101–102, 135
src/algokit_utils/accounts
   account_manager.py2133385%162, 181–182, 206–211, 229–230, 247, 264–269, 316–318, 347, 386, 406–410, 423, 482, 503, 660, 766, 845, 850, 869–870, 893
   kmd_account_manager.py72889%49–53, 94, 150, 157
src/algokit_utils/applications
   abi.py1307145%14, 74, 110, 116, 118, 120, 124–125, 140–159, 175, 178–184, 200–213, 226–238, 253–264
   app_client.py72021171%65–73, 131, 139, 401–404, 407, 410, 413, 416, 428–431, 434, 437, 440, 443, 455, 464, 473, 476–543, 556–614, 638–640, 657–660, 668–671, 679–682, 690–693, 701–704, 715–718, 731, 829–832, 866, 878, 890, 902, 914, 929, 944, 954, 964, 974, 984, 994, 1031–1044, 1060, 1077, 1094, 1111, 1132, 1153, 1243, 1388, 1435–1436, 1467, 1469, 1475, 1520–1528, 1561–1564, 1567–1570, 1591, 1639, 1713–1720, 1761, 1778, 1780, 1783, 1787, 1914, 1925–1926, 1949, 1959–1961, 1964–1986, 1996, 2005–2020, 2025–2030
   app_deployer.py2094081%97, 195, 202, 212–217, 220–224, 262–276, 291–292, 481–494, 504, 509, 515, 521–523, 530, 544, 555–596
   app_factory.py2692790%357, 367, 370, 514, 522, 534, 683, 697–702, 708–709, 727, 752, 763–764, 800, 808–822
   app_manager.py2181693%226, 285–286, 318–323, 349, 367–368, 398, 419–422, 445, 454
src/algokit_utils/applications/app_spec
   arc32.py95892%198–207
   arc56.py4703692%72–74, 183, 318, 336–337, 415, 437–439, 495, 504, 506, 574, 769, 779, 783, 943, 945, 978–989, 1002, 1004–1005, 1021
src/algokit_utils/assets
   asset_manager.py1061289%266–267, 276, 282–306, 316
src/algokit_utils/clients
   client_manager.py1765469%24–26, 74–81, 95, 127–129, 185, 196–199, 224, 263, 298–303, 338–340, 370, 388, 407, 441–444, 477–480, 514–517, 547–550, 568–593, 623, 632, 640
   dispenser_api_client.py831286%126–127, 131–134, 169–171, 190–192
src/algokit_utils/errors
   logic_error.py561180%14, 105–121
src/algokit_utils/models
   account.py861286%30, 32, 123, 131, 155–162, 176–177, 185, 193
   amount.py1071586%119, 129, 135, 143, 148–150, 157, 162–164, 171, 178, 191, 197
   application.py42198%8
   state.py36586%51, 55–58
   transaction.py51394%66, 86, 91
src/algokit_utils/protocols
   account.py11282%17, 22
   typed_clients.py24483%12–24
src/algokit_utils/transactions
   transaction_composer.py95213086%35–42, 620, 623, 628, 632–643, 675, 716, 783, 790, 806, 839, 902–965, 994, 1012–1014, 1020–1035, 1040, 1048, 1050, 1052, 1068, 1074, 1109–1116, 1119–1126, 1137, 1231, 1280, 1528–1529, 1568–1569, 1608, 1659–1663, 1819, 1822, 1841, 1846, 1870–1872, 1909–1945, 1952–1959, 2108, 2111, 2239, 2241–2242, 2292–2293
   transaction_creator.py75791%116, 121, 126, 131, 136, 141, 156
   transaction_sender.py1481093%88, 243, 286–287, 431–436, 441–442, 487
TOTAL626592485% 

Tests Skipped Failures Errors Time
396 0 💤 0 ❌ 0 🔥 4m 35s ⏱️

…ls-ts

- Moving all v2 code into legacy_v2 folder inside src
- Moving all v2 tests into legacy_v2_tests
- Moving all files in beta into more granular folder structure
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from f569a20 to 9389170 Compare October 23, 2024 13:00
@aorumbayev
Copy link
Contributor Author

aorumbayev commented Oct 23, 2024

@neilcampbell @robdmoore , please note the bit around proposal with each folder having its own models.py might be revised. As im implementing the composer and moving out some of the legacy abstractions back to root models folder i might have to ditch the initial models per folder idea and create files account, transaction and etc under root models so that all models are under one namespace but primarily to avoid circular imports for abstractions that were moved out from legacy but are also used within legacy code (instead of duplicating them which i think can lead to bigger issues)

@aorumbayev aorumbayev changed the title feat: algokit-utils-ts feature parity [WIP DRAFT] feat: algokit-utils-py v3 implementation [WIP DRAFT] Oct 24, 2024
aorumbayev and others added 7 commits November 4, 2024 17:16
…g refactoring efforts (#120)

* feat: Initial AppManager implementation; wip on Composer; mypy tweaks; initial tests

- Add AppManager class with methods for compiling TEAL, managing app state, and handling template variables
- Update TransactionComposer to use AppManager
- Move Account model to a separate file and update imports
- Add new models for ABI values and application constants
- Improve type annotations and remove unnecessary type ignores
- Add initial tests for AppManager template substitution and comment stripping
- Update mypy configuration to *globally* exclude untyped calls in algosdk -> removing ~50 individual mypy type ignore for algosdk

* chore: removing models.py folders in favour of  granular modules in root models namespace

* chore: wip

* feat: initial implementation of TransactionComposer
…ractions (#123)

* chore: wip

* feat: initial implementation of TransactionSender, TransactionCreator and AssetManager
…ments on top of existing new interfaces (#124)

* chore: bump ruff

* chore: wip; arc32 to arc56 converter

* chore: wip

* chore: wip

* chore: wip

* chore: wip

* chore: finalizing initial tests around call

* chore: wip

* chore: extra tests; wip

* chore: adding initial logic error exposer

* chore: resource population; skeletons for appdeployer and appfactory

* chore: adding draft deprecation warnings; wip

* chore: wip

* chore: wip

* chore: wip

* chore: wip

* chore: mypy and ruff tweaks wip

* chore: make some asset param fields optional; add subtraction dunder to AlgoAmount

* chore: more tests; updating deprecation decorators; initial tweaks for ruff
…population tests (#125)

* fix: configure method tweaks; fixing appdeployresult init

* test: adding first half of resource population tests; improving composer txn generation
* chore: wip

* chore: refining AppFactory and AppDeployer implementations

* chore: adding missing client retrieval methods; missing box state accessor

* chore: aligning kmd config resolution

* chore: fixing default signer assignment in app factory

* chore: fix state accessor

* refactor: reusing useful legacy code; refining pyproject; refining deploy response in factory

* chore: adding module deprecation warnings; aliasing applicationspec to arc32contract

* refactor: rewriting arc56 converter and arc56contract class

* refactor: remaining batch of refactoring efforts; improving project structure
pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from 57aa2ab to 92774f7 Compare December 23, 2024 12:00
aorumbayev and others added 2 commits December 23, 2024 16:46
* docs: adding rewritten app client amount and account sections; respective docstrings

* docs: initial rewrites for appmanager; clients and debugger docs

* docs: adding migration guide, refining remaining capabilities; adding missing exports

* chore: addressing pr comments

Renaming network related namings from *_net to *net

* chore: update docs/source/capabilities/transfer.md

Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au>

---------

Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au>
@aorumbayev aorumbayev changed the title feat: algokit-utils-py v3 implementation [WIP DRAFT] feat: algokit-utils-py v3 implementation Dec 23, 2024
Copy link
Contributor

@neilcampbell neilcampbell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working through the code.

src/algokit_utils/_debugging.py Outdated Show resolved Hide resolved
src/algokit_utils/_legacy_v2/asset.py Outdated Show resolved Hide resolved
src/algokit_utils/_legacy_v2/asset.py Outdated Show resolved Hide resolved
src/algokit_utils/_legacy_v2/deploy.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_client.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_client.py Show resolved Hide resolved
src/algokit_utils/applications/app_client.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_client.py Show resolved Hide resolved
src/algokit_utils/applications/app_factory.py Outdated Show resolved Hide resolved
src/algokit_utils/assets/asset_manager.py Show resolved Hide resolved
src/algokit_utils/clients/algorand_client.py Outdated Show resolved Hide resolved
src/algokit_utils/clients/client_manager.py Outdated Show resolved Hide resolved
src/algokit_utils/models/amount.py Outdated Show resolved Hide resolved
src/algokit_utils/models/amount.py Outdated Show resolved Hide resolved
src/algokit_utils/protocols/client.py Outdated Show resolved Hide resolved
src/algokit_utils/transactions/transaction_composer.py Outdated Show resolved Hide resolved
src/algokit_utils/transactions/utils.py Outdated Show resolved Hide resolved
aorumbayev and others added 5 commits January 22, 2025 12:54
* chore: initial methods for typed client generator

* fix: fixing arc2 note generation in AppDeployer

* fix: changing CompiledTeal compiled to str from bytes; patching _build_source_map

* refactor: adding usage of collections.abc.Sequence for args params

* refactor: expose algorand client protocol; expand to cover latest interface

* refactor: patch compile_teal_template behaviour around deployment_metadata

* refactor: using generics for abi_return type in AppFactoryCreateMethodCallResult

* refactor: making deploy arg types in app factory rely on generic (for redefinition in client generator)

* refactor: further leveraging generics to match ts behaviour, the abi_return type turns into ABIValue

* fix: proper use of type vars for client manager typed class getters

* refactor: make all bare properties on app client send/createTxn/params optional

* refactor: add error handler for simulate responses

* fix: proper handling of default args from hints

* fix: proper handling of getting abi args with default values (when no args given)

* fix: typo in generics inheritance

* refactor: ensure send calls from AppClient for methods parse output to arc56 values

* fix: skip snake case conversion for struct field in arc56

* fix: group id generation for log during send atc

* fix: exposing AppMethodCallTransactionArgument for typed client

* fix: fixing params creation in factory

* fix: safer global state decoding

* refactor: parametrize indent in to_json methods of arc classes

* fix: typo in get_map decoding

* fix: box key decoding

* refactor: contravariant typevars for typed factory protocol

plus a fix for box decoding
src/algokit_utils/accounts/account_manager.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_factory.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_factory.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_factory.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_factory.py Outdated Show resolved Hide resolved
src/algokit_utils/applications/app_client.py Outdated Show resolved Hide resolved
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch 5 times, most recently from e61b723 to b8911e0 Compare January 27, 2025 19:21
@aorumbayev aorumbayev marked this pull request as ready for review January 27, 2025 19:48
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from b8911e0 to 690b567 Compare January 27, 2025 22:14
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from eb81ab6 to 2f2bb17 Compare January 28, 2025 19:58
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch 5 times, most recently from 7a77b62 to 38238ea Compare January 29, 2025 14:19
- excluding html folder from generation (until produciton release is out) -> as this will refresh self hosted docs
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from 38238ea to f8cb58f Compare January 29, 2025 14:22
docs/source/capabilities/account.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/algorand-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/app-client.md Outdated Show resolved Hide resolved
docs/source/capabilities/app-deploy.md Outdated Show resolved Hide resolved
docs/source/capabilities/app-deploy.md Outdated Show resolved Hide resolved
docs/source/capabilities/transaction-composer.md Outdated Show resolved Hide resolved
docs/source/capabilities/transaction-composer.md Outdated Show resolved Hide resolved
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch 2 times, most recently from 81ddc55 to 226a32a Compare January 29, 2025 17:49
@aorumbayev aorumbayev force-pushed the prerelease/ts-feature-parity branch from 226a32a to 9af713d Compare January 29, 2025 17:52
@aorumbayev aorumbayev merged commit 428dab1 into main Jan 29, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants