Skip to content

Generate python.exe and pythonw.exe in globals directory for default runtime. #145

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/manage/install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,20 @@
shortcut_written = {}
for i in cmd.get_installs():
if cmd.global_dir:
for a in i.get("alias", ()):
aliases = i.get("alias", ())

# Generate a python.exe for the default runtime in case the user
# later disables/removes the global python.exe command.
if i.get("default"):
aliases = list(i.get("alias", ()))
alias_1 = [a for a in aliases if not a.get("windowed")]
alias_2 = [a for a in aliases if a.get("windowed")]
if alias_1:
aliases.append({**alias_1[0], "name": "python.exe"})
if alias_2:
aliases.append({**alias_2[0], "name": "pythonw.exe"})

for a in aliases:
if a["name"].casefold() in alias_written:
continue
target = i["prefix"] / a["target"]
Expand Down Expand Up @@ -576,6 +589,10 @@

cmd.tags = []

if cmd.virtual_env:
LOGGER.debug("Clearing virtual_env setting to avoid conflicts during install.")
cmd.virtual_env = None

Check warning on line 594 in src/manage/install_command.py

View check run for this annotation

Codecov / codecov/patch

src/manage/install_command.py#L593-L594

Added lines #L593 - L594 were not covered by tests

if cmd.refresh:
if cmd.args:
LOGGER.warn("Ignoring arguments; --refresh always refreshes all installs.")
Expand Down Expand Up @@ -673,9 +690,6 @@
else:
cmd.tags.append(tag_or_range(cmd.default_tag))

if cmd.virtual_env:
LOGGER.debug("Clearing virtual_env setting to avoid conflicts during install.")
cmd.virtual_env = None
installed = list(cmd.get_installs())

if cmd.download:
Expand Down
41 changes: 41 additions & 0 deletions tests/test_install_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,47 @@ def test_write_alias_fallback_platform(alias_checker):
alias_checker.check_w64(alias_checker.Cmd("-spam"), "1.0", "testB")


@pytest.mark.parametrize("default", [1, 0])
def test_write_alias_default(alias_checker, monkeypatch, tmp_path, default):
prefix = Path(tmp_path) / "runtime"

class Cmd:
global_dir = Path(tmp_path) / "bin"
launcher_exe = None
def get_installs(self):
return [
{
"alias": [
{"name": "python3.exe", "target": "p.exe"},
{"name": "pythonw3.exe", "target": "pw.exe", "windowed": 1},
],
"default": default,
"prefix": prefix,
}
]

prefix.mkdir(exist_ok=True, parents=True)
(prefix / "p.exe").write_bytes(b"")
(prefix / "pw.exe").write_bytes(b"")

written = []
def write_alias(*a):
written.append(a)

monkeypatch.setattr(IC, "_write_alias", write_alias)
monkeypatch.setattr(IC, "SHORTCUT_HANDLERS", {})

IC.update_all_shortcuts(Cmd())

if default:
# Main test: python.exe and pythonw.exe are added in automatically
assert sorted(w[2]["name"] for w in written) == ["python.exe", "python3.exe", "pythonw.exe", "pythonw3.exe"]
else:
assert sorted(w[2]["name"] for w in written) == ["python3.exe", "pythonw3.exe"]
# Ensure we still only have the two targets
assert set(w[3].name for w in written) == {"p.exe", "pw.exe"}


def test_print_cli_shortcuts(patched_installs, assert_log, monkeypatch, tmp_path):
class Cmd:
global_dir = Path(tmp_path)
Expand Down