-
Notifications
You must be signed in to change notification settings - Fork 1
Make showcase launch independent of shell setup #94
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,21 @@ | ||
| #!/bin/sh | ||
| # Launch the checkout's showcase through an isolated, locked environment. | ||
| set -eu | ||
|
|
||
| if ! command -v uvx >/dev/null 2>&1; then | ||
| echo "Install uv (which provides uvx): https://docs.astral.sh/uv/getting-started/installation/" >&2 | ||
| exit 127 | ||
| fi | ||
|
|
||
| repo_root=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P) | ||
| cd "$repo_root" | ||
|
|
||
| # Avoid borrowing an activated environment or a stale checkout .venv. | ||
| unset VIRTUAL_ENV CONDA_PREFIX | ||
| export POETRY_VIRTUALENVS_CREATE=true | ||
| export POETRY_VIRTUALENVS_IN_PROJECT=false | ||
| export POETRY_VIRTUALENVS_USE_POETRY_PYTHON=true | ||
|
|
||
| uvx --python 3.12 --from poetry==2.4.3 poetry env use 3.12 | ||
| uvx --python 3.12 --from poetry==2.4.3 poetry install --with test --no-interaction | ||
| exec uvx --python 3.12 --from poetry==2.4.3 poetry run python -m textui run "$repo_root/examples/showcase/app.ui" |
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,100 @@ | ||
| """Run the checkout launcher with only the external installer replaced.""" | ||
|
|
||
| import json | ||
| import os | ||
| from pathlib import Path | ||
| import shutil | ||
| import subprocess | ||
| import sys | ||
|
|
||
| def run_launcher(tmp_path, *, env_exit=0, install_exit=0, run_exit=0, missing_uvx=False): | ||
| source = Path(__file__).parents[1] / "showcase" | ||
| assert source.is_file(), "The checkout needs a showcase launcher" | ||
| checkout = tmp_path / "checkout with spaces" | ||
| checkout.mkdir() | ||
| launcher = checkout / "showcase" | ||
| shutil.copy2(source, launcher) | ||
| caller = tmp_path / "another directory" | ||
| caller.mkdir() | ||
| tools = tmp_path / "tools" | ||
| tools.mkdir() | ||
| calls = tmp_path / "calls.jsonl" | ||
| fake = tools / "uvx" | ||
| fake.write_text( | ||
| f"#!{sys.executable}\n" | ||
| "import json, os, sys\n" | ||
| "with open(os.environ['LAUNCH_CALLS'], 'a') as output:\n" | ||
| " output.write(json.dumps({'args': sys.argv[1:], 'cwd': os.getcwd(), " | ||
| "'active_env': os.environ.get('VIRTUAL_ENV'), " | ||
| "'conda_env': os.environ.get('CONDA_PREFIX'), " | ||
| "'create': os.environ.get('POETRY_VIRTUALENVS_CREATE'), " | ||
| "'in_project': os.environ.get('POETRY_VIRTUALENVS_IN_PROJECT'), " | ||
| "'poetry_python': os.environ.get('POETRY_VIRTUALENVS_USE_POETRY_PYTHON')}) + '\\n')\n" | ||
| "stage = 'ENV_EXIT' if 'env' in sys.argv else 'INSTALL_EXIT' if 'install' in sys.argv else 'RUN_EXIT'\n" | ||
| "sys.exit(int(os.environ[stage]))\n", | ||
| encoding="utf-8", | ||
| ) | ||
| fake.chmod(0o755) | ||
| environment = { | ||
| **os.environ, | ||
| "PATH": "" if missing_uvx else f"{tools}{os.pathsep}/usr/bin{os.pathsep}/bin", | ||
| "LAUNCH_CALLS": str(calls), | ||
| "ENV_EXIT": str(env_exit), | ||
| "INSTALL_EXIT": str(install_exit), | ||
| "RUN_EXIT": str(run_exit), | ||
| "VIRTUAL_ENV": str(tmp_path / "unrelated environment"), | ||
| "CONDA_PREFIX": str(tmp_path / "unrelated conda"), | ||
| "POETRY_VIRTUALENVS_CREATE": "false", | ||
| "POETRY_VIRTUALENVS_IN_PROJECT": "true", | ||
| "POETRY_VIRTUALENVS_USE_POETRY_PYTHON": "false", | ||
| } | ||
| result = subprocess.run( | ||
| [str(launcher)], cwd=caller, env=environment, capture_output=True, text=True, | ||
| ) | ||
| recorded = [json.loads(line) for line in calls.read_text().splitlines()] if calls.exists() else [] | ||
| return result, recorded, checkout | ||
|
|
||
|
|
||
| def test_launcher_installs_then_runs_showcase_from_another_directory(tmp_path): | ||
| result, calls, checkout = run_launcher(tmp_path) | ||
|
|
||
| assert result.returncode == 0, result.stderr | ||
| prefix = ["--python", "3.12", "--from", "poetry==2.4.3", "poetry"] | ||
| assert [call["args"] for call in calls] == [ | ||
| prefix + ["env", "use", "3.12"], | ||
| prefix + ["install", "--with", "test", "--no-interaction"], | ||
| prefix + ["run", "python", "-m", "textui", "run", str(checkout / "examples/showcase/app.ui")], | ||
| ] | ||
| assert all(call["cwd"] == str(checkout) for call in calls) | ||
| assert all(call["active_env"] is None and call["conda_env"] is None for call in calls) | ||
| assert all(call["create"] == "true" and call["in_project"] == "false" for call in calls) | ||
| assert all(call["poetry_python"] == "true" for call in calls) | ||
|
|
||
|
|
||
| def test_launcher_does_not_run_after_installation_fails(tmp_path): | ||
| result, calls, _ = run_launcher(tmp_path, install_exit=17) | ||
|
|
||
| assert result.returncode == 17 | ||
| assert len(calls) == 2 | ||
|
|
||
|
|
||
| def test_launcher_preserves_application_exit_status(tmp_path): | ||
| result, calls, _ = run_launcher(tmp_path, run_exit=23) | ||
|
|
||
| assert result.returncode == 23 | ||
| assert len(calls) == 3 | ||
|
|
||
|
|
||
| def test_launcher_stops_when_python_environment_selection_fails(tmp_path): | ||
| result, calls, _ = run_launcher(tmp_path, env_exit=19) | ||
|
|
||
| assert result.returncode == 19 | ||
| assert len(calls) == 1 | ||
|
|
||
|
|
||
| def test_launcher_explains_missing_uvx_without_attempting_setup(tmp_path): | ||
| result, calls, _ = run_launcher(tmp_path, missing_uvx=True) | ||
|
|
||
| assert result.returncode == 127 | ||
| assert "uv" in result.stderr and "https://docs.astral.sh/uv/" in result.stderr | ||
| assert not calls |
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.