Skip to content

Commit

Permalink
feat(doctor): fix git windows one
Browse files Browse the repository at this point in the history
add python and python 3
  • Loading branch information
mzaatar committed Dec 16, 2022
1 parent 5ed13e1 commit 4fb2a2c
Show file tree
Hide file tree
Showing 15 changed files with 245 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/algokit/cli/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def doctor_command(*, copy_to_clipboard: bool) -> None:
service_outputs["Docker Compose"] = doctor_functions.get_docker_compose_info()
service_outputs["Git"] = doctor_functions.get_git_info(os_type)
service_outputs["AlgoKit Python"] = doctor_functions.get_algokit_python_info()
service_outputs["Global Python"] = doctor_functions.get_global_python_info()
service_outputs["Global Python"] = doctor_functions.get_global_python_info("python")
service_outputs["Global Python3"] = doctor_functions.get_global_python_info("python3")
service_outputs["Pipx"] = doctor_functions.get_pipx_info()
service_outputs["Poetry"] = doctor_functions.get_poetry_info()
service_outputs["Node.js"] = doctor_functions.get_node_info()
Expand Down
16 changes: 9 additions & 7 deletions src/algokit/core/doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def get_docker_compose_info() -> ProcessResult:
def get_git_info(system: str) -> ProcessResult:
try:
process_results = proc.run(["git", "--version"]).output.splitlines()[0].split(" ")[2]
major, minor, build = map(int, process_results.split("."))
major, minor, build = get_version_from_str(process_results)
return ProcessResult(f"{major}.{minor}.{build}", 0)
except Exception:
if system == "windows":
Expand All @@ -138,19 +138,20 @@ def get_git_info(system: str) -> ProcessResult:
def get_algokit_python_info() -> ProcessResult:
try:
return ProcessResult(
f"{sys_version_info.major}.{sys_version_info.minor}.{sys_version_info.micro} {sys_executable}", 0
f"{sys_version_info.major}.{sys_version_info.minor}.{sys_version_info.micro} (location: {sys_executable})",
0,
)
except Exception:
return ProcessResult("None found.", 1)


def get_global_python_info() -> ProcessResult:
def get_global_python_info(python_command_name: str) -> ProcessResult:
try:
major, minor, build = get_version_from_str(
proc.run(["python3", "--version"]).output.splitlines()[0].split(" ")[1]
proc.run([python_command_name, "--version"]).output.splitlines()[0].split(" ")[1]
)
global_python3_location = shutil.which("python3")
return ProcessResult(f"{major}.{minor}.{build} {global_python3_location}", 0)
global_python3_location = shutil.which(python_command_name)
return ProcessResult(f"{major}.{minor}.{build} (location: {global_python3_location})", 0)
except Exception:
return ProcessResult("None found.", 1)

Expand Down Expand Up @@ -211,5 +212,6 @@ def is_minimum_version(system_version: str, minimum_version: str) -> bool:


def get_version_from_str(version: str) -> tuple[int, int, int]:
major, minor, build = map(int, version.split("."))
# take only the first three parts x.y.z of the version to ignore weird version
major, minor, build = map(int, version.split(".")[:3])
return major, minor, build
85 changes: 84 additions & 1 deletion tests/doctor/test_doctor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def mock_dependencies(mocker: MockerFixture) -> None:
mocked_date.now.return_value = datetime(1990, 12, 31, 10, 9, 8)
# Mock shutil
mocked_shutil = mocker.patch("algokit.core.doctor.shutil")
mocked_shutil.which.return_value = "/Library/Frameworks/Python.framework/Versions/3.11/bin/python3"
mocked_shutil.which.side_effect = mock_shutil_which
# Mock sys - Tuple[int, int, int, str, int]
mocker.patch("algokit.core.doctor.sys_version_info", VersionInfoType(3, 6, 2, "blah", 0))
mocker.patch("algokit.core.doctor.sys_executable", "{current_working_directory}/.venv/bin/python")
Expand All @@ -54,13 +54,22 @@ def mock_happy_values(proc_mock: ProcMock) -> None:
proc_mock.set_output(["docker", "-v"], ["Docker version 20.10.21, build baeda1f"])
proc_mock.set_output(["docker-compose", "-v"], ["Docker Compose version v2.12.2"])
proc_mock.set_output(["git", "--version"], ["git version 2.37.1 (Apple Git-137.1)"])
proc_mock.set_output(["python", "--version"], ["Python 3.10.0"])
proc_mock.set_output(["python3", "--version"], ["Python 3.11.0"])
proc_mock.set_output(["pipx", "--version"], ["1.1.0"])
proc_mock.set_output(["poetry", "--version"], ["blah blah", "", "Poetry (version 1.2.2)"])
proc_mock.set_output(["node", "-v"], ["v18.12.1"])
proc_mock.set_output(["npm", "-v"], ["8.19.2"])


def mock_shutil_which(python_command_name: str) -> str:
if python_command_name == "python":
return "/Library/Frameworks/Python.framework/Versions/3.10/bin/python"
if python_command_name == "python3":
return "/Library/Frameworks/Python.framework/Versions/3.11/bin/python3"
return ""


def make_output_scrubber(**extra_tokens: str) -> Scrubber:
default_tokens = {"test_parent_directory": str(PARENT_DIRECTORY)}
tokens = default_tokens | extra_tokens
Expand Down Expand Up @@ -145,13 +154,72 @@ def test_doctor_with_git_warning_on_windows(mocker: MockerFixture, proc_mock: Pr


def test_doctor_all_failed_on_mac(mocker: MockerFixture, proc_mock: ProcMock):

mocker.patch("algokit.core.doctor.sys_version_info", "")
mocker.patch("algokit.core.doctor.sys_executable", "")

proc_mock.set_output(["pipx", "list", "--short"], [])
proc_mock.set_output(["pipx", "environment"], [])
proc_mock.set_output(["choco"], [])
proc_mock.set_output(["brew", "-v"], [])
proc_mock.set_output(["docker", "-v"], [])
proc_mock.set_output(["docker-compose", "-v"], [])
proc_mock.set_output(["git", "--version"], [])
proc_mock.set_output(["python", "--version"], [])
proc_mock.set_output(["python3", "--version"], [])
proc_mock.set_output(["pipx", "--version"], [])
proc_mock.set_output(["poetry", "--version"], [])
proc_mock.set_output(["node", "-v"], [])
proc_mock.set_output(["npm", "-v"], [])

result = invoke("doctor")

assert result.exit_code == 1
verify(result.output, scrubber=make_output_scrubber())


def test_doctor_all_failed_on_windows(mocker: MockerFixture, proc_mock: ProcMock):
mocked_os = mocker.patch("algokit.cli.doctor.platform")
mocked_os.system.return_value = "windows"

mocker.patch("algokit.core.doctor.sys_version_info", "")
mocker.patch("algokit.core.doctor.sys_executable", "")

proc_mock.set_output(["pipx", "list", "--short"], [])
proc_mock.set_output(["pipx", "environment"], [])
proc_mock.set_output(["choco"], [])
proc_mock.set_output(["brew", "-v"], [])
proc_mock.set_output(["docker", "-v"], [])
proc_mock.set_output(["docker-compose", "-v"], [])
proc_mock.set_output(["git", "--version"], [])
proc_mock.set_output(["python", "--version"], [])
proc_mock.set_output(["python3", "--version"], [])
proc_mock.set_output(["pipx", "--version"], [])
proc_mock.set_output(["poetry", "--version"], [])
proc_mock.set_output(["node", "-v"], [])
proc_mock.set_output(["npm", "-v"], [])

result = invoke("doctor")

assert result.exit_code == 1
verify(result.output, scrubber=make_output_scrubber())


def test_doctor_all_failed_on_linux(mocker: MockerFixture, proc_mock: ProcMock):
mocked_os = mocker.patch("algokit.cli.doctor.platform")
mocked_os.system.return_value = "linux"

mocker.patch("algokit.core.doctor.sys_version_info", "")
mocker.patch("algokit.core.doctor.sys_executable", "")

proc_mock.set_output(["pipx", "list", "--short"], [])
proc_mock.set_output(["pipx", "environment"], [])
proc_mock.set_output(["choco"], [])
proc_mock.set_output(["brew", "-v"], [])
proc_mock.set_output(["docker", "-v"], [])
proc_mock.set_output(["docker-compose", "-v"], [])
proc_mock.set_output(["git", "--version"], [])
proc_mock.set_output(["python", "--version"], [])
proc_mock.set_output(["python3", "--version"], [])
proc_mock.set_output(["pipx", "--version"], [])
proc_mock.set_output(["poetry", "--version"], [])
Expand All @@ -172,3 +240,18 @@ def test_doctor_with_weird_values_on_mac(mocker: MockerFixture, proc_mock: ProcM
assert result.exit_code == 0
verify(result.output, scrubber=make_output_scrubber())


def test_doctor_with_weird_values_on_windows(mocker: MockerFixture, proc_mock: ProcMock):
mocked_os = mocker.patch("algokit.cli.doctor.platform")
mocked_os.system.return_value = "windows"

proc_mock.set_output(["git", "--version"], ["git version 2.31.0.windows.1"])
proc_mock.set_output(
["choco"], ["Chocolatey v0.10.15", "choco: Please run 'choco -?' or 'choco <command> -?' for help menu."]
)
proc_mock.set_output(["npm", "-v"], [" 16.17.0 "])

result = invoke("doctor")

assert result.exit_code == 0
verify(result.output, scrubber=make_output_scrubber())
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DEBUG: Running 'pipx list --short' in '{current_working_directory}'
DEBUG: Running 'docker -v' in '{current_working_directory}'
DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: Running 'pipx --version' in '{current_working_directory}'
DEBUG: Running 'poetry --version' in '{current_working_directory}'
DEBUG: Running 'node -v' in '{current_working_directory}'
DEBUG: Running 'npm -v' in '{current_working_directory}'
Time: 1990-12-31T10:09:08
AlgoKit: None found
OS: Unix/Linux linux_version
Docker: None found.
Docker required to `run algokit sandbox` command; install via https://docs.docker.com/get-docker/
Docker Compose: None found.
Docker Compose 2.5 required to `run algokit sandbox command`; install via https://docs.docker.com/compose/install/
Git: None found.
Git required to run `algokit init`; install via https://github.com/git-guides/install-git
AlgoKit Python: None found.
Global Python: None found.
Global Python3: None found.
Pipx: None found.
Pipx is required to install Poetry; install via https://pypa.github.io/pipx/
Poetry: None found.
Poetry is required for some Python-based templates; install via `algokit bootstrap` within project directory, or via https://python-poetry.org/docs/#installation
Node.js: None found.
Node.js is required for some Node.js-based templates; install via `algokit bootstrap` within project directory, or via https://nodejs.dev/en/learn/how-to-install-nodejs/
Npm: None found.
If you are experiencing a problem with algokit, feel free to submit an issue via https://github.com/algorandfoundation/algokit-cli/issues/new; please include this output, if you want to populate this message in your clipboard, run `algokit doctor -c`
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ DEBUG: Running 'brew -v' in '{current_working_directory}'
DEBUG: Running 'docker -v' in '{current_working_directory}'
DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: Running 'pipx --version' in '{current_working_directory}'
DEBUG: Running 'poetry --version' in '{current_working_directory}'
Expand All @@ -18,8 +19,9 @@ Docker Compose: None found.
Docker Compose 2.5 required to `run algokit sandbox command`; install via https://docs.docker.com/compose/install/
Git: None found.
Git required to run `algokit init`; install via https://github.com/git-guides/install-git
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
AlgoKit Python: None found.
Global Python: None found.
Global Python3: None found.
Pipx: None found.
Pipx is required to install Poetry; install via https://pypa.github.io/pipx/
Poetry: None found.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
DEBUG: Running 'pipx list --short' in '{current_working_directory}'
DEBUG: Running 'choco' in '{current_working_directory}'
DEBUG: Running 'docker -v' in '{current_working_directory}'
DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: Running 'pipx --version' in '{current_working_directory}'
DEBUG: Running 'poetry --version' in '{current_working_directory}'
DEBUG: Running 'node -v' in '{current_working_directory}'
DEBUG: Running 'npm -v' in '{current_working_directory}'
Time: 1990-12-31T10:09:08
AlgoKit: None found
Chocolatey: None found
OS: Windows windows_version
Docker: None found.
Docker required to `run algokit sandbox` command; install via https://docs.docker.com/get-docker/
Docker Compose: None found.
Docker Compose 2.5 required to `run algokit sandbox command`; install via https://docs.docker.com/compose/install/
Git: None found.
Git required to `run algokit init`; install via `choco install git` if using Chocolatey or via https://github.com/git-guides/install-git#install-git-on-windows
AlgoKit Python: None found.
Global Python: None found.
Global Python3: None found.
Pipx: None found.
Pipx is required to install Poetry; install via https://pypa.github.io/pipx/
Poetry: None found.
Poetry is required for some Python-based templates; install via `algokit bootstrap` within project directory, or via https://python-poetry.org/docs/#installation
Node.js: None found.
Node.js is required for some Node.js-based templates; install via `algokit bootstrap` within project directory, or via https://nodejs.dev/en/learn/how-to-install-nodejs/
Npm: None found.
If you are experiencing a problem with algokit, feel free to submit an issue via https://github.com/algorandfoundation/algokit-cli/issues/new; please include this output, if you want to populate this message in your clipboard, run `algokit doctor -c`
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: docker-compose: Docker Compose version v2.12.2
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: git: git version 2.37.1 (Apple Git-137.1)
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: python: Python 3.10.0
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: python3: Python 3.11.0
DEBUG: Running 'pipx --version' in '{current_working_directory}'
Expand All @@ -29,8 +31,9 @@ OS: Unix/Linux linux_version
Docker: 20.10.21
Docker Compose: 2.12.2
Git: 2.37.1
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
Global Python: 3.11.0 /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
AlgoKit Python: 3.6.2 (location: {current_working_directory}/.venv/bin/python)
Global Python: 3.10.0 (location: /Library/Frameworks/Python.framework/Versions/3.10/bin/python)
Global Python3: 3.11.0 (location: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
Pipx: 1.1.0
Poetry: 1.2.2
Node.js: 18.12.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: docker-compose: Docker Compose version v2.12.2
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: git: git version 2.37.1 (Apple Git-137.1)
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: python: Python 3.10.0
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: python3: Python 3.11.0
DEBUG: Running 'pipx --version' in '{current_working_directory}'
Expand All @@ -33,8 +35,9 @@ OS: Mac OS X mac_os_version
Docker: 20.10.21
Docker Compose: 2.12.2
Git: 2.37.1
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
Global Python: 3.11.0 /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
AlgoKit Python: 3.6.2 (location: {current_working_directory}/.venv/bin/python)
Global Python: 3.10.0 (location: /Library/Frameworks/Python.framework/Versions/3.10/bin/python)
Global Python3: 3.11.0 (location: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
Pipx: 1.1.0
Poetry: 1.2.2
Node.js: 18.12.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: docker-compose: Docker Compose version v2.12.2
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: git: git version 2.37.1 (Apple Git-137.1)
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: python: Python 3.10.0
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: python3: Python 3.11.0
DEBUG: Running 'pipx --version' in '{current_working_directory}'
Expand All @@ -33,8 +35,9 @@ OS: Windows windows_version
Docker: 20.10.21
Docker Compose: 2.12.2
Git: 2.37.1
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
Global Python: 3.11.0 /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
AlgoKit Python: 3.6.2 (location: {current_working_directory}/.venv/bin/python)
Global Python: 3.10.0 (location: /Library/Frameworks/Python.framework/Versions/3.10/bin/python)
Global Python3: 3.11.0 (location: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
Pipx: 1.1.0
Poetry: 1.2.2
Node.js: 18.12.1
Expand Down
7 changes: 5 additions & 2 deletions tests/doctor/test_doctor.test_doctor_with_copy.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: docker-compose: Docker Compose version v2.12.2
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: git: git version 2.37.1 (Apple Git-137.1)
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: python: Python 3.10.0
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: python3: Python 3.11.0
DEBUG: Running 'pipx --version' in '{current_working_directory}'
Expand All @@ -33,8 +35,9 @@ OS: Mac OS X mac_os_version
Docker: 20.10.21
Docker Compose: 2.12.2
Git: 2.37.1
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
Global Python: 3.11.0 /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
AlgoKit Python: 3.6.2 (location: {current_working_directory}/.venv/bin/python)
Global Python: 3.10.0 (location: /Library/Frameworks/Python.framework/Versions/3.10/bin/python)
Global Python3: 3.11.0 (location: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
Pipx: 1.1.0
Poetry: 1.2.2
Node.js: 18.12.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DEBUG: Running 'docker-compose -v' in '{current_working_directory}'
DEBUG: docker-compose: Docker Compose version v2.1.3
DEBUG: Running 'git --version' in '{current_working_directory}'
DEBUG: git: git version 2.37.1 (Apple Git-137.1)
DEBUG: Running 'python --version' in '{current_working_directory}'
DEBUG: python: Python 3.10.0
DEBUG: Running 'python3 --version' in '{current_working_directory}'
DEBUG: python3: Python 3.11.0
DEBUG: Running 'pipx --version' in '{current_working_directory}'
Expand All @@ -34,8 +36,9 @@ Docker: 20.10.21
Docker Compose: 2.1.3
Docker Compose 2.5 required to `run algokit sandbox command`; install via https://docs.docker.com/compose/install/
Git: 2.37.1
AlgoKit Python: 3.6.2 {current_working_directory}/.venv/bin/python
Global Python: 3.11.0 /Library/Frameworks/Python.framework/Versions/3.11/bin/python3
AlgoKit Python: 3.6.2 (location: {current_working_directory}/.venv/bin/python)
Global Python: 3.10.0 (location: /Library/Frameworks/Python.framework/Versions/3.10/bin/python)
Global Python3: 3.11.0 (location: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3)
Pipx: 1.1.0
Poetry: 1.2.2
Node.js: 18.12.1
Expand Down
Loading

0 comments on commit 4fb2a2c

Please sign in to comment.