Back
+20 XP
Concept

Console Scripts & Entry Points Definition

To create terminal commands (like `pytest` or `ruff`), packages declare CLI entry points in `pyproject.toml` under `[project.scripts]`. The installer automatically creates binary executable wrappers in your environment's `bin/` folder 💻.

python
# In pyproject.toml:
# [project.scripts]
# xicae = "xicae.cli:main"

import importlib.metadata

eps = importlib.metadata.entry_points().select(group="console_scripts")
sample = [ep.name for ep in list(eps)[:3]]
print(f"Sample discovered scripts: {sample} 💻")

# 95. Console Scripts & Entry Points Definition To create terminal commands (like `pytest` or `ruff`), packages declare CLI entry points in `pyproject.toml` under `[project.scripts]`. The installer automatically creates binary executable wrappers in your environment's `bin/` folder 💻. ```python # In pyproject.toml: # [project.scripts] # xicae = "xicae.cli:main" import importlib.metadata eps = importlib.metadata.entry_points().select(group="console_scripts") sample = [ep.name for ep in list(eps)[:3]] print(f"Sample discovered scripts: {sample} 💻") ``` On Windows, `pip` generates `.exe` shim wrappers; on POSIX/Linux, it writes small Python launcher scripts containing a `sys.exit(main())` call with the appropriate shebang `#!/path/to/venv/bin/python` 🚀! --- ### Question Which standard table in `pyproject.toml` maps CLI command names to Python callables? 🧠 - [ ] a. `[project.scripts]`, mapping command aliases to `'module.path:function'` callables 💻 - [ ] b. `[build-system.executables]`, containing compiled C binaries - [ ] c. `[system.binaries]`, writing symlinks to `/usr/local/bin` - [ ] d. `[tool.terminal]`, configuring shell history autocompletion --- ### Challenge Given entry point target string `'mypackage.cli:main'`, split it into `module` and `func`. Print the tuple `(module, func)`. 🎯 <details> <summary>Solution</summary> ```python ep = 'mypackage.cli:main' module, func = ep.split(':') print((module, func)) ``` </details>

Checkpoint

Which standard table in `pyproject.toml` maps CLI command names to Python callables? 🧠

Practice

Given entry point target string `'mypackage.cli:main'`, split it into `module` and `func`. Print the tuple `(module, func)`. 🎯

Terminal
01
Tap code blocks below to assemble
Available Blocks