Skip to content

Commit 9ef15ca

Browse files
Prepare for 1.1.1 (#71)
1 parent 578b752 commit 9ef15ca

File tree

7 files changed

+63
-26
lines changed

7 files changed

+63
-26
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
strategy:
2727
fail-fast: false
2828
matrix:
29-
python-version: [3.8, 3.9, "3.10", "3.11", "3.12"]
29+
python-version: [3.9, "3.10", "3.11", "3.12", "3.13"]
3030

3131
steps:
3232
- uses: actions/checkout@v1
@@ -57,26 +57,9 @@ jobs:
5757
with:
5858
python-version: ${{ matrix.python-version }}
5959

60-
- uses: actions/cache@v1
61-
id: depcache
62-
with:
63-
path: deps
64-
key: requirements-pip-${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }}
65-
66-
- name: Download dependencies
67-
if: steps.depcache.outputs.cache-hit != 'true'
68-
run: |
69-
pip download --dest=deps -r requirements.txt
70-
7160
- name: Install dependencies
7261
run: |
73-
PYVER=`python -V 2>&1`
74-
75-
if [ "${PYVER:0:-2}" == "Python 3.10" ]; then
76-
pip install -r requirements.txt
77-
else
78-
pip install -U --no-index --find-links=deps deps/*
79-
fi
62+
pip install -r requirements.txt
8063
8164
- name: Run tests
8265
run: |
@@ -103,18 +86,18 @@ jobs:
10386
10487
- name: Install distribution dependencies
10588
run: pip install build
106-
if: matrix.python-version == '3.11'
89+
if: matrix.python-version == '3.12'
10790

10891
- name: Create distribution package
10992
run: python -m build
110-
if: matrix.python-version == '3.11'
93+
if: matrix.python-version == '3.12'
11194

11295
- name: Upload distribution package
11396
uses: actions/upload-artifact@v4
11497
with:
11598
name: dist-${{ matrix.os }}-${{ matrix.python-version }}
11699
path: dist
117-
if: matrix.python-version == '3.11'
100+
if: matrix.python-version == '3.12'
118101

119102
publish:
120103
runs-on: ubuntu-latest
@@ -128,10 +111,10 @@ jobs:
128111
merge-multiple: true
129112
path: dist
130113

131-
- name: Use Python 3.11
114+
- name: Use Python 3.12
132115
uses: actions/setup-python@v1
133116
with:
134-
python-version: '3.11'
117+
python-version: '3.12'
135118

136119
- name: Install dependencies
137120
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ dist/
1717

1818
# for downloaded dependencies
1919
deps/
20+
.local

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.1] 2025-04-18 🌵
9+
10+
- Improve the `contribs` plugin to not pollute the logs with
11+
`dateutil.parser.ParseError` while working on a new file that is not
12+
committed in Git, yet.
13+
- Add the possibility to enable and disable the `contribs` plugin by env
14+
variable, through plugin configuration. To use, specify the following
15+
setting:
16+
17+
```yaml
18+
- neoteroi.contribs:
19+
enabled_by_env: "GIT_CONTRIBS_ON" # Use the name you wish here for the env var
20+
```
21+
22+
- When `enabled_by_env` is not empty, the Git contributors plugin is only
23+
enabled if such variable exists and its value is a value in `{"1", "true"}`
24+
(case insensitive). This is useful to disable the plugin by default during
25+
local development, and enable it only during an automated build that builds
26+
the documentation for publishing. The rationale for this setting is that
27+
this plugin has an heavy impact on the build performance as it uses the Git
28+
CLI to obtain the list of contributors who worked on each page.
29+
- Remove Python 3.8 from the build matrix, add 3.13.
30+
831
## [1.1.0] 2024-08-10 🐢
932

1033
- Improve the `cards` plugin to automatically use cards' titles for the `alt`

neoteroi/mkdocs/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.1.0"
1+
__version__ = "1.1.1"

neoteroi/mkdocs/contribs/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import logging
11+
import os
1112
from datetime import datetime
1213
from fnmatch import fnmatch
1314
from pathlib import Path
@@ -60,6 +61,7 @@ class ContribsPlugin(BasePlugin):
6061
("contributors", c.Type(list, default=[])),
6162
("show_last_modified_time", c.Type(bool, default=True)),
6263
("show_contributors_title", c.Type(bool, default=False)),
64+
("enabled_by_env", c.Type(str, default="")),
6365
("exclude", c.Type(list, default=[])),
6466
)
6567

@@ -156,6 +158,11 @@ def _get_last_commit_date(self, page_file: File) -> datetime:
156158
def _set_contributors(self, markdown: str, page: Page) -> str:
157159
page_file = page.file
158160
last_commit_date = self._get_last_commit_date(page_file)
161+
162+
if last_commit_date.replace(tzinfo=None) == datetime.min:
163+
# The page was never committed, skip
164+
return markdown
165+
159166
contributors = self._get_contributors(page_file)
160167
return (
161168
markdown
@@ -182,7 +189,25 @@ def _is_ignored_page(self, page: Page) -> bool:
182189
for ignored_pattern in self.config["exclude"]
183190
)
184191

192+
def _is_enabled_by_env(self):
193+
"""
194+
Returns a value indicating if the plugin is enabled by env variable
195+
(default True if there is no env variable).
196+
If the user specified in the plugin configuration an env variable that controls
197+
if the plugin is enabled, read the env variable by that name and check if its
198+
value is (ci) {"1", "true"} to continue.
199+
"""
200+
enabled_by_env = self.config.get("enabled_by_env")
201+
if enabled_by_env:
202+
env_var = os.environ.get(enabled_by_env)
203+
if env_var is None:
204+
return False
205+
return env_var.lower() in {"1", "true"}
206+
return True # enabled since the user did not specify `enabled_by_env` setting
207+
185208
def on_page_markdown(self, markdown, *args, **kwargs):
209+
if not self._is_enabled_by_env():
210+
return
186211
if self._is_ignored_page(kwargs["page"]):
187212
return markdown
188213
try:

neoteroi/mkdocs/contribs/git.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from pathlib import Path
1212
from typing import Iterable, List, Tuple
1313

14+
from dateutil.parser import ParserError
1415
from dateutil.parser import parse as parse_date
1516

1617
from neoteroi.mkdocs.contribs.domain import ContributionsReader, Contributor
@@ -70,4 +71,7 @@ def get_last_modified_date(self, file_path: Path) -> datetime:
7071
["git", "log", "-1", "--pretty=format:%ci", str(file_path)]
7172
)
7273
)
73-
return parse_date(result)
74+
try:
75+
return parse_date(result)
76+
except ParserError:
77+
return datetime.min

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ classifiers = [
1919
"Programming Language :: Python :: 3.10",
2020
"Programming Language :: Python :: 3.11",
2121
"Programming Language :: Python :: 3.12",
22+
"Programming Language :: Python :: 3.13",
2223
"Operating System :: OS Independent",
2324
]
2425
keywords = [

0 commit comments

Comments
 (0)