mkdocs-git-authors-plugin 0.9.5__tar.gz → 0.9.6__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.5/src/mkdocs_git_authors_plugin.egg-info → mkdocs_git_authors_plugin-0.9.6}/PKG-INFO +1 -1
  2. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/pyproject.toml +1 -1
  3. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/page.py +79 -9
  4. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6/src/mkdocs_git_authors_plugin.egg-info}/PKG-INFO +1 -1
  5. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/tests/test_basic.py +25 -8
  6. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/tests/test_util.py +61 -42
  7. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/LICENSE +0 -0
  8. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/README.md +0 -0
  9. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/setup.cfg +0 -0
  10. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/__init__.py +0 -0
  11. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/ci.py +0 -0
  12. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/config.py +0 -0
  13. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/exclude.py +0 -0
  14. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/__init__.py +0 -0
  15. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/author.py +0 -0
  16. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/command.py +0 -0
  17. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/commit.py +0 -0
  18. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/git/repo.py +0 -0
  19. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/plugin.py +0 -0
  20. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin/util.py +0 -0
  21. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/SOURCES.txt +0 -0
  22. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/dependency_links.txt +0 -0
  23. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/entry_points.txt +0 -0
  24. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/requires.txt +0 -0
  25. {mkdocs_git_authors_plugin-0.9.5 → mkdocs_git_authors_plugin-0.9.6}/src/mkdocs_git_authors_plugin.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-git-authors-plugin
3
- Version: 0.9.5
3
+ Version: 0.9.6
4
4
  Summary: Mkdocs plugin to display git authors of a page
5
5
  Author-email: Tim Vink <vinktim@gmail.com>
6
6
  License: MIT
@@ -12,7 +12,7 @@ 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 = "0.9.5"
15
+ version = "0.9.6"
16
16
  requires-python = ">=3.8"
17
17
  dependencies = ["mkdocs>=1.0"]
18
18
  classifiers = [
@@ -149,7 +149,7 @@ class Page(AbstractRepoObject):
149
149
  args.append("--ignore-revs-file")
150
150
  args.append(self.repo().config("ignore_commits"))
151
151
  args.append("--porcelain")
152
- args.append("-w") # Ignore whitespace changes
152
+ args.append("-w") # Ignore whitespace changes
153
153
  args.append(str(self._path))
154
154
  cmd = GitCommand("blame", args)
155
155
  cmd.run()
@@ -189,15 +189,85 @@ class Page(AbstractRepoObject):
189
189
  author_tz=commit_data.get("author-tz"),
190
190
  summary=commit_data.get("summary"),
191
191
  )
