]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
doc/conf.py: fetch copyright year from git commit
authorOto Šťáva <oto.stava@nic.cz>
Thu, 3 Nov 2022 07:16:16 +0000 (08:16 +0100)
committerOto Šťáva <oto.stava@nic.cz>
Thu, 3 Nov 2022 07:28:08 +0000 (08:28 +0100)
Using Git commit to avoid problems with reproducible builds; with
fallback to system time in case Git is not available for whatever
reason.

doc/conf.py

index 05e0d8de9fd220f1249aeb547df03f23ddd3438e..ab7e6db2e687d48ed3233c0f53789bd71505d95c 100644 (file)
@@ -4,6 +4,7 @@
 import os
 import re
 import subprocess
+from datetime import date
 
 import sphinx_rtd_theme
 
@@ -24,9 +25,20 @@ breathe_domain_by_extension = {"h": "c"}
 source_suffix = '.rst'
 master_doc = 'index'
 
+# Get current year (preferably from Git commit)
+commit_year = date.today().year
+
+try:
+    commit_date_str = subprocess.check_output(['git', 'show', '--no-patch', '--format=%cs'])\
+            .decode().strip()
+    commit_date = date.fromisoformat(commit_date_str)
+    commit_year = commit_date.year
+except BaseException as e:
+    print('Could not get current commit, using system time for copyright:', e)
+
 # General information about the project.
 project = u'Knot Resolver'
-copyright = u'2014-2020 CZ.NIC labs'
+copyright = u'2014-{current} CZ.NIC labs'.format(current=commit_year)
 with open('../meson.build') as f:
     for line in f:
         match = re.match(r"\s*version\s*:\s*'([^']+)'.*", line)