lektor-limit-dependencies


Namelektor-limit-dependencies JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummaryLektor plugin to limit dependencies created by queries
upload_time2023-01-31 22:22:23
maintainer
docs_urlNone
author
requires_python>=3.7
licenseCopyright © 2020 Geoffrey T. Dairiki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords lektor plugin
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Lektor Limit Dependencies

[![PyPI version](https://img.shields.io/pypi/v/lektor-limit-dependencies.svg)](https://pypi.org/project/lektor-limit-dependencies/)
[![PyPI Supported Python Versions](https://img.shields.io/pypi/pyversions/lektor-limit-dependencies.svg)](https://pypi.python.org/pypi/lektor-limit-dependencies/)
[![GitHub license](https://img.shields.io/github/license/dairiki/lektor-limit-dependencies)](https://github.com/dairiki/lektor-limit-dependencies/blob/master/LICENSE)
[![GitHub Actions (Tests)](https://github.com/dairiki/lektor-limit-dependencies/workflows/Tests/badge.svg)](https://github.com/dairiki/lektor-limit-dependencies)


This is an experimental [Lektor][] plugin which aims to provide tools (or,
at least, a tool) to help keep Lektor’s dependency tracking under
control.

[lektor]: <https://www.getlektor.com/>


## Introduction

### Motivating Example

Suppose that you would like to list the three most recent blog posts
in the sidebar of your Lektor-based site.  This can be done by adding
something like to your site base template:

```html+jinja
<h3>Recent Posts</h3>
<ul>
  {% for post in site.query('/blog').order_by('-pub_date').limit(3) %}
    <li><a href="{{ post|url }}">{{ post.title }}</a></li>
  {% endfor %}
</ul>
```

This is not without drawbacks, however.  To sort the post query by
date, Lektor iterates through ***all*** of the blog’s posts, then sorts
them.  In so doing, it records all of the blog posts as dependencies
*of every page on which this most-recent-post query is used*.  If this
is in the sidebar of every page on your site, *now every page on your
site will be rebuilt whenever any blog post at all* (not just one of
the three most recent posts) *is edited*.

Technically, it is true that all pages now depend on all posts.  You
might well edit the `pub_date` of one of your older posts, such that
it should now appear in the most-recent listing.  However, it is not
true that all pages need to be rebuilt for *any* edit of any post.
Unfortunately, Lektor’s dependency tracking system is not elaborate
enough to be able to express details about *how* pages are
dependent on other pages; it only records that they *are*
dependent, so Lektor has no option but to rebuild everything.

### A Solution?

This plugin introduces a Jinja filter, `limit_dependencies`.  It
expects, as input, a Lektor [query][] instance.  It iterates through the
input query, and returns a new query instance which will yield the
same results.  While it is doing its iteration, it — essentially —
monkey-patches Lektor’s dependency tracking machinery to prevent it
from recording any dependencies.

At the end, `limit_dependencies` records one dependency on a [virtual
source object][virtual] which depends only on the sequence of the identities
of the records in the query result.  (Lektor provides a means by which
virtual source objects can report checksums.  The
dependency tracking mechanism records those checksums, and will
trigger a rebuild should the checksum change.  `Limit_dependencies`
generates a virtual source object whose checksum depends on the
sequence of identities in the query result.)

In the above example, this is exactly what we want.  We only want to
trigger a rebuild if the order or composition of the most-recent three
posts changes.  (Or if any of their titles change.  Note that this
gets covered, too, since when the resulting query is iterated over in
the `{% for %}` loop, dependencies will be recorded on the three
most-recent posts.)

Thus, the example above, if replaced by:

```html+jinja
<h3>Recent Posts</h3>
<ul>
  {% for post in site.query('/blog').order_by('-pub_date').limit(3)|limit_dependencies %}
    <li><a href="{{ post|url }}">{{ post.title }}</a></li>
  {% endfor %}
</ul>
```

will work in a much more efficient and sane manner.  Pages will be
rebuilt only if there are changes in the order, composition or content
of the three most recent posts.


[virtual]: <https://www.getlektor.com/docs/api/db/obj/#virtual-source-objects>
    "Lektor documentation on Virtual Source Objects"

[query]: <https://www.getlektor.com/docs/api/db/query/>
    "Lektor documentation on the Query class"

## Installation

Add lektor-limit-dependencies to your project from command line:

```
lektor plugins add lektor-limit-dependencies
```

See [the Lektor plugin documentation][plugins] for more information.

[plugins]: <https://www.getlektor.com/docs/plugins/>

## Author

Jeff Dairiki <dairiki@dairiki.org>

## Changelog

### Release 1.0.0 (2023-01-31)

No code changes from 1.0.0b1.

Test under python 3.11.

### Release 1.0.0b1 (2021-03-29)

Drop support for python<3.7 and lektor<3.3.

### Release 0.1 (2021-02-05)

No code changes.

Update development status classifier to "stable".

Test under python 3.9.  Stop testing under 3.5.

### Release 0.1a1 (2020-05-19)

Initial release.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "lektor-limit-dependencies",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "Lektor plugin",
    "author": "",
    "author_email": "Jeff Dairiki <dairiki@dairiki.org>",
    "download_url": "https://files.pythonhosted.org/packages/44/c2/d3e52d93141f7f0f55f4226a6047416c0e9e26f92a0da2acd4809d391416/lektor-limit-dependencies-1.0.0.tar.gz",
    "platform": null,
    "description": "# Lektor Limit Dependencies\n\n[![PyPI version](https://img.shields.io/pypi/v/lektor-limit-dependencies.svg)](https://pypi.org/project/lektor-limit-dependencies/)\n[![PyPI Supported Python Versions](https://img.shields.io/pypi/pyversions/lektor-limit-dependencies.svg)](https://pypi.python.org/pypi/lektor-limit-dependencies/)\n[![GitHub license](https://img.shields.io/github/license/dairiki/lektor-limit-dependencies)](https://github.com/dairiki/lektor-limit-dependencies/blob/master/LICENSE)\n[![GitHub Actions (Tests)](https://github.com/dairiki/lektor-limit-dependencies/workflows/Tests/badge.svg)](https://github.com/dairiki/lektor-limit-dependencies)\n\n\nThis is an experimental [Lektor][] plugin which aims to provide tools (or,\nat least, a tool) to help keep Lektor\u2019s dependency tracking under\ncontrol.\n\n[lektor]: <https://www.getlektor.com/>\n\n\n## Introduction\n\n### Motivating Example\n\nSuppose that you would like to list the three most recent blog posts\nin the sidebar of your Lektor-based site.  This can be done by adding\nsomething like to your site base template:\n\n```html+jinja\n<h3>Recent Posts</h3>\n<ul>\n  {% for post in site.query('/blog').order_by('-pub_date').limit(3) %}\n    <li><a href=\"{{ post|url }}\">{{ post.title }}</a></li>\n  {% endfor %}\n</ul>\n```\n\nThis is not without drawbacks, however.  To sort the post query by\ndate, Lektor iterates through ***all*** of the blog\u2019s posts, then sorts\nthem.  In so doing, it records all of the blog posts as dependencies\n*of every page on which this most-recent-post query is used*.  If this\nis in the sidebar of every page on your site, *now every page on your\nsite will be rebuilt whenever any blog post at all* (not just one of\nthe three most recent posts) *is edited*.\n\nTechnically, it is true that all pages now depend on all posts.  You\nmight well edit the `pub_date` of one of your older posts, such that\nit should now appear in the most-recent listing.  However, it is not\ntrue that all pages need to be rebuilt for *any* edit of any post.\nUnfortunately, Lektor\u2019s dependency tracking system is not elaborate\nenough to be able to express details about *how* pages are\ndependent on other pages; it only records that they *are*\ndependent, so Lektor has no option but to rebuild everything.\n\n### A Solution?\n\nThis plugin introduces a Jinja filter, `limit_dependencies`.  It\nexpects, as input, a Lektor [query][] instance.  It iterates through the\ninput query, and returns a new query instance which will yield the\nsame results.  While it is doing its iteration, it \u2014 essentially \u2014\nmonkey-patches Lektor\u2019s dependency tracking machinery to prevent it\nfrom recording any dependencies.\n\nAt the end, `limit_dependencies` records one dependency on a [virtual\nsource object][virtual] which depends only on the sequence of the identities\nof the records in the query result.  (Lektor provides a means by which\nvirtual source objects can report checksums.  The\ndependency tracking mechanism records those checksums, and will\ntrigger a rebuild should the checksum change.  `Limit_dependencies`\ngenerates a virtual source object whose checksum depends on the\nsequence of identities in the query result.)\n\nIn the above example, this is exactly what we want.  We only want to\ntrigger a rebuild if the order or composition of the most-recent three\nposts changes.  (Or if any of their titles change.  Note that this\ngets covered, too, since when the resulting query is iterated over in\nthe `{% for %}` loop, dependencies will be recorded on the three\nmost-recent posts.)\n\nThus, the example above, if replaced by:\n\n```html+jinja\n<h3>Recent Posts</h3>\n<ul>\n  {% for post in site.query('/blog').order_by('-pub_date').limit(3)|limit_dependencies %}\n    <li><a href=\"{{ post|url }}\">{{ post.title }}</a></li>\n  {% endfor %}\n</ul>\n```\n\nwill work in a much more efficient and sane manner.  Pages will be\nrebuilt only if there are changes in the order, composition or content\nof the three most recent posts.\n\n\n[virtual]: <https://www.getlektor.com/docs/api/db/obj/#virtual-source-objects>\n    \"Lektor documentation on Virtual Source Objects\"\n\n[query]: <https://www.getlektor.com/docs/api/db/query/>\n    \"Lektor documentation on the Query class\"\n\n## Installation\n\nAdd lektor-limit-dependencies to your project from command line:\n\n```\nlektor plugins add lektor-limit-dependencies\n```\n\nSee [the Lektor plugin documentation][plugins] for more information.\n\n[plugins]: <https://www.getlektor.com/docs/plugins/>\n\n## Author\n\nJeff Dairiki <dairiki@dairiki.org>\n\n## Changelog\n\n### Release 1.0.0 (2023-01-31)\n\nNo code changes from 1.0.0b1.\n\nTest under python 3.11.\n\n### Release 1.0.0b1 (2021-03-29)\n\nDrop support for python<3.7 and lektor<3.3.\n\n### Release 0.1 (2021-02-05)\n\nNo code changes.\n\nUpdate development status classifier to \"stable\".\n\nTest under python 3.9.  Stop testing under 3.5.\n\n### Release 0.1a1 (2020-05-19)\n\nInitial release.\n",
    "bugtrack_url": null,
    "license": "Copyright \u00a9 2020 Geoffrey T. Dairiki  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Lektor plugin to limit dependencies created by queries",
    "version": "1.0.0",
    "split_keywords": [
        "lektor",
        "plugin"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5057a578a4831cafe39b4e8fa8db1442f0bf649234e379316a3e46c74ad3c71",
                "md5": "26a7456a5885de33f6a1ad3f2c9d8381",
                "sha256": "0bdc488176cc3ffb249df5cf071bc1b21cc19456232a08d7ac3af0017264fb90"
            },
            "downloads": -1,
            "filename": "lektor_limit_dependencies-1.0.0-py3-none-any.whl",
            "has_sig": true,
            "md5_digest": "26a7456a5885de33f6a1ad3f2c9d8381",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 6968,
            "upload_time": "2023-01-31T22:22:21",
            "upload_time_iso_8601": "2023-01-31T22:22:21.352445Z",
            "url": "https://files.pythonhosted.org/packages/b5/05/7a578a4831cafe39b4e8fa8db1442f0bf649234e379316a3e46c74ad3c71/lektor_limit_dependencies-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "44c2d3e52d93141f7f0f55f4226a6047416c0e9e26f92a0da2acd4809d391416",
                "md5": "80299ebc10a931f48d7ec55dcc4f91d5",
                "sha256": "ad3fb239eadcf97b81651669be0747d60cb9b137d738a706c5df67528b0fdd1d"
            },
            "downloads": -1,
            "filename": "lektor-limit-dependencies-1.0.0.tar.gz",
            "has_sig": true,
            "md5_digest": "80299ebc10a931f48d7ec55dcc4f91d5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 11865,
            "upload_time": "2023-01-31T22:22:23",
            "upload_time_iso_8601": "2023-01-31T22:22:23.431924Z",
            "url": "https://files.pythonhosted.org/packages/44/c2/d3e52d93141f7f0f55f4226a6047416c0e9e26f92a0da2acd4809d391416/lektor-limit-dependencies-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-31 22:22:23",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "lektor-limit-dependencies"
}
        
Elapsed time: 0.03397s