From 08104d83d753a32d1438b79d7a100e10895ab79c Mon Sep 17 00:00:00 2001 From: "Augusto W. Andreoli" Date: Tue, 16 Mar 2021 22:10:05 +0100 Subject: [PATCH] feat: cache remote styles to avoid HTTP requests (#312) * feat: option to cache styles forever, never and with a time unit * test: fixture: project with a remote style (loaded from a URL) * feat: read cache config from [tool.nitpick]cache * feat: default cache is 1 hour * test: cache option with pytest instead of doctest * docs: document cache options and default --- .bumpversion.cfg | 8 +- ..._nitpick_section.rst => configuration.rst} | 79 +++++++++- docs/index.rst | 2 +- docs/styles.rst | 4 +- package.json | 2 +- poetry.lock | 106 +++++++++++--- pyproject.toml | 4 +- src/nitpick/enums.py | 17 ++- src/nitpick/project.py | 10 +- src/nitpick/style.py | 132 +++++++++++------ tasks.py | 8 +- tests/conftest.py | 35 ++++- tests/helpers.py | 22 ++- tests/test_cache.py | 136 ++++++++++++++++++ tests/test_ini.py | 4 +- tests/test_style.py | 2 +- tox.ini | 2 + 17 files changed, 485 insertions(+), 88 deletions(-) rename docs/{tool_nitpick_section.rst => configuration.rst} (51%) create mode 100644 tests/test_cache.py diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 466cfa6e..f082fac9 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -11,19 +11,19 @@ replace = {new_version} search = version = "{current_version}" replace = version = "{new_version}" -[bumpversion:file:docs/examples.rst] +[bumpversion:file:docs/configuration.rst] search = {current_version} replace = {new_version} -[bumpversion:file:docs/quickstart.rst] +[bumpversion:file:docs/examples.rst] search = {current_version} replace = {new_version} -[bumpversion:file:docs/targets.rst] +[bumpversion:file:docs/quickstart.rst] search = {current_version} replace = {new_version} -[bumpversion:file:docs/tool_nitpick_section.rst] +[bumpversion:file:docs/targets.rst] search = {current_version} replace = {new_version} diff --git a/docs/tool_nitpick_section.rst b/docs/configuration.rst similarity index 51% rename from docs/tool_nitpick_section.rst rename to docs/configuration.rst index d2748bea..1da120e7 100644 --- a/docs/tool_nitpick_section.rst +++ b/docs/configuration.rst @@ -1,7 +1,7 @@ -.. _tool_nitpick: +.. _configuration: -The [tool.nitpick] section -========================== +Configuration +============= :ref:`the-style-file` for your project should be configured in the ``[tool.nitpick]`` section of your ``pyproject.toml`` file. @@ -31,6 +31,72 @@ You can also use the raw URL of a `GitHub Gist `_: [tool.nitpick] style = "https://gist.githubusercontent.com/andreoliwa/f4fccf4e3e83a3228e8422c01a48be61/raw/ff3447bddfc5a8665538ddf9c250734e7a38eabb/remote-style.toml" +Cache +----- + +Remote styles can be cached to avoid unnecessary HTTP requests. +The cache can be configured with the ``cache`` key; see the examples below. + +By default, remote styles will be cached for **one hour**. +This default will also be used if the ``cache`` key has an invalid value. + +Expiring after a predefined time +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The cache can be set to expire after a defined time unit. +Use the format ``cache = "