Fix how docs gets pip version, to work around an issue with readthedocs

This commit is contained in:
Paul Moore 2018-04-07 10:57:08 +01:00
parent 5a8150f82c
commit ddbbafaabb
1 changed files with 22 additions and 8 deletions

View File

@ -12,6 +12,7 @@
# serve to show the default.
import os
import re
import sys
import glob
@ -59,14 +60,27 @@ copyright = '2008-2017, PyPA'
# built documents.
#
# The short X.Y version.
try:
from pip import __version__
# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
except ImportError:
version = release = 'dev'
version = release = 'dev'
# Readthedocs seems to install pip as an egg (via setup.py install) which
# is somehow resulting in "import pip" picking up an older copy of pip.
# Rather than trying to force RTD to install pip properly, we'll simply
# read the version direct from the __init__.py file. (Yes, this is
# fragile, but it works...)
root = os.path.dirname(os.path.dirname(__file__))
pip_init = os.path.join(root, 'src', 'pip', '__init__.py')
with open(pip_init, encoding='utf-8') as f:
for line in f:
m = re.match(r'__version__ = "(.*)"', line)
if m:
__version__ = m.group(1)
# The short X.Y version.
version = '.'.join(__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
release = __version__
break
# We have this here because readthedocs plays tricks sometimes and there seems
# to be a hiesenbug, related to the version of pip discovered. This is here to