Skip to content

Commit 63c80d3

Browse files
committed
📝 Add a GitHub Stars badge to docs
1 parent 20064f5 commit 63c80d3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/conf.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""
88

99
from email import message_from_string
10+
from itertools import chain
1011
import pkg_resources
1112

1213
# -- Path setup --------------------------------------------------------------
@@ -36,6 +37,18 @@ def get_supported_pythons(classifiers):
3637
return vers
3738

3839

40+
def get_github_data(project_urls):
41+
"""Retrieve GitHub user/org and repo name from a bunch of links."""
42+
partitioned_urls = (p.partition(', ') for p in project_urls)
43+
for _url_type, _sep, url in partitioned_urls:
44+
proto, _gh, uri = url.partition('://github.com/')
45+
if proto not in ('http', 'https'):
46+
continue
47+
return uri.split('/')[:2]
48+
49+
raise LookupError('There are no project URLs pointing to GitHub')
50+
51+
3952
PYTHON_DISTRIBUTION_NAME = 'octomachinery'
4053

4154
PRJ_DIST = pkg_resources.get_distribution(PYTHON_DISTRIBUTION_NAME)
@@ -46,6 +59,12 @@ def get_supported_pythons(classifiers):
4659
PRJ_DESCRIPTION = PRJ_META['Description']
4760
PRJ_PY_VER_RANGE = get_supported_pythons(PRJ_META.get_all('Classifier'))
4861
PRJ_PY_MIN_SUPPORTED, PRJ_PY_MAX_SUPPORTED = map('.'.join, PRJ_PY_VER_RANGE)
62+
PRJ_GITHUB_USER, PRJ_GITHUB_REPO = get_github_data(
63+
chain(
64+
(PRJ_META['Home-page'], ),
65+
PRJ_META.get_all('Project-URL'),
66+
),
67+
)
4968

5069
project = PRJ_DIST.project_name # pylint: disable=invalid-name
5170
author = PRJ_AUTHOR # pylint: disable=invalid-name
@@ -132,6 +151,9 @@ def get_supported_pythons(classifiers):
132151
# documentation.
133152
#
134153
html_theme_options = {
154+
'github_user': PRJ_GITHUB_USER,
155+
'github_repo': PRJ_GITHUB_REPO,
156+
'github_type': 'star',
135157
'github_banner': True,
136158
'show_relbars': True,
137159
'show_related': True,

0 commit comments

Comments
 (0)