From 82280c02107fa1b3f946de89325f1575cdd8287b Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Wed, 19 Jun 2024 21:37:22 +1000 Subject: [PATCH 1/4] Add HTML snippet for Plausible metrics Metrics are only collected for the main packaging.python.org documentation deployments. Closes #1561 --- source/conf.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/source/conf.py b/source/conf.py index 831f9c9ea..be5f7f149 100644 --- a/source/conf.py +++ b/source/conf.py @@ -1,6 +1,14 @@ # -- Project information --------------------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information +import os + +# Some options are only enabled for the main packaging.python.org deployment builds +RTD_BUILD = bool(os.getenv("READTHEDOCS")) +RTD_PR_BUILD = RTD_BUILD and os.getenv("READTHEDOCS_VERSION_TYPE") == "external" +RTD_URL = os.getenv("READTHEDOCS_CANONICAL_URL") +RTD_CANONICAL_BUILD = RTD_BUILD and not RTD_PR_BUILD and "packaging.python.org" in RTD_URL + project = "Python Packaging User Guide" copyright = "2013–2020, PyPA" @@ -55,6 +63,15 @@ html_favicon = "assets/py.png" html_last_updated_fmt = "" +_metrics_js_files = [ + ("https://plausible.io/js/script.js", {"data-domain": "packaging.python.org"}) +] +html_js_files = [] +if RTD_CANONICAL_BUILD: + # Enable collection of the visitor metrics reported at + # https://plausible.io/packaging.python.org + html_js_files.extend(_metrics_js_files) + # -- Options for HTML help output ------------------------------------------------------ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-help-output From 5bf53f3eba538f4e8953ca66f36ddb5d3e8963d9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 11:37:57 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/conf.py b/source/conf.py index be5f7f149..3817ce1d3 100644 --- a/source/conf.py +++ b/source/conf.py @@ -7,7 +7,9 @@ RTD_BUILD = bool(os.getenv("READTHEDOCS")) RTD_PR_BUILD = RTD_BUILD and os.getenv("READTHEDOCS_VERSION_TYPE") == "external" RTD_URL = os.getenv("READTHEDOCS_CANONICAL_URL") -RTD_CANONICAL_BUILD = RTD_BUILD and not RTD_PR_BUILD and "packaging.python.org" in RTD_URL +RTD_CANONICAL_BUILD = ( + RTD_BUILD and not RTD_PR_BUILD and "packaging.python.org" in RTD_URL +) project = "Python Packaging User Guide" From c37de0523ac61c8b2a9608a9e7b2314c88d293b0 Mon Sep 17 00:00:00 2001 From: Alyssa Coghlan Date: Wed, 19 Jun 2024 23:22:36 +1000 Subject: [PATCH 3/4] Defer loading metrics JS --- source/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/conf.py b/source/conf.py index 3817ce1d3..92c1290cc 100644 --- a/source/conf.py +++ b/source/conf.py @@ -66,7 +66,7 @@ html_last_updated_fmt = "" _metrics_js_files = [ - ("https://plausible.io/js/script.js", {"data-domain": "packaging.python.org"}) + ("https://plausible.io/js/script.js", {"data-domain": "packaging.python.org", "defer": "defer"}) ] html_js_files = [] if RTD_CANONICAL_BUILD: From db35d2764a9ad62dedf231b75bab05d1046ead4c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 19 Jun 2024 13:22:48 +0000 Subject: [PATCH 4/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- source/conf.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/conf.py b/source/conf.py index 92c1290cc..cd459ffb2 100644 --- a/source/conf.py +++ b/source/conf.py @@ -66,7 +66,10 @@ html_last_updated_fmt = "" _metrics_js_files = [ - ("https://plausible.io/js/script.js", {"data-domain": "packaging.python.org", "defer": "defer"}) + ( + "https://plausible.io/js/script.js", + {"data-domain": "packaging.python.org", "defer": "defer"}, + ) ] html_js_files = [] if RTD_CANONICAL_BUILD: