{"html_url": "https://github.com/simonw/datasette/issues/1461#issuecomment-914441037", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1461", "id": 914441037, "node_id": "IC_kwDOBm6k_c42gUNN", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-09-07T16:13:59Z", "updated_at": "2021-09-07T16:13:59Z", "author_association": "OWNER", "body": "I don't think I'll adopt it for this project. For example, here:\r\n```diff\r\n response = Response.redirect(\"/\")\r\n- response.set_cookie(\"ds_actor\", datasette.sign({\r\n- \"a\": {\r\n- \"id\": \"cleopaws\"\r\n- }\r\n- }, \"actor\"))\r\n+ response.set_cookie(\"ds_actor\", datasette.sign({\"a\": {\"id\": \"cleopaws\"}}, \"actor\"))\r\n```\r\nI chose to use the multi-line version to help emphasize the structure - the single-line replacement loses that. I think I'll continue to make my own editorial choices about how the code examples are laid out.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 989986586, "label": "Try blacken-docs"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1461#issuecomment-914440282", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1461", "id": 914440282, "node_id": "IC_kwDOBm6k_c42gUBa", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-09-07T16:12:57Z", "updated_at": "2021-09-07T16:12:57Z", "author_association": "OWNER", "body": "Here's the diff it produced from that first run:\r\n```diff\r\ndiff --git a/docs/authentication.rst b/docs/authentication.rst\r\nindex 0d98cf8..8008023 100644\r\n--- a/docs/authentication.rst\r\n+++ b/docs/authentication.rst\r\n@@ -381,11 +381,7 @@ Authentication plugins can set signed ``ds_actor`` cookies themselves like so:\r\n .. code-block:: python\r\n \r\n response = Response.redirect(\"/\")\r\n- response.set_cookie(\"ds_actor\", datasette.sign({\r\n- \"a\": {\r\n- \"id\": \"cleopaws\"\r\n- }\r\n- }, \"actor\"))\r\n+ response.set_cookie(\"ds_actor\", datasette.sign({\"a\": {\"id\": \"cleopaws\"}}, \"actor\"))\r\n \r\n Note that you need to pass ``\"actor\"`` as the namespace to :ref:`datasette_sign`.\r\n \r\n@@ -412,12 +408,16 @@ To include an expiry, add a ``\"e\"`` key to the cookie value containing a `base62\r\n expires_at = int(time.time()) + (24 * 60 * 60)\r\n \r\n response = Response.redirect(\"/\")\r\n- response.set_cookie(\"ds_actor\", datasette.sign({\r\n- \"a\": {\r\n- \"id\": \"cleopaws\"\r\n- },\r\n- \"e\": baseconv.base62.encode(expires_at),\r\n- }, \"actor\"))\r\n+ response.set_cookie(\r\n+ \"ds_actor\",\r\n+ datasette.sign(\r\n+ {\r\n+ \"a\": {\"id\": \"cleopaws\"},\r\n+ \"e\": baseconv.base62.encode(expires_at),\r\n+ },\r\n+ \"actor\",\r\n+ ),\r\n+ )\r\n \r\n The resulting cookie will encode data that looks something like this:\r\n \r\ndiff --git a/docs/spatialite.rst b/docs/spatialite.rst\r\nindex d1b300b..556bad8 100644\r\n--- a/docs/spatialite.rst\r\n+++ b/docs/spatialite.rst\r\n@@ -58,19 +58,22 @@ Here's a recipe for taking a table with existing latitude and longitude columns,\r\n .. code-block:: python\r\n \r\n import sqlite3\r\n- conn = sqlite3.connect('museums.db')\r\n+\r\n+ conn = sqlite3.connect(\"museums.db\")\r\n # Lead the spatialite extension:\r\n conn.enable_load_extension(True)\r\n- conn.load_extension('/usr/local/lib/mod_spatialite.dylib')\r\n+ conn.load_extension(\"/usr/local/lib/mod_spatialite.dylib\")\r\n # Initialize spatial metadata for this database:\r\n- conn.execute('select InitSpatialMetadata(1)')\r\n+ conn.execute(\"select InitSpatialMetadata(1)\")\r\n # Add a geometry column called point_geom to our museums table:\r\n conn.execute(\"SELECT AddGeometryColumn('museums', 'point_geom', 4326, 'POINT', 2);\")\r\n # Now update that geometry column with the lat/lon points\r\n- conn.execute('''\r\n+ conn.execute(\r\n+ \"\"\"\r\n UPDATE museums SET\r\n point_geom = GeomFromText('POINT('||\"longitude\"||' '||\"latitude\"||')',4326);\r\n- ''')\r\n+ \"\"\"\r\n+ )\r\n # Now add a spatial index to that column\r\n conn.execute('select CreateSpatialIndex(\"museums\", \"point_geom\");')\r\n # If you don't commit your changes will not be persisted:\r\n@@ -186,13 +189,14 @@ Here's Python code to create a SQLite database, enable SpatiaLite, create a plac\r\n .. code-block:: python\r\n \r\n import sqlite3\r\n- conn = sqlite3.connect('places.db')\r\n+\r\n+ conn = sqlite3.connect(\"places.db\")\r\n # Enable SpatialLite extension\r\n conn.enable_load_extension(True)\r\n- conn.load_extension('/usr/local/lib/mod_spatialite.dylib')\r\n+ conn.load_extension(\"/usr/local/lib/mod_spatialite.dylib\")\r\n # Create the masic countries table\r\n- conn.execute('select InitSpatialMetadata(1)')\r\n- conn.execute('create table places (id integer primary key, name text);')\r\n+ conn.execute(\"select InitSpatialMetadata(1)\")\r\n+ conn.execute(\"create table places (id integer primary key, name text);\")\r\n # Add a MULTIPOLYGON Geometry column\r\n conn.execute(\"SELECT AddGeometryColumn('places', 'geom', 4326, 'MULTIPOLYGON', 2);\")\r\n # Add a spatial index against the new column\r\n@@ -201,13 +205,17 @@ Here's Python code to create a SQLite database, enable SpatiaLite, create a plac\r\n from shapely.geometry.multipolygon import MultiPolygon\r\n from shapely.geometry import shape\r\n import requests\r\n- geojson = requests.get('https://data.whosonfirst.org/404/227/475/404227475.geojson').json()\r\n+\r\n+ geojson = requests.get(\r\n+ \"https://data.whosonfirst.org/404/227/475/404227475.geojson\"\r\n+ ).json()\r\n # Convert to \"Well Known Text\" format\r\n- wkt = shape(geojson['geometry']).wkt\r\n+ wkt = shape(geojson[\"geometry\"]).wkt\r\n # Insert and commit the record\r\n- conn.execute(\"INSERT INTO places (id, name, geom) VALUES(null, ?, GeomFromText(?, 4326))\", (\r\n- \"Wales\", wkt\r\n- ))\r\n+ conn.execute(\r\n+ \"INSERT INTO places (id, name, geom) VALUES(null, ?, GeomFromText(?, 4326))\",\r\n+ (\"Wales\", wkt),\r\n+ )\r\n conn.commit()\r\n \r\n Querying polygons using within()\r\ndiff --git a/docs/writing_plugins.rst b/docs/writing_plugins.rst\r\nindex bd60a4b..5af01f6 100644\r\n--- a/docs/writing_plugins.rst\r\n+++ b/docs/writing_plugins.rst\r\n@@ -18,9 +18,10 @@ The quickest way to start writing a plugin is to create a ``my_plugin.py`` file\r\n \r\n from datasette import hookimpl\r\n \r\n+\r\n @hookimpl\r\n def prepare_connection(conn):\r\n- conn.create_function('hello_world', 0, lambda: 'Hello world!')\r\n+ conn.create_function(\"hello_world\", 0, lambda: \"Hello world!\")\r\n \r\n If you save this in ``plugins/my_plugin.py`` you can then start Datasette like this::\r\n \r\n@@ -60,22 +61,18 @@ The example consists of two files: a ``setup.py`` file that defines the plugin:\r\n \r\n from setuptools import setup\r\n \r\n- VERSION = '0.1'\r\n+ VERSION = \"0.1\"\r\n \r\n setup(\r\n- name='datasette-plugin-demos',\r\n- description='Examples of plugins for Datasette',\r\n- author='Simon Willison',\r\n- url='https://github.com/simonw/datasette-plugin-demos',\r\n- license='Apache License, Version 2.0',\r\n+ name=\"datasette-plugin-demos\",\r\n+ description=\"Examples of plugins for Datasette\",\r\n+ author=\"Simon Willison\",\r\n+ url=\"https://github.com/simonw/datasette-plugin-demos\",\r\n+ license=\"Apache License, Version 2.0\",\r\n version=VERSION,\r\n- py_modules=['datasette_plugin_demos'],\r\n- entry_points={\r\n- 'datasette': [\r\n- 'plugin_demos = datasette_plugin_demos'\r\n- ]\r\n- },\r\n- install_requires=['datasette']\r\n+ py_modules=[\"datasette_plugin_demos\"],\r\n+ entry_points={\"datasette\": [\"plugin_demos = datasette_plugin_demos\"]},\r\n+ install_requires=[\"datasette\"],\r\n )\r\n \r\n And a Python module file, ``datasette_plugin_demos.py``, that implements the plugin:\r\n@@ -88,12 +85,12 @@ And a Python module file, ``datasette_plugin_demos.py``, that implements the plu\r\n \r\n @hookimpl\r\n def prepare_jinja2_environment(env):\r\n- env.filters['uppercase'] = lambda u: u.upper()\r\n+ env.filters[\"uppercase\"] = lambda u: u.upper()\r\n \r\n \r\n @hookimpl\r\n def prepare_connection(conn):\r\n- conn.create_function('random_integer', 2, random.randint)\r\n+ conn.create_function(\"random_integer\", 2, random.randint)\r\n \r\n \r\n Having built a plugin in this way you can turn it into an installable package using the following command::\r\n@@ -123,11 +120,13 @@ To bundle the static assets for a plugin in the package that you publish to PyPI\r\n \r\n .. code-block:: python\r\n \r\n- package_data={\r\n- 'datasette_plugin_name': [\r\n- 'static/plugin.js',\r\n- ],\r\n- },\r\n+ package_data = (\r\n+ {\r\n+ \"datasette_plugin_name\": [\r\n+ \"static/plugin.js\",\r\n+ ],\r\n+ },\r\n+ )\r\n \r\n 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.\r\n \r\n@@ -152,11 +151,13 @@ Templates should be bundled for distribution using the same ``package_data`` mec\r\n \r\n .. code-block:: python\r\n \r\n- package_data={\r\n- 'datasette_plugin_name': [\r\n- 'templates/my_template.html',\r\n- ],\r\n- },\r\n+ package_data = (\r\n+ {\r\n+ \"datasette_plugin_name\": [\r\n+ \"templates/my_template.html\",\r\n+ ],\r\n+ },\r\n+ )\r\n \r\n You can also use wildcards here such as ``templates/*.html``. See `datasette-edit-schema `__ for an example of this pattern.\r\n ```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 989986586, "label": "Try blacken-docs"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/datasette/issues/1461#issuecomment-914439356", "issue_url": "https://api.github.com/repos/simonw/datasette/issues/1461", "id": 914439356, "node_id": "IC_kwDOBm6k_c42gTy8", "user": {"value": 9599, "label": "simonw"}, "created_at": "2021-09-07T16:11:37Z", "updated_at": "2021-09-07T16:11:37Z", "author_association": "OWNER", "body": "```\r\n(datasette) datasette % blacken-docs docs/*.rst\r\ndocs/authentication.rst: Rewriting...\r\ndocs/internals.rst:169: code block parse error Cannot parse: 14:0: \r\ndocs/plugin_hooks.rst:251: code block parse error Cannot parse: 6:4: ]\r\ndocs/plugin_hooks.rst:312: code block parse error Cannot parse: 38:0: \r\ndocs/spatialite.rst: Rewriting...\r\ndocs/testing_plugins.rst:135: code block parse error Cannot parse: 5:0: \r\ndocs/writing_plugins.rst: Rewriting...\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 989986586, "label": "Try blacken-docs"}, "performed_via_github_app": null}