77"""
88
99from email import message_from_string
10+ from itertools import chain
1011import 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+
3952PYTHON_DISTRIBUTION_NAME = 'octomachinery'
4053
4154PRJ_DIST = pkg_resources .get_distribution (PYTHON_DISTRIBUTION_NAME )
@@ -46,6 +59,12 @@ def get_supported_pythons(classifiers):
4659PRJ_DESCRIPTION = PRJ_META ['Description' ]
4760PRJ_PY_VER_RANGE = get_supported_pythons (PRJ_META .get_all ('Classifier' ))
4861PRJ_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
5069project = PRJ_DIST .project_name # pylint: disable=invalid-name
5170author = PRJ_AUTHOR # pylint: disable=invalid-name
@@ -132,6 +151,9 @@ def get_supported_pythons(classifiers):
132151# documentation.
133152#
134153html_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