From 1acc4992d42950b54a7be1b0dcacdaac35d32436 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 13 Mar 2015 21:47:29 -0500 Subject: [PATCH] Parse version number out of requests/__init__.py With the new import machinery in requests/packages/__init__.py people using `python setup.py test` will not be able to run the tests the first time on a new environment. The VendorAlias logic breaks the import machinery and the tests fail. By removing the import of requests in setup.py, we avoid the issue where sys.meta_path continues to have the version of VendorAlias from the import in setup.py. Closes #2462 --- setup.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 813fc87..4637291 100755 --- a/setup.py +++ b/setup.py @@ -1,10 +1,9 @@ #!/usr/bin/env python import os +import re import sys -import requests - from codecs import open try: @@ -29,6 +28,18 @@ packages = [ requires = [] +version = '' +with open('requests/__init__.py', 'r') as fd: + reg = re.compile(r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]') + for line in fd: + m = reg.match(line) + if m: + version = m.group(1) + break + +if not version: + raise RuntimeError('Cannot find version information') + with open('README.rst', 'r', 'utf-8') as f: readme = f.read() with open('HISTORY.rst', 'r', 'utf-8') as f: @@ -36,7 +47,7 @@ with open('HISTORY.rst', 'r', 'utf-8') as f: setup( name='requests', - version=requests.__version__, + version=version, description='Python HTTP for Humans.', long_description=readme + '\n\n' + history, author='Kenneth Reitz', @@ -60,7 +71,6 @@ setup( 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4' - ), extras_require={ 'security': ['pyOpenSSL', 'ndg-httpsclient', 'pyasn1'], -- 2.34.1