Skip to content

Commit

Permalink
Flake & Make (#273)
Browse files Browse the repository at this point in the history
* Linting related changes:
  *`.flake8`: 
    * Based on my experience in `graviton` and a couple of extra ignores for formatting that was conflicting with `black`
    * replace `from pyteal import *` with `import pyteal as pt` in our tests, and for other files ignore the * import error on a per file basis (_this is the reason line changes number in the thousands which amounts to almost 25% of the entire codebase_)
    * Incorporate #277 
* Additional changes:
  * Removing `requirements.txt` (but keeping `docs/requirements.txt`)
  * `setup.py`: `extras_require={"development" ... ` replaces the former `requirements.txt`
  * `.github/workflows/build.yml` + `Makefile`: unify as much of the logic as possible. Needed regular `python` instead of `python-slim` in order to have `make`. `black` is applied to all python files, as before, and `flake8` is as well. `mypy` is applied to `scripts` in addition to `pyteal` (in upcoming #260 this will be expanded to `tests` as well).
  * `README.md` - applying [mardkownlint](https://github.com/DavidAnson/markdownlint) (without automation)
  • Loading branch information
tzaffi committed Apr 19, 2022
1 parent a8f7bb6 commit a464b5c
Show file tree
Hide file tree
Showing 83 changed files with 6,121 additions and 5,828 deletions.
26 changes: 26 additions & 0 deletions .flake8
@@ -0,0 +1,26 @@
[flake8]
ignore =
E203,
E241,
W291,
E302,
E501,
W503,
E741,

per-file-ignores =
pyteal/compiler/optimizer/__init__.py: F401
examples/application/asset.py: F403, F405
examples/application/security_token.py: F403, F405
examples/application/vote.py: F403, F405
examples/signature/atomic_swap.py: F403, F405
examples/signature/basic.py: F403, F405
examples/signature/dutch_auction.py: F403, F405
examples/signature/periodic_payment_deploy.py: F403, F405
examples/signature/recurring_swap.py: F403, F405
examples/signature/split.py: F403, F405
examples/signature/periodic_payment.py: F403, F405
examples/signature/recurring_swap_deploy.py: F403, F405
pyteal/__init__.py: F401, F403
pyteal/ir/ops.py: E221
tests/module_test.py: F401, F403
34 changes: 12 additions & 22 deletions .github/workflows/build.yml
Expand Up @@ -6,10 +6,11 @@ on:
- v**
branches:
- master

jobs:
build-test:
runs-on: ubuntu-20.04
container: python:${{ matrix.python }}-slim
container: python:${{ matrix.python }}
strategy:
matrix:
python: ['3.10']
Expand All @@ -19,16 +20,11 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install pip dependencies
run: |
pip install -r requirements.txt
pip install -e .
- name: Install python dependencies
run: make setup-development
- name: Build and Test
run: |
python scripts/generate_init.py --check
black --check .
mypy pyteal
pytest
run: make build-and-test

build-docset:
runs-on: ubuntu-20.04
container: python:3.10 # Needs `make`, can't be slim
Expand All @@ -37,22 +33,16 @@ jobs:
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install pip dependencies
run: |
pip install -r requirements.txt
pip install -r docs/requirements.txt
pip install doc2dash
- name: Install python dependencies
run: make setup-docs
- name: Make docs
run: |
cd docs
make html
doc2dash --name pyteal --index-page index.html --online-redirect-url https://pyteal.readthedocs.io/en/ _build/html
tar -czvf pyteal.docset.tar.gz pyteal.docset
run: make bundle-docs
- name: Archive docset
uses: actions/upload-artifact@v2
with:
name: pyteal.docset
path: docs/pyteal.docset.tar.gz

upload-to-pypi:
runs-on: ubuntu-20.04
container: python:3.10
Expand All @@ -64,9 +54,9 @@ jobs:
with:
fetch-depth: 0
- name: Install dependencies
run: pip install wheel
run: make setup-wheel
- name: Build package
run: python setup.py sdist bdist_wheel
run: make bdist-wheel
- name: Release
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
10 changes: 6 additions & 4 deletions .gitignore
@@ -1,5 +1,3 @@
.DS_Store

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down Expand Up @@ -54,8 +52,8 @@ coverage.xml
.pytest_cache/

# Tests generating TEAL output to compared against an expected example.
tests/teal/*.teal
!tests/teal/*_expected.teal
tests/**/*.teal
!tests/**/*_expected.teal

# Translations
*.mo
Expand All @@ -76,6 +74,7 @@ instance/

# Sphinx documentation
docs/_build/
pyteal.docset*

# PyBuilder
target/
Expand Down Expand Up @@ -133,3 +132,6 @@ dmypy.json
# IDE
.idea
.vscode

# mac OS
.DS_Store
49 changes: 49 additions & 0 deletions Makefile
@@ -0,0 +1,49 @@
setup-development:
pip install -e.[development]

setup-docs: setup-development
pip install -r docs/requirements.txt
pip install doc2dash

setup-wheel:
pip install wheel

bdist-wheel:
python setup.py sdist bdist_wheel

bundle-docs-clean:
rm -rf docs/pyteal.docset

bundle-docs: bundle-docs-clean
cd docs && \
make html && \
doc2dash --name pyteal --index-page index.html --online-redirect-url https://pyteal.readthedocs.io/en/ _build/html && \
tar -czvf pyteal.docset.tar.gz pyteal.docset

generate-init:
python -m scripts.generate_init

check-generate-init:
python -m scripts.generate_init --check

ALLPY = docs examples pyteal scripts tests *.py
black:
black --check $(ALLPY)

flake8:
flake8 $(ALLPY)

MYPY = pyteal scripts
mypy:
mypy $(MYPY)

lint: black flake8 mypy

test-unit:
pytest

build-and-test: check-generate-init lint test-unit

# Extras:
coverage:
pytest --cov-report html --cov=pyteal
47 changes: 29 additions & 18 deletions README.md
@@ -1,5 +1,6 @@
![PyTeal logo](https://github.com/algorand/pyteal/blob/master/docs/pyteal.png?raw=true)
<!-- markdownlint-disable-file MD041 -->

![PyTeal logo](https://github.com/algorand/pyteal/blob/master/docs/pyteal.png?raw=true)

# PyTeal: Algorand Smart Contracts in Python

Expand All @@ -8,59 +9,69 @@
[![Documentation Status](https://readthedocs.org/projects/pyteal/badge/?version=latest)](https://pyteal.readthedocs.io/en/latest/?badge=latest)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

PyTeal is a Python language binding for [Algorand Smart Contracts (ASC1s)](https://developer.algorand.org/docs/features/asc1/).
PyTeal is a Python language binding for [Algorand Smart Contracts (ASC1s)](https://developer.algorand.org/docs/features/asc1/).

Algorand Smart Contracts are implemented using a new language that is stack-based,
called [Transaction Execution Approval Language (TEAL)](https://developer.algorand.org/docs/features/asc1/teal/).
Algorand Smart Contracts are implemented using a new language that is stack-based,
called [Transaction Execution Approval Language (TEAL)](https://developer.algorand.org/docs/features/asc1/teal/).

However, TEAL is essentially an assembly language. With PyTeal, developers can express smart contract logic purely using Python.
However, TEAL is essentially an assembly language. With PyTeal, developers can express smart contract logic purely using Python.
PyTeal provides high level, functional programming style abstractions over TEAL and does type checking at construction time.

### Install
## Install

PyTeal requires Python version >= 3.10.

To manage multiple Python versions use tooling like [pyenv](https://github.com/pyenv/pyenv).

#### Recommended: Install from PyPi
### Recommended: Install from PyPi

Install the latest official release from PyPi:

* `pip install pyteal`

#### Install Latest Commit
### Install Latest Commit

If needed, it's possible to install directly from the latest commit on master to use unreleased features:

> **WARNING:** Unreleased code is experimental and may not be backwards compatible or function properly. Use extreme caution when installing PyTeal this way.
* `pip install git+https://github.com/algorand/pyteal`

### Documentation
## Documentation

* [PyTeal Docs](https://pyteal.readthedocs.io/)
* `docs/` ([README](docs/README.md)) contains raw docs.

### Development Setup
## Development Setup

Setup venv (one time):
* `python3 -m venv venv`

* `python3 -m venv venv`

Active venv:
* `. venv/bin/activate` (if your shell is bash/zsh)
* `. venv/bin/activate.fish` (if your shell is fish)

Pip install PyTeal in editable state
* `pip install -e .`
* `. venv/bin/activate` (if your shell is bash/zsh)
* `. venv/bin/activate.fish` (if your shell is fish)

Pip install PyTeal in editable state with dependencies:

* `make setup-development`
* OR if you don't have `make` installed:
* `pip install -e.[development]`
* Note, that if you're using `zsh` you'll need to escape the brackets: `pip install -e.\[development\]`

Install dependencies:
* `pip install -r requirements.txt`

Type checking using mypy:

* `mypy pyteal`

Run tests:

* `pytest`

Format code:

* `black .`

Lint using flake8:

* `flake8 docs examples pyteal scripts tests *.py`
1 change: 0 additions & 1 deletion examples/application/vote_deploy.py
@@ -1,7 +1,6 @@
# based off https://github.com/algorand/docs/blob/cdf11d48a4b1168752e6ccaf77c8b9e8e599713a/examples/smart_contracts/v2/python/stateful_smart_contracts.py

import base64
import datetime

from algosdk.future import transaction
from algosdk import account, mnemonic
Expand Down
10 changes: 7 additions & 3 deletions examples/signature/periodic_payment_deploy.py
@@ -1,9 +1,13 @@
#!/usr/bin/env python3

from pyteal import *
import uuid, params, base64
import base64
import params
import uuid

from algosdk import algod, transaction, account, mnemonic
from periodic_payment import periodic_payment, tmpl_amt
from periodic_payment import periodic_payment

from pyteal import *

# --------- compile & send transaction using Goal and Python SDK ----------

Expand Down
16 changes: 12 additions & 4 deletions examples/signature/recurring_swap_deploy.py
@@ -1,11 +1,19 @@
#!/usr/bin/env python3

from pyteal import *
import base64
from nacl import encoding, hash
from recurring_swap import recurring_swap, tmpl_provider
from algosdk import algod, account
import params
import re
import time
import uuid

from algosdk import algod
from algosdk.future import transaction
import uuid, params, re, base64, time

from pyteal import *

from recurring_swap import recurring_swap


# ------- generate provider's account -----------------------------------------------
key_fn = str(uuid.uuid4()) + ".key"
Expand Down
5 changes: 0 additions & 5 deletions pyteal/ast/acct.py
@@ -1,13 +1,8 @@
from typing import TYPE_CHECKING

from ..types import TealType, require_type
from ..ir import Op
from .expr import Expr
from .maybe import MaybeValue

if TYPE_CHECKING:
from ..compiler import CompileOptions


class AccountParam:
@classmethod
Expand Down

0 comments on commit a464b5c

Please sign in to comment.