Skip to content

Commit

Permalink
feat: Add puyapy compile integration (#457)
Browse files Browse the repository at this point in the history
* feat: enable puya integration

* chore: doc

* chore: refactor compile command and enhance the docs

* docs: wording tweaks to the compile docs

* chore: change install to run, as I think it is the behaviour we want

* chore: fix snapshots

* fix: resolve issue running on windows

* chore: add info about PuyaPy Python version and matching behaviour.

* chore: fix snapshots

* chore: wording tweaks

* chore: allowing running puya with no color

* docs: adjust compile command terminology

---------

Co-authored-by: Neil Campbell <[email protected]>
  • Loading branch information
PatrickDinh and neilcampbell authored Mar 25, 2024
1 parent 794cccc commit 03f0816
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 121 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ This is an open source project managed by the Algorand Foundation. See the [cont

## Prerequisites

The key required dependency is Python 3.10+, but some of the installation options below will install that for you.
The key required dependency is Python 3.10+, but some of the installation options below will install that for you. We recommend using Python 3.12+, as the `algokit compile python` command requires this version.

AlgoKit also has some runtime dependencies that also need to be available for particular commands.

Expand Down Expand Up @@ -126,10 +126,12 @@ AlgoKit can be installed using OS specific package managers, or using the python
> **App Installer python.exe** or **App Installer python3.exe**.
3. Install pipx:

```
pip install --user pipx
python -m pipx ensurepath
```
4. Restart the terminal to ensure pipx is available on the path
5. Install AlgoKit via pipx: `pipx install algokit`
6. Restart the terminal to ensure AlgoKit is available on the path
Expand Down
132 changes: 92 additions & 40 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,73 @@
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci-1)
- [npm](#npm)
- [poetry](#poetry)
- [compile](#compile)
- [Options](#options-4)
- [-v, --version ](#-v---version-)
- [py](#py)
- [Arguments](#arguments)
- [PUYAPY_ARGS](#puyapy_args)
- [python](#python)
- [Arguments](#arguments-1)
- [PUYAPY_ARGS](#puyapy_args-1)
- [completions](#completions)
- [install](#install)
- [Options](#options-4)
- [Options](#options-5)
- [--shell ](#--shell-)
- [uninstall](#uninstall)
- [Options](#options-5)
- [Options](#options-6)
- [--shell ](#--shell--1)
- [config](#config)
- [version-prompt](#version-prompt)
- [Arguments](#arguments)
- [Arguments](#arguments-2)
- [ENABLE](#enable)
- [deploy](#deploy)
- [Options](#options-6)
- [Options](#options-7)
- [-C, --command ](#-c---command-)
- [--interactive, --non-interactive, --ci](#--interactive---non-interactive---ci-2)
- [-P, --path ](#-p---path-)
- [--deployer ](#--deployer-)
- [--dispenser ](#--dispenser-)
- [Arguments](#arguments-1)
- [Arguments](#arguments-3)
- [ENVIRONMENT_NAME](#environment_name)
- [dispenser](#dispenser)
- [fund](#fund)
- [Options](#options-7)
- [Options](#options-8)
- [-r, --receiver ](#-r---receiver-)
- [-a, --amount ](#-a---amount-)
- [--whole-units](#--whole-units)
- [limit](#limit)
- [Options](#options-8)
- [Options](#options-9)
- [--whole-units](#--whole-units-1)
- [login](#login)
- [Options](#options-9)
- [Options](#options-10)
- [--ci](#--ci)
- [-o, --output ](#-o---output-)
- [-f, --file ](#-f---file-)
- [logout](#logout)
- [refund](#refund)
- [Options](#options-10)
- [Options](#options-11)
- [-t, --txID ](#-t---txid-)
- [doctor](#doctor)
- [Options](#options-11)
- [Options](#options-12)
- [-c, --copy-to-clipboard](#-c---copy-to-clipboard)
- [explore](#explore)
- [Arguments](#arguments-2)
- [Arguments](#arguments-4)
- [NETWORK](#network)
- [generate](#generate)
- [client](#client)
- [Options](#options-12)
- [Options](#options-13)
- [-o, --output ](#-o---output--1)
- [-l, --language ](#-l---language-)
- [Arguments](#arguments-3)
- [Arguments](#arguments-5)
- [APP_SPEC_PATH_OR_DIR](#app_spec_path_or_dir)
- [goal](#goal)
- [Options](#options-13)
- [Options](#options-14)
- [--console](#--console)
- [Arguments](#arguments-4)
- [Arguments](#arguments-6)
- [GOAL_ARGS](#goal_args)
- [init](#init)
- [Options](#options-14)
- [Options](#options-15)
- [-n, --name ](#-n---name-)
- [-t, --template ](#-t---template-)
- [--template-url ](#--template-url-)
Expand All @@ -91,33 +100,33 @@
- [console](#console)
- [explore](#explore-1)
- [logs](#logs)
- [Options](#options-15)
- [Options](#options-16)
- [--follow, -f](#--follow--f)
- [--tail ](#--tail-)
- [reset](#reset)
- [Options](#options-16)
- [Options](#options-17)
- [--update, --no-update](#--update---no-update)
- [start](#start)
- [Options](#options-17)
- [Options](#options-18)
- [-n, --name ](#-n---name--1)
- [status](#status)
- [stop](#stop)
- [task](#task)
- [analyze](#analyze)
- [Options](#options-18)
- [Options](#options-19)
- [-r, --recursive](#-r---recursive)
- [--force](#--force-1)
- [--diff](#--diff)
- [-o, --output ](#-o---output--2)
- [-e, --exclude ](#-e---exclude-)
- [Arguments](#arguments-5)
- [Arguments](#arguments-7)
- [INPUT_PATHS](#input_paths)
- [ipfs](#ipfs)
- [Options](#options-19)
- [Options](#options-20)
- [-f, --file ](#-f---file--1)
- [-n, --name ](#-n---name--2)
- [mint](#mint)
- [Options](#options-20)
- [Options](#options-21)
- [--creator ](#--creator-)
- [-n, --name ](#-n---name--3)
- [-u, --unit ](#-u---unit-)
Expand All @@ -129,66 +138,66 @@
- [--nft, --ft](#--nft---ft)
- [-n, --network ](#-n---network-)
- [nfd-lookup](#nfd-lookup)
- [Options](#options-21)
- [Options](#options-22)
- [-o, --output ](#-o---output--3)
- [Arguments](#arguments-6)
- [Arguments](#arguments-8)
- [VALUE](#value)
- [opt-in](#opt-in)
- [Options](#options-22)
- [Options](#options-23)
- [-a, --account ](#-a---account-)
- [-n, --network ](#-n---network--1)
- [Arguments](#arguments-7)
- [Arguments](#arguments-9)
- [ASSET_IDS](#asset_ids)
- [opt-out](#opt-out)
- [Options](#options-23)
- [Options](#options-24)
- [-a, --account ](#-a---account--1)
- [--all](#--all)
- [-n, --network ](#-n---network--2)
- [Arguments](#arguments-8)
- [Arguments](#arguments-10)
- [ASSET_IDS](#asset_ids-1)
- [send](#send)
- [Options](#options-24)
- [Options](#options-25)
- [-f, --file ](#-f---file--2)
- [-t, --transaction ](#-t---transaction-)
- [-n, --network ](#-n---network--3)
- [sign](#sign)
- [Options](#options-25)
- [Options](#options-26)
- [-a, --account ](#-a---account--2)
- [-f, --file ](#-f---file--3)
- [-t, --transaction ](#-t---transaction--1)
- [-o, --output ](#-o---output--4)
- [--force](#--force-2)
- [transfer](#transfer)
- [Options](#options-26)
- [Options](#options-27)
- [-s, --sender ](#-s---sender-)
- [-r, --receiver ](#-r---receiver--1)
- [--asset, --id ](#--asset---id-)
- [-a, --amount ](#-a---amount--1)
- [--whole-units](#--whole-units-2)
- [-n, --network ](#-n---network--4)
- [vanity-address](#vanity-address)
- [Options](#options-27)
- [Options](#options-28)
- [-m, --match ](#-m---match-)
- [-o, --output ](#-o---output--5)
- [-a, --alias ](#-a---alias-)
- [--file-path ](#--file-path-)
- [-f, --force](#-f---force)
- [Arguments](#arguments-9)
- [Arguments](#arguments-11)
- [KEYWORD](#keyword)
- [wallet](#wallet)
- [Options](#options-28)
- [Options](#options-29)
- [-a, --address ](#-a---address-)
- [-m, --mnemonic](#-m---mnemonic)
- [-f, --force](#-f---force-1)
- [Arguments](#arguments-10)
- [Arguments](#arguments-12)
- [ALIAS_NAME](#alias_name)
- [Arguments](#arguments-11)
- [Arguments](#arguments-13)
- [ALIAS](#alias)
- [Options](#options-29)
- [Options](#options-30)
- [-f, --force](#-f---force-2)
- [Arguments](#arguments-12)
- [Arguments](#arguments-14)
- [ALIAS](#alias-1)
- [Options](#options-30)
- [Options](#options-31)
- [-f, --force](#-f---force-3)

# algokit
Expand Down Expand Up @@ -278,6 +287,49 @@ Installs Python Poetry (if not present) and runs poetry install in the current w
algokit bootstrap poetry [OPTIONS]
```

## compile

Compile smart contracts and smart signatures written in a supported high-level language
to a format deployable on the Algorand Virtual Machine (AVM).

```shell
algokit compile [OPTIONS] COMMAND [ARGS]...
```

### Options


### -v, --version <version>
The compiler version to pin to, for example, 1.0.0. If no version is specified, AlgoKit checks if the compiler is installed and runs the installed version. If the compiler is not installed, AlgoKit runs the latest version. If a version is specified, AlgoKit checks if an installed version matches and runs the installed version. Otherwise, AlgoKit runs the specified version.

### py

Compile Algorand Python contract(s) using the PuyaPy compiler.

```shell
algokit compile py [OPTIONS] [PUYAPY_ARGS]...
```

### Arguments


### PUYAPY_ARGS
Optional argument(s)

### python

Compile Algorand Python contract(s) using the PuyaPy compiler.

```shell
algokit compile python [OPTIONS] [PUYAPY_ARGS]...
```

### Arguments


### PUYAPY_ARGS
Optional argument(s)

## completions

Install and Uninstall AlgoKit shell integrations.
Expand Down
98 changes: 98 additions & 0 deletions docs/features/compile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# AlgoKit Compile

The AlgoKit Compile feature enables you to compile smart contracts (apps) and smart signatures (logic signatures) written in a supported high-level language to a format deployable on the Algorand Virtual Machine (AVM).

When running the compile command, AlgoKit will take care of working out which compiler you need and dynamically resolve it. Additionally, AlgoKit will detect if a matching compiler version is already installed globally on your machine or is included in your project and use that.

## Prerequisites

See [Compile Python - Prerequisites](#prerequisites-1) for details.

## What is Algorand Python & PuyaPy?

Algorand Python is a semantically and syntactically compatible, typed Python language that works with standard Python tooling and allows you to express smart contracts (apps) and smart signatures (logic signatures) for deployment on the Algorand Virtual Machine (AVM).

Algorand Python can be deployed to Algorand by using the PuyaPy optimising compiler, which takes Algorand Python and outputs [ARC-32](https://github.com/algorandfoundation/ARCs/blob/main/ARCs/arc-0032.md) application spec files (among other formats) which, [when deployed](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md#1-typed-clients), will result in AVM bytecode execution semantics that match the given Python code.

If you want to learn more, check out the [PuyaPy docs](https://github.com/algorandfoundation/puya/blob/main/docs/index.md).

Below is an example Algorand Python smart contract.

```py
from puyapy import ARC4Contract, arc4

class HelloWorldContract(ARC4Contract):
@arc4.abimethod
def hello(self, name: arc4.String) -> arc4.String:
return "Hello, " + name
```

For more complex examples, see the [examples](https://github.com/algorandfoundation/puya/tree/main/examples) in the [PuyaPy repo](https://github.com/algorandfoundation/puya).

## Usage

Available commands and possible usage are as follows:

```
Usage: algokit compile [OPTIONS] COMMAND [ARGS]...
Compile smart contracts and smart signatures written in a supported high-level language to a format deployable on
the Algorand Virtual Machine (AVM).
Options:
-v, --version TEXT The compiler version to pin to, for example, 1.0.0. If no version is specified, AlgoKit checks
if the compiler is installed and runs the installed version. If the compiler is not installed,
AlgoKit runs the latest version. If a version is specified, AlgoKit checks if an installed
version matches and runs the installed version. Otherwise, AlgoKit runs the specified version.
-h, --help Show this message and exit.
Commands:
py Compile Algorand Python contract(s) using the PuyaPy compiler.
python Compile Algorand Python contract(s) using the PuyaPy compiler.
```

### Compile Python

The command `algokit compile python` or `algokit compile py` will run the [PuyaPy](https://github.com/algorandfoundation/puya) compiler against the supplied Algorand Python smart contract.

All arguments supplied to the command are passed directly to PuyaPy, therefore this command supports all options supported by the PuyaPy compiler.

Any errors detected by PuyaPy during the compilation process will be printed to the output.

#### Prerequisites

PuyaPy requires Python 3.12+, so please ensure your Python version satisfies this requirement.

This command will attempt to resolve a matching installed PuyaPy compiler, either globally installed in the system or locally installed in your project (via [Poetry](https://python-poetry.org/)). If no appropriate match is found, the PuyaPy compiler will be dynamically run using [pipx](https://pipx.pypa.io/stable/). In this case pipx is also required.

#### Examples

To see a list of the supported PuyaPy options, run the following:

```shell
algokit compile python -h
```

To determine the version of the PuyaPy compiler in use, execute the following command:

```shell
algokit compile python --version
```

To compile a single Algorand Python smart contract and write the output to a specific location, run the following:

```shell
algokit compile python hello_world/contract.py --out-dir hello_world/out
```

To compile multiple Algorand Python smart contracts and write the output to a specific location, run the following:

```shell
algokit compile python hello_world/contract.py calculator/contract.py --out-dir my_contracts
```

To compile a directory of Algorand Python smart contracts and write the output to the default location, run the following:

```shell
algokit compile python my_contracts
```
Loading

0 comments on commit 03f0816

Please sign in to comment.