Permalink
Browse files

Added a pip.__version__ variable that is used in the setup.py and the…

… docs' conf.py.
  • Loading branch information...
1 parent 77376b7 commit d9599ec6df654329d967edc5253e377d7e2acebd @jezdez jezdez committed Sep 1, 2012
Showing with 37 additions and 21 deletions.
  1. +11 −4 docs/conf.py
  2. +7 −3 pip/__init__.py
  3. +19 −14 setup.py
View
@@ -11,12 +11,13 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
-import sys, os
+import os
+import sys
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.append(os.path.abspath('.'))
+sys.path.insert(0, os.path.abspath(os.pardir))
#sys.path.append(os.path.join(os.path.dirname(__file__), '../'))
# -- General configuration -----------------------------------------------------
@@ -47,8 +48,14 @@
# built documents.
#
# The short X.Y version.
-release = "1.1.post2"
-version = '.'.join(release.split('.')[:2])
+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'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
View
@@ -14,6 +14,10 @@
from pip.vcs import git, mercurial, subversion, bazaar
+# The version as used in the setup.py and the docs conf.py
+__version__ = "1.2"
+
+
def autocomplete():
"""Command and option completion for the main option parser (and options)
and its subcommands (and options).
@@ -26,7 +30,7 @@ def autocomplete():
cwords = os.environ['COMP_WORDS'].split()[1:]
cword = int(os.environ['COMP_CWORD'])
try:
- current = cwords[cword-1]
+ current = cwords[cword - 1]
except IndexError:
current = ''
load_all_commands()
@@ -59,7 +63,7 @@ def autocomplete():
for opt in subcommand.parser.option_list
if opt.help != optparse.SUPPRESS_HELP]
# filter out previously specified options from available options
- prev_opts = [x.split('=')[0] for x in cwords[1:cword-1]]
+ prev_opts = [x.split('=')[0] for x in cwords[1:cword - 1]]
options = [(x, v) for (x, v) in options if x not in prev_opts]
# filter options by current input
options = [(k, v) for k, v in options if k.startswith(current)]
@@ -184,7 +188,7 @@ def __str__(self):
req = self.req
if self.editable:
req = '-e %s' % req
- return '\n'.join(list(self.comments)+[str(req)])+'\n'
+ return '\n'.join(list(self.comments) + [str(req)]) + '\n'
if __name__ == '__main__':
View
@@ -1,13 +1,22 @@
-import sys
+import codecs
import os
+import re
+import sys
from setuptools import setup
-# If you change this version, change it also in docs/conf.py
-version = "1.2"
-doc_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), "docs")
-index_filename = os.path.join(doc_dir, "index.txt")
-news_filename = os.path.join(doc_dir, "news.txt")
+def read(*parts):
+ return codecs.open(os.path.join(os.path.abspath(os.path.dirname(__file__)), *parts), 'r').read()
+
+
+def find_version(*file_paths):
+ version_file = read(*file_paths)
+ version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
+ version_file, re.M)
+ if version_match:
+ return version_match.group(1)
+ raise RuntimeError("Unable to find version string.")
+
long_description = """
The main website for pip is `www.pip-installer.org
@@ -16,17 +25,13 @@
of pip with ``easy_install pip==dev``.
"""
-f = open(index_filename)
# remove the toctree from sphinx index, as it breaks long_description
-parts = f.read().split("split here", 2)
-long_description = parts[0] + long_description + parts[2]
-f.close()
-f = open(news_filename)
-long_description += "\n\n" + f.read()
-f.close()
+parts = read("docs", "index.txt").split("split here", 2)
+long_description = (parts[0] + long_description + parts[2] +
+ "\n\n" + read("docs", "news.txt"))
setup(name="pip",
- version=version,
+ version=find_version('pip', '__init__.py'),
description="pip installs packages. Python packages. An easy_install replacement",
long_description=long_description,
classifiers=[

0 comments on commit d9599ec

Please sign in to comment.