Skip to content

Dispatch layup verbs from installed metadata, not PATH (#500) - #506

Merged
matthewholman merged 4 commits into
mainfrom
fix/500-cli-under-test
Sep 3, 2026
Merged

Dispatch layup verbs from installed metadata, not PATH (#500)#506
matthewholman merged 4 commits into
mainfrom
fix/500-cli-under-test

Conversation

@matthewholman

Copy link
Copy Markdown
Collaborator

layup <verb> chose which program to run by PATH order.

find_layup_verbs() walked every PATH directory for executables named
layup-*, and the dispatcher ran layup-<verb> as a bare name, so resolution
was left to the OS.

Two consequences. With two layup installations on one machine, layup comet
from one environment can execute the other's layup-comet -- that is how this
surfaced, and it is what made the three CLI tests in #500 fail. And any
executable named layup-<verb> in a writable directory earlier on PATH runs
in preference to the real one, with the user's privileges; an empty PATH
entry means the working directory, and shared systems often carry
group-writable bin directories.

Verbs now come from the installed distribution's entry points and run in this
process, so nothing is resolved by name.

Also pins the three CLI subprocess tests to this environment's console script.
With the conda installation first on PATH -- the configuration that was
failing -- all three now pass. Full suite: 488 passed, 1 skipped.

Closes #500. Suggest v1.0: this is a correctness problem in the shipped CLI
rather than the test hygiene the issue describes.

find_layup_verbs() walked every PATH directory for executables named
layup-*, and the dispatcher ran `layup-<verb>` as a bare name, leaving the
choice of program to PATH order.

With two layup installations on one machine, `layup comet` from one
environment could execute the other's layup-comet. Worse, any executable
named layup-<verb> in a writable directory earlier on PATH would be run in
preference to the real one, with the user's privileges -- an empty PATH
entry means the working directory, and shared scientific systems often
carry group-writable bin directories. PATH could also inject verbs into
layup's own help output.

Verbs now come from the installed distribution's entry points, and the verb
runs in this process. Nothing is resolved by name, so the code that runs is
always this installation's.

Also pins the three CLI subprocess tests to this environment's console
script rather than PATH's, which is how the problem surfaced.
Comment thread src/layup_cmdline/main.py
dropped in any writable directory earlier on ``PATH`` (an empty ``PATH``
entry means the working directory) would be run in preference to the real
one, with the user's privileges.
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole docstring isn't what this code is doing adn is convoluted- it's what the AI thinks it fixed. I think it needs to be rewritten by a human for who is going to edit this code in 6 months or 6 years from now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please take charge of that, @mschwamb ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd get rid of that function and that would solve the issue. As per my other feedback comment.

Comment thread src/layup_cmdline/main.py
for ep in distribution("layup").entry_points:
if ep.group == "console_scripts" and ep.name.startswith("layup-"):
verbs[ep.name[len("layup-") :]] = ep
return verbs

@mschwamb mschwamb Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this in a separate function? It's a bit of Russian doll to read though. These lines could easily be in find_layup_verbs() and it would say having to dive into a separate function

@mschwamb mschwamb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some feedback to consider

Resolved in tests/test_comet.py and tests/test_predict.py: keep this branch's
layup_cli() wrapper, which pins the call to the environment under test, and take
main's post-#503 argument convention (--stem for the file stem, -o for the
output directory).
Review feedback: the two-function form was a step to read through for no gain.
find_layup_verbs() now returns the verb -> entry point mapping directly, main()
reuses it instead of reading the distribution metadata a second time, and the
argparse choices are sorted at the point of use so the help text keeps a stable
order.

Also corrects the layup_cli() docstring, which gave a broken assist/rebound link
as the example failure. The failure actually seen is an older layup on PATH
rejecting arguments the current code added.
@matthewholman

Copy link
Copy Markdown
Collaborator Author

I think this addresses your concerns, @mschwamb

Per review: the previous text was a changelog rather than a description. Two of
its three sentences explained what the change fixed and instructed a future
editor not to undo it, which is commit-message material -- someone meeting this
function in six years needs to know what it returns and why it reads metadata
rather than scanning PATH, and nothing else.

Wording reviewed and adopted by M. J. Holman.
@matthewholman
matthewholman merged commit 6ab2d38 into main Sep 3, 2026
7 checks passed
@matthewholman
matthewholman deleted the fix/500-cli-under-test branch September 3, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Three tests run whichever layup is first on PATH, not the one under test

2 participants