mkdocs-git-authors-plugin 0.9.0__tar.gz → 0.9.2__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.
Files changed (25) hide show
  1. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/PKG-INFO +4 -2
  2. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/ci.py +5 -4
  3. mkdocs_git_authors_plugin-0.9.2/mkdocs_git_authors_plugin/config.py +21 -0
  4. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/author.py +16 -16
  5. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/command.py +10 -8
  6. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/commit.py +6 -4
  7. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/page.py +17 -17
  8. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/repo.py +17 -13
  9. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/plugin.py +67 -45
  10. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/util.py +24 -23
  11. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/PKG-INFO +4 -2
  12. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +1 -0
  13. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/setup.py +14 -12
  14. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/tests/test_basic.py +139 -88
  15. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/tests/test_util.py +23 -21
  16. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/LICENSE +0 -0
  17. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/README.md +0 -0
  18. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/__init__.py +0 -0
  19. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/exclude.py +0 -0
  20. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin/git/__init__.py +0 -0
  21. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
  22. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
  23. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -0
  24. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
  25. {mkdocs_git_authors_plugin-0.9.0 → mkdocs_git_authors_plugin-0.9.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mkdocs-git-authors-plugin
3
- Version: 0.9.0
3
+ Version: 0.9.2
4
4
  Summary: Mkdocs plugin to display git authors of a page
5
5
  Home-page: https://github.com/timvink/mkdocs-git-authors-plugin
6
6
  Author: Tim Vink
@@ -14,11 +14,13 @@ Classifier: Programming Language :: Python :: 3.8
14
14
  Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
17
19
  Classifier: Programming Language :: Python :: 3 :: Only
18
20
  Classifier: License :: OSI Approved :: MIT License
19
21
  Classifier: Topic :: Documentation
20
22
  Classifier: Topic :: Text Processing
21
- Requires-Python: >=3.7
23
+ Requires-Python: >=3.8
22
24
  Description-Content-Type: text/markdown
23
25
  License-File: LICENSE
24
26
  Requires-Dist: mkdocs>=1.0
@@ -6,16 +6,17 @@ This is because often CI runners do not have access to full git history.
6
6
  Taken from https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/master/mkdocs_git_revision_date_localized_plugin/ci.py
7
7
  """
8
8
 
9
+ import logging
9
10
  import os
10
11
  from contextlib import contextmanager
11
- import logging
12
12
  from pathlib import Path
13
- from typing import Union
13
+ from typing import Any, Generator, Union
14
+
14
15
  from mkdocs_git_authors_plugin.git.command import GitCommand
15
16
 
16
17
 
17
18
  @contextmanager
18
- def working_directory(path: Union[str, Path]):
19
+ def working_directory(path: Union[str, Path]) -> Generator[None, Any, None]:
19
20
  """
20
21
  Temporarily change working directory.
21
22
  A context manager which changes the working directory to the given
@@ -27,7 +28,7 @@ def working_directory(path: Union[str, Path]):
27
28
  # Do something in new directory
28
29
  # Back to old directory
29
30
  ```
30
- """
31
+ """
31
32
  origin = Path().absolute()
32
33
  try:
33
34
  os.chdir(path)
@@ -0,0 +1,21 @@
1
+ from mkdocs.config import config_options
2
+ from mkdocs.config.base import Config
3
+
4
+
5
+ class GitAuthorsPluginConfig(Config):
6
+ show_contribution = config_options.Type(bool, default=False)
7
+ show_line_count = config_options.Type(bool, default=False)
8
+ show_email_address = config_options.Type(bool, default=True)
9
+ href = config_options.Type(str, default="mailto:{email}")
10
+ count_empty_lines = config_options.Type(bool, default=True)
11
+ fallback_to_empty = config_options.Type(bool, default=False)
12
+ exclude = config_options.Type(list, default=[])
13
+ ignore_commits = config_options.Type(str, default="")
14
+ ignore_authors = config_options.Type(list, default=[])
15
+ enabled = config_options.Type(bool, default=True)
16
+ enabled_on_serve = config_options.Type(bool, default=True)
17
+ sort_authors_by = config_options.Type(str, default="name")
18
+ authorship_threshold_percent = config_options.Type(int, default=0)
19
+ strict = config_options.Type(bool, default=True)
20
+ # sort_authors_by_name = config_options.Type(bool, default=True)
21
+ # sort_reverse = config_options.Type(bool, default=False)
@@ -1,8 +1,8 @@
1
- from .repo import AbstractRepoObject, Repo
2
- from .page import Page
3
- from .commit import Commit
1
+ from typing import Dict, Union
4
2
 
5
- from typing import Dict
3
+ from mkdocs_git_authors_plugin.git.commit import Commit
4
+ from mkdocs_git_authors_plugin.git.page import Page
5
+ from mkdocs_git_authors_plugin.git.repo import AbstractRepoObject, Repo
6
6
 
7
7
 
8
8
  class Author(AbstractRepoObject):
@@ -10,7 +10,7 @@ class Author(AbstractRepoObject):
10
10
  Abstraction of an author in the Git repository.
11
11
  """
12
12
 
13
- def __init__(self, repo: Repo, name: str, email: str):
13
+ def __init__(self, repo: Repo, name: str, email: str) -> None:
14
14
  """
15
15
  Instantiate an Author.
16
16
 
@@ -24,7 +24,7 @@ class Author(AbstractRepoObject):
24
24
  self._email = email
25
25
  self._pages: Dict[str, dict] = dict()
26
26
 
27
- def add_lines(self, page: Page, commit: Commit, lines: int = 1):
27
+ def add_lines(self, page: Page, commit: Commit, lines: int = 1) -> None:
28
28
  """
29
29
  Add line(s) in a given page/commit to the author's data.
30
30
 
@@ -42,7 +42,7 @@ class Author(AbstractRepoObject):
42
42
  entry["datetime"] = commit_dt
43
43
  entry["datetime_str"] = commit.datetime(str)
44
44
 
45
- def contribution(self, path=None, _type=float):
45
+ def contribution(self, path=None, _type=float) -> Union[float, str]:
46
46
  """
47
47
  The author's relative contribution to a page or the repository.
48
48
 
@@ -60,17 +60,17 @@ class Author(AbstractRepoObject):
60
60
  formatted string or floating point number
61
61
  """
62
62
  lines = self.lines(path)
63
- total_lines = (
63
+ total_lines: int = (
64
64
  self.page(path)["page"].total_lines() if path else self.repo().total_lines()
65
65
  )
66
66
 
67
67
  # Some pages are empty, that case contribution is 0 by default
68
68
  if total_lines == 0:
69
- result = 0
69
+ result = 0.0
70
70
  else:
71
71
  result = lines / total_lines
72
72
 
73
- if _type == float:
73
+ if _type is float:
74
74
  return result
75
75
  else:
76
76
  return str(round(result * 100, 2)) + "%"
@@ -87,10 +87,10 @@ class Author(AbstractRepoObject):
87
87
  a formatted string (fmt=str)
88
88
  or a datetime.datetime object with tzinfo
89
89
  """
90
- key = "datetime_str" if fmt == str else "datetime"
90
+ key = "datetime_str" if fmt is str else "datetime"
91
91
  return self.page(path).get(key)
92
92
 
93
- def email(self):
93
+ def email(self) -> str:
94
94
  """
95
95
  The author's email address
96
96
 
@@ -101,7 +101,7 @@ class Author(AbstractRepoObject):
101
101
  """
102
102
  return self._email
103
103
 
104
- def lines(self, path=None):
104
+ def lines(self, path=None) -> int:
105
105
  """
106
106
  The author's total number of lines on a page or in the repository.
107
107
 
@@ -117,7 +117,7 @@ class Author(AbstractRepoObject):
117
117
  else:
118
118
  return sum([v["lines"] for v in self._pages.values()])
119
119
 
120
- def name(self):
120
+ def name(self) -> str:
121
121
  """
122
122
  The author's full name
123
123
 
@@ -128,7 +128,7 @@ class Author(AbstractRepoObject):
128
128
  """
129
129
  return self._name
130
130
 
131
- def page(self, path, page=None):
131
+ def page(self, path, page=None) -> dict:
132
132
  """
133
133
  A dictionary with the author's contribution to a page.
134
134
 
@@ -154,7 +154,7 @@ class Author(AbstractRepoObject):
154
154
  if not self._pages.get(path):
155
155
  self._pages[path] = {
156
156
  "page": page or self.repo().page(path),
157
- "lines": 0
157
+ "lines": 0,
158
158
  # datetime and datetime_str will be populated later
159
159
  }
160
160
  return self._pages[path]
@@ -1,4 +1,5 @@
1
1
  import subprocess
2
+ from typing import List, Union
2
3
 
3
4
 
4
5
  class GitCommandError(Exception):
@@ -24,7 +25,7 @@ class GitCommand(object):
24
25
  In case of an error a verbose GitCommandError is raised.
25
26
  """
26
27
 
27
- def __init__(self, command: str, args: list = []):
28
+ def __init__(self, command: str, args: List = []) -> None:
28
29
  """
29
30
  Initialize the GitCommand.
30
31
 
@@ -40,7 +41,7 @@ class GitCommand(object):
40
41
  self._stderr = None
41
42
  self._completed = False
42
43
 
43
- def run(self):
44
+ def run(self) -> int:
44
45
  """
45
46
  Execute the configured Git command.
46
47
 
@@ -68,8 +69,9 @@ class GitCommand(object):
68
69
  p.check_returncode()
69
70
  except subprocess.CalledProcessError:
70
71
  msg = ["GitCommand error:"]
71
- msg.append('Command "%s" failed' % " ".join(args))
72
- msg.append("Return code: %s" % p.returncode)
72
+ joined_args = " ".join(args)
73
+ msg.append(f'Command "{joined_args}" failed')
74
+ msg.append(f"Return code: {p.returncode}")
73
75
  msg.append("Output:")
74
76
  msg.append(p.stdout.decode("utf-8"))
75
77
  msg.append("Error messages:")
@@ -82,7 +84,7 @@ class GitCommand(object):
82
84
  self._completed = True
83
85
  return int(str(p.returncode))
84
86
 
85
- def set_args(self, args: list):
87
+ def set_args(self, args: List) -> None:
86
88
  """
87
89
  Change the command arguments.
88
90
 
@@ -91,7 +93,7 @@ class GitCommand(object):
91
93
  """
92
94
  self._args = args
93
95
 
94
- def set_command(self, command: str):
96
+ def set_command(self, command: str) -> None:
95
97
  """
96
98
  Change the Git command.
97
99
 
@@ -100,7 +102,7 @@ class GitCommand(object):
100
102
  """
101
103
  self._command = command
102
104
 
103
- def stderr(self):
105
+ def stderr(self) -> Union[None, List[str]]:
104
106
  """
105
107
  Return the stderr output of the command as a string list.
106
108
 
@@ -113,7 +115,7 @@ class GitCommand(object):
113
115
  raise GitCommandError("Trying to read from uncompleted GitCommand")
114
116
  return self._stderr
115
117
 
116
- def stdout(self):
118
+ def stdout(self) -> Union[None, List[str]]:
117
119
  """
118
120
  Return the stdout output of the command as a string list.
119
121
 
@@ -1,6 +1,8 @@
1
1
  import re
2
- from .repo import AbstractRepoObject, Repo
3
- from .. import util
2
+ from typing import Union
3
+
4
+ from mkdocs_git_authors_plugin import util
5
+ from mkdocs_git_authors_plugin.git.repo import AbstractRepoObject, Repo
4
6
 
5
7
 
6
8
  class Commit(AbstractRepoObject):
@@ -58,7 +60,7 @@ class Commit(AbstractRepoObject):
58
60
  """
59
61
  return self._author
60
62
 
61
- def datetime(self, _type=str):
63
+ def datetime(self, _type=str) -> Union[str, util.datetime]:
62
64
  """
63
65
  The commit's commit time.
64
66
 
@@ -71,4 +73,4 @@ class Commit(AbstractRepoObject):
71
73
  The commit's commit time, either as a formatted string (_type=str)
72
74
  or as a datetime.datetime expression with tzinfo
73
75
  """
74
- return self._datetime_string if _type == str else self._datetime
76
+ return self._datetime_string if _type is str else self._datetime
@@ -1,11 +1,11 @@
1
- from pathlib import Path
2
- import re
3
1
  import logging
4
- from .repo import Repo, AbstractRepoObject
5
- from .command import GitCommand, GitCommandError
6
-
2
+ import re
3
+ from pathlib import Path
7
4
  from typing import List
8
5
 
6
+ from mkdocs_git_authors_plugin.git.command import GitCommand, GitCommandError
7
+ from mkdocs_git_authors_plugin.git.repo import AbstractRepoObject, Repo
8
+
9
9
  logger = logging.getLogger("mkdocs.plugins")
10
10
 
11
11
 
@@ -18,7 +18,7 @@ class Page(AbstractRepoObject):
18
18
  modified by that commit.
19
19
  """
20
20
 
21
- def __init__(self, repo: Repo, path: Path, strict: bool):
21
+ def __init__(self, repo: Repo, path: Path, strict: bool) -> None:
22
22
  """
23
23
  Instantiate a Page object
24
24
 
@@ -32,22 +32,20 @@ class Page(AbstractRepoObject):
32
32
  self._total_lines = 0
33
33
  self._authors: List[dict] = list()
34
34
  self._strict = strict
35
-
35
+
36
36
  try:
37
37
  self._process_git_blame()
38
38
  except GitCommandError:
39
39
  if self._strict:
40
40
  logger.warning(
41
- "[git-authors-plugin] %s has not been committed yet. Lines are not counted"
42
- % path
41
+ f"[git-authors-plugin] {path} has not been committed yet. Lines are not counted"
43
42
  )
44
43
  else:
45
44
  logger.info(
46
- "[git-authors-plugin] %s has not been committed yet. Lines are not counted"
47
- % path
45
+ f"[git-authors-plugin] {path} has not been committed yet. Lines are not counted"
48
46
  )
49
47
 
50
- def add_total_lines(self, cnt: int = 1):
48
+ def add_total_lines(self, cnt: int = 1) -> None:
51
49
  """
52
50
  Add line(s) to the count of total lines for the page.
53
51
 
@@ -56,7 +54,7 @@ class Page(AbstractRepoObject):
56
54
  """
57
55
  self._total_lines += cnt
58
56
 
59
- def get_authors(self):
57
+ def get_authors(self) -> List[dict]:
60
58
  """
61
59
  Return a sorted list of authors for the page
62
60
 
@@ -86,7 +84,7 @@ class Page(AbstractRepoObject):
86
84
  ]
87
85
  return self._authors
88
86
 
89
- def _process_git_blame(self):
87
+ def _process_git_blame(self) -> None:
90
88
  """
91
89
  Execute git blame and parse the results.
92
90
 
@@ -190,7 +188,9 @@ class Page(AbstractRepoObject):
190
188
  author_tz=commit_data.get("author-tz"),
191
189
  summary=commit_data.get("summary"),
192
190
  )
193
- if commit.author().email() not in ignore_authors and (len(line) > 1 or self.repo().config("count_empty_lines")):
191
+ if commit.author().email() not in ignore_authors and (
192
+ len(line) > 1 or self.repo().config("count_empty_lines")
193
+ ):
194
194
  author = commit.author()
195
195
  if author not in self._authors:
196
196
  self._authors.append(author)
@@ -198,7 +198,7 @@ class Page(AbstractRepoObject):
198
198
  self.add_total_lines()
199
199
  self.repo().add_total_lines()
200
200
 
201
- def path(self):
201
+ def path(self) -> Path:
202
202
  """
203
203
  The path to the markdown file.
204
204
 
@@ -209,7 +209,7 @@ class Page(AbstractRepoObject):
209
209
  """
210
210
  return self._path
211
211
 
212
- def total_lines(self):
212
+ def total_lines(self) -> int:
213
213
  """
214
214
  Total number of lines in the markdown source file.
215
215
 
@@ -1,5 +1,7 @@
1
1
  from pathlib import Path
2
- from .command import GitCommand
2
+ from typing import Any, Union
3
+
4
+ from mkdocs_git_authors_plugin.git.command import GitCommand
3
5
 
4
6
 
5
7
  class Repo(object):
@@ -7,7 +9,7 @@ class Repo(object):
7
9
  Abstraction of a Git repository (i.e. the MkDocs project).
8
10
  """
9
11
 
10
- def __init__(self):
12
+ def __init__(self) -> None:
11
13
  self._root = self.find_repo_root()
12
14
  self._total_lines = 0
13
15
 
@@ -18,7 +20,7 @@ class Repo(object):
18
20
  # Store Author objects, indexed by email
19
21
  self._authors = {}
20
22
 
21
- def add_total_lines(self, cnt: int = 1):
23
+ def add_total_lines(self, cnt: int = 1) -> None:
22
24
  """
23
25
  Add line(s) to the number of total lines in the repository.
24
26
 
@@ -47,7 +49,7 @@ class Repo(object):
47
49
  self._authors[email] = Author(self, name, email)
48
50
  return self._authors[email]
49
51
 
50
- def get_authors(self):
52
+ def get_authors(self) -> list:
51
53
  """
52
54
  Sorted list of authors in the repository.
53
55
 
@@ -67,7 +69,7 @@ class Repo(object):
67
69
  reverse=reverse,
68
70
  )
69
71
 
70
- def config(self, key: str = ""):
72
+ def config(self, key: str = "") -> Any:
71
73
  """
72
74
  Return the plugin configuration dictionary or a single config value.
73
75
 
@@ -76,7 +78,7 @@ class Repo(object):
76
78
  """
77
79
  return self._config.get(key) if key else self._config
78
80
 
79
- def find_repo_root(self):
81
+ def find_repo_root(self) -> str:
80
82
  """
81
83
  Determine the root directory of the Git repository,
82
84
  in case the current working directory is different from that.
@@ -91,9 +93,11 @@ class Repo(object):
91
93
  """
92
94
  cmd = GitCommand("rev-parse", ["--show-toplevel"])
93
95
  cmd.run()
94
- return cmd.stdout()[0]
96
+ stdout = cmd.stdout()
97
+ assert stdout is not None
98
+ return stdout[0]
95
99
 
96
- def get_commit(self, sha: str, **kwargs):
100
+ def get_commit(self, sha: str, **kwargs) -> Union[Any, None]:
97
101
  """
98
102
  Return the (cached) Commit object for given sha.
99
103
 
@@ -125,7 +129,7 @@ class Repo(object):
125
129
  Returns:
126
130
  Page object
127
131
  """
128
- if type(path) == str:
132
+ if isinstance(path, str):
129
133
  path = Path(path)
130
134
  if not self._pages.get(path):
131
135
  from .page import Page
@@ -133,7 +137,7 @@ class Repo(object):
133
137
  self._pages[path] = Page(self, path, self.config("strict"))
134
138
  return self._pages[path]
135
139
 
136
- def set_config(self, plugin_config):
140
+ def set_config(self, plugin_config) -> None:
137
141
  """
138
142
  Store the plugin configuration in the Repo instance.
139
143
 
@@ -142,7 +146,7 @@ class Repo(object):
142
146
  """
143
147
  self._config = plugin_config
144
148
 
145
- def _sort_key(self, author):
149
+ def _sort_key(self, author) -> Any:
146
150
  """
147
151
  Return a sort key for an author.
148
152
 
@@ -182,10 +186,10 @@ class AbstractRepoObject(object):
182
186
  Base class for objects that live with a repository context.
183
187
  """
184
188
 
185
- def __init__(self, repo: Repo):
189
+ def __init__(self, repo: Repo) -> None:
186
190
  self._repo = repo
187
191
 
188
- def repo(self):
192
+ def repo(self) -> Repo:
189
193
  """
190
194
  Return a reference to the Repo object.
191
195