Skip to content

Commit

Permalink
Merge branch 'next-release-notes' of github.com:pybamm-team/pybamm.or…
Browse files Browse the repository at this point in the history
…g into next-release-notes
  • Loading branch information
brosaplanella committed Nov 21, 2024
2 parents df646ce + db5b105 commit e21aa41
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

- name: Link checker
id: lychee
uses: lycheeverse/lychee-action@7cd0af4c74a61395d455af97419279d86aafaede
uses: lycheeverse/lychee-action@f81112d0d2814ded911bd23e3beaa9dda9093915
with:
# Same as those in the PyBaMM repository
args: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repos:

# Python files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand Down
26 changes: 26 additions & 0 deletions assets/css/search.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.search-button {
border-radius: 20px;
padding: 8px;
margin-right: 15px;
cursor: pointer;
}
.search-dialog {
padding: 15px;
width: 80%;
border-radius: 1rem;
}
.search-dialog::backdrop {
background-color: rgb(0, 0, 0, 0.5);
backdrop-filter: blur(3px);
}
.search-dialog input {
padding: 10px 15px;
color: #333;
}
.pagefind-ui button {
border: none;
}
/* unset a pagefind color setting to make results more legible in dark mode */
.pagefind-ui__result-title > .pagefind-ui__result-link {
color: unset !important;
}
123 changes: 123 additions & 0 deletions assets/js/search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// This file is attributed to the Scientific Python Developers
// Source: https://github.com/scientific-python/scientific-python-hugo-theme/pull/615/files

// BSD 3-Clause License

// Copyright (c) 2021--2023, Scientific Python Developers
// All rights reserved.

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:

// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.

// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.

// 3. Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// ----

// Adapted from the Hugo Fresh theme, which has the following license:

// MIT License

// Copyright (c) 2019 Stefan M.

// 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.

"use strict";

window.addEventListener("DOMContentLoaded", () => {
let searchDialog = document.querySelector(".search-dialog");
let searchButton = document.getElementById("search-button");

// Do nothing here if search is not enabled.
if (!searchDialog || !searchButton) return;

const isMac = /(Mac|iPhone|iPod|iPad)/i.test(navigator.userAgent);
searchButton.title = `Search (${isMac ? "⌘" : "Ctrl"} + K)`;

new PagefindUI({
element: ".search-dialog",
autofocus: true,
resetStyles: false,
showSubResults: true,
});

let showSearch = () => searchDialog.showModal();
let hideSearch = () => searchDialog.close();

let toggleSearch = () => {
if (!searchDialog.open) {
showSearch();
} else {
hideSearch();
}
};

let isClickOutside = (elem, clickEvt) => {
const elemDims = elem.getBoundingClientRect();
return (
clickEvt.clientX < elemDims.left ||
clickEvt.clientX > elemDims.right ||
clickEvt.clientY < elemDims.top ||
clickEvt.clientY > elemDims.bottom
);
};

// Close the search dialog if user clicks outside of it when it is open.
// This feels like functionality that should really be natively supported
// by the dialog element already.
// https://blog.webdevsimplified.com/2023-04/html-dialog/
searchDialog.addEventListener("click", (evt) => {
if (searchDialog.open && isClickOutside(searchDialog, evt)) {
hideSearch();
}
});

window.addEventListener("keydown", (evt) => {
if (
((isMac && evt.metaKey) || (!isMac && evt.ctrlKey)) &&
evt.key === "k"
) {
evt.preventDefault(); // prevents default browser behaviour
toggleSearch();
}
});

document
.querySelector(".search-button")
.addEventListener("click", showSearch);
});
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ params:
description: "PyBaMM (Python Battery Mathematical Modelling) is an open-source battery simulation package written in Python."
author:
name: PyBaMM Team
search: true
# Privacy-preserving analytics
plausible:
dataDomain: pybamm.org
Expand Down Expand Up @@ -92,6 +93,8 @@ params:
is_external: true
- title: Governance
url: /governance/
- title: Telemetry
url: /telemetry/
- title: PyBaMM Teams
url: /teams/

