mkdocs-git-authors-plugin 0.8.0__tar.gz → 0.9.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.
Files changed (24) hide show
  1. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/PKG-INFO +1 -1
  2. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/page.py +9 -2
  3. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/plugin.py +2 -0
  4. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/PKG-INFO +1 -1
  5. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/setup.py +1 -1
  6. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/tests/test_basic.py +17 -0
  7. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/tests/test_util.py +143 -0
  8. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/LICENSE +0 -0
  9. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/README.md +0 -0
  10. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/__init__.py +0 -0
  11. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/ci.py +0 -0
  12. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/exclude.py +0 -0
  13. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/__init__.py +0 -0
  14. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/author.py +0 -0
  15. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/command.py +0 -0
  16. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/commit.py +0 -0
  17. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/git/repo.py +0 -0
  18. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin/util.py +0 -0
  19. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +0 -0
  20. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
  21. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
  22. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -0
  23. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
  24. {mkdocs-git-authors-plugin-0.8.0 → mkdocs_git_authors_plugin-0.9.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mkdocs-git-authors-plugin
3
- Version: 0.8.0
3
+ Version: 0.9.0
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
@@ -146,7 +146,13 @@ class Page(AbstractRepoObject):
146
146
 
147
147
  re_sha = re.compile(r"^\w{40}")
148
148
 
149
- cmd = GitCommand("blame", ["--porcelain", str(self._path)])
149
+ args = []
150
+ if self.repo().config("ignore_commits"):
151
+ args.append("--ignore-revs-file")
152
+ args.append(self.repo().config("ignore_commits"))
153
+ args.append("--porcelain")
154
+ args.append(str(self._path))
155
+ cmd = GitCommand("blame", args)
150
156
  cmd.run()
151
157
 
152
158
  lines = cmd.stdout()
@@ -155,6 +161,7 @@ class Page(AbstractRepoObject):
155
161
  if len(lines) == 0:
156
162
  raise GitCommandError
157
163
 
164
+ ignore_authors = self.repo().config("ignore_authors")
158
165
  commit_data = {}
159
166
  for line in lines:
160
167
  key = line.split(" ")[0]
@@ -183,7 +190,7 @@ class Page(AbstractRepoObject):
183
190
  author_tz=commit_data.get("author-tz"),
184
191
  summary=commit_data.get("summary"),
185
192
  )
186
- if len(line) > 1 or self.repo().config("count_empty_lines"):
193
+ if commit.author().email() not in ignore_authors and (len(line) > 1 or self.repo().config("count_empty_lines")):
187
194
  author = commit.author()
188
195
  if author not in self._authors:
189
196
  self._authors.append(author)
@@ -21,6 +21,8 @@ class GitAuthorsPlugin(BasePlugin):
21
21
  ("count_empty_lines", config_options.Type(bool, default=True)),
22
22
  ("fallback_to_empty", config_options.Type(bool, default=False)),
23
23
  ("exclude", config_options.Type(list, default=[])),
24
+ ("ignore_commits", config_options.Type(str, default=None)),
25
+ ("ignore_authors", config_options.Type(list, default=[])),
24
26
  ("enabled", config_options.Type(bool, default=True)),
25
27
  ("enabled_on_serve", config_options.Type(bool, default=True)),
26
28
  ("sort_authors_by", config_options.Type(str, default="name")),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mkdocs-git-authors-plugin
3
- Version: 0.8.0
3
+ Version: 0.9.0
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
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name="mkdocs-git-authors-plugin",
8
- version="0.8.0",
8
+ version="0.9.0",
9
9
  description="Mkdocs plugin to display git authors of a page",
10
10
  long_description=long_description,
11
11
  long_description_content_type="text/markdown",
@@ -146,6 +146,23 @@ def test_exclude_working(tmp_path):
146
146
 
147
147
 
148
148
 
149
+ def test_ignore_authors_working(tmp_path):
150
+
151
+ result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path)
152
+ assert result.exit_code == 0, (
153
+ "'mkdocs build' command failed. Error: %s" % result.stdout
154
+ )
155
+
156
+ page_file = tmp_path / "page_with_tag/index.html"
157
+ assert page_file.exists(), "%s does not exist" % page_file
158
+
159
+ contents = page_file.read_text()
160
+ assert re.search("<span class='git-page-authors", contents)
161
+ assert re.search("<a href='mailto:vinktim@gmail.com'>Tim Vink</a>", contents)
162
+ assert not re.search("Julien", contents)
163
+
164
+
165
+
149
166
  def test_exclude_working_with_genfiles(tmp_path):
