Skip to content

Commit f27e111

Browse files
feat: removing .env files, adding env-file generator (#31)
* feat: refining template, removing env files, adding new env file generator * docs: refining docs * docs: refining docs * chore: apply suggestions from code review Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au> * chore: minor tweaks in gitattributes * chore: hiding copier answers file --------- Co-authored-by: Neil Campbell <neil.campbell@makerx.com.au>
1 parent 3880851 commit f27e111

File tree

75 files changed

+401
-190
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+401
-190
lines changed

examples/generators/production_python_smart_contract_python/.algokit.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[algokit]
22
min_version = "v2.0.0"
33

4-
[generate.smart_contract]
5-
description = "Adds new smart contract to existing project"
4+
[generate.smart-contract]
5+
description = "Generate a new smart contract for existing project"
66
path = ".algokit/generators/create_contract"
77

8+
[generate.env-file]
9+
description = "Generate a new generic or Algorand network specific .env file"
10+
path = ".algokit/generators/create_env_file"
11+
812
[project]
913
type = 'contract'
1014
name = 'production_python_smart_contract_python'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
_tasks:
2+
- "echo '==== Successfully generated new .env file 🚀 ===='"
3+
4+
use_generic_env:
5+
type: bool
6+
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
7+
placeholder: "true"
8+
default: "true"
9+
10+
target_network:
11+
type: str
12+
help: Name of your target network.
13+
choices:
14+
- mainnet
15+
- testnet
16+
- localnet
17+
- custom
18+
default: "localnet"
19+
when: "{{ not use_generic_env }}"
20+
21+
custom_network_name:
22+
type: str
23+
help: Name of your custom Algorand network.
24+
placeholder: "custom"
25+
when: "{{ not use_generic_env and target_network == 'custom' }}"
26+
27+
_templates_suffix: ".j2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
3+
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
4+
ALGOD_PORT={YOUR_ALGOD_PORT}
5+
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
6+
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
7+
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_SERVER=https://mainnet-api.algonode.cloud
3+
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

examples/generators/production_python_smart_contract_python/.algokit/generators/create_env_file/{% if use_generic_env %}.env.j2{% endif %}

Whitespace-only changes.

examples/generators/production_python_smart_contract_python/.env.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/generators/production_python_smart_contract_python/README.md

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

3434
### Development Workflow
@@ -58,7 +58,25 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
5858
## AlgoKit Workspaces and Project Management
5959
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.
6060

61-
> 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)
61+
## AlgoKit Generators
62+
63+
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.
64+
65+
### Generate Smart Contract
66+
67+
By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:
68+
69+
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.
70+
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy_config.py`file.
71+
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.
72+
73+
> 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.
74+
75+
### Generate '.env' files
76+
77+
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}`.
78+
79+
To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`### Continuous Integration / Continuous Deployment (CI/CD)
6280

6381
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.
6482

examples/generators/production_python_smart_contract_python/smart_contracts/README.md

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
from pathlib import Path
2-
31
import pytest
42
from algokit_utils import (
53
get_algod_client,
4+
get_default_localnet_config,
65
get_indexer_client,
7-
is_localnet,
86
)
97
from algosdk.v2client.algod import AlgodClient
108
from algosdk.v2client.indexer import IndexerClient
11-
from dotenv import load_dotenv
12-
139

14-
@pytest.fixture(autouse=True, scope="session")
15-
def environment_fixture() -> None:
16-
env_path = Path(__file__).parent.parent / ".env.localnet"
17-
load_dotenv(env_path)
10+
# Uncomment if you want to load network specific or generic .env file
11+
# @pytest.fixture(autouse=True, scope="session")
12+
# def environment_fixture() -> None:
13+
# env_path = Path(__file__).parent.parent / ".env"
14+
# load_dotenv(env_path)
1815

1916

2017
@pytest.fixture(scope="session")
2118
def algod_client() -> AlgodClient:
22-
client = get_algod_client()
23-
24-
# you can remove this assertion to test on other networks,
25-
# included here to prevent accidentally running against other networks
26-
assert is_localnet(client)
19+
# by default we are using localnet algod
20+
client = get_algod_client(get_default_localnet_config("algod"))
2721
return client
2822

2923

3024
@pytest.fixture(scope="session")
3125
def indexer_client() -> IndexerClient:
32-
return get_indexer_client()
26+
return get_indexer_client(get_default_localnet_config("indexer"))

examples/generators/production_python_smart_contract_typescript/.algokit.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[algokit]
22
min_version = "v2.0.0"
33

4-
[generate.smart_contract]
5-
description = "Adds new smart contract to existing project"
4+
[generate.smart-contract]
5+
description = "Generate a new smart contract for existing project"
66
path = ".algokit/generators/create_contract"
77

8+
[generate.env-file]
9+
description = "Generate a new generic or Algorand network specific .env file"
10+
path = ".algokit/generators/create_env_file"
11+
812
[project]
913
type = 'contract'
1014
name = 'production_python_smart_contract_typescript'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
_tasks:
2+
- "echo '==== Successfully generated new .env file 🚀 ===='"
3+
4+
use_generic_env:
5+
type: bool
6+
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
7+
placeholder: "true"
8+
default: "true"
9+
10+
target_network:
11+
type: str
12+
help: Name of your target network.
13+
choices:
14+
- mainnet
15+
- testnet
16+
- localnet
17+
- custom
18+
default: "localnet"
19+
when: "{{ not use_generic_env }}"
20+
21+
custom_network_name:
22+
type: str
23+
help: Name of your custom Algorand network.
24+
placeholder: "custom"
25+
when: "{{ not use_generic_env and target_network == 'custom' }}"
26+
27+
_templates_suffix: ".j2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
3+
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
4+
ALGOD_PORT={YOUR_ALGOD_PORT}
5+
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
6+
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
7+
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_SERVER=https://mainnet-api.algonode.cloud
3+
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

examples/generators/production_python_smart_contract_typescript/.algokit/generators/create_env_file/{% if use_generic_env %}.env.j2{% endif %}

Whitespace-only changes.

examples/generators/production_python_smart_contract_typescript/.env.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/generators/production_python_smart_contract_typescript/README.md

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

3434
### Development Workflow
@@ -58,7 +58,26 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
5858
## AlgoKit Workspaces and Project Management
5959
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.
6060

61-
> 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)
61+
## AlgoKit Generators
62+
63+
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.
64+
65+
### Generate Smart Contract
66+
67+
By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:
68+
69+
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.
70+
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy-config.ts`file.
71+
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.
72+
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.
73+
74+
> 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.
75+
76+
### Generate '.env' files
77+
78+
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}`.
79+
80+
To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`### Continuous Integration / Continuous Deployment (CI/CD)
6281

