Skip to content

Commit 50ce441

Browse files
authored
feat: adding ability to execute with extra args (backwards compatible) (#55)
* feat: adding ability to execute with extra args (backwards compatible) * cI: reverting algokit version
1 parent 0232bb6 commit 50ce441

File tree

25 files changed

+199
-74
lines changed

25 files changed

+199
-74
lines changed

examples/generators/production_python_smart_contract_python/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Run the following commands within the project folder:
3535
#### Terminal
3636
Directly manage and interact with your project using AlgoKit commands:
3737

38-
1. **Build Contracts**: `algokit project run build` compiles all smart contracts.
39-
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network.
38+
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
39+
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
40+
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
41+
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
4042

4143
#### VS Code
4244
For a seamless experience with breakpoint debugging and other features:

examples/generators/production_python_smart_contract_python/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
description = "Algorand smart contracts"
55
authors = ["None <None>"]
66
readme = "README.md"
7+
package-mode = false
78

89
[tool.poetry.dependencies]
910
python = "^3.12"

examples/generators/production_python_smart_contract_python/smart_contracts/__main__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424
root_path = Path(__file__).parent
2525

2626

27-
def main(action: str) -> None:
27+
def main(action: str, contract_name: str | None = None) -> None:
2828
artifact_path = root_path / "artifacts"
29+
30+
# Filter contracts if a specific contract name is provided
31+
filtered_contracts = [
32+
c for c in contracts if contract_name is None or c.name == contract_name
33+
]
34+
2935
match action:
3036
case "build":
31-
for contract in contracts:
37+
for contract in filtered_contracts:
3238
logger.info(f"Building app at {contract.path}")
3339
build(artifact_path / contract.name, contract.path)
3440
case "deploy":
35-
for contract in contracts:
41+
for contract in filtered_contracts:
3642
logger.info(f"Deploying app {contract.name}")
3743
output_dir = artifact_path / contract.name
3844
app_spec_file_name = next(
@@ -49,7 +55,7 @@ def main(action: str) -> None:
4955
if contract.deploy:
5056
deploy(app_spec_path, contract.deploy)
5157
case "all":
52-
for contract in contracts:
58+
for contract in filtered_contracts:
5359
logger.info(f"Building app at {contract.path}")
5460
app_spec_path = build(artifact_path / contract.name, contract.path)
5561
if contract.deploy:
@@ -58,7 +64,9 @@ def main(action: str) -> None:
5864

5965

6066
if __name__ == "__main__":
61-
if len(sys.argv) > 1:
67+
if len(sys.argv) > 2:
68+
main(sys.argv[1], sys.argv[2])
69+
elif len(sys.argv) > 1:
6270
main(sys.argv[1])
6371
else:
6472
main("all")

examples/generators/production_python_smart_contract_typescript/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Run the following commands within the project folder:
3535
#### Terminal
3636
Directly manage and interact with your project using AlgoKit commands:
3737

38-
1. **Build Contracts**: `algokit project run build` compiles all smart contracts.
39-
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network.
38+
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
39+
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
40+
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
41+
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
4042

4143
#### VS Code
4244
For a seamless experience with breakpoint debugging and other features:

examples/generators/production_python_smart_contract_typescript/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
description = "Algorand smart contracts"
55
authors = ["None <None>"]
66
readme = "README.md"
7+
package-mode = false
78

89
[tool.poetry.dependencies]
910
python = "^3.12"

examples/generators/production_python_smart_contract_typescript/smart_contracts/__main__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@
1818
root_path = Path(__file__).parent
1919

2020

21-
def main(action: str) -> None:
21+
def main(action: str, contract_name: str | None = None) -> None:
2222
artifact_path = root_path / "artifacts"
23+
24+
# Filter contracts if a specific contract name is provided
25+
filtered_contracts = [
26+
c for c in contracts if contract_name is None or c.name == contract_name
27+
]
28+
2329
match action:
2430
case "build":
25-
for contract in contracts:
31+
for contract in filtered_contracts:
2632
logger.info(f"Building app at {contract.path}")
2733
build(artifact_path / contract.name, contract.path)
2834

2935

3036
if __name__ == "__main__":
31-
if len(sys.argv) > 1:
37+
if len(sys.argv) > 2:
38+
main(sys.argv[1], sys.argv[2])
39+
elif len(sys.argv) > 1:
3240
main(sys.argv[1])
3341
else:
3442
main("build")

examples/generators/production_python_smart_contract_typescript/smart_contracts/index.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,41 @@ async function importDeployerIfExists(dir: string) {
2020
const deployerPath = path.resolve(dir, 'deploy-config')
2121
if (fs.existsSync(deployerPath + '.ts') || fs.existsSync(deployerPath + '.js')) {
2222
const deployer = await import(deployerPath)
23-
return deployer.deploy
23+
return { ...deployer, name: path.basename(dir) }
2424
}
25+
return null
2526
}
2627

2728
// get a list of all deployers from the subdirectories
2829
async function getDeployers() {
29-
const directories = fs.readdirSync(baseDir, { withFileTypes: true })
30-
.filter(dirent => dirent.isDirectory())
31-
.map(dirent => path.resolve(baseDir, dirent.name))
30+
const directories = fs
31+
.readdirSync(baseDir, { withFileTypes: true })
32+
.filter((dirent) => dirent.isDirectory())
33+
.map((dirent) => path.resolve(baseDir, dirent.name))
3234

33-
return Promise.all(directories.map(importDeployerIfExists))
35+
const deployers = await Promise.all(directories.map(importDeployerIfExists))
36+
return deployers.filter((deployer) => deployer !== null) // Filter out null values
3437
}
3538

3639
// execute all the deployers
3740
(async () => {
38-
const contractDeployers = (await getDeployers()).filter(Boolean)
41+
const contractName = process.argv.length > 2 ? process.argv[2] : undefined
42+
const contractDeployers = await getDeployers()
43+
44+
const filteredDeployers = contractName
45+
? contractDeployers.filter(deployer => deployer.name === contractName)
46+
: contractDeployers
47+
48+
if (contractName && filteredDeployers.length === 0) {
49+
console.warn(`No deployer found for contract name: ${contractName}`)
50+
return
51+
}
3952

40-
for (const deployer of contractDeployers) {
53+
for (const deployer of filteredDeployers) {
4154
try {
42-
await deployer()
55+
await deployer.deploy()
4356
} catch (e) {
44-
console.error(e)
57+
console.error(`Error deploying ${deployer.name}:`, e)
4558
}
4659
}
4760
})()

examples/generators/starter_python_smart_contract_python/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Run the following commands within the project folder:
3535
#### Terminal
3636
Directly manage and interact with your project using AlgoKit commands:
3737

38-
1. **Build Contracts**: `algokit project run build` compiles all smart contracts.
39-
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network.
38+
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
39+
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
40+
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
41+
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
4042

4143
#### VS Code
4244
For a seamless experience with breakpoint debugging and other features:

examples/generators/starter_python_smart_contract_python/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
description = "Algorand smart contracts"
55
authors = ["None <None>"]
66
readme = "README.md"
7+
package-mode = false
78

89
[tool.poetry.dependencies]
910
python = "^3.12"

examples/generators/starter_python_smart_contract_python/smart_contracts/__main__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424
root_path = Path(__file__).parent
2525

2626

27-
def main(action: str) -> None:
27+
def main(action: str, contract_name: str | None = None) -> None:
2828
artifact_path = root_path / "artifacts"
29+
30+
# Filter contracts if a specific contract name is provided
31+
filtered_contracts = [
32+
c for c in contracts if contract_name is None or c.name == contract_name
33+
]
34+
2935
match action:
3036
case "build":
31-
for contract in contracts:
37+
for contract in filtered_contracts:
3238
logger.info(f"Building app at {contract.path}")
3339
build(artifact_path / contract.name, contract.path)
3440
case "deploy":
35-
for contract in contracts:
41+
for contract in filtered_contracts:
3642
logger.info(f"Deploying app {contract.name}")
3743
output_dir = artifact_path / contract.name
3844
app_spec_file_name = next(
@@ -49,7 +55,7 @@ def main(action: str) -> None:
4955
if contract.deploy:
5056
deploy(app_spec_path, contract.deploy)
5157
case "all":
52-
for contract in contracts:
58+
for contract in filtered_contracts:
5359
logger.info(f"Building app at {contract.path}")
5460
app_spec_path = build(artifact_path / contract.name, contract.path)
5561
if contract.deploy:
@@ -58,7 +64,9 @@ def main(action: str) -> None:
5864

5965

6066
if __name__ == "__main__":
61-
if len(sys.argv) > 1:
67+
if len(sys.argv) > 2:
68+
main(sys.argv[1], sys.argv[2])
69+
elif len(sys.argv) > 1:
6270
main(sys.argv[1])
6371
else:
6472
main("all")

examples/generators/starter_python_smart_contract_typescript/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Run the following commands within the project folder:
3535
#### Terminal
3636
Directly manage and interact with your project using AlgoKit commands:
3737

38-
1. **Build Contracts**: `algokit project run build` compiles all smart contracts.
39-
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network.
38+
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
39+
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
40+
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
41+
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
4042

4143
#### VS Code
4244
For a seamless experience with breakpoint debugging and other features:

examples/generators/starter_python_smart_contract_typescript/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
description = "Algorand smart contracts"
55
authors = ["None <None>"]
66
readme = "README.md"
7+
package-mode = false
78

89
[tool.poetry.dependencies]
910
python = "^3.12"

examples/generators/starter_python_smart_contract_typescript/smart_contracts/__main__.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,25 @@
1818
root_path = Path(__file__).parent
1919

2020

21-
def main(action: str) -> None:
21+
def main(action: str, contract_name: str | None = None) -> None:
2222
artifact_path = root_path / "artifacts"
23+
24+
# Filter contracts if a specific contract name is provided
25+
filtered_contracts = [
26+
c for c in contracts if contract_name is None or c.name == contract_name
27+
]
28+
2329
match action:
2430
case "build":
25-
for contract in contracts:
31+
for contract in filtered_contracts:
2632
logger.info(f"Building app at {contract.path}")
2733
build(artifact_path / contract.name, contract.path)
2834

2935

3036
if __name__ == "__main__":
31-
if len(sys.argv) > 1:
37+
if len(sys.argv) > 2:
38+
main(sys.argv[1], sys.argv[2])
39+
elif len(sys.argv) > 1:
3240
main(sys.argv[1])
3341
else:
3442
main("build")

examples/generators/starter_python_smart_contract_typescript/smart_contracts/index.ts

+22-9
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,41 @@ async function importDeployerIfExists(dir: string) {
2020
const deployerPath = path.resolve(dir, 'deploy-config')
2121
if (fs.existsSync(deployerPath + '.ts') || fs.existsSync(deployerPath + '.js')) {
2222
const deployer = await import(deployerPath)
23-
return deployer.deploy
23+
return { ...deployer, name: path.basename(dir) }
2424
}
25+
return null
2526
}
2627

2728
// get a list of all deployers from the subdirectories
2829
async function getDeployers() {
29-
const directories = fs.readdirSync(baseDir, { withFileTypes: true })
30-
.filter(dirent => dirent.isDirectory())
31-
.map(dirent => path.resolve(baseDir, dirent.name))
30+
const directories = fs
31+
.readdirSync(baseDir, { withFileTypes: true })
32+
.filter((dirent) => dirent.isDirectory())
33+
.map((dirent) => path.resolve(baseDir, dirent.name))
3234

33-
return Promise.all(directories.map(importDeployerIfExists))
35+
const deployers = await Promise.all(directories.map(importDeployerIfExists))
36+
return deployers.filter((deployer) => deployer !== null) // Filter out null values
3437
}
3538

3639
// execute all the deployers
3740
(async () => {
38-
const contractDeployers = (await getDeployers()).filter(Boolean)
41+
const contractName = process.argv.length > 2 ? process.argv[2] : undefined
42+
const contractDeployers = await getDeployers()
43+
44+
const filteredDeployers = contractName
45+
? contractDeployers.filter(deployer => deployer.name === contractName)
46+
: contractDeployers
47+
48+
if (contractName && filteredDeployers.length === 0) {
49+
console.warn(`No deployer found for contract name: ${contractName}`)
50+
return
51+
}
3952

40-
for (const deployer of contractDeployers) {
53+
for (const deployer of filteredDeployers) {
4154
try {
42-
await deployer()
55+
await deployer.deploy()
4356
} catch (e) {
44-
console.error(e)
57+
console.error(`Error deploying ${deployer.name}:`, e)
4558
}
4659
}
4760
})()

examples/production_python/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ Run the following commands within the project folder:
3535
#### Terminal
3636
Directly manage and interact with your project using AlgoKit commands:
3737

38-
1. **Build Contracts**: `algokit project run build` compiles all smart contracts.
39-
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network.
38+
1. **Build Contracts**: `algokit project run build` compiles all smart contracts. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
39+
For example: `algokit project run build -- hello_world` will only build the `hello_world` contract.
40+
2. **Deploy**: Use `algokit project deploy localnet` to deploy contracts to the local network. You can also specify a specific contract by passing the name of the contract folder as an extra argument.
41+
For example: `algokit project deploy localnet -- hello_world` will only deploy the `hello_world` contract.
4042

4143
#### VS Code
4244
For a seamless experience with breakpoint debugging and other features:

examples/production_python/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
description = "Algorand smart contracts"
55
authors = ["None <None>"]
66
readme = "README.md"
7+
package-mode = false
78

89
[tool.poetry.dependencies]
910
python = "^3.12"

examples/production_python/smart_contracts/__main__.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,21 @@
2424
root_path = Path(__file__).parent
2525

2626

27-
def main(action: str) -> None:
27+
def main(action: str, contract_name: str | None = None) -> None:
2828
artifact_path = root_path / "artifacts"
29+
30+
# Filter contracts if a specific contract name is provided
31+
filtered_contracts = [
32+
c for c in contracts if contract_name is None or c.name == contract_name
33+
]
34+
2935
match action:
3036
case "build":
31-
for contract in contracts:
37+
for contract in filtered_contracts:
3238
logger.info(f"Building app at {contract.path}")
3339
build(artifact_path / contract.name, contract.path)
3440
case "deploy":
35-
for contract in contracts:
41+
for contract in filtered_contracts:
3642
logger.info(f"Deploying app {contract.name}")
3743
output_dir = artifact_path / contract.name
3844
app_spec_file_name = next(
@@ -49,7 +55,7 @@ def main(action: str) -> None:
4955
if contract.deploy:
5056
deploy(app_spec_path, contract.deploy)
5157
case "all":
52-
for contract in contracts:
58+
for contract in filtered_contracts:
5359
logger.info(f"Building app at {contract.path}")
5460
app_spec_path = build(artifact_path / contract.name, contract.path)
5561
if contract.deploy:
@@ -58,7 +64,9 @@ def main(action: str) -> None:
5864

5965

6066
if __name__ == "__main__":
61-
if len(sys.argv) > 1:
67+
if len(sys.argv) > 2:
68+
main(sys.argv[1], sys.argv[2])
69+
elif len(sys.argv) > 1:
6270
main(sys.argv[1])
6371
else:
6472
main("all")

0 commit comments

Comments
 (0)