Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 7 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v1
Expand Down Expand Up @@ -57,26 +57,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- uses: actions/cache@v1
id: depcache
with:
path: deps
key: requirements-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}

- name: Download dependencies
if: steps.depcache.outputs.cache-hit != 'true'
run: |
pip download --dest=deps -r requirements.txt

- name: Install dependencies
run: |
PYVER=`python -V 2>&1`

if [ "${PYVER:0:-2}" == "Python 3.10" ]; then
pip install -r requirements.txt
else
pip install -U --no-index --find-links=deps deps/*
fi
pip install -r requirements.txt

- name: Run tests
run: |
Expand All @@ -103,18 +86,18 @@ jobs:

- name: Install distribution dependencies
run: pip install build
if: matrix.python-version == '3.11'
if: matrix.python-version == '3.12'

- name: Create distribution package
run: python -m build
if: matrix.python-version == '3.11'
if: matrix.python-version == '3.12'

- name: Upload distribution package
uses: actions/upload-artifact@v4
with:
name: dist-${{ matrix.os }}-${{ matrix.python-version }}
path: dist
if: matrix.python-version == '3.11'
if: matrix.python-version == '3.12'

publish:
runs-on: ubuntu-latest
Expand All @@ -128,10 +111,10 @@ jobs:
merge-multiple: true
path: dist

- name: Use Python 3.11
- name: Use Python 3.12
uses: actions/setup-python@v1
with:
python-version: '3.11'
python-version: '3.12'

- name: Install dependencies
run: |
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dist/

# for downloaded dependencies
deps/
.local
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.1] 2025-04-18 🌵

- Improve the `contribs` plugin to not pollute the logs with
`dateutil.parser.ParseError` while working on a new file that is not
committed in Git, yet.
- Add the possibility to enable and disable the `contribs` plugin by env
variable, through plugin configuration. To use, specify the following
setting:

```yaml
- neoteroi.contribs:
enabled_by_env: "GIT_CONTRIBS_ON" # Use the name you wish here for the env var
```

- When `enabled_by_env` is not empty, the Git contributors plugin is only
enabled if such variable exists and its value is a value in `{"1", "true"}`
(case insensitive). This is useful to disable the plugin by default during
local development, and enable it only during an automated build that builds
the documentation for publishing. The rationale for this setting is that
this plugin has an heavy impact on the build performance as it uses the Git
CLI to obtain the list of contributors who worked on each page.
- Remove Python 3.8 from the build matrix, add 3.13.

## [1.1.0] 2024-08-10 🐢

- Improve the `cards` plugin to automatically use cards' titles for the `alt`
Expand Down
2 changes: 1 addition & 1 deletion neoteroi/mkdocs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.1.0"
__version__ = "1.1.1"
25 changes: 25 additions & 0 deletions neoteroi/mkdocs/contribs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import logging
import os
from datetime import datetime
from fnmatch import fnmatch
from pathlib import Path
Expand Down Expand Up @@ -60,6 +61,7 @@ class ContribsPlugin(BasePlugin):
("contributors", c.Type(list, default=[])),
("show_last_modified_time", c.Type(bool, default=True)),
("show_contributors_title", c.Type(bool, default=False)),
("enabled_by_env", c.Type(str, default="")),
("exclude", c.Type(list, default=[])),
)

Expand Down Expand Up @@ -156,6 +158,11 @@ def _get_last_commit_date(self, page_file: File) -> datetime:
def _set_contributors(self, markdown: str, page: Page) -> str:
page_file = page.file
last_commit_date = self._get_last_commit_date(page_file)

if last_commit_date.replace(tzinfo=None) == datetime.min:
# The page was never committed, skip
return markdown

contributors = self._get_contributors(page_file)
return (
markdown
Expand All @@ -182,7 +189,25 @@ def _is_ignored_page(self, page: Page) -> bool:
for ignored_pattern in self.config["exclude"]
)

def _is_enabled_by_env(self):
"""
Returns a value indicating if the plugin is enabled by env variable
(default True if there is no env variable).
If the user specified in the plugin configuration an env variable that controls
if the plugin is enabled, read the env variable by that name and check if its
value is (ci) {"1", "true"} to continue.
"""
enabled_by_env = self.config.get("enabled_by_env")
if enabled_by_env:
env_var = os.environ.get(enabled_by_env)
if env_var is None:
return False
return env_var.lower() in {"1", "true"}
return True # enabled since the user did not specify `enabled_by_env` setting

def on_page_markdown(self, markdown, *args, **kwargs):
if not self._is_enabled_by_env():
return
if self._is_ignored_page(kwargs["page"]):
return markdown
try:
Expand Down
6 changes: 5 additions & 1 deletion neoteroi/mkdocs/contribs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from pathlib import Path
from typing import Iterable, List, Tuple

from dateutil.parser import ParserError
from dateutil.parser import parse as parse_date

from neoteroi.mkdocs.contribs.domain import ContributionsReader, Contributor
Expand Down Expand Up @@ -70,4 +71,7 @@ def get_last_modified_date(self, file_path: Path) -> datetime:
["git", "log", "-1", "--pretty=format:%ci", str(file_path)]
)
)
return parse_date(result)
try:
return parse_date(result)
except ParserError:
return datetime.min
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Operating System :: OS Independent",
]
keywords = [
Expand Down