Skip to content
Myr

rename extension from .rst to .md

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by denuoweb · committed by denuoweb · parent d9b37c7 · Browse files · 2 files+87 added−87 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+87 added−87 removed

  • other:+87 added−87 removed

2 files+87 added−87 removed

added:docs/entry-points.md+87 added
1Packaging Entry Points2======================34It's recommended to write command line utilities as installable packages with5entry points instead of telling users to run ``python hello.py``.67A distribution package is a ``.whl`` file you install with pip or another Python8installer. You use a ``pyproject.toml`` file to describe the project and how it9is built into a package. You might upload this package to PyPI, or distribute it10to your users in another way.1112Python installers create executable scripts that will run a specified Python13function. These are known as "entry points". The installer knows how to create14an executable regardless of the operating system, so it will work on Linux,15Windows, MacOS, etc.161718Project Files19-------------2021To install your app with an entry point, all you need is the script and a22``pyproject.toml`` file. Here's an example project directory:2324.. code-block:: text2526 hello-project/27 src/28 hello/29 __init__.py30 hello.py31 pyproject.toml3233Contents of ``hello.py``:3435.. click:example::3637 import click3839 @click.command()40 def cli():41 """Prints a greeting."""42 click.echo("Hello, World!")4344Contents of ``pyproject.toml``:4546.. code-block:: toml4748 [project]49 name = "hello"50 version = "1.0.0"51 description = "Hello CLI"52 requires-python = ">=3.11"53 dependencies = [54 "click>=8.1",55 ]5657 [project.scripts]58 hello = "hello.hello:cli"5960 [build-system]61 requires = ["flit_core<4"]62 build-backend = "flit_core.buildapi"6364The magic is in the ``project.scripts`` section. Each line identifies one executable65script. The first part before the equals sign (``=``) is the name of the script that66should be generated, the second part is the import path followed by a colon67(``:``) with the function to call (the Click command).686970Installation71------------7273When your package is installed, the installer will create an executable script74based on the configuration. During development, you can install in editable75mode using the ``-e`` option. Remember to use a virtual environment!7677.. code-block:: console7879 $ python -m venv .venv80 $ . .venv/bin/activate81 $ pip install -e .8283Afterwards, your command should be available:8485.. click:run::8687 invoke(cli, prog_name="hello")
deleted:docs/entry-points.rst-87 removed
1Packaging Entry Points2======================34It's recommended to write command line utilities as installable packages with5entry points instead of telling users to run ``python hello.py``.67A distribution package is a ``.whl`` file you install with pip or another Python8installer. You use a ``pyproject.toml`` file to describe the project and how it9is built into a package. You might upload this package to PyPI, or distribute it10to your users in another way.1112Python installers create executable scripts that will run a specified Python13function. These are known as "entry points". The installer knows how to create14an executable regardless of the operating system, so it will work on Linux,15Windows, MacOS, etc.161718Project Files19-------------2021To install your app with an entry point, all you need is the script and a22``pyproject.toml`` file. Here's an example project directory:2324.. code-block:: text2526 hello-project/27 src/28 hello/29 __init__.py30 hello.py31 pyproject.toml3233Contents of ``hello.py``:3435.. click:example::3637 import click3839 @click.command()40 def cli():41 """Prints a greeting."""42 click.echo("Hello, World!")4344Contents of ``pyproject.toml``:4546.. code-block:: toml4748 [project]49 name = "hello"50 version = "1.0.0"51 description = "Hello CLI"52 requires-python = ">=3.11"53 dependencies = [54 "click>=8.1",55 ]5657 [project.scripts]58 hello = "hello.hello:cli"5960 [build-system]61 requires = ["flit_core<4"]62 build-backend = "flit_core.buildapi"6364The magic is in the ``project.scripts`` section. Each line identifies one executable65script. The first part before the equals sign (``=``) is the name of the script that66should be generated, the second part is the import path followed by a colon67(``:``) with the function to call (the Click command).686970Installation71------------7273When your package is installed, the installer will create an executable script74based on the configuration. During development, you can install in editable75mode using the ``-e`` option. Remember to use a virtual environment!7677.. code-block:: console7879 $ python -m venv .venv80 $ . .venv/bin/activate81 $ pip install -e .8283Afterwards, your command should be available:8485.. click:run::8687 invoke(cli, prog_name="hello")