Skip to content

Commit c25ec7e

Browse files
authored
Fixes welcome message and alias display (#417)
Also adds ruff.toml to exclude noisy rules.
1 parent 6350dd2 commit c25ec7e

8 files changed

Lines changed: 66 additions & 21 deletions

File tree

ruff.toml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[lint]
2+
# When using Ruff to check source correctness, feel free to aggressively add
3+
# codes to ignore. We don't care to use it as a nitpicker, just a quick way to
4+
# check for actual incorrect code.
5+
ignore = [
6+
"B006",
7+
"BLE001",
8+
"C401",
9+
"C408",
10+
"FURB",
11+
"G010",
12+
"I001",
13+
"PIE808",
14+
"PLC",
15+
"PLR1730",
16+
"RUF012",
17+
"RUF015",
18+
"RUF022",
19+
"RUF059",
20+
"SIM",
21+
"UP012",
22+
"UP032",
23+
]

src/manage/commands.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828

2929
HELP_URL = "https://docs.python.org/using/windows"
30+
CHANGELOG_URL = f"https://github.com/python/pymanager/releases/tag/{__version__}"
3031

3132

3233
COPYRIGHT = f"""Python installation manager {__version__}
@@ -40,8 +41,15 @@
4041

4142
WELCOME = f"""!B!Python install manager was successfully updated to {__version__}.!W!
4243
43-
Additional shebang configuration is now available. Please see
44-
!B!{HELP_URL}#shebang-lines!W! for more information.
44+
Please see !B!{CHANGELOG_URL}!W! for all changes.
45+
"""
46+
47+
# Temporarily use an ARM64-specific welcome message
48+
# This should be reverted around October 2027.
49+
WELCOME_ARM64 = f"""!B!Python install manager was successfully updated to {__version__}.!W!
50+
51+
The default platform on this PC is now !Y!-arm64!W! instead of !Y!-64!W!.
52+
Please see !B!{CHANGELOG_URL}!W! for more details and all other changes.
4553
"""
4654

4755
# The 'py help' or 'pymanager help' output is constructed by these default docs,
@@ -533,13 +541,22 @@ def show_welcome(self, copyright=True):
533541
if __version__ == "0.1a0":
534542
last_update_file.unlink()
535543
return
544+
545+
# Temporarily use an ARM64-specific welcome message
546+
# This should be reverted around October 2027.
547+
from _native import get_processor_architecture
548+
if get_processor_architecture() == "-arm64":
549+
msg = WELCOME_ARM64
550+
else:
551+
msg = WELCOME
552+
536553
try:
537554
ensure_tree(last_update_file)
538-
last_update_file.write_text(f"{__version__}\n\n{WELCOME}")
555+
last_update_file.write_text(f"{__version__}\n\n{msg}")
539556
except OSError:
540557
LOGGER.debug("Failed to update %s", last_update_file, exc_info=True)
541558
return
542-
LOGGER.info(WELCOME)
559+
LOGGER.info(msg)
543560

544561
def dump_arguments(self):
545562
try:

src/manage/install_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,13 @@ def print_cli_shortcuts(cmd):
371371
if not verbose:
372372
if i.get("default"):
373373
LOGGER.debug("%s will be launched by !G!python.exe!W!", i["display-name"])
374-
names = get_install_alias_names(aliases, windowed=True)
374+
names = get_install_alias_names(aliases, windowed=True, default_platform=cmd.default_platform)
375375
LOGGER.debug("%s will be launched by %s", i["display-name"], ", ".join(names))
376376

377377
if not install_matches_any(i, tags):
378378
continue
379379

380-
names = get_install_alias_names(aliases, windowed=False)
380+
names = get_install_alias_names(aliases, windowed=False, default_platform=cmd.default_platform)
381381
if i.get("default") and names:
382382
LOGGER.info("%s will be launched by !G!python.exe!W! and also %s",
383383
i["display-name"], ", ".join(names))

src/manage/installs.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,19 @@ def _make_alias_key(alias):
148148
return n1, w, n2, plat, n3
149149

150150

151-
def _make_opt_part(parts):
151+
def _make_opt_part(parts, default=""):
152152
if not parts:
153153
return ""
154-
if len(parts) == 1:
155-
return list(parts)[0]
156-
return "[{}]".format("|".join(sorted(p for p in parts if p)))
154+
# If there's an explicit default, then we ignore empty parts.
155+
if default:
156+
parts = sorted(p for p in parts if p)
157+
else:
158+
parts = sorted(parts)
159+
if not parts:
160+
return ""
161+
if len(parts) == 1 and (not parts[0] or parts[0] != default):
162+
return parts[0]
163+
return "[{}]".format("|".join(p for p in parts if p))
157164

158165

159166
def _sk_sub(m):
@@ -191,17 +198,11 @@ def get_install_alias_names(aliases, friendly=True, windowed=True, default_platf
191198

192199
result = []
193200
for k, (n1, n2, n3) in seen.items():
194-
plat_parts = plats.get(k)
195-
plat = _make_opt_part(plat_parts)
196-
if default_platform and plat_parts == {default_platform}:
197-
# The bare alias was already shown for another install, but the
198-
# suffix is still optional when it matches the default platform.
199-
plat = f"[{default_platform}]"
200201
result.append("".join([
201202
n1,
202203
_make_opt_part(has_w.get(k)),
203204
n2,
204-
plat,
205+
_make_opt_part(plats.get(k), default_platform),
205206
n3,
206207
]))
207208
return sorted(result, key=_make_alias_name_sortkey)

src/manage/scriptutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _parse_shebang(cmd, line, *, windowed=None):
255255
"'false' in your configuration file.")
256256
try:
257257
return _find_on_path(cmd, full_cmd)
258-
except LookupError as ex:
258+
except LookupError:
259259
LOGGER.error("Could not launch '%s'. Using default interpreter "
260260
"instead.", full_cmd)
261261
raise

tests/test_install_command.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def test_print_cli_shortcuts(patched_installs, assert_log, monkeypatch, tmp_path
5959
class Cmd:
6060
scratch = {}
6161
global_dir = Path(tmp_path)
62+
default_platform = "-64"
6263
def get_installs(self):
6364
return installs.get_installs(None)
6465

tests/test_installs.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ def test_install_alias_opt_part():
147147
assert "" == installs._make_opt_part([])
148148
assert "x" == installs._make_opt_part(["x"])
149149
assert "[x]" == installs._make_opt_part(["x", ""])
150+
assert "[x]" == installs._make_opt_part(["x"], default="x")
151+
assert "[x]" == installs._make_opt_part(["x", ""], default="x")
152+
assert "y" == installs._make_opt_part(["y", ""], default="x")
150153
assert "[x|y]" == installs._make_opt_part(["", "y", "x"])
151154

152155

@@ -155,5 +158,5 @@ def test_install_alias_names():
155158
input.extend([{"name": i, "windowed": 1} for i in ["xy3.exe", "XY3-64.exe", "XYW3.exe", "xyw3-64.exe"]])
156159
expect = ["py[w]3[-64].exe"]
157160
expectw = ["py[w]3[-64].exe", "xy[w]3[-64].exe"]
158-
assert expect == installs.get_install_alias_names(input, friendly=True, windowed=False)
159-
assert expectw == installs.get_install_alias_names(input, friendly=True, windowed=True)
161+
assert expect == installs.get_install_alias_names(input, friendly=True, windowed=False, default_platform="-64")
162+
assert expectw == installs.get_install_alias_names(input, friendly=True, windowed=True, default_platform="-64")

tests/test_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def online_install(tag, plat):
177177
])
178178
assert_log(
179179
(r"!B!Tag\s+Name\s+Managed By\s+Version\s+Alias\s*!W!", ()),
180-
(r"3\.15-dev-32.*" + re.escape("python[w]3[-32].exe, python[w]3.15[-32].exe"), ()),
180+
(r"3\.15-dev-32.*" + re.escape("python[w]3-32.exe, python[w]3.15-32.exe"), ()),
181181
(r"3\.15-dev\[-64\].*" + re.escape("python[w]3[-64].exe, python[w]3.15[-64].exe"), ()),
182182
(r"3\.15-dev-arm64.*" + re.escape("python[w]3-arm64.exe, python[w]3.15-arm64.exe"), ()),
183183
)

0 commit comments

Comments
 (0)