Skip to content

Commit 9ef7b51

Browse files
authored
fix: raise min required copier version to 3.6.0 (#623)
* fix: raise min required copier version to 3.6.0 * refactor: fix failing tests; add verbose mode for doctor command * chore: addressing pr comments
1 parent 44984fd commit 9ef7b51

File tree

8 files changed

+94
-18
lines changed

8 files changed

+94
-18
lines changed

.vscode/launch.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@
1010
"cwd": "${workspaceFolder}",
1111
"request": "launch",
1212
"module": "debug",
13-
"justMyCode": true,
13+
"justMyCode": false,
1414
"console": "integratedTerminal"
15+
},
16+
{
17+
"name": "Python: Debug Pytest",
18+
"type": "debugpy",
19+
"request": "launch",
20+
"program": "${file}",
21+
"purpose": ["debug-test"],
22+
"console": "integratedTerminal",
23+
"justMyCode": false,
24+
"env": {
25+
"PYTHONPATH": "${workspaceFolder}/src",
26+
"PYTEST_ADDOPTS": "--no-cov"
27+
}
1528
}
1629
]
1730
}

docs/features/doctor.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The AlgoKit Doctor allows you to make sure that your system has the correct depe
88

99
Please run this command to if you are facing an issue running AlgoKit. It is recommended to run it before [submitting an issue to AlgoKit](https://github.com/algorandfoundation/algokit-cli/issues/new). You can copy the contents of the Doctor command message (in Markdown format) to your clipboard by providing the `-c` flag to the command as follows `algokit doctor -c`.
1010

11+
> NOTE: You can also use the `--verbose` or `-v` flag to show additional information including package dependencies of the AlgoKit CLI: `algokit -v doctor`. This only works when `algokit` is installed as a Python package (e.g., via `pipx install algokit`).
12+
1113
# Examples
1214

1315
For example, running `algokit doctor` with all prerequisites installed will result in output similar to the following:
@@ -37,11 +39,13 @@ Please include this output, if you want to populate this message in your clipboa
3739
The doctor command will indicate if there is any issues to address, for example:
3840

3941
If AlgoKit detects a newer version, this will be indicated next to the AlgoKit version
42+
4043
```
4144
AlgoKit: 1.2.3 (latest: 4.5.6)
4245
```
4346

4447
If the detected version of docker compose is unsupported, this will be shown:
48+
4549
```
4650
docker compose: 2.1.3
4751
Docker Compose 2.5.0 required to run `algokit localnet command`;

poetry.lock

Lines changed: 8 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ readme = "README.md"
1010
python = ">=3.10,<3.14"
1111
click = "^8.1.3"
1212
httpx = "^0.23.1"
13-
copier = "^9.2.0"
13+
copier = "^9.6.0"
1414
questionary = "^1.10.0"
1515
pyclip = "^0.7.0"
1616
shellingham = "^1.5.4"

src/algokit/cli/doctor.py

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99
from algokit.core.conf import get_current_package_version
1010
from algokit.core.config_commands.version_prompt import get_latest_github_version
1111
from algokit.core.doctor import DoctorResult, check_dependency
12+
from algokit.core.log_handlers import CONSOLE_LOG_HANDLER_NAME
1213
from algokit.core.sandbox import (
1314
COMPOSE_VERSION_COMMAND,
1415
get_min_compose_version,
1516
)
17+
from algokit.core.utils import is_binary_mode
1618
from algokit.core.utils import is_windows as get_is_windows
1719

1820
logger = logging.getLogger(__name__)
@@ -35,13 +37,20 @@
3537
is_flag=True,
3638
default=False,
3739
)
38-
def doctor_command(*, copy_to_clipboard: bool) -> None:
40+
def doctor_command(*, copy_to_clipboard: bool) -> None: # noqa: C901, PLR0912
3941
"""Diagnose potential environment issues that may affect AlgoKit.
4042
4143
Will search the system for AlgoKit dependencies and show their versions, as well as identifying any
4244
potential issues."""
4345
from algokit.core.config_commands.container_engine import get_container_engine
4446

47+
# Check if we're in verbose mode by examining the console log handler level
48+
verbose = False
49+
for handler in logging.getLogger().handlers:
50+
if handler.name == CONSOLE_LOG_HANDLER_NAME and handler.level <= logging.DEBUG:
51+
verbose = True
52+
break
53+
4554
os_type = platform.system()
4655
is_windows = get_is_windows()
4756
container_engine = get_container_engine()
@@ -119,6 +128,15 @@ def doctor_command(*, copy_to_clipboard: bool) -> None:
119128
msg += f"\n {ln}"
120129
logger.info(msg)
121130

131+
# Get dependencies info if in verbose mode and not running from a binary
132+
dependencies = {}
133+
if verbose and not is_binary_mode():
134+
# Add package dependencies section
135+
logger.info("\nCLI package dependencies:")
136+
dependencies = _get_production_dependencies()
137+
for package, version in dependencies.items():
138+
logger.info(f"{package}: {version}")
139+
122140
# print end message anyway
123141
logger.info(
124142
"\n"
@@ -128,12 +146,19 @@ def doctor_command(*, copy_to_clipboard: bool) -> None:
128146
)
129147

130148
if copy_to_clipboard:
131-
pyclip.copy(
132-
"\n".join(
133-
f"* {key}: " + "\n ".join([value.output, *(value.extra_help or [])])
134-
for key, value in service_outputs.items()
135-
)
136-
)
149+
output_lines = []
150+
151+
# Add service outputs
152+
for key, value in service_outputs.items():
153+
output_lines.append(f"* {key}: " + "\n ".join([value.output, *(value.extra_help or [])]))
154+
155+
# Add package dependencies if verbose
156+
if verbose:
157+
output_lines.append("\n* Package dependencies:")
158+
for package, version in dependencies.items():
159+
output_lines.append(f" * {package}: {version}")
160+
161+
pyclip.copy("\n".join(output_lines))
137162

138163
if any(not value.ok for value in service_outputs.values()):
139164
raise click.exceptions.Exit(code=1)
@@ -151,3 +176,28 @@ def _get_algokit_version_output() -> DoctorResult:
151176
else:
152177
output = click.style(current, fg=WARNING_COLOR) + f" (latest: {latest})"
153178
return DoctorResult(ok=True, output=output)
179+
180+
181+
def _get_production_dependencies() -> dict[str, str]:
182+
"""Gets versions of all direct production dependencies."""
183+
try:
184+
import importlib.metadata
185+
import re
186+
187+
# Get package dependencies from metadata
188+
dist = importlib.metadata.distribution("algokit")
189+
requires = dist.requires or []
190+
191+
result = {}
192+
for req in requires:
193+
if match := re.match(r"^([A-Za-z0-9_\-\.]+)", req):
194+
dep = match.group(1)
195+
try:
196+
result[dep] = importlib.metadata.version(dep)
197+
except importlib.metadata.PackageNotFoundError:
198+
result[dep] = "Not installed"
199+
200+
return result
201+
202+
except Exception:
203+
return {"Error": "Could not retrieve dependencies"}

src/algokit/cli/init.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ def init_command( # noqa: PLR0913, C901, PLR0915
357357
expected_answers_file = project_path / ".algokit" / ".copier-answers.yml"
358358
relative_answers_file = expected_answers_file.relative_to(project_path) if expected_answers_file.exists() else None
359359

360+
# Ensure target directory exists (`copier` >=9.6.0 not creating parent directories during copy automatically)
361+
project_path.mkdir(parents=True, exist_ok=True)
362+
360363
with Worker(
361364
src_path=template.url,
362365
dst_path=project_path,

tests/compile/test_typescript.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ def typescript_test_dir(tmp_path_factory: pytest.TempPathFactory) -> Path:
6363
test_dir = tmp_path_factory.mktemp("ts_test", numbered=True)
6464

6565
# Create package.json with required dependencies
66+
# TODO: update to use latest versions once they are released out of beta
6667
package_json_content = """{
6768
"name": "algokit-test",
6869
"version": "1.0.0",
6970
"dependencies": {
70-
"@algorandfoundation/puya-ts": "^1.0.0-beta.48",
71-
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.25"
71+
"@algorandfoundation/puya-ts": "~1.0.0-beta.48 <1.0.0",
72+
"@algorandfoundation/algorand-typescript": "~1.0.0-beta.25 <1.0.0"
7273
}
7374
}"""
7475

tests/doctor/test_doctor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ def _mock_doctor_dependencies(mocker: MockerFixture) -> None:
3939
sys_module = mocker.patch("algokit.cli.doctor.sys")
4040
sys_module.version = "3.6.2"
4141
sys_module.prefix = "/home/me/.local/pipx/venvs/algokit"
42+
# Mock enable binary mode to ignore outputting package information to
43+
# simplify snapshot diffs - otherwise each new run may fail whenever main prod
44+
# dependencies are updated
45+
mocker.patch("algokit.cli.doctor.is_binary_mode").return_value = True
4246

4347

4448
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)