Description:
Currently, ferret run expects a direct file path to a Python script (e.g., ferret run ./my_script.py). However, users frequently want to profile installed CLI tools or library modules, such as pytest, uvicorn, or even the standard library's http.server.
To do this currently, a user must use which to find the executable path (e.g., ferret run $(which pytest)), which is clumsy and platform-dependent. Standard Python tooling solves this with the -m flag (e.g., python -m pytest), and Ferret should support the same convention.
Proposed Solution:
Update the run command to accept a --module / -m flag. When present, Ferret should resolve the target module using Python's import system, locate its entry point (typically __main__.py), and execute it just as it would a standard script.
Tasks:
Acceptance Criteria:
ferret run -m http.server successfully starts a web server and records traces.
ferret run -m pytest runs the test suite and captures the execution of the tests.
- Invalid modules return a helpful error message (e.g., "Module 'foo' not found").
Description:
Currently,
ferret runexpects a direct file path to a Python script (e.g.,ferret run ./my_script.py). However, users frequently want to profile installed CLI tools or library modules, such aspytest,uvicorn, or even the standard library'shttp.server.To do this currently, a user must use
whichto find the executable path (e.g.,ferret run $(which pytest)), which is clumsy and platform-dependent. Standard Python tooling solves this with the-mflag (e.g.,python -m pytest), and Ferret should support the same convention.Proposed Solution:
Update the
runcommand to accept a--module/-mflag. When present, Ferret should resolve the target module using Python's import system, locate its entry point (typically__main__.py), and execute it just as it would a standard script.Tasks:
ferret/cli.py):runcommand signature to acceptmodule: bool = typer.Option(False, "--module", "-m").scriptargument can be interpreted as a module name when this flag is set.importlib.util.find_spec(module_name)to locate the module spec.black), look for__main__.pyinside it.http.server), use its source file.sys.path[0]is set to the current working directory (standardpython -mbehavior) rather than the script's directory.sys.argv[0]to the full path of the resolved script.Acceptance Criteria:
ferret run -m http.serversuccessfully starts a web server and records traces.ferret run -m pytestruns the test suite and captures the execution of the tests.