mkdocs-git-authors-plugin 0.10.0__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mkdocs_git_authors_plugin-1.1.0/PKG-INFO +60 -0
- mkdocs_git_authors_plugin-1.1.0/README.md +33 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/pyproject.toml +11 -8
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/aggregate.py +113 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/authors_file.py +63 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/cache.py +48 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/ci.py +75 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin/config.py +20 -5
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/git/porcelain.py +88 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/git/runner.py +196 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/model.py +38 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/paths.py +70 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/plugin.py +606 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin/render.py +104 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin.egg-info/PKG-INFO +60 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +33 -0
- mkdocs_git_authors_plugin-1.1.0/src/mkdocs_git_authors_plugin.egg-info/requires.txt +1 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_aggregation.py +204 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_authors_file.py +242 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_blame_parser.py +145 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_build.py +230 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_ci.py +51 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_faster_builds.py +385 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_git_runner.py +153 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_paths.py +119 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_plugin_events.py +728 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_render.py +177 -0
- mkdocs_git_authors_plugin-1.1.0/tests/test_submodules.py +264 -0
- mkdocs_git_authors_plugin-0.10.0/PKG-INFO +0 -87
- mkdocs_git_authors_plugin-0.10.0/README.md +0 -60
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/ci.py +0 -132
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/exclude.py +0 -43
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/git/author.py +0 -160
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/git/command.py +0 -129
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/git/commit.py +0 -89
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/git/page.py +0 -251
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/git/repo.py +0 -269
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/plugin.py +0 -299
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin/util.py +0 -177
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin.egg-info/PKG-INFO +0 -87
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +0 -23
- mkdocs_git_authors_plugin-0.10.0/src/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -1
- mkdocs_git_authors_plugin-0.10.0/tests/test_basic.py +0 -400
- mkdocs_git_authors_plugin-0.10.0/tests/test_util.py +0 -731
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/LICENSE +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/setup.cfg +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin/git/__init__.py +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
- {mkdocs_git_authors_plugin-0.10.0 → mkdocs_git_authors_plugin-1.1.0}/src/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mkdocs-git-authors-plugin
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Mkdocs plugin to display git authors of a page
|
|
5
|
+
Author-email: Tim Vink <vinktim@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/timvink/mkdocs-git-authors-plugin
|
|
8
|
+
Keywords: mkdocs,git,contributors,committers,authors,plugin
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Programming Language :: Python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
18
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
20
|
+
Classifier: Topic :: Documentation
|
|
21
|
+
Classifier: Topic :: Text Processing
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: mkdocs>=1.5
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
[](https://github.com/timvink/mkdocs-git-authors-plugin/actions)
|
|
29
|
+

|
|
30
|
+

|
|
31
|
+

|
|
32
|
+
[](https://codecov.io/gh/timvink/mkdocs-git-authors-plugin)
|
|
33
|
+
|
|
34
|
+
# mkdocs-git-authors-plugin
|
|
35
|
+
|
|
36
|
+
An [MkDocs](https://www.mkdocs.org/) plugin that shows the git authors of each page:
|
|
37
|
+
|
|
38
|
+
> Authors: Jane Doe, John Doe
|
|
39
|
+
|
|
40
|
+
It uses `git blame`, so it only counts authors of the lines that are on the page now.
|
|
41
|
+
|
|
42
|
+
## Setup
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install mkdocs-git-authors-plugin
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Add the plugin to `mkdocs.yml`:
|
|
49
|
+
|
|
50
|
+
```yaml
|
|
51
|
+
plugins:
|
|
52
|
+
- search
|
|
53
|
+
- git-authors
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
[Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) 9.5.0 and newer shows the authors without further setup. With other themes, add `{{ git_page_authors }}` to a page or template.
|
|
57
|
+
|
|
58
|
+
## Documentation
|
|
59
|
+
|
|
60
|
+
See [timvink.github.io/mkdocs-git-authors-plugin](https://timvink.github.io/mkdocs-git-authors-plugin/) for options, usage and contributing guidelines.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
[](https://github.com/timvink/mkdocs-git-authors-plugin/actions)
|
|
2
|
+

|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
[](https://codecov.io/gh/timvink/mkdocs-git-authors-plugin)
|
|
6
|
+
|
|
7
|
+
# mkdocs-git-authors-plugin
|
|
8
|
+
|
|
9
|
+
An [MkDocs](https://www.mkdocs.org/) plugin that shows the git authors of each page:
|
|
10
|
+
|
|
11
|
+
> Authors: Jane Doe, John Doe
|
|
12
|
+
|
|
13
|
+
It uses `git blame`, so it only counts authors of the lines that are on the page now.
|
|
14
|
+
|
|
15
|
+
## Setup
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install mkdocs-git-authors-plugin
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Add the plugin to `mkdocs.yml`:
|
|
22
|
+
|
|
23
|
+
```yaml
|
|
24
|
+
plugins:
|
|
25
|
+
- search
|
|
26
|
+
- git-authors
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
[Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) 9.5.0 and newer shows the authors without further setup. With other themes, add `{{ git_page_authors }}` to a page or template.
|
|
30
|
+
|
|
31
|
+
## Documentation
|
|
32
|
+
|
|
33
|
+
See [timvink.github.io/mkdocs-git-authors-plugin](https://timvink.github.io/mkdocs-git-authors-plugin/) for options, usage and contributing guidelines.
|
|
@@ -12,19 +12,19 @@ authors = [
|
|
|
12
12
|
]
|
|
13
13
|
keywords = ["mkdocs", "git", "contributors", "committers", "authors", "plugin"]
|
|
14
14
|
urls = {Homepage = "https://github.com/timvink/mkdocs-git-authors-plugin"}
|
|
15
|
-
version = "
|
|
16
|
-
requires-python = ">=3.
|
|
17
|
-
dependencies = ["mkdocs>=1.
|
|
15
|
+
version = "1.1.0"
|
|
16
|
+
requires-python = ">=3.11"
|
|
17
|
+
dependencies = ["mkdocs>=1.5"]
|
|
18
18
|
classifiers = [
|
|
19
|
+
"Development Status :: 5 - Production/Stable",
|
|
19
20
|
"Operating System :: OS Independent",
|
|
20
21
|
"Programming Language :: Python",
|
|
21
22
|
"Programming Language :: Python :: 3",
|
|
22
|
-
"Programming Language :: Python :: 3.8",
|
|
23
|
-
"Programming Language :: Python :: 3.9",
|
|
24
|
-
"Programming Language :: Python :: 3.10",
|
|
25
23
|
"Programming Language :: Python :: 3.11",
|
|
26
24
|
"Programming Language :: Python :: 3.12",
|
|
27
25
|
"Programming Language :: Python :: 3.13",
|
|
26
|
+
"Programming Language :: Python :: 3.14",
|
|
27
|
+
"Programming Language :: Python :: 3.15",
|
|
28
28
|
"Programming Language :: Python :: 3 :: Only",
|
|
29
29
|
"License :: OSI Approved :: MIT License",
|
|
30
30
|
"Topic :: Documentation",
|
|
@@ -41,12 +41,15 @@ package-dir = {"" = "src"}
|
|
|
41
41
|
dev = [
|
|
42
42
|
"click>=8.1.8",
|
|
43
43
|
"codecov>=2.1.13",
|
|
44
|
-
"gitpython>=3.1.44",
|
|
45
44
|
"mkapi!=2.0.*",
|
|
46
45
|
"mkdocs>=1.6.1",
|
|
46
|
+
"mkdocs-gen-files>=0.5.0",
|
|
47
47
|
"mkdocs-git-revision-date-localized-plugin>=1.4.4",
|
|
48
48
|
"mkdocs-macros-plugin>=1.3.7",
|
|
49
49
|
"mkdocs-material>=9.6.7",
|
|
50
|
-
"pytest>=
|
|
50
|
+
"pytest>=9.2.0",
|
|
51
51
|
"pytest-cov>=5.0.0",
|
|
52
52
|
]
|
|
53
|
+
|
|
54
|
+
[tool.uv]
|
|
55
|
+
exclude-newer = "24 hours"
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Count blamed lines per author, and rank authors."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Collection, Iterable, Mapping, Sequence
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from mkdocs_git_authors_plugin.git.porcelain import BlameLine
|
|
7
|
+
from mkdocs_git_authors_plugin.model import Author, PageStats, SiteStats
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def page_stats(
|
|
11
|
+
path: Path,
|
|
12
|
+
blame: Iterable[BlameLine],
|
|
13
|
+
co_authors: Mapping[str, Sequence[tuple[str, str]]],
|
|
14
|
+
*,
|
|
15
|
+
ignore_authors: Collection[str] = (),
|
|
16
|
+
count_empty_lines: bool = True,
|
|
17
|
+
) -> PageStats:
|
|
18
|
+
"""
|
|
19
|
+
Credit each line to its commit's author and co-authors (by commit SHA).
|
|
20
|
+
|
|
21
|
+
Emails are compared lowercased. A line counts towards the page's total
|
|
22
|
+
when anyone is credited for it.
|
|
23
|
+
"""
|
|
24
|
+
ignored = {email.lower() for email in ignore_authors}
|
|
25
|
+
stats = PageStats(path)
|
|
26
|
+
commits = set()
|
|
27
|
+
for line in blame:
|
|
28
|
+
email = line.email.lower()
|
|
29
|
+
line_co_authors = [
|
|
30
|
+
(name, e.lower()) for name, e in co_authors.get(line.sha, ())
|
|
31
|
+
]
|
|
32
|
+
if line.sha not in commits:
|
|
33
|
+
commits.add(line.sha)
|
|
34
|
+
for name, co_email in line_co_authors:
|
|
35
|
+
stats.names.setdefault(co_email, name)
|
|
36
|
+
stats.names.setdefault(email, line.author)
|
|
37
|
+
# Whitespace-only lines (including a CRLF line's "\r") are empty
|
|
38
|
+
if not (count_empty_lines or line.content.strip()):
|
|
39
|
+
continue
|
|
40
|
+
credited = [] if email in ignored else [email]
|
|
41
|
+
for _, co_email in line_co_authors:
|
|
42
|
+
if (
|
|
43
|
+
co_email not in ignored
|
|
44
|
+
and co_email != email
|
|
45
|
+
and co_email not in credited
|
|
46
|
+
):
|
|
47
|
+
credited.append(co_email)
|
|
48
|
+
if credited:
|
|
49
|
+
stats.total_lines += 1
|
|
50
|
+
for e in credited:
|
|
51
|
+
stats.lines[e] = stats.lines.get(e, 0) + 1
|
|
52
|
+
if e not in stats.last or line.when > stats.last[e]:
|
|
53
|
+
stats.last[e] = line.when
|
|
54
|
+
return stats
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def site_stats(
|
|
58
|
+
pages: Iterable[PageStats], profiles: Mapping[str, Mapping[str, str]] = {}
|
|
59
|
+
) -> SiteStats:
|
|
60
|
+
"""
|
|
61
|
+
Combine pages; the first name seen for an email wins. Profiles (from the
|
|
62
|
+
authors_file) override an email's name and add its url and avatar.
|
|
63
|
+
"""
|
|
64
|
+
pages = {page.path: page for page in pages}
|
|
65
|
+
authors: dict[str, Author] = {}
|
|
66
|
+
for page in pages.values():
|
|
67
|
+
for email, name in page.names.items():
|
|
68
|
+
if email not in authors:
|
|
69
|
+
authors[email] = Author(
|
|
70
|
+
**{"name": name, **profiles.get(email, {}), "email": email}
|
|
71
|
+
)
|
|
72
|
+
lines = {
|
|
73
|
+
email: sum(page.lines.get(email, 0) for page in pages.values())
|
|
74
|
+
for email in authors
|
|
75
|
+
}
|
|
76
|
+
return SiteStats(
|
|
77
|
+
pages=pages,
|
|
78
|
+
authors=authors,
|
|
79
|
+
lines={email: n for email, n in lines.items() if n},
|
|
80
|
+
total_lines=sum(page.total_lines for page in pages.values()),
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def contribution(scope: PageStats | SiteStats, email: str) -> float:
|
|
85
|
+
"""An author's share of the lines of a page or the site, between 0 and 1."""
|
|
86
|
+
return scope.lines.get(email, 0) / scope.total_lines if scope.total_lines else 0.0
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def rank_authors(
|
|
90
|
+
scope: PageStats | SiteStats,
|
|
91
|
+
site: SiteStats,
|
|
92
|
+
*,
|
|
93
|
+
by_contribution: bool = False,
|
|
94
|
+
threshold: int = 0,
|
|
95
|
+
) -> list[Author]:
|
|
96
|
+
"""
|
|
97
|
+
The authors with lines in scope, sorted by name or by descending contribution.
|
|
98
|
+
|
|
99
|
+
Ties keep the order in which authors were first seen. Authors contributing
|
|
100
|
+
less than threshold percent are left out; a sole author always has 100%.
|
|
101
|
+
"""
|
|
102
|
+
authors = [site.authors[email] for email, n in scope.lines.items() if n]
|
|
103
|
+
if by_contribution:
|
|
104
|
+
authors.sort(key=lambda a: contribution(scope, a.email), reverse=True)
|
|
105
|
+
else:
|
|
106
|
+
authors.sort(key=lambda a: a.name)
|
|
107
|
+
if threshold:
|
|
108
|
+
authors = [
|
|
109
|
+
a
|
|
110
|
+
for a in authors
|
|
111
|
+
if round(contribution(scope, a.email) * 100, 2) >= threshold
|
|
112
|
+
]
|
|
113
|
+
return authors
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""Read the authors_file, which sets how authors are shown."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import yaml
|
|
6
|
+
from mkdocs.exceptions import PluginError
|
|
7
|
+
|
|
8
|
+
FIELDS = ("name", "url", "avatar")
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _Loader(yaml.SafeLoader):
|
|
12
|
+
"""Rejects duplicate keys (ignoring case), which YAML would silently overwrite."""
|
|
13
|
+
|
|
14
|
+
def construct_mapping(self, node, deep=False):
|
|
15
|
+
seen = set()
|
|
16
|
+
for key_node, _ in node.value:
|
|
17
|
+
# Merge keys (<<: *anchor) are merged by the parent class
|
|
18
|
+
if key_node.tag == "tag:yaml.org,2002:merge":
|
|
19
|
+
continue
|
|
20
|
+
key = self.construct_object(key_node, deep=deep)
|
|
21
|
+
if isinstance(key, str):
|
|
22
|
+
if key.lower() in seen:
|
|
23
|
+
raise yaml.MarkedYAMLError(
|
|
24
|
+
problem=f"duplicate key '{key}' (keys ignore case)",
|
|
25
|
+
problem_mark=key_node.start_mark,
|
|
26
|
+
)
|
|
27
|
+
seen.add(key.lower())
|
|
28
|
+
return super().construct_mapping(node, deep)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def load_authors_file(path: Path) -> dict[str, dict[str, str]]:
|
|
32
|
+
"""The name, url and avatar to show for each (lowercased) email address."""
|
|
33
|
+
|
|
34
|
+
def error(message: str) -> PluginError:
|
|
35
|
+
return PluginError(f"[git-authors-plugin] The authors_file '{path}' {message}")
|
|
36
|
+
|
|
37
|
+
if not path.is_file():
|
|
38
|
+
raise error("does not exist.")
|
|
39
|
+
try:
|
|
40
|
+
data = yaml.load(path.read_bytes(), Loader=_Loader)
|
|
41
|
+
except yaml.YAMLError as e:
|
|
42
|
+
raise error(f"is not valid YAML: {e}") from e
|
|
43
|
+
if data is None:
|
|
44
|
+
return {}
|
|
45
|
+
if not isinstance(data, dict):
|
|
46
|
+
raise error("must map email addresses to authors.")
|
|
47
|
+
|
|
48
|
+
authors: dict[str, dict[str, str]] = {}
|
|
49
|
+
for email, author in data.items():
|
|
50
|
+
if not isinstance(email, str):
|
|
51
|
+
raise error(f"has a key {email!r} that is not an email address.")
|
|
52
|
+
if not isinstance(author, dict):
|
|
53
|
+
raise error(f"must map '{email}' to {', '.join(FIELDS)} or some of them.")
|
|
54
|
+
if unknown := sorted(set(author) - set(FIELDS), key=str):
|
|
55
|
+
raise error(
|
|
56
|
+
f"has unknown keys for '{email}': {', '.join(map(str, unknown))}."
|
|
57
|
+
f" Expected {', '.join(FIELDS)}."
|
|
58
|
+
)
|
|
59
|
+
for key, value in author.items():
|
|
60
|
+
if not (isinstance(value, str) and value):
|
|
61
|
+
raise error(f"must have a non-empty string as '{key}' of '{email}'.")
|
|
62
|
+
authors[email.lower()] = author
|
|
63
|
+
return authors
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Keys that tell when `git blame` output can be reused across `mkdocs serve` rebuilds."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import stat
|
|
7
|
+
from collections.abc import Iterable
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from mkdocs_git_authors_plugin.paths import directories_up_to
|
|
11
|
+
|
|
12
|
+
_FILTER = re.compile(r"(?:^|\s)filter=", re.MULTILINE)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def file_key(path: Path) -> tuple | None:
|
|
16
|
+
"""
|
|
17
|
+
A file's type, modification time and size, with a symlink's target or a
|
|
18
|
+
regular file's content digest; None if it does not exist.
|
|
19
|
+
"""
|
|
20
|
+
try:
|
|
21
|
+
st = path.lstat()
|
|
22
|
+
if stat.S_ISLNK(st.st_mode):
|
|
23
|
+
content = os.readlink(path)
|
|
24
|
+
elif stat.S_ISREG(st.st_mode):
|
|
25
|
+
content = hashlib.sha256(path.read_bytes()).hexdigest()
|
|
26
|
+
else:
|
|
27
|
+
content = None
|
|
28
|
+
except OSError:
|
|
29
|
+
return None
|
|
30
|
+
return stat.S_IFMT(st.st_mode), st.st_mtime_ns, st.st_size, content
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def attributes_files(path: Path, root: Path) -> list[Path]:
|
|
34
|
+
"""The .gitattributes files that may apply to path, from root down to its directory."""
|
|
35
|
+
directories = directories_up_to(path.parent, root) or [Path(os.path.realpath(root))]
|
|
36
|
+
return [directory / ".gitattributes" for directory in reversed(directories)]
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def assigns_filter(paths: Iterable[Path]) -> bool:
|
|
40
|
+
"""Whether an attributes file assigns a filter driver, which may change file content."""
|
|
41
|
+
for path in paths:
|
|
42
|
+
try:
|
|
43
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
44
|
+
except OSError:
|
|
45
|
+
continue
|
|
46
|
+
if _FILTER.search(text):
|
|
47
|
+
return True
|
|
48
|
+
return False
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Warn when a CI runner's shallow clone may hide authors.
|
|
3
|
+
|
|
4
|
+
Adapted from https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/master/mkdocs_git_revision_date_localized_plugin/ci.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from mkdocs_git_authors_plugin.git.runner import commit_count, is_shallow
|
|
12
|
+
|
|
13
|
+
# Not the "mkdocs" logger, so these warnings do not fail strict builds
|
|
14
|
+
logger = logging.getLogger(__name__)
|
|
15
|
+
|
|
16
|
+
# (environment variable, warn if the clone has fewer commits than this, message)
|
|
17
|
+
_PROVIDERS = [
|
|
18
|
+
(
|
|
19
|
+
"GITLAB_CI",
|
|
20
|
+
50,
|
|
21
|
+
"""
|
|
22
|
+
[git-authors] Running on a GitLab runner might lead to wrong
|
|
23
|
+
git authors due to a shallow git fetch depth.
|
|
24
|
+
|
|
25
|
+
Make sure to set GIT_DEPTH to 1000 in your .gitlab-ci.yml file
|
|
26
|
+
(see https://docs.gitlab.com/ee/user/project/pipelines/settings.html#git-shallow-clone).
|
|
27
|
+
""",
|
|
28
|
+
),
|
|
29
|
+
(
|
|
30
|
+
"GITHUB_ACTIONS",
|
|
31
|
+
2,
|
|
32
|
+
"""
|
|
33
|
+
[git-authors] Running on GitHub Actions might lead to wrong
|
|
34
|
+
git authors due to a shallow git fetch depth.
|
|
35
|
+
|
|
36
|
+
Try setting fetch-depth to 0 in your GitHub Action
|
|
37
|
+
(see https://github.com/actions/checkout).
|
|
38
|
+
""",
|
|
39
|
+
),
|
|
40
|
+
(
|
|
41
|
+
"BITBUCKET_BUILD_NUMBER",
|
|
42
|
+
50,
|
|
43
|
+
"""
|
|
44
|
+
[git-authors] Running on bitbucket pipelines might lead to wrong
|
|
45
|
+
git authors due to a shallow git fetch depth.
|
|
46
|
+
|
|
47
|
+
Try setting "clone: depth" to "full" in your pipeline
|
|
48
|
+
(see https://support.atlassian.com/bitbucket-cloud/docs/configure-bitbucket-pipelinesyml/
|
|
49
|
+
and search 'depth').
|
|
50
|
+
""",
|
|
51
|
+
),
|
|
52
|
+
(
|
|
53
|
+
"TF_BUILD",
|
|
54
|
+
None,
|
|
55
|
+
"""
|
|
56
|
+
[git-authors] Running on Azure pipelines with limited
|
|
57
|
+
fetch-depth might lead to wrong git authors due to a shallow git fetch depth.
|
|
58
|
+
|
|
59
|
+
Remove any Shallow Fetch settings
|
|
60
|
+
(see https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/pipeline-options-for-git?view=azure-devops#shallow-fetch).
|
|
61
|
+
""",
|
|
62
|
+
),
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def raise_ci_warnings(root: Path) -> None:
|
|
67
|
+
"""Warn when the repository at root is a shallow clone on a known CI provider."""
|
|
68
|
+
if not is_shallow(root):
|
|
69
|
+
return
|
|
70
|
+
n_commits = commit_count(root)
|
|
71
|
+
for env_var, min_commits, message in _PROVIDERS:
|
|
72
|
+
if os.getenv(env_var) is not None and (
|
|
73
|
+
min_commits is None or n_commits < min_commits
|
|
74
|
+
):
|
|
75
|
+
logger.warning(message)
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
from mkdocs.config import config_options
|
|
2
|
-
from mkdocs.config.base import Config
|
|
2
|
+
from mkdocs.config.base import Config, ValidationError
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class _Percentage(config_options.Type):
|
|
6
|
+
def __init__(self, default: int) -> None:
|
|
7
|
+
super().__init__(int, default=default)
|
|
8
|
+
|
|
9
|
+
def run_validation(self, value: object) -> int:
|
|
10
|
+
value = super().run_validation(value)
|
|
11
|
+
if not 0 <= value <= 100:
|
|
12
|
+
raise ValidationError(
|
|
13
|
+
f"Expected a percentage between 0 and 100, got {value}"
|
|
14
|
+
)
|
|
15
|
+
return value
|
|
3
16
|
|
|
4
17
|
|
|
5
18
|
class GitAuthorsPluginConfig(Config):
|
|
@@ -7,16 +20,18 @@ class GitAuthorsPluginConfig(Config):
|
|
|
7
20
|
show_line_count = config_options.Type(bool, default=False)
|
|
8
21
|
show_email_address = config_options.Type(bool, default=True)
|
|
9
22
|
add_co_authors = config_options.Type(bool, default=False)
|
|
23
|
+
add_page_meta = config_options.Type(bool, default=True)
|
|
10
24
|
href = config_options.Type(str, default="mailto:{email}")
|
|
11
25
|
count_empty_lines = config_options.Type(bool, default=True)
|
|
12
26
|
fallback_to_empty = config_options.Type(bool, default=False)
|
|
13
27
|
exclude = config_options.Type(list, default=[])
|
|
14
28
|
ignore_commits = config_options.Type(str, default="")
|
|
29
|
+
authors_file = config_options.Type(str, default="")
|
|
15
30
|
ignore_authors = config_options.Type(list, default=[])
|
|
31
|
+
copy_detection = config_options.Choice((0, 1, 2, 3), default=0)
|
|
16
32
|
enabled = config_options.Type(bool, default=True)
|
|
17
33
|
enabled_on_serve = config_options.Type(bool, default=True)
|
|
18
|
-
sort_authors_by = config_options.
|
|
19
|
-
authorship_threshold_percent =
|
|
34
|
+
sort_authors_by = config_options.Choice(("name", "contribution"), default="name")
|
|
35
|
+
authorship_threshold_percent = _Percentage(default=0)
|
|
20
36
|
strict = config_options.Type(bool, default=True)
|
|
21
|
-
|
|
22
|
-
# sort_reverse = config_options.Type(bool, default=False)
|
|
37
|
+
enable_parallel_processing = config_options.Type(bool, default=True)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""Parse `git blame --porcelain` output and commit messages, without running git."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from datetime import datetime, timedelta, timezone
|
|
6
|
+
|
|
7
|
+
UNCOMMITTED_SHA = "0" * 40
|
|
8
|
+
_SHA = re.compile(r"[0-9a-f]{40}(?:[0-9a-f]{24})?")
|
|
9
|
+
_CO_AUTHOR = re.compile(
|
|
10
|
+
r"co-authored-by:\s*([^<>\s][^<>]*?)\s*<([^<>]+)>", re.IGNORECASE
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@dataclass(frozen=True, slots=True)
|
|
15
|
+
class BlameLine:
|
|
16
|
+
sha: str
|
|
17
|
+
author: str
|
|
18
|
+
email: str
|
|
19
|
+
when: datetime
|
|
20
|
+
content: str
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def parse_blame(text: str) -> list[BlameLine]:
|
|
24
|
+
"""
|
|
25
|
+
Parse `git blame --porcelain` output into one BlameLine per line of the file.
|
|
26
|
+
|
|
27
|
+
Each line has a header starting with the commit SHA. The commit's metadata
|
|
28
|
+
(author, author-mail, ...) follows only the first time a commit appears,
|
|
29
|
+
and the line's content follows prefixed with a TAB.
|
|
30
|
+
"""
|
|
31
|
+
commits: dict[str, dict[str, str]] = {}
|
|
32
|
+
lines = []
|
|
33
|
+
sha = ""
|
|
34
|
+
# Content lines may contain other line separators, so split on "\n" only
|
|
35
|
+
for line in text.split("\n"):
|
|
36
|
+
if line.startswith("\t"):
|
|
37
|
+
meta = commits[sha]
|
|
38
|
+
lines.append(
|
|
39
|
+
BlameLine(
|
|
40
|
+
sha=sha,
|
|
41
|
+
author=meta["author"],
|
|
42
|
+
email=meta["author-mail"].strip("<>"),
|
|
43
|
+
when=_timestamp(meta["author-time"], meta["author-tz"]),
|
|
44
|
+
content=line[1:],
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
continue
|
|
48
|
+
key, _, value = line.partition(" ")
|
|
49
|
+
if _SHA.fullmatch(key):
|
|
50
|
+
sha = key
|
|
51
|
+
commits.setdefault(sha, {})
|
|
52
|
+
elif line:
|
|
53
|
+
commits[sha][key] = value
|
|
54
|
+
return lines
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def synthetic_blame(text: str, when: datetime) -> list[BlameLine]:
|
|
58
|
+
"""Attribute every line of a new file to 'Not Committed Yet', as git blame does for uncommitted lines."""
|
|
59
|
+
contents = text.split("\n")
|
|
60
|
+
if contents[-1] == "":
|
|
61
|
+
contents.pop()
|
|
62
|
+
return [
|
|
63
|
+
BlameLine(
|
|
64
|
+
UNCOMMITTED_SHA, "Not Committed Yet", "not.committed.yet", when, content
|
|
65
|
+
)
|
|
66
|
+
for content in contents
|
|
67
|
+
]
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def is_uncommitted(sha: str) -> bool:
|
|
71
|
+
"""Whether sha marks uncommitted lines: 40 zeros, or 64 in a SHA-256 repository."""
|
|
72
|
+
return not sha.strip("0")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def parse_co_authors(message: str) -> list[tuple[str, str]]:
|
|
76
|
+
"""The (name, email) of each `Co-authored-by: Name <email>` trailer in a commit message."""
|
|
77
|
+
return [
|
|
78
|
+
(m[1], m[2])
|
|
79
|
+
for line in message.split("\n")
|
|
80
|
+
if (m := _CO_AUTHOR.fullmatch(line.strip()))
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _timestamp(seconds: str, tz: str) -> datetime:
|
|
85
|
+
"""An aware datetime from a Unix timestamp and a +hhmm offset."""
|
|
86
|
+
sign = -1 if tz[0] == "-" else 1
|
|
87
|
+
offset = timedelta(hours=int(tz[1:3]), minutes=int(tz[3:5]))
|
|
88
|
+
return datetime.fromtimestamp(int(seconds), timezone(sign * offset))
|