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

Commit

Permalink
Merge pull request #76 from algorandfoundation/deprecate-template
Browse files Browse the repository at this point in the history
Added task to copier to warn that template is deprecated and updated …
  • Loading branch information
lempira authored Nov 26, 2024
2 parents 9ef75ee + 159fe64 commit 435a1a2
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
<a target="_blank" href="https://developer.algorand.org/algokit/"><img src="https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%2Falgorandfoundation%2Falgokit-beaker-default-template&countColor=%2300dc94&style=flat" /></a>
</p>

---
# DEPRECATED
This template has been deprecated. Beaker for Algorand Smart Contract development is no longer supported. Please use Algorand Python instead. The Algorand Python template can be found at https://github.com/algorandfoundation/algokit-python-template.

---

This template provides a production-ready baseline for developing and deploying [Beaker](https://github.com/algorand-devrel/beaker) smart contracts.
Expand Down
51 changes: 38 additions & 13 deletions copier.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
_subdirectory: template_content
_templates_suffix: ".jinja"

use_deprecated_template:
type: bool
help: |
WARNING: This template has been deprecated. Beaker for Algorand Smart Contract development is no longer supported.
Please use Algorand Python instead. The Algorand Python template can be found at https://github.com/algorandfoundation/algokit-python-template
Do you still want to proceed with using the deprecated template?
default: no

_tasks:
- '"{{ python_path if python_path else _copier_python }}" post_init.py {{ use_deprecated_template }} {{ use_workspace }}'

use_workspace:
type: bool
when: false # never prompted to user explicitly, instead expect cli to auto fill (supported cli versions > v1.13.x)
when: false # never prompted to user explicitly, expect CLI to auto-fill
help: Automatically filled by AlgoKit CLI (>1.13.x) - passes the --workspace/--no-workspace flag's value, can be used to reason whether this template is currently being instantiated as part of a workspace or not.
default: no

# Auto determined by algokit-cli from v1.11.3 to allow execution of python script
# in binary mode.
python_path:
type: str
help: Path to the sys.executable.
when: false

# questions
project_name:
type: str
help: Name for this project.
placeholder: "algorand-app"
when: "{{ use_deprecated_template }}"

author_name:
type: str
help: Package author name
placeholder: "Your Name"
default: "Your Name"
when: "{{ use_deprecated_template }}"

author_email:
type: str
help: Package author email
placeholder: "[email protected]"
default: "[email protected]"
when: "{{ use_deprecated_template }}"

contract_name:
type: str
Expand All @@ -34,6 +55,7 @@ contract_name:
{% if not (contract_name | regex_search('^[a-z]+(?:_[a-z]+)*$')) %}
contract_name must be formatted in snake case.
{% endif %}
when: "{{ use_deprecated_template }}"

preset_name:
type: str
Expand All @@ -43,6 +65,7 @@ preset_name:
"Production - for confidently deploying to MainNet and/or more complex projects": "production"
"Custom - for tailoring the template output to your needs": "custom"
default: "starter"
when: "{{ use_deprecated_template }}"

deployment_language:
type: str
Expand All @@ -51,41 +74,43 @@ deployment_language:
Python: "python"
TypeScript: "typescript"
default: "python"
when: "{{ use_deprecated_template }}"

ide_vscode:
type: bool
help: Do you want to add VSCode configuration?
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
default: yes

code_tours:
type: bool
help: Do you want to add interactive VSCode CodeTour walkthrough?
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
default: yes

ide_jetbrains:
type: bool
help: Do you want to add JetBrains configuration (primarily optimized for PyCharm CE)?
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"
when: "{{ use_deprecated_template }}"

use_python_pytest:
type: bool
when: "{{ deployment_language == 'python' and preset_name == 'custom' }}"
when: "{{ deployment_language == 'python' and preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to include unit tests (via pytest)?
default: "{{ 'yes' if preset_name == 'production' and deployment_language == 'python' else 'no' }}"

use_typescript_jest:
type: bool
when: "{{ deployment_language == 'typescript' and preset_name == 'custom' }}"
when: "{{ deployment_language == 'typescript' and preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to include unit tests (via jest)?
default: "{{ 'yes' if preset_name == 'production' and deployment_language == 'typescript' else 'no' }}"

python_linter:
type: str
help: Do you want to use a Python linter?
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
choices:
Ruff: "ruff"
Flake8: "flake8"
Expand All @@ -95,35 +120,35 @@ python_linter:
use_python_black:
type: bool
help: Do you want to use a Python formatter (via Black)?
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_python_mypy:
type: bool
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to use a Python type checker (via mypy)?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_python_pip_audit:
type: bool
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to include Python dependency vulnerability scanning (via pip-audit)?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_github_actions:
type: bool
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to include Github Actions workflows for build and testnet deployment?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_pre_commit:
type: bool
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to include pre-commit for linting, type checking and formatting?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"

use_dispenser:
type: bool
when: "{{ preset_name == 'custom' }}"
when: "{{ preset_name == 'custom' and use_deprecated_template }}"
help: Do you want to fund your deployment account using an optional dispenser account?
default: "{{ 'yes' if preset_name == 'production' else 'no' }}"
40 changes: 40 additions & 0 deletions template_content/post_init.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import shutil
import sys
from pathlib import Path
import os


def main():
# Get the use_deprecated_template argument
use_deprecated_template = sys.argv[1].lower() in ("true", "yes", "1", "t", "y")
use_workspace = sys.argv[2].lower() in ("true", "yes", "1", "t", "y")

if not use_deprecated_template:
# Get the parent directory of this script which should be the generated project root
project_dir = Path(__file__).parent
project_dir = project_dir.parent.parent if use_workspace else project_dir

# Print warning
print("WARNING: Template generation cancelled!\n")
print(
"This template is deprecated. Use Algorand Python instead: https://github.com/algorandfoundation/algokit-python-template\n"
)

if project_dir.exists():
try:
os.chdir(project_dir.parent)
shutil.rmtree(project_dir)
except Exception as e:
print(
f"Failed to clean up {project_dir}. You will have to manually delete the project folder. Error: {str(e)}",
file=sys.stderr,
)

sys.exit(1)

# If we get here, template was approved to be used
print("Proceeding with deprecated template generation...")


if __name__ == "__main__":
main()
16 changes: 16 additions & 0 deletions tests/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def run_generator(


@pytest.mark.parametrize("language", ["python", "typescript"])
@pytest.mark.skip(reason="This test is deprecated since the template is deprecated")
def test_smart_contract_generator_default_starter_preset(
language: str, working_dir: Path
) -> None:
Expand Down Expand Up @@ -207,6 +208,7 @@ def test_smart_contract_generator_default_starter_preset(


@pytest.mark.parametrize("language", ["python", "typescript"])
@pytest.mark.skip(reason="This test is deprecated since the template is deprecated")
def test_smart_contract_generator_default_production_preset(
language: str, working_dir: Path
) -> None:
Expand Down Expand Up @@ -235,3 +237,17 @@ def test_smart_contract_generator_default_production_preset(

response = check_codebase(working_dir, test_name)
assert response.returncode == 0, response.stdout


def test_template_fail() -> None:
test_name = "production_beaker_smart_contract_fail"

response = run_init(
root,
test_name,
answers={
"preset_name": "starter",
"deployment_language": "python",
},
)
assert response.returncode == 1, response.stdout
1 change: 1 addition & 0 deletions tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def get_questions_from_copier_yaml(


@pytest.mark.parametrize(("question_name", "answer"), get_questions_from_copier_yaml())
@pytest.mark.skip(reason="This test is deprecated since the template is deprecated")
def test_parameters(working_dir: Path, question_name: str, answer: str | bool) -> None:
response = run_init_kwargs(working_dir, **{question_name: answer})
assert response.returncode == 0, response.stdout

0 comments on commit 435a1a2

Please sign in to comment.