1This rule is to make it easier to generate `console_script` entry points 2as per Python [specification]. 3 4Generate a `py_binary` target for a particular console_script `entry_point` 5from a PyPI package, e.g. for creating an executable `pylint` target use: 6```starlark 7load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") 8 9py_console_script_binary( 10 name = "pylint", 11 pkg = "@pip//pylint", 12) 13``` 14 15Or for more advanced setups you can also specify extra dependencies and the 16exact script name you want to call. It is useful for tools like `flake8`, `pylint`, 17`pytest`, which have plugin discovery methods and discover dependencies from the 18PyPI packages available in the `PYTHONPATH`. 19```starlark 20load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") 21 22py_console_script_binary( 23 name = "pylint_with_deps", 24 pkg = "@pip//pylint", 25 # Because `pylint` has multiple console_scripts available, we have to 26 # specify which we want if the name of the target name 'pylint_with_deps' 27 # cannot be used to guess the entry_point script. 28 script = "pylint", 29 deps = [ 30 # One can add extra dependencies to the entry point. 31 # This specifically allows us to add plugins to pylint. 32 "@pip//pylint_print", 33 ], 34) 35``` 36 37A specific Python version can be forced by using the generated version-aware 38wrappers, e.g. to force Python 3.9: 39```starlark 40load("@python_versions//3.9:defs.bzl", "py_console_script_binary") 41 42py_console_script_binary( 43 name = "yamllint", 44 pkg = "@pip//yamllint", 45) 46``` 47 48Alternatively, the [`py_console_script_binary.binary_rule`] arg can be passed 49the version-bound `py_binary` symbol, or any other `py_binary`-compatible rule 50of your choosing: 51```starlark 52load("@python_versions//3.9:defs.bzl", "py_binary") 53load("@rules_python//python/entry_points:py_console_script_binary.bzl", "py_console_script_binary") 54 55py_console_script_binary( 56 name = "yamllint", 57 pkg = "@pip//yamllint:pkg", 58 binary_rule = py_binary, 59) 60``` 61 62[specification]: https://packaging.python.org/en/latest/specifications/entry-points/ 63[`py_console_script_binary.binary_rule`]: #py_console_script_binary_binary_rule 64 65