150
167
  """
151
168
  A warning for uncommited files should not show up
@@ -35,6 +35,7 @@ DEFAULT_CONFIG = {
35
35
  "sort_reverse": False,
36
36
  "sort_authors_by": "name",
37
37
  "authorship_threshold_percent": 0,
38
+ "ignore_authors": [],
38
39
  }
39
40
 
40
41
  #### Helpers ####
@@ -275,6 +276,148 @@ def test_retrieve_authors(tmp_path):
275
276
  os.chdir(cwd)
276
277
 
277
278
 
279
+ def test_retrieve_authors_ignoring_commits(tmp_path):
280
+ """
281
+ Builds a fake git project with some commits.
282
+
283
+ Args:
284
+ tmp_path (PosixPath): Directory of a tempdir
285
+ """
286
+ cwd = os.getcwd()
287
+ os.chdir(str(tmp_path))
288
+
289
+ # Create file
290
+ file_name = str(tmp_path / "new-file")
291
+ with open(file_name, "w") as the_file:
292
+ the_file.write("line 1\n")
293
+ the_file.write("line 2\n")
294
+
295
+ # Create git repo and commit file
296
+ r = gitpython.Repo.init(tmp_path)
297
+ r.index.add([file_name])
298
+ author = gitpython.Actor("Tim", "abc@abc.com")
299
+ r.index.commit("initial commit", author=author)
300
+
301
+ # Update the file
302
+ with open(file_name, "w") as the_file:
303
+ the_file.write("line 1.1\n")
304
+ the_file.write("line 2.1\n")
305
+ r.index.add([file_name])
306
+ author = gitpython.Actor("John", "john@abc.com")
307
+ commit = r.index.commit("second commit", author=author)
308
+
309
+ repo_instance = repo.Repo()
310
+ repo_instance.set_config(DEFAULT_CONFIG)
311
+ repo_instance.page(file_name)
312
+ authors = repo_instance.get_authors()
313
+ authors = util.page_authors(authors, file_name)
314
+ authors[0]["last_datetime"] = None
315
+
316
+ assert authors == [
317
+ {
318
+ "name": "John",
319
+ "email": "john@abc.com",
320
+ "last_datetime": None,
321
+ "lines": 2,
322
+ "lines_all_pages": 2,
323
+ "contribution": "100.0%",
324
+ "contribution_all_pages": "100.0%",
325
+ }
326
+ ]
327
+
328
+ # Get the authors while ignoring the last commit
329
+ ignored_commits_files = str(tmp_path / "ignored_commits.txt")
330
+ with open(ignored_commits_files, "w") as the_file:
331
+ the_file.write(commit.hexsha + "\n")
332
+ repo_instance = repo.Repo()
333
+ config = DEFAULT_CONFIG.copy()
334
+ config['ignore_commits'] = ignored_commits_files
335
+ repo_instance.set_config(config)
336
+ repo_instance.page(file_name)
337
+ authors = repo_instance.get_authors()
338
+ authors = util.page_authors(authors, file_name)
339
+ authors[0]["last_datetime"] = None
340
+
341
+ assert authors == [
342
+ {
343
+ "name": "Tim",
344
+ "email": "abc@abc.com",
345
+ "last_datetime": None,
346
+ "lines": 2,
347
+ "lines_all_pages": 2,
348
+ "contribution": "100.0%",
349
+ "contribution_all_pages": "100.0%",
350
+ },
351
+ ]
352
+
353
+ os.chdir(cwd)
354
+
355
+
356
+ def test_retrieve_authors_ignoring_emails(tmp_path):
357
+ """
358
+ Builds a fake git project with some commits.
359
+
360
+ Args:
361
+ tmp_path (PosixPath): Directory of a tempdir
362
+ """
363
+ cwd = os.getcwd()
364
+ os.chdir(str(tmp_path))
365
+
366
+ # Create file
367
+ file_name = str(tmp_path / "new-file")
368
+ with open(file_name, "w") as the_file:
369
+ the_file.write("line 1\n")
370
+ the_file.write("line 2\n")
371
+
372
+ # Create git repo and commit file
373
+ r = gitpython.Repo.init(tmp_path)
374
+ r.index.add([file_name])
375
+ author = gitpython.Actor("Tim", "abc@abc.com")
376
+ r.index.commit("initial commit", author=author)
377
+
378
+ # Add more content
379
+ with open(file_name, "a+") as the_file:
380
+ the_file.write("line 3\n")
381
+ the_file.write("line 4\n")
382
+ r.index.add([file_name])
383
+ author = gitpython.Actor("John", "john@abc.com")
384
+ r.index.commit("second commit", author=author)
385
+
386
+ # Get the authors while ignoring john@abc.com user
387
+ repo_instance = repo.Repo()
388
+ config = DEFAULT_CONFIG.copy()
389
+ config['ignore_authors'] = ['john@abc.com']
390
+ repo_instance.set_config(config)
391
+ repo_instance.page(file_name)
392
+ authors = repo_instance.get_authors()
393
+ authors = util.page_authors(authors, file_name)
394
+ authors[0]["last_datetime"] = None
395
+ authors[1]["last_datetime"] = None
396
+
397
+ assert authors == [
398
+ {
399
+ "contribution": "0.0%",
400
+ "contribution_all_pages": "0.0%",
401
+ "email": "john@abc.com",
402
+ "last_datetime": None,
403
+ "lines": 0,
404
+ "lines_all_pages": 0,
405
+ "name": "John"
406
+ },
407
+ {
408
+ "name": "Tim",
409
+ "email": "abc@abc.com",
410
+ "last_datetime": None,
411
+ "lines": 2,
412
+ "lines_all_pages": 2,
413
+ "contribution": "100.0%",
414
+ "contribution_all_pages": "100.0%",
415
+ },
416
+ ]
417
+
418
+ os.chdir(cwd)
419
+
420
+
278
421
  def test_mkdocs_in_git_subdir(tmp_path):
279
422
  """
280
423
  Sometimes `mkdocs.yml` is not in the root of the repo.