Search code examples
pythonsetuptoolsentry-point

How do I create a python setuptools entrypoint for package.__main__?


I want to have a directory structure like so:

package
package/__init__.py
package/__main__.py
setup.py

And use package.__main__ as a entry point

setuptools.setup(
    name="package",
    version=0.1,
    ...
    entry_points={"console_scripts": ["llmcli=llmcli"]},
)

Can I set entrypoints to do this?


Solution

  • The easiest is to refactor your __main__.py slightly, so that it calls a main function internally:

    def main():
        ...
    
    if __name__ == "__main__":
        main()
    

    Then you can add it as an entrypoint as mymodule.__main__:main.