Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
fc64f28
[WIP] Start implementation of entrypoint support
zooba Nov 20, 2025
8b83213
[WIP] Updated, implemented, and existing tests pass
zooba Nov 24, 2025
7ff8626
Add test
zooba Nov 25, 2025
1263c28
Improved script and fixed names
zooba Nov 25, 2025
fc4793f
Fix tests
zooba Nov 25, 2025
bd20de5
Fix tests
zooba Nov 25, 2025
36118d8
Add tests to improve coverage
zooba Nov 26, 2025
81808f3
More test coverage
zooba Nov 26, 2025
2a3839b
Minor refactor, improved test coverage
zooba Nov 27, 2025
16a60c1
Remove unused import
zooba Nov 27, 2025
52d27a7
Add comment and update scratch key
zooba Nov 27, 2025
e05fbad
Add some missing log messages
zooba Nov 27, 2025
e621dd4
Minor bug fixes
zooba Nov 27, 2025
5916e76
Properly handle launching script executable (not DLL)
zooba Nov 27, 2025
5be8d04
Ensure pip.exe exists
zooba Dec 2, 2025
0a3924e
Merge main
zooba Dec 3, 2025
2069514
Add welcome message
zooba Dec 3, 2025
fddc8cc
Add refresh step to entrypoint test
zooba Dec 3, 2025
c67f0e5
Fix paths
zooba Dec 3, 2025
7f24d36
Minor refactoring on alias creation
zooba Dec 3, 2025
ea6d7c7
Fix calls
zooba Dec 3, 2025
935ab05
Merge main
zooba Dec 8, 2025
198a73f
Refactor and simplify code for aliases
zooba Dec 9, 2025
2eec6d2
Improved edge case handling and test
zooba Dec 9, 2025
a36f76a
Update args
zooba Dec 9, 2025
fb9b7c0
Remove some dead code
zooba Dec 9, 2025
13c57b7
Naming conventions
zooba Dec 9, 2025
42b51bb
Fixes and improvements suggested by reviewer
zooba Dec 9, 2025
753b295
Split names before testing
zooba Dec 9, 2025
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
Prev Previous commit
Next Next commit
Add test
  • Loading branch information
zooba committed Nov 25, 2025
commit 7ff862646d830b7bdc86eb1a98d734b31e33051c
68 changes: 36 additions & 32 deletions src/manage/aliasutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,10 @@ def create_alias(cmd, install, alias, target, *, script_code=None, _link=os.link


def _parse_entrypoint_line(line):
line = line.partition("#")[0]
name, sep, rest = line.partition("=")
name = name.strip()
if name and sep and rest:
if name and name[0].isalnum() and sep and rest:
mod, sep, rest = rest.partition(":")
mod = mod.strip()
if mod and sep and rest:
Expand All @@ -140,40 +141,43 @@ def _parse_entrypoint_line(line):
return None, None, None


def _scan_one(root):
# Scan d for dist-info directories with entry_points.txt
dist_info = [d for d in root.glob("*.dist-info") if d.is_dir()]
LOGGER.debug("Found %i dist-info directories in %s", len(dist_info), root)
entrypoints = [f for f in [d / "entry_points.txt" for d in dist_info] if f.is_file()]
LOGGER.debug("Found %i entry_points.txt files in %s", len(entrypoints), root)

# Filter down to [console_scripts] and [gui_scripts]
for ep in entrypoints:
try:
f = open(ep, "r", encoding="utf-8", errors="strict")
except OSError:
LOGGER.debug("Failed to read %s", ep, exc_info=True)
continue

with f:
alias = None
for line in f:
if line.strip() == "[console_scripts]":
alias = dict(windowed=0)
elif line.strip() == "[gui_scripts]":
alias = dict(windowed=1)
elif line.lstrip().startswith("["):
alias = None
elif alias is not None:
name, mod, func = _parse_entrypoint_line(line)
if name and mod and func:
yield (
{**alias, "name": name},
f"import sys; from {mod} import {func}; sys.exit({func}())",
)


def _scan(prefix, dirs):
for dirname in dirs or ():
root = prefix / dirname

# Scan d for dist-info directories with entry_points.txt
dist_info = [d for d in root.listdir() if d.match("*.dist-info") and d.is_dir()]
LOGGER.debug("Found %i dist-info directories in %s", len(dist_info), root)
entrypoints = [f for f in [d / "entry_points.txt" for d in dist_info] if f.is_file()]
LOGGER.debug("Found %i entry_points.txt files in %s", len(entrypoints), root)

# Filter down to [console_scripts] and [gui_scripts]
for ep in entrypoints:
try:
f = open(ep, "r", encoding="utf-8", errors="strict")
except OSError:
LOGGER.debug("Failed to read %s", ep, exc_info=True)
continue

with f:
alias = None
for line in f:
if line.strip() == "[console_scripts]":
alias = dict(windowed=0)
elif line.strip() == "[gui_scripts]":
alias = dict(windowed=1)
elif line.lstrip().startswith("["):
alias = None
elif alias is not None:
name, mod, func = _parse_entrypoint_line(line)
if name and mod and func:
yield (
{**alias, "name": name},
f"import sys; from {mod} import {func}; sys.exit({func}())",
)
yield from _scan_one(root)


def scan_and_create_entrypoints(cmd, install, shortcut, _create_alias=create_alias):
Expand Down
39 changes: 39 additions & 0 deletions tests/test_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,42 @@ def fake_link(x, y):
assert_log.end_of_log(),
)


def test_parse_entrypoint_line():
for line, expect in [
("", (None, None, None)),
("# comment", (None, None, None)),
("name-only", (None, None, None)),
("name=value", (None, None, None)),
("name=mod:func", ("name", "mod", "func")),
("name=mod:func#comment", ("name", "mod", "func")),
(" name = mod : func ", ("name", "mod", "func")),
("name=mod:func[extra]", ("name", "mod", "func")),
("name=mod:func [extra]", ("name", "mod", "func")),
]:
assert expect == AU._parse_entrypoint_line(line)


def test_scan_entrypoints(tmp_path):
site = tmp_path / "site"
A = site / "a.dist-info"
B = site / "b.dist-info"
A.mkdir(exist_ok=True, parents=True)
B.mkdir(exist_ok=True, parents=True)
(A / "entry_points.txt").write_text("""# Test entries
[console_scripts]
a_cmd = a:main
a2_cmd = a:main2 [spam]

[gui_scripts]
aw_cmd = a:main
""")
actual = list(AU._scan_one(site))
assert [a[0]["name"] for a in actual] == [
"a_cmd", "a2_cmd", "aw_cmd"
]
assert [a[0]["windowed"] for a in actual] == [0, 0, 1]
assert [a[1].rpartition("; ")[2] for a in actual] == [
"sys.exit(main())", "sys.exit(main2())", "sys.exit(main())"
]