For example, using -m
for pdb and post-mortem debugging, you can do:
python -m pdb script.py arg1 --kwarg
(say for instance that arg1
and kwarg
are parsed from sys.argv
with the argparse
module).
A CLI tool can be created with pip/setuptools' entry points:
setup(
...
entry_points={
"console_scripts": [
"toolname = my_project.script:main"
]
},
)
Now after installing pip install my_project
, toolname
can be used instead of python /path/to/script.py
. Is it possible to pass arguments directly to python - like -m
to invoke pdb
?
Edit:
Unlike python setup tools console_scripts with arguments I know how to pass arguments to the script, and I'm looking for how to pass arguments to python itself.
The python -m pdb $(which myscript)
method, used in How to start debugger with an entry_point script is pretty good, but it only works if the script actually calls main()
when executed (script may be from a third-party library).
python -c "import pdb, pkg_resources; pdb.run('pkg_resources.load_entry_point(\'mylocalpkg\', \'console_scripts\', \'myscript\')()')"
supports more scripts and platforms, but I'm not sure if it works for other python options other than -m pdb
.