mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Apply Black to code examples in documentation, refs #1718
Uses blacken-docs. This has a deliberate error which I hope will fail CI.
This commit is contained in:
parent
40ef8ebac2
commit
36573638b0
5 changed files with 81 additions and 41 deletions
|
|
@ -18,9 +18,12 @@ The quickest way to start writing a plugin is to create a ``my_plugin.py`` file
|
|||
|
||||
from datasette import hookimpl
|
||||
|
||||
|
||||
@hookimpl
|
||||
def prepare_connection(conn):
|
||||
conn.create_function('hello_world', 0, lambda: 'Hello world!')
|
||||
conn.create_function(
|
||||
"hello_world", 0, lambda: "Hello world!"
|
||||
)
|
||||
|
||||
If you save this in ``plugins/my_plugin.py`` you can then start Datasette like this::
|
||||
|
||||
|
|
@ -60,22 +63,22 @@ The example consists of two files: a ``setup.py`` file that defines the plugin:
|
|||
|
||||
from setuptools import setup
|
||||
|
||||
VERSION = '0.1'
|
||||
VERSION = "0.1"
|
||||
|
||||
setup(
|
||||
name='datasette-plugin-demos',
|
||||
description='Examples of plugins for Datasette',
|
||||
author='Simon Willison',
|
||||
url='https://github.com/simonw/datasette-plugin-demos',
|
||||
license='Apache License, Version 2.0',
|
||||
name="datasette-plugin-demos",
|
||||
description="Examples of plugins for Datasette",
|
||||
author="Simon Willison",
|
||||
url="https://github.com/simonw/datasette-plugin-demos",
|
||||
license="Apache License, Version 2.0",
|
||||
version=VERSION,
|
||||
py_modules=['datasette_plugin_demos'],
|
||||
py_modules=["datasette_plugin_demos"],
|
||||
entry_points={
|
||||
'datasette': [
|
||||
'plugin_demos = datasette_plugin_demos'
|
||||
"datasette": [
|
||||
"plugin_demos = datasette_plugin_demos"
|
||||
]
|
||||
},
|
||||
install_requires=['datasette']
|
||||
install_requires=["datasette"],
|
||||
)
|
||||
|
||||
And a Python module file, ``datasette_plugin_demos.py``, that implements the plugin:
|
||||
|
|
@ -88,12 +91,14 @@ And a Python module file, ``datasette_plugin_demos.py``, that implements the plu
|
|||
|
||||
@hookimpl
|
||||
def prepare_jinja2_environment(env):
|
||||
env.filters['uppercase'] = lambda u: u.upper()
|
||||
env.filters["uppercase"] = lambda u: u.upper()
|
||||
|
||||
|
||||
@hookimpl
|
||||
def prepare_connection(conn):
|
||||
conn.create_function('random_integer', 2, random.randint)
|
||||
conn.create_function(
|
||||
"random_integer", 2, random.randint
|
||||
)
|
||||
|
||||
|
||||
Having built a plugin in this way you can turn it into an installable package using the following command::
|
||||
|
|
@ -123,11 +128,13 @@ To bundle the static assets for a plugin in the package that you publish to PyPI
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
package_data={
|
||||
'datasette_plugin_name': [
|
||||
'static/plugin.js',
|
||||
],
|
||||
},
|
||||
package_data = (
|
||||
{
|
||||
"datasette_plugin_name": [
|
||||
"static/plugin.js",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
Where ``datasette_plugin_name`` is the name of the plugin package (note that it uses underscores, not hyphens) and ``static/plugin.js`` is the path within that package to the static file.
|
||||
|
||||
|
|
@ -152,11 +159,13 @@ Templates should be bundled for distribution using the same ``package_data`` mec
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
package_data={
|
||||
'datasette_plugin_name': [
|
||||
'templates/my_template.html',
|
||||
],
|
||||
},
|
||||
package_data = (
|
||||
{
|
||||
"datasette_plugin_name": [
|
||||
"templates/my_template.html",
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
You can also use wildcards here such as ``templates/*.html``. See `datasette-edit-schema <https://github.com/simonw/datasette-edit-schema>`__ for an example of this pattern.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue