'Error during execution of console_scripts in setup.cfg

While running the console_script entry point defined in setup.cfg I am getting the below error. not sure why its complaining about the positional args.

start-prediction-engine
Traceback (most recent call last):
  File "/usr/local/bin/start-prediction-engine", line 8, in <module>
    sys.exit(app())
TypeError: __call__() missing 3 required positional arguments: 'scope', 'receive', and 'send'

here is the content in setup.cfg file

[options.entry_points]
console_scripts =
  start-prediction-engine = prediction_engine.prediction_engine:app

in the file prediction_engine.py

if __name__ == "__main__":
    uvicorn.run("prediction_engine:app", host="0.0.0.0", port=8888, reload=True, log_level="info")


Solution 1:[1]

I fell into this same trap.

The issue is you're trying to register a console script to the app object (which I'm assuming is a FastAPI app instance).

Console scripts must be registered to a function. See the introduction here for more information.

To remedy this, you can simply create a function that runs your app:

# prediction_engine.py
def main():
    uvicorn.run("prediction_engine:app", host="0.0.0.0", port=8888, reload=True, log_level="info")

if __name__ == "__main__":
    sys.exit(main())

Adding the if __name__ == "__main__": section is unnecessary if you will always run from your console script, but this also lets you run it by doing i.e.

python prediction_engine.py

Finally, you'll want to point your console_script entry in your setup.cfg to the main() function:

# setup.cfg
[options.entry_points]
console_scripts =
  start-prediction-engine = prediction_engine.prediction_engine:main

Incidentally, the error you're getting

TypeError: __call__() missing 3 required positional arguments: 'scope', 'receive', and 'send'

is what happens when you try to call the FastAPI app instance (i.e. app()) which is what the generated executable does.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tdpu