-
Notifications
You must be signed in to change notification settings - Fork 76
DOC: add some documentation on how to use entry points #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daknuett
wants to merge
7
commits into
mesonbuild:main
Choose a base branch
from
daknuett:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4aaeb97
added some documentation on how to use entry points
daknuett d72adf4
removed to trainling whitespace lines
daknuett 78faab6
fixed trailing whitespace
daknuett 581094a
added link to entrypoints
daknuett 809e5cb
adapted some requested changes
daknuett 667a5fc
adapted some more requested changes; test application working
daknuett 4efbb5a
removed one trailing whitespace
daknuett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,96 @@ | |
Entry points | ||
************ | ||
|
||
|
||
.. todo:: | ||
|
||
- Mention what is the purpose of entry points | ||
- Give an example of a console entry point | ||
- Give an example of a custom entry point | ||
- Mention pluggy maybe for an example use-case? | ||
|
||
Introduction | ||
============ | ||
|
||
Entry points provide a mechanism to advertise components of an installed | ||
distribution to other code or users. Most notably, the ``console_scripts`` | ||
entry points will create a command line wrapper. | ||
|
||
See the `PyPA documentation on entry points <https://packaging.python.org/en/latest/specifications/entry-points/>`_. | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Using entry points with meson-python | ||
==================================== | ||
|
||
Entry points are defined in the ``pyproject.toml`` `metadata specification | ||
<https://packaging.python.org/en/latest/specifications/declaring-project-metadata/#entry-points>`_. | ||
No further configuration is required when using ``meson-python``. | ||
|
||
Console entry point | ||
------------------- | ||
|
||
To show the usage of console entry points we build a simple | ||
python script: | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. code-block:: python | ||
:caption: src/simpleapp/console.py | ||
|
||
""" | ||
Simple test application. | ||
|
||
Usage: | ||
simpleapp --help | ||
simpleapp doc | ||
simpleapp run [<file>] [options] | ||
|
||
Options: | ||
-h --help display this help message | ||
--workdir-path=<workdir-path> directory in which to run [default: none] | ||
|
||
""" | ||
import docopt | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
|
||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def main(): | ||
args = docopt.docopt(__doc__) | ||
# Just print the arguments for now. | ||
print(args) | ||
|
||
if __name__ == "__main__": | ||
main() | ||
|
||
This script will be part of a larger python package (called ``simpleapp``). | ||
The meson build file is very simple and only installs the python sources. | ||
|
||
.. code-block:: meson | ||
:caption: meson.build | ||
|
||
project('simpleapp', version:'0.0.1') | ||
|
||
|
||
pymod = import('python') | ||
python = pymod.find_installation('python3') | ||
pydep = python.dependency() | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
python.install_sources( | ||
'src/simpleapp/__init__.py', 'src/simpleapp/console.py' | ||
, pure: true | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
, subdir: 'simpleapp' | ||
) | ||
|
||
The entry points are then specified in the ``pyproject.toml`` metadata specification. | ||
|
||
|
||
.. code-block:: toml | ||
:caption: pyproject.toml | ||
|
||
rgommers marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[project] | ||
name = "simpleapp" | ||
description = "simple app" | ||
requires-python = ">=3.6" | ||
dependencies = ["docopt"] | ||
version = "0.0.1" | ||
|
||
[project.scripts] | ||
simpleapp = "simpleapp.console:main" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest adding two print("You discovered the PyInstaller plugin for simpleapp") |
||
[build-system] | ||
daknuett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requires = ["meson", "toml", "ninja", "meson-python"] | ||
build-backend = 'mesonpy' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.