192
- if commit.author().email() not in ignore_authors and (
193
- len(line) > 1 or self.repo().config("count_empty_lines")
192
+ if len(line) > 1 or self.repo().config("count_empty_lines"):
193
+ if commit.author().email() not in ignore_authors:
194
+ author = commit.author()
195
+ if author not in self._authors:
196
+ self._authors.append(author)
197
+ author.add_lines(self, commit)
198
+ self.add_total_lines()
199
+ self.repo().add_total_lines()
200
+ # Process co-authors if present
201
+ self._process_git_log(commit_data.get("sha"), commit)
202
+
203
+ def _process_git_log(self, sha, commit) -> None:
204
+ """
205
+ Execute git log and parse the results.
206
+
207
+ This retrieves [co-authors](https://docs.github.com/en/pull-requests/committing-changes-to-your-project/creating-and-editing-commits/creating-a-commit-with-multiple-authors) from comment.
208
+ Each line will be associated with a Commit object and counted
209
+ to its co-author's "account".
210
+ Whether empty lines are counted is determined by the
211
+ count_empty_lines configuration option.
212
+
213
+ git log -1 <sha> will produce output like the following
214
+ for each line in a file:
215
+
216
+ When a commit does not contain co-authors:
217
+ commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
218
+ Author: John Doe <jdoe@john.com>
219
+ Date: Sun Dec 22 11:10:32 2019 +0100
220
+
221
+ add plugin skeleton
222
+
223
+ When a commit contains co-authors:
224
+ commit ca8b32b24af1ce97fb29c5139b2f80e0c2ad9d1c
225
+ Author: John Doe <jdoe@john.com>
226
+ Date: Sun Dec 22 11:10:32 2019 +0100
227
+
228
+ add plugin skeleton
229
+
230
+ Co-authored-by: John Doe <jdoe@john.com>
231
+ Co-authored-by: Rock Smith <rsmith@smith.com>
232
+
233
+ In this case we skip the original author as redundant using email address to detect it.
234
+
235
+ Args:
236
+ sha: the SHA of the commit to process
237
+ Returns:
238
+ --- (this method works through side effects)
239
+ """
240
+
241
+ args = []
242
+ args.append("-1") # Only existing sha
243
+ args.append(sha)
244
+ cmd = GitCommand("log", args)
245
+ cmd.run()
246
+
247
+ lines = cmd.stdout()
248
+
249
+ # in case of empty, non-committed files, raise error
250
+ if len(lines) == 0:
251
+ raise GitCommandError
252
+
253
+ ignore_authors = self.repo().config("ignore_authors")
254
+ for line in lines:
255
+ if line.startswith("Author: "):
256
+ # skip author as already available in Commit object
257
+ continue
258
+
259
+ result = re.search(r"Co-authored-by: (.*) <(.*)>", line)
260
+ if result is not None and result.group(1) != "" and result.group(2) != "":
261
+ # Extract co-authors from the commit
262
+ co_author = self.repo().author(result.group(1), result.group(2))
263
+ if (
264
+ co_author.email() not in ignore_authors
265
+ and co_author.email() != commit.author().email()
194
266
  ):
195
- author = commit.author()
196
- if author not in self._authors:
197
- self._authors.append(author)
198
- author.add_lines(self, commit)
199
- self.add_total_lines()
200
- self.repo().add_total_lines()
267
+ # Create the co-author
268
+ if co_author not in self._authors:
269
+ self._authors.append(co_author)
270
+ co_author.add_lines(self, commit)
201
271
 
202
272
  def path(self) -> Path:
203
273
  """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-git-authors-plugin
3
- Version: 0.9.5
3
+ Version: 0.9.6
4
4
  Summary: Mkdocs plugin to display git authors of a page
5
5
  Author-email: Tim Vink <vinktim@gmail.com>
6
6
  License: MIT
@@ -45,8 +45,6 @@ SITES_THAT_SHOULD_SUCCEED = [
45
45
  ]
46
46
 
47
47
 
48
-
49
-
50
48
  def build_docs_setup(mkdocs_path, output_path) -> Result:
51
49
  runner = CliRunner()
52
50
  return runner.invoke(
@@ -144,6 +142,25 @@ def test_ignore_authors_working(tmp_path) -> None:
144
142
  assert not re.search("Julien", contents)
145
143
 
146
144
 
145
+ def test_co_authors_working(tmp_path) -> None:
146
+ result = build_docs_setup("tests/basic_setup/mkdocs_ignore_authors.yml", tmp_path)
147
+ assert (
148
+ result.exit_code == 0
149
+ ), f"'mkdocs build' command failed. Error: {result.stdout}"
150
+
151
+ page_file = tmp_path / "page_with_co_authors/index.html"
152
+ assert page_file.exists(), f"{page_file} does not exist"
153
+
154
+ contents = page_file.read_text()
155
+ assert re.search("<span class='git-page-authors", contents)
156
+ assert re.search(
157
+ "fpozzobon@users.noreply.github.com'>Fabien Pozzobon</a>",
158
+ contents,
159
+ )
160
+ assert re.search("<a href='mailto:jdoe@john.com'>John Doe</a>", contents)
161
+ assert not re.search("Julien", contents)
162
+
163
+
147
164
  def test_exclude_working_with_genfiles(tmp_path) -> None:
148
165
  """
149
166
  A warning for uncommited files should not show up
@@ -331,11 +348,12 @@ def test_mkapi_v20x(tmp_path) -> None:
331
348
  assert True
332
349
 
333
350
 
334
- @pytest.mark.skipif(sys.version_info < (3, 7) or sys.version_info > (3, 9), reason="Requires Python 3.7 or higher")
335
351
  @pytest.mark.skipif(
336
- not (
337
- Version(mkdocs.__version__) < Version("1.6")
338
- ),
352
+ sys.version_info < (3, 7) or sys.version_info > (3, 9),
353
+ reason="Requires Python 3.7 or higher",
354
+ )
355
+ @pytest.mark.skipif(
356
+ not (Version(mkdocs.__version__) < Version("1.6")),
339
357
  reason="Requires mkdocs >= 1.6",
340
358
  )
341
359
  def test_mkapi_v1(tmp_path) -> None:
@@ -354,12 +372,12 @@ def test_mkapi_v1(tmp_path) -> None:
354
372
  contents,
355
373
  )
356
374
 
375
+
357
376
  def test_custom_docs_dir(tmp_path):
358
377
 
359
378
  testproject_path = tmp_path / "testproject"
360
379
  shutil.copytree("tests/custom_docs_dir", testproject_path)
361
380
 
362
-
363
381
  # init git inside the docs directory
364
382
  with working_directory(str(testproject_path / "documentation")):
365
383
  # setup git history
@@ -380,4 +398,3 @@ def test_custom_docs_dir(tmp_path):
380
398
 
381
399
  contents = index_file.read_text()
382
400
  assert re.search("<span class='git-page-authors", contents)
383
-
@@ -42,8 +42,8 @@ DEFAULT_CONFIG = {
42
42
  "sort_authors_by": "name",
43
43
  "authorship_threshold_percent": 0,
44
44
  "strict": True,
45
- #"sort_authors_by_name": True,
46
- #"sort_reverse": False,
45
+ # "sort_authors_by_name": True,
46
+ # "sort_reverse": False,
47
47
  }
48
48
 
49
49
  #### Helpers ####
@@ -127,6 +127,11 @@ def setup_commit_history(testproject_path):
127
127
  repo.git.commit(message="homepage", author=author)
128
128
  repo.git.add("docs/page_with_tag.md")
129
129
  repo.git.commit(message="homepage", author=author)
130
+ repo.git.add("docs/page_with_co_authors.md")
131
+ repo.git.commit(
132
+ message="co-authors commit\nCo-authored-by: Test Person <testtest@gmail.com>\nCo-authored-by: Roger Doe <rdoe@john.com>",
133
+ author=author,
134
+ )
130
135
  os.chdir(str(cwd))
131
136
  except:
132
137
  os.chdir(str(cwd))
@@ -140,7 +145,7 @@ def commit_lines(r, file_name, author_name, author_email, num_of_lines=1):
140
145
  with open(file_name, "a") as the_file:
141
146
  for i in range(num_of_lines):
142
147
  the_file.write("Hello\n")
143
-
148
+
144
149
  r.index.add([file_name])
145
150
  author = gitpython.Actor(author_name, author_email)
146
151
  r.index.commit("some commit", author=author)
@@ -512,17 +517,18 @@ def test_page_authors_summary(tmp_path):
512
517
 
513
518
  # Initial commit
514
519
  commit_lines(r, file_name, "Tim", "abc@abc.com")
515
-
520
+
516
521
  repo_instance = repo.Repo()
517
522
  repo_instance.set_config(config)
518
523
  page_instance = repo_instance.page(file_name)
519
524
 
520
525
  authors_summary = util.page_authors_summary(page_instance, config)
521
526
 
522
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
523
- "<a href='mailto:abc@abc.com'>Tim</a>"\
524
- "</span>"
525
-
527
+ assert (
528
+ authors_summary == "<span class='git-page-authors git-authors'>"
529
+ "<a href='mailto:abc@abc.com'>Tim</a>"
530
+ "</span>"
531
+ )
526
532
 
527
533
  # Now add a line to the file
528
534
  # From a second author with same email
@@ -534,10 +540,11 @@ def test_page_authors_summary(tmp_path):
534
540
 
535
541
  authors_summary = util.page_authors_summary(page_instance, config)
536
542
 
537
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
538
- "<a href='mailto:abc@abc.com'>Tim</a>"\
539
- "</span>"
540
-
543
+ assert (
544
+ authors_summary == "<span class='git-page-authors git-authors'>"
545
+ "<a href='mailto:abc@abc.com'>Tim</a>"
546
+ "</span>"
547
+ )
541
548
 
542
549
  # Then a third commit from a new author
543
550
  commit_lines(r, file_name, "John", "john@abc.com")
@@ -548,10 +555,12 @@ def test_page_authors_summary(tmp_path):
548
555
 
549
556
  authors_summary = util.page_authors_summary(page_instance, config)
550
557
 
551
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
552
- "<a href='mailto:john@abc.com'>John</a>, "\
553
- "<a href='mailto:abc@abc.com'>Tim</a>"\
554
- "</span>"
558
+ assert (
559
+ authors_summary == "<span class='git-page-authors git-authors'>"
560
+ "<a href='mailto:john@abc.com'>John</a>, "
561
+ "<a href='mailto:abc@abc.com'>Tim</a>"
562
+ "</span>"
563
+ )
555
564
 
556
565
  os.chdir(cwd)
557
566
 
@@ -575,7 +584,7 @@ def test_page_authors_summary_showing_contribution(tmp_path):
575
584
 
576
585
  # Initial commit
577
586
  commit_lines(r, file_name, "Tim", "abc@abc.com")
578
-
587
+
579
588
  repo_instance = repo.Repo()
580
589
  repo_instance.set_config(config)
581
590
  page_instance = repo_instance.page(file_name)
@@ -583,10 +592,11 @@ def test_page_authors_summary_showing_contribution(tmp_path):
583
592
  authors_summary = util.page_authors_summary(page_instance, config)
584
593
 
585
594
  # Contribution is not shown if there is only single Author