Expand Down
12 changes: 12 additions & 0 deletions content/telemetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Telemetry
shortcutDepth: 2
summary: Information about the telemetry collection system in PyBaMM
---

From release 24.11 onwards, PyBaMM includes an **opt-in** telemetry collection system to help us better understand how PyBaMM is being used. This system collects anonymous usage data, such as the version of PyBaMM being used, the operating system, and the Python version. This data will help us make informed decisions about the future of PyBaMM. We would like to assure you that no personal data is collected, and the data is only used by the PyBaMM team. Here are some details:

- **What is collected**: Basic usage information like PyBaMM version, Python version, and which functions are run.
- **Why**: To understand how PyBaMM is used and prioritize development efforts.
- **Permanent opt-out**: To disable telemetry permanently, set the environment variable `PYBAMM_DISABLE_TELEMETRY=true` (or any value other than `false`) or use `pybamm.telemetry.disable()` in your code. You can also select "no" when PyBaMM asks if you would like to enable telemetry.
- **Privacy**: No personal information (name, email, etc) or sensitive information (parameter values, simulation results, etc) is ever collected. The data is used only by the PyBaMM team and is not shared with any third parties. The data is stored securely and is only accessible to the PyBaMM team. Please read PostHog's policy on [GDPR compliance](https://posthog.com/docs/privacy/gdpr-compliance) for more.
6 changes: 5 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[build.environment]
PYTHON_VERSION = "3.8" # Netlify currently only supports 2.7 and 3.8
HUGO_VERSION = "0.135.0"
NODE_VERSION = "20"
DART_SASS_VERSION = "1.79.4"
DART_SASS_URL = "https://github.com/sass/dart-sass/releases/download/"

Expand Down Expand Up @@ -57,5 +58,8 @@
tar -xf ${DART_SASS_TARBALL} && \
rm ${DART_SASS_TARBALL} && \
export PATH=/opt/build/repo/dart-sass:$PATH && \
hugo --gc --minify
python3 -m pip install nox && \
nox -s themes && \
nox -s html && \
nox -s search
"""
23 changes: 17 additions & 6 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

nox.options.reuse_existing_virtualenvs = True
nox.options.default_venv_backend = "none"
nox.options.sessions = ["themes", "html", "serve-dev"]
nox.options.sessions = ["themes", "html", "search", "serve-dev"]

HUGO_ERR_MSG = """there was an error running this command. Please ensure that the extended version of Hugo is installed and that the site configuration is valid"""
ERR_MSG = """there was an error running this command. Please ensure that npm/npx and the extended version of Hugo are installed and that the site configuration is valid."""

@nox.session(name="themes")
def run_themes(session):
Expand All @@ -30,9 +30,19 @@ def run_themes(session):
def build_html(session):
"""Build the Hugo site using the 'hugo' command."""
try:
session.run("hugo")
session.run("hugo", "--gc", "--minify")
except Exception:
session.error(HUGO_ERR_MSG)
session.error(ERR_MSG)


@nox.session(name="search")
def add_search(session):
"""Enable pagefind search. Requires pagefind to be installed via npm or npx."""
session.log("Installing pagefind")
try:
session.run("npx", "--yes", "pagefind", "--site", "public")
except Exception:
session.error(ERR_MSG)


@nox.session(name="serve")
Expand All @@ -41,7 +51,7 @@ def serve(session):
try:
session.run("hugo", "--printI18nWarnings", "server")
except Exception:
session.error(HUGO_ERR_MSG)
session.error(ERR_MSG)


@nox.session(name="serve-dev")
Expand All @@ -50,7 +60,8 @@ def serve_dev(session):
try:
session.run("hugo", "--printI18nWarnings", "server", "--disableFastRender")
except Exception:
session.error(HUGO_ERR_MSG)
session.error(ERR_MSG)


@nox.session(name="clean")
def clean_build(session):
Expand Down

0 comments on commit e21aa41

Please sign in to comment.