-
Notifications
You must be signed in to change notification settings - Fork 35
feat(cli): add self update command to jmp #1053
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
Merged
mangelajo
merged 1 commit into
jumpstarter-dev:main
from
engelmi:python-cli-add-self-update
Sep 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import click | ||
|
|
||
| from .self_update import self_update | ||
|
|
||
|
|
||
| @click.group | ||
| def self(): | ||
| """ | ||
| Manage the jumpstarter executables | ||
| """ | ||
| pass | ||
|
|
||
|
|
||
| self.add_command(self_update) |
43 changes: 43 additions & 0 deletions
43
python/packages/jumpstarter-cli/jumpstarter_cli/self_update.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import shutil | ||
| import subprocess | ||
| import urllib.request | ||
| from pathlib import Path | ||
|
|
||
| import click | ||
| from jumpstarter_cli_common.exceptions import handle_exceptions | ||
|
|
||
|
|
||
| def _determine_install_dir() -> Path | None: | ||
| jmp_path = shutil.which("jmp") | ||
| if jmp_path: | ||
| return Path(jmp_path).parent.parent | ||
| return None | ||
|
|
||
| def _fetch_install_script() -> str: | ||
| INSTALL_SCRIPT_URL = "https://raw.githubusercontent.com/jumpstarter-dev/jumpstarter/main/python/install.sh" | ||
| with urllib.request.urlopen(INSTALL_SCRIPT_URL) as response: | ||
| return response.read().decode("utf-8") | ||
|
|
||
|
|
||
| @click.command("update") | ||
| @click.option( | ||
| "--source", | ||
| type=str, | ||
| help="Overwrites the current installation source. Available: latest, rc, main and release-x.x", | ||
| default=None, | ||
| ) | ||
| @handle_exceptions | ||
| def self_update(source: str): | ||
| """ | ||
| Update jumpstarter | ||
| """ | ||
| install_dir = _determine_install_dir() | ||
| script = _fetch_install_script() | ||
|
|
||
| cmd = ["bash", "-s", "-"] | ||
| if install_dir: | ||
| cmd.extend(["--dir", f"{install_dir}"]) | ||
| if source: | ||
| cmd.extend(["--source", source]) | ||
|
|
||
| subprocess.run(cmd, input=script, check=True) | ||
66 changes: 66 additions & 0 deletions
66
python/packages/jumpstarter-cli/jumpstarter_cli/self_update_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| from pathlib import Path | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
| from click.testing import CliRunner | ||
|
|
||
| from .self import self | ||
| from .self_update import _determine_install_dir, _fetch_install_script | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "jmp_path,expected_install_dir", | ||
| [ | ||
| ("", None), | ||
| (None, None), | ||
| ("/home/user/.local/jumpstarter/bin/jmp", Path("/home/user/.local/jumpstarter")), | ||
| ], | ||
| ) | ||
| @patch("shutil.which") | ||
| def test__determine_install_dir(which_mock, jmp_path, expected_install_dir): | ||
| which_mock.return_value = jmp_path | ||
| install_dir = _determine_install_dir() | ||
| assert install_dir == expected_install_dir | ||
|
|
||
| @patch("urllib.request.urlopen") | ||
| def test__fetch_install_script(urlopen_mock): | ||
| response = MagicMock() | ||
| response.read.return_value = b"#!/bin/sh" | ||
| urlopen_mock.return_value.__enter__.return_value = response | ||
| script = _fetch_install_script() | ||
| assert script == "#!/bin/sh" | ||
|
|
||
| @pytest.mark.parametrize( | ||
| "source,install_dir,expected_cmd", | ||
| [ | ||
| (None, None, ["bash", "-s", "-"]), | ||
| (None, "/home/user/.local/jumpstarter", ["bash", "-s", "-", "--dir", "/home/user/.local/jumpstarter"]), | ||
| ("main", None, ["bash", "-s", "-", "--source", "main"]), | ||
| ("main", "/home/user/.local/jumpstarter", [ | ||
| "bash", "-s", "-", | ||
| "--dir", "/home/user/.local/jumpstarter", | ||
| "--source", "main"] | ||
| ), | ||
| ], | ||
| ) | ||
| @patch("jumpstarter_cli.self_update._determine_install_dir") | ||
| @patch("jumpstarter_cli.self_update._fetch_install_script") | ||
| @patch("subprocess.run") | ||
| def test_self_update( | ||
| subprocess_mock, | ||
| fetch_install_script_mock, | ||
| determine_install_dir_mock, | ||
| source, | ||
| install_dir, | ||
| expected_cmd | ||
| ): | ||
| determine_install_dir_mock.return_value = install_dir | ||
| fetch_install_script_mock.return_value = "#!/bin/sh" | ||
|
|
||
| CliRunner().invoke(self, ["update", "--source", source]) | ||
|
engelmi marked this conversation as resolved.
|
||
|
|
||
| subprocess_mock.assert_called_once_with( | ||
| expected_cmd, | ||
| input="#!/bin/sh", | ||
| check=True, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.