Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding minimum required version for algokit. #273

Merged
merged 10 commits into from
Jun 2, 2023
Empty file added algokit.toml
Empty file.
4 changes: 2 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ questionary = "^1.10.0"
pyclip = "^0.7.0"
shellingham = "^1.5.0.post1"
algokit-client-generator = "^0.1.0b6"
tomli = "^2.0.1"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
Expand Down
9 changes: 8 additions & 1 deletion src/algokit/cli/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@

import click

from algokit.core.bootstrap import bootstrap_any_including_subdirs, bootstrap_env, bootstrap_npm, bootstrap_poetry
from algokit.core.bootstrap import (
bootstrap_any_including_subdirs,
bootstrap_env,
bootstrap_npm,
bootstrap_poetry,
version_check,
)

logger = logging.getLogger(__name__)

Expand All @@ -24,6 +30,7 @@ def bootstrap_group() -> None:
def bootstrap_all() -> None:
cwd = Path.cwd()
bootstrap_any_including_subdirs(cwd)
version_check(cwd)
logger.info(f"Finished bootstrapping {cwd}")


Expand Down
24 changes: 24 additions & 0 deletions src/algokit/core/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from shutil import which

import click
import tomli
from packaging import version

from algokit.core import proc, questionary_extensions
from algokit.core.conf import get_current_package_version

ENV_TEMPLATE = ".env.template"
logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -218,3 +221,24 @@ def _get_base_python_path() -> str | None:
return str(candidate_path)
# give up, we tried...
return this_python


def version_check(cwd: Path) -> None:
"""
Checks the current version of AlgoKit against the minimum required version specified in algokit.toml.
daniel-makerx marked this conversation as resolved.
Show resolved Hide resolved
"""
try:
with Path.open(cwd / ".algokit.toml", "rb") as f:
daniel-makerx marked this conversation as resolved.
Show resolved Hide resolved
config = tomli.load(f)
min_version = config["algokit"]["min_version"]
algokit_version = get_current_package_version()
if version.parse(algokit_version) < version.parse(min_version):
logger.warning(
f"This template requires algokit version {min_version} or higher, "
daniel-makerx marked this conversation as resolved.
Show resolved Hide resolved
f"but you have algokit version {algokit_version}. "
f"Please update algokit."
daniel-makerx marked this conversation as resolved.
Show resolved Hide resolved
)
except FileNotFoundError:
logger.debug("No algokit.toml file found in the current directory.")
except KeyError:
logger.debug("No 'min_version' specified in algokit.toml file.")