586
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
587
- "<a href='mailto:abc@abc.com'>Tim</a>"\
588
- "</span>"
589
-
595
+ assert (
596
+ authors_summary == "<span class='git-page-authors git-authors'>"
597
+ "<a href='mailto:abc@abc.com'>Tim</a>"
598
+ "</span>"
599
+ )
590
600
 
591
601
  # Now add a line to the file
592
602
  # From a second author with same email
@@ -599,10 +609,11 @@ def test_page_authors_summary_showing_contribution(tmp_path):
599
609
  authors_summary = util.page_authors_summary(page_instance, config)
600
610
 
601
611
  # Contribution is not shown if there is only single Author
602
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
603
- "<a href='mailto:abc@abc.com'>Tim</a>"\
604
- "</span>"
605
-
612
+ assert (
613
+ authors_summary == "<span class='git-page-authors git-authors'>"
614
+ "<a href='mailto:abc@abc.com'>Tim</a>"
615
+ "</span>"
616
+ )
606
617
 
607
618
  # Then a third commit from a new author
608
619
  commit_lines(r, file_name, "John", "john@abc.com")
@@ -614,15 +625,19 @@ def test_page_authors_summary_showing_contribution(tmp_path):
614
625
  authors_summary = util.page_authors_summary(page_instance, config)
615
626
 
616
627
  # Contribution is shown if there are multiple authors, ordered by contribution
617
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
618
- "<a href='mailto:abc@abc.com'>Tim</a> (66.67%), "\
619
- "<a href='mailto:john@abc.com'>John</a> (33.33%)"\
620
- "</span>"
628
+ assert (
629
+ authors_summary == "<span class='git-page-authors git-authors'>"
630
+ "<a href='mailto:abc@abc.com'>Tim</a> (66.67%), "
631
+ "<a href='mailto:john@abc.com'>John</a> (33.33%)"
632
+ "</span>"
633
+ )
621
634
 
622
635
  os.chdir(cwd)
623
636
 
624
637
 
625
- def test_page_authors_summary_showing_contribution_ordering_by_page_contribution(tmp_path):
638
+ def test_page_authors_summary_showing_contribution_ordering_by_page_contribution(
639
+ tmp_path,
640
+ ):
626
641
  """
627
642
  Builds a fake git project with some commits.
628
643
 
@@ -648,7 +663,7 @@ def test_page_authors_summary_showing_contribution_ordering_by_page_contribution
648
663
  commit_lines(r, file_name2, "Tim", "tim@abc.com", 4)
649
664
  commit_lines(r, file_name2, "John", "john@abc.com", 16)
650
665
  commit_lines(r, file_name2, "Thomas", "thomas@abc.com", 8)
651
-
666
+
652
667
  repo_instance = repo.Repo()
653
668
  repo_instance.set_config(config)
654
669
  page_instance = repo_instance.page(file_name)
@@ -657,19 +672,23 @@ def test_page_authors_summary_showing_contribution_ordering_by_page_contribution
657
672
  authors_summary = util.page_authors_summary(page_instance, config)
658
673
 
659
674
  # Contribution is shown if there are multiple authors, ordered by contribution on page
660
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
661
- "<a href='mailto:tim@abc.com'>Tim</a> (57.14%), "\
662
- "<a href='mailto:john@abc.com'>John</a> (28.57%), "\
663
- "<a href='mailto:thomas@abc.com'>Thomas</a> (14.29%)"\
664
- "</span>"
665
-
675
+ assert (
676
+ authors_summary == "<span class='git-page-authors git-authors'>"
677
+ "<a href='mailto:tim@abc.com'>Tim</a> (57.14%), "
678
+ "<a href='mailto:john@abc.com'>John</a> (28.57%), "
679
+ "<a href='mailto:thomas@abc.com'>Thomas</a> (14.29%)"
680
+ "</span>"
681
+ )
682
+
666
683
  authors_summary = util.page_authors_summary(page_instance2, config)
667
684
 
668
- assert authors_summary == "<span class='git-page-authors git-authors'>"\
669
- "<a href='mailto:john@abc.com'>John</a> (57.14%), "\
670
- "<a href='mailto:thomas@abc.com'>Thomas</a> (28.57%), "\
671
- "<a href='mailto:tim@abc.com'>Tim</a> (14.29%)"\
672
- "</span>"
685
+ assert (
686
+ authors_summary == "<span class='git-page-authors git-authors'>"
687
+ "<a href='mailto:john@abc.com'>John</a> (57.14%), "
688
+ "<a href='mailto:thomas@abc.com'>Thomas</a> (28.57%), "
689
+ "<a href='mailto:tim@abc.com'>Tim</a> (14.29%)"
690
+ "</span>"
691
+ )
673
692
 
674
693
  os.chdir(cwd)
675
694