How can you define a custom shortcut (script) in pyproject.toml so that it can be run as 'poetry run my-script'?

Python interview question for Advanced practice.

Answer

By defining it under the [tool.poetry.scripts] section as 'scriptname = "module:function"'.

Explanation

Poetry allows you to map command names to specific Python functions under the [tool.poetry.scripts] section of the pyproject.toml file.

Related Questions