Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
feat: removing .env files and propagating conventions from python tem…
Browse files Browse the repository at this point in the history
…plate (#70)

* feat: removing .env files and propagating conventions from python template

* chore: tmp changing the algokit instance
  • Loading branch information
aorumbayev authored Jul 8, 2024
1 parent 2373a7f commit 99af720
Show file tree
Hide file tree
Showing 69 changed files with 396 additions and 116 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: pipx install poetry

- name: Install algokit
run: pipx install algokit
run: pipx install git+https://github.com/algorandfoundation/algokit-cli.git@fix/copier-answers-lookup

- name: Run algokit localnet
run: algokit localnet start
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[algokit]
min_version = "v2.0.0"

[generate.smart_contract]
[generate.smart-contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[generate.env-file]
description = "Generate a new generic or Algorand network specific .env file"
path = ".algokit/generators/create_env_file"

[project]
type = 'contract'
name = 'production_beaker_smart_contract_python'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_tasks:
- "echo '==== Successfully generated new .env file 🚀 ===='"

use_generic_env:
type: bool
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
placeholder: "true"
default: "true"

target_network:
type: str
help: Name of your target network.
choices:
- mainnet
- testnet
- localnet
- custom
default: "localnet"
when: "{{ not use_generic_env }}"

custom_network_name:
type: str
help: Name of your custom Algorand network.
placeholder: "custom"
when: "{{ not use_generic_env and target_network == 'custom' }}"

_templates_suffix: ".j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
ALGOD_PORT={YOUR_ALGOD_PORT}
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_SERVER=https://mainnet-api.algonode.cloud
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run the following commands within the project folder:
- **Install Poetry**: Required for Python dependency management. [Installation Guide](https://python-poetry.org/docs/#installation). Verify with `poetry -V` to see version `1.2`+.
- **Setup Project**: Execute `algokit project bootstrap all` to:
- Install dependencies and setup a Python virtual environment in `.venv`.
- Copy `.env.template` to `.env`.
- Configure '.env' files if needed (see [AlgoKit Generators](#algokit-generators)).
- **Start LocalNet**: Use `algokit localnet start` to initiate a local Algorand network.

### Development Workflow
Expand Down Expand Up @@ -58,7 +58,25 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
## AlgoKit Workspaces and Project Management
This project supports both standalone and monorepo setups through AlgoKit workspaces. Leverage [`algokit project run`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/run.md) commands for efficient monorepo project orchestration and management across multiple projects within a workspace.

> For guidance on `smart_contracts` folder and adding new contracts to the project please see [README](smart_contracts/README.md) on the respective folder.### Continuous Integration / Continuous Deployment (CI/CD)
## AlgoKit Generators

This template provides a set of [algokit generators](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) that allow you to further modify the project instantiated from the template to fit your needs, as well as giving you a base to build your own extensions to invoke via the `algokit generate` command.

### Generate Smart Contract

By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:

1. From the root of the project (`../`) execute `algokit generate smart-contract`. This will create a new starter smart contract and deployment configuration file under `{your_contract_name}` subfolder in the `smart_contracts` directory.
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy_config.py`file.
3. `config.py` file will automatically build all contracts in the `smart_contracts` directory. If you want to build specific contracts manually, modify the default code provided by the template in `config.py` file.

> Please note, above is just a suggested convention tailored for the base configuration and structure of this template. The default code supplied by the template in `config.py` and `index.ts` (if using ts clients) files are tailored for the suggested convention. You are free to modify the structure and naming conventions as you see fit.
### Generate '.env' files

By default the template instance would not contain any env files. Using [`algokit project deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/deploy.md) against `localnet` | `testnet` | `mainnet` will use default values for `algod` and `indexer` unless overwritten via `.env` or `.env.{target_network}`.

To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`### Continuous Integration / Continuous Deployment (CI/CD)

This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [.github/workflows](`.github/workflows`) folder.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
from pathlib import Path

import pytest
from algokit_utils import (
get_algod_client,
get_default_localnet_config,
get_indexer_client,
is_localnet,
)
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from dotenv import load_dotenv


@pytest.fixture(autouse=True, scope="session")
def environment_fixture() -> None:
env_path = Path(__file__).parent.parent / ".env.localnet"
load_dotenv(env_path)
# Uncomment if you want to load network specific or generic .env file
# @pytest.fixture(autouse=True, scope="session")
# def environment_fixture() -> None:
# env_path = Path(__file__).parent.parent / ".env"
# load_dotenv(env_path)


@pytest.fixture(scope="session")
def algod_client() -> AlgodClient:
client = get_algod_client()

# you can remove this assertion to test on other networks,
# included here to prevent accidentally running against other networks
assert is_localnet(client)
# by default we are using localnet algod
client = get_algod_client(get_default_localnet_config("algod"))
return client


@pytest.fixture(scope="session")
def indexer_client() -> IndexerClient:
return get_indexer_client()
return get_indexer_client(get_default_localnet_config("indexer"))
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[algokit]
min_version = "v2.0.0"

[generate.smart_contract]
[generate.smart-contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[generate.env-file]
description = "Generate a new generic or Algorand network specific .env file"
path = ".algokit/generators/create_env_file"

[project]
type = 'contract'
name = 'production_beaker_smart_contract_typescript'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_tasks:
- "echo '==== Successfully generated new .env file 🚀 ===='"

use_generic_env:
type: bool
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
placeholder: "true"
default: "true"

target_network:
type: str
help: Name of your target network.
choices:
- mainnet
- testnet
- localnet
- custom
default: "localnet"
when: "{{ not use_generic_env }}"

custom_network_name:
type: str
help: Name of your custom Algorand network.
placeholder: "custom"
when: "{{ not use_generic_env and target_network == 'custom' }}"

_templates_suffix: ".j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
ALGOD_PORT={YOUR_ALGOD_PORT}
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_SERVER=https://mainnet-api.algonode.cloud
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run the following commands within the project folder:
- **Install Poetry**: Required for Python dependency management. [Installation Guide](https://python-poetry.org/docs/#installation). Verify with `poetry -V` to see version `1.2`+.
- **Setup Project**: Execute `algokit project bootstrap all` to:
- Install dependencies and setup a Python virtual environment in `.venv`.
- Copy `.env.template` to `.env`.
- Configure '.env' files if needed (see [AlgoKit Generators](#algokit-generators)).
- **Start LocalNet**: Use `algokit localnet start` to initiate a local Algorand network.

### Development Workflow
Expand Down Expand Up @@ -58,7 +58,26 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
## AlgoKit Workspaces and Project Management
This project supports both standalone and monorepo setups through AlgoKit workspaces. Leverage [`algokit project run`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/run.md) commands for efficient monorepo project orchestration and management across multiple projects within a workspace.

> For guidance on `smart_contracts` folder and adding new contracts to the project please see [README](smart_contracts/README.md) on the respective folder.### Continuous Integration / Continuous Deployment (CI/CD)
## AlgoKit Generators

This template provides a set of [algokit generators](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) that allow you to further modify the project instantiated from the template to fit your needs, as well as giving you a base to build your own extensions to invoke via the `algokit generate` command.

### Generate Smart Contract

By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:

1. From the root of the project (`../`) execute `algokit generate smart-contract`. This will create a new starter smart contract and deployment configuration file under `{your_contract_name}` subfolder in the `smart_contracts` directory.
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy-config.ts`file.
3. `config.py` file will automatically build all contracts in the `smart_contracts` directory. If you want to build specific contracts manually, modify the default code provided by the template in `config.py` file.
4. Since you are generating a TypeScript client, you also need to reference your contract deployment logic in `index.ts` file. However, similar to config.py, by default, `index.ts` will auto import all TypeScript deployment files under `smart_contracts` directory. If you want to manually import specific contracts, modify the default code provided by the template in `index.ts` file.

> Please note, above is just a suggested convention tailored for the base configuration and structure of this template. The default code supplied by the template in `config.py` and `index.ts` (if using ts clients) files are tailored for the suggested convention. You are free to modify the structure and naming conventions as you see fit.
### Generate '.env' files

By default the template instance would not contain any env files. Using [`algokit project deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/deploy.md) against `localnet` | `testnet` | `mainnet` will use default values for `algod` and `indexer` unless overwritten via `.env` or `.env.{target_network}`.

To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`### Continuous Integration / Continuous Deployment (CI/CD)

This project uses [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions) to define CI/CD workflows, which are located in the [.github/workflows](`.github/workflows`) folder.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[algokit]
min_version = "v2.0.0"

[generate.smart_contract]
[generate.smart-contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[generate.env-file]
description = "Generate a new generic or Algorand network specific .env file"
path = ".algokit/generators/create_env_file"

[project]
type = 'contract'
name = 'starter_beaker_smart_contract_python'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_tasks:
- "echo '==== Successfully generated new .env file 🚀 ===='"

use_generic_env:
type: bool
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
placeholder: "true"
default: "true"

target_network:
type: str
help: Name of your target network.
choices:
- mainnet
- testnet
- localnet
- custom
default: "localnet"
when: "{{ not use_generic_env }}"

custom_network_name:
type: str
help: Name of your custom Algorand network.
placeholder: "custom"
when: "{{ not use_generic_env and target_network == 'custom' }}"

_templates_suffix: ".j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
ALGOD_PORT={YOUR_ALGOD_PORT}
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_SERVER=https://mainnet-api.algonode.cloud
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

This file was deleted.

22 changes: 20 additions & 2 deletions examples/generators/starter_beaker_smart_contract_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Run the following commands within the project folder:
- **Install Poetry**: Required for Python dependency management. [Installation Guide](https://python-poetry.org/docs/#installation). Verify with `poetry -V` to see version `1.2`+.
- **Setup Project**: Execute `algokit project bootstrap all` to:
- Install dependencies and setup a Python virtual environment in `.venv`.
- Copy `.env.template` to `.env`.
- Configure '.env' files if needed (see [AlgoKit Generators](#algokit-generators)).
- **Start LocalNet**: Use `algokit localnet start` to initiate a local Algorand network.

### Development Workflow
Expand Down Expand Up @@ -58,7 +58,25 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
## AlgoKit Workspaces and Project Management
This project supports both standalone and monorepo setups through AlgoKit workspaces. Leverage [`algokit project run`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/run.md) commands for efficient monorepo project orchestration and management across multiple projects within a workspace.

> For guidance on `smart_contracts` folder and adding new contracts to the project please see [README](smart_contracts/README.md) on the respective folder.
## AlgoKit Generators

This template provides a set of [algokit generators](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/generate.md) that allow you to further modify the project instantiated from the template to fit your needs, as well as giving you a base to build your own extensions to invoke via the `algokit generate` command.

### Generate Smart Contract

By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:

1. From the root of the project (`../`) execute `algokit generate smart-contract`. This will create a new starter smart contract and deployment configuration file under `{your_contract_name}` subfolder in the `smart_contracts` directory.
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy_config.py`file.
3. `config.py` file will automatically build all contracts in the `smart_contracts` directory. If you want to build specific contracts manually, modify the default code provided by the template in `config.py` file.

> Please note, above is just a suggested convention tailored for the base configuration and structure of this template. The default code supplied by the template in `config.py` and `index.ts` (if using ts clients) files are tailored for the suggested convention. You are free to modify the structure and naming conventions as you see fit.
### Generate '.env' files

By default the template instance would not contain any env files. Using [`algokit project deploy`](https://github.com/algorandfoundation/algokit-cli/blob/main/docs/features/project/deploy.md) against `localnet` | `testnet` | `mainnet` will use default values for `algod` and `indexer` unless overwritten via `.env` or `.env.{target_network}`.

To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`

# Tools

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
[algokit]
min_version = "v2.0.0"

[generate.smart_contract]
[generate.smart-contract]
description = "Adds new smart contract to existing project"
path = ".algokit/generators/create_contract"

[generate.env-file]
description = "Generate a new generic or Algorand network specific .env file"
path = ".algokit/generators/create_env_file"

[project]
type = 'contract'
name = 'starter_beaker_smart_contract_typescript'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
_tasks:
- "echo '==== Successfully generated new .env file 🚀 ===='"

use_generic_env:
type: bool
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
placeholder: "true"
default: "true"

target_network:
type: str
help: Name of your target network.
choices:
- mainnet
- testnet
- localnet
- custom
default: "localnet"
when: "{{ not use_generic_env }}"

custom_network_name:
type: str
help: Name of your custom Algorand network.
placeholder: "custom"
when: "{{ not use_generic_env and target_network == 'custom' }}"

_templates_suffix: ".j2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
ALGOD_PORT={YOUR_ALGOD_PORT}
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file contains algorand network settings for interacting with testnet via algonode
ALGOD_SERVER=https://mainnet-api.algonode.cloud
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

This file was deleted.

Loading

0 comments on commit 99af720

Please sign in to comment.