Rolled setuptools support back into setup.py but made it much more robust.
This commit is contained in:
38
setup.py
38
setup.py
@@ -17,10 +17,14 @@
|
|||||||
Also installs included versions of third party libraries, if those libraries
|
Also installs included versions of third party libraries, if those libraries
|
||||||
are not already installed.
|
are not already installed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import setup_utils
|
import setup_utils
|
||||||
|
|
||||||
# Modules, not packages, that might need to be installed.
|
has_setuptools = False
|
||||||
|
try:
|
||||||
|
from setuptools import setup
|
||||||
|
has_setuptools = True
|
||||||
|
except ImportError:
|
||||||
|
from distutils.core import setup
|
||||||
|
|
||||||
packages = [
|
packages = [
|
||||||
'apiclient',
|
'apiclient',
|
||||||
@@ -32,29 +36,41 @@ packages = [
|
|||||||
'apiclient.contrib.moderator',
|
'apiclient.contrib.moderator',
|
||||||
'uritemplate',
|
'uritemplate',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
install_requires = []
|
||||||
py_modules = []
|
py_modules = []
|
||||||
|
|
||||||
third_party_packages = ['httplib2', 'oauth2']
|
|
||||||
third_party_modules = ['gflags', 'gflags_validators']
|
|
||||||
|
|
||||||
# Don't clobber installed versions of third party libraries
|
# (module to test for, install_requires to add if missing, packages to add if missing, py_modules to add if missing)
|
||||||
# with what we include.
|
REQUIREMENTS = [
|
||||||
packages.extend(setup_utils.get_missing_requirements(third_party_packages))
|
('httplib2', 'httplib2', 'httplib2', None),
|
||||||
py_modules.extend(setup_utils.get_missing_requirements(third_party_modules))
|
('oauth2', 'oauth2', 'oauth2', None),
|
||||||
|
('gflags', 'python-gflags', None, ['gflags', 'gflags_validators']),
|
||||||
|
(['json', 'simplejson', 'django.utils'], 'simplejson', 'simplejson', None)
|
||||||
|
]
|
||||||
|
|
||||||
|
for import_name, requires, package, modules in REQUIREMENTS:
|
||||||
|
if setup_utils.is_missing(import_name):
|
||||||
|
if has_setuptools:
|
||||||
|
install_requires.append(requires)
|
||||||
|
else:
|
||||||
|
if package is not None:
|
||||||
|
packages.append(package)
|
||||||
|
else:
|
||||||
|
py_modules.extend(modules)
|
||||||
|
|
||||||
# It appears setuptools can't have packages and py_modules, but this project does.
|
|
||||||
from distutils.core import setup
|
|
||||||
|
|
||||||
long_desc = """The Google API Client for Python is a client library for
|
long_desc = """The Google API Client for Python is a client library for
|
||||||
accessing the Buzz, Moderator, and Latitude APIs."""
|
accessing the Buzz, Moderator, and Latitude APIs."""
|
||||||
|
|
||||||
setup(name="google-api-python-client",
|
setup(name="google-api-python-client",
|
||||||
version="1.0alpha9",
|
version="1.0alpha10",
|
||||||
description="Google API Client Library for Python",
|
description="Google API Client Library for Python",
|
||||||
long_description=long_desc,
|
long_description=long_desc,
|
||||||
author="Joe Gregorio",
|
author="Joe Gregorio",
|
||||||
author_email="jcgregorio@google.com",
|
author_email="jcgregorio@google.com",
|
||||||
url="http://code.google.com/p/google-api-python-client/",
|
url="http://code.google.com/p/google-api-python-client/",
|
||||||
|
install_requires=install_requires,
|
||||||
packages=packages,
|
packages=packages,
|
||||||
py_modules=py_modules,
|
py_modules=py_modules,
|
||||||
package_data={
|
package_data={
|
||||||
|
|||||||
@@ -17,11 +17,13 @@
|
|||||||
|
|
||||||
__author__ = 'tom.h.miller@gmail.com (Tom Miller)'
|
__author__ = 'tom.h.miller@gmail.com (Tom Miller)'
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
def get_missing_requirements(third_party_reqs):
|
|
||||||
"""Return a list of missing third party packages."""
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
def is_missing(packages):
|
||||||
|
"""Return True if a package can't be imported."""
|
||||||
|
|
||||||
|
retval = True
|
||||||
sys_path_original = sys.path[:]
|
sys_path_original = sys.path[:]
|
||||||
# Remove the current directory from the list of paths to check when
|
# Remove the current directory from the list of paths to check when
|
||||||
# importing modules.
|
# importing modules.
|
||||||
@@ -34,55 +36,17 @@ def get_missing_requirements(third_party_reqs):
|
|||||||
sys.path.remove(os.path.abspath(os.path.curdir))
|
sys.path.remove(os.path.abspath(os.path.curdir))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
missing_pkgs = []
|
if not isinstance(packages, type([])):
|
||||||
for pkg in third_party_reqs:
|
packages = [packages]
|
||||||
|
for name in packages:
|
||||||
try:
|
try:
|
||||||
__import__(pkg)
|
__import__(name)
|
||||||
|
retval = False
|
||||||
except ImportError:
|
except ImportError:
|
||||||
missing_pkgs.append(pkg)
|
retval = True
|
||||||
# JSON support gets its own special logic
|
if retval == False:
|
||||||
try:
|
break
|
||||||
import_json(sys.path)
|
|
||||||
except ImportError:
|
|
||||||
missing_pkgs.append('simplejson')
|
|
||||||
|
|
||||||
sys.path = sys_path_original
|
sys.path = sys_path_original
|
||||||
return missing_pkgs
|
|
||||||
|
|
||||||
|
return retval
|
||||||
def import_json(import_path=None):
|
|
||||||
"""Return a package that will provide JSON support.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
import_path: list Value to assing to sys.path before checking for packages.
|
|
||||||
Default None for default sys.path.
|
|
||||||
Return:
|
|
||||||
A package, one of 'json' (if running python 2.6),
|
|
||||||
'django.utils.simplejson' (if django is installed)
|
|
||||||
'simplejson' (if third party library simplejson is found)
|
|
||||||
Raises:
|
|
||||||
ImportError if none of those packages are found.
|
|
||||||
"""
|
|
||||||
import sys
|
|
||||||
sys_path_orig = sys.path[:]
|
|
||||||
if import_path is not None:
|
|
||||||
sys.path = import_path
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Should work for Python 2.6.
|
|
||||||
pkg = __import__('json')
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
pkg = __import__('django.utils').simplejson
|
|
||||||
except ImportError:
|
|
||||||
try:
|
|
||||||
pkg = __import__('simplejson')
|
|
||||||
except ImportError:
|
|
||||||
pkg = None
|
|
||||||
|
|
||||||
if import_path is not None:
|
|
||||||
sys.path = sys_path_orig
|
|
||||||
if pkg:
|
|
||||||
return pkg
|
|
||||||
else:
|
|
||||||
raise ImportError('Cannot find json support')
|
|
||||||
|
|||||||
Reference in New Issue
Block a user