6382
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.
6483

examples/generators/production_python_smart_contract_typescript/smart_contracts/README.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/generators/starter_python_smart_contract_python/.algokit.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[algokit]
22
min_version = "v2.0.0"
33

4-
[generate.smart_contract]
5-
description = "Adds new smart contract to existing project"
4+
[generate.smart-contract]
5+
description = "Generate a new smart contract for existing project"
66
path = ".algokit/generators/create_contract"
77

8+
[generate.env-file]
9+
description = "Generate a new generic or Algorand network specific .env file"
10+
path = ".algokit/generators/create_env_file"
11+
812
[project]
913
type = 'contract'
1014
name = 'starter_python_smart_contract_python'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
_tasks:
2+
- "echo '==== Successfully generated new .env file 🚀 ===='"
3+
4+
use_generic_env:
5+
type: bool
6+
help: Create generic empty .env file (true) or create a network specific .env.{network_name} file (false).
7+
placeholder: "true"
8+
default: "true"
9+
10+
target_network:
11+
type: str
12+
help: Name of your target network.
13+
choices:
14+
- mainnet
15+
- testnet
16+
- localnet
17+
- custom
18+
default: "localnet"
19+
when: "{{ not use_generic_env }}"
20+
21+
custom_network_name:
22+
type: str
23+
help: Name of your custom Algorand network.
24+
placeholder: "custom"
25+
when: "{{ not use_generic_env and target_network == 'custom' }}"
26+
27+
_templates_suffix: ".j2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_TOKEN={YOUR_ALGOD_TOKEN}
3+
ALGOD_SERVER={YOUR_ALGOD_SERVER_URL}
4+
ALGOD_PORT={YOUR_ALGOD_PORT}
5+
INDEXER_TOKEN={YOUR_INDEXER_TOKEN}
6+
INDEXER_SERVER={YOUR_INDEXER_SERVER_URL}
7+
INDEXER_PORT={YOUR_INDEXER_PORT}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# this file contains algorand network settings for interacting with testnet via algonode
2+
ALGOD_SERVER=https://mainnet-api.algonode.cloud
3+
INDEXER_SERVER=https://mainnet-idx.algonode.cloud

examples/generators/starter_python_smart_contract_python/.algokit/generators/create_env_file/{% if use_generic_env %}.env.j2{% endif %}

Whitespace-only changes.

examples/generators/starter_python_smart_contract_python/.env.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/generators/starter_python_smart_contract_python/README.md

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

3434
### Development Workflow
@@ -58,7 +58,25 @@ While primarily optimized for VS Code, JetBrains IDEs are supported:
5858
## AlgoKit Workspaces and Project Management
5959
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.
6060

61-
> For guidance on `smart_contracts` folder and adding new contracts to the project please see [README](smart_contracts/README.md) on the respective folder.
61+
## AlgoKit Generators
62+
63+
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.
64+
65+
### Generate Smart Contract
66+
67+
By default the template creates a single `HelloWorld` contract under hello_world folder in the `smart_contracts` directory. To add a new contract:
68+
69+
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.
70+
2. Each contract potentially has different creation parameters and deployment steps. Hence, you need to define your deployment logic in `deploy_config.py`file.
71+
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.
72+
73+
> 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.
74+
75+
### Generate '.env' files
76+
77+
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}`.
78+
79+
To generate a new `.env` or `.env.{target_network}` file, run `algokit generate env-file`
6280

6381
# Tools
6482

0 commit comments

Comments
 (0)