Skip to content
Newer
Older
100644 135 lines (118 sloc) 5.01 KB
8e7d5f6 @pablohoffman - fixed setup.py script (closes #80)
pablohoffman authored
1 # Scrapy setup.py script
2 #
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
3 # It doesn't depend on setuptools, but if setuptools is available it'll use
4 # some of its features, like package dependencies.
97a790d @pablohoffman improved mechanism for tagging version with hg revision
pablohoffman authored
5
6 from __future__ import with_statement
7
8e7d5f6 @pablohoffman - fixed setup.py script (closes #80)
pablohoffman authored
8 from distutils.command.install_data import install_data
9 from distutils.command.install import INSTALL_SCHEMES
9206806 @pablohoffman setup.py: added support for generating version from hg revision
pablohoffman authored
10 from subprocess import Popen, PIPE
8e7d5f6 @pablohoffman - fixed setup.py script (closes #80)
pablohoffman authored
11 import os
12 import sys
a85e530 in the way of setuptooling
eduardo authored
13
8e7d5f6 @pablohoffman - fixed setup.py script (closes #80)
pablohoffman authored
14 class osx_install_data(install_data):
15 # On MacOS, the platform-specific lib dir is /System/Library/Framework/Python/.../
16 # which is wrong. Python 2.5 supplied with MacOS 10.5 has an Apple-specific fix
17 # for this in distutils.command.install_data#306. It fixes install_lib but not
18 # install_data, which is why we roll our own install_data class.
19
20 def finalize_options(self):
21 # By the time finalize_options is called, install.install_lib is set to the
22 # fixed directory, so we set the installdir to install_lib. The
23 # install_data class uses ('install_data', 'install_dir') instead.
24 self.set_undefined_options('install', ('install_lib', 'install_dir'))
25 install_data.finalize_options(self)
26
27 if sys.platform == "darwin":
28 cmdclasses = {'install_data': osx_install_data}
29 else:
30 cmdclasses = {'install_data': install_data}
31
32 def fullsplit(path, result=None):
33 """
34 Split a pathname into components (the opposite of os.path.join) in a
35 platform-neutral way.
36 """
37 if result is None:
38 result = []
39 head, tail = os.path.split(path)
40 if head == '':
41 return [tail] + result
42 if head == path:
43 return result
44 return fullsplit(head, [tail] + result)
45
46 # Tell distutils to put the data_files in platform-specific installation
47 # locations. See here for an explanation:
48 # http://groups.google.com/group/comp.lang.python/browse_thread/thread/35ec7b2fed36eaec/2105ee4d9e8042cb
49 for scheme in INSTALL_SCHEMES.values():
50 scheme['data'] = scheme['purelib']
51
52 # Compile the list of packages available, because distutils doesn't have
53 # an easy way to do this.
54 packages, data_files = [], []
55 root_dir = os.path.dirname(__file__)
56 if root_dir != '':
57 os.chdir(root_dir)
58
59 def is_not_module(filename):
60 return os.path.splitext(f)[1] not in ['.py', '.pyc', '.pyo']
61
37e9c5d @pablohoffman Added new Scrapy service with support for:
pablohoffman authored
62 for scrapy_dir in ['scrapy', 'scrapyd']:
63 for dirpath, dirnames, filenames in os.walk(scrapy_dir):
64 # Ignore dirnames that start with '.'
65 for i, dirname in enumerate(dirnames):
66 if dirname.startswith('.'): del dirnames[i]
67 if '__init__.py' in filenames:
68 packages.append('.'.join(fullsplit(dirpath)))
69 data = [f for f in filenames if is_not_module(f)]
70 if data:
71 data_files.append([dirpath, [os.path.join(dirpath, f) for f in data]])
72 elif filenames:
73 data_files.append([dirpath, [os.path.join(dirpath, f) for f in filenames]])
8e7d5f6 @pablohoffman - fixed setup.py script (closes #80)
pablohoffman authored
74
75 # Small hack for working with bdist_wininst.
76 # See http://mail.python.org/pipermail/distutils-sig/2004-August/004134.html
77 if len(sys.argv) > 1 and sys.argv[1] == 'bdist_wininst':
78 for file_info in data_files:
79 file_info[0] = '\\PURELIB\\%s' % file_info[0]
80
e7b3247 @pablohoffman Updated some missing references to scrapy-ws script
pablohoffman authored
81 scripts = ['bin/scrapy']
34554da @pablohoffman Deprecated scrapy-ctl.py command in favour of simpler "scrapy" comman…
pablohoffman authored
82 if os.name == 'nt':
83 scripts.append('extras/scrapy.bat')
84
b6220b8 @pablohoffman use git describe for building version from git, and removed support f…
pablohoffman authored
85 if os.environ.get('SCRAPY_VERSION_FROM_GIT'):
86 v = Popen("git describe", shell=True, stdout=PIPE).communicate()[0]
97a790d @pablohoffman improved mechanism for tagging version with hg revision
pablohoffman authored
87 with open('scrapy/__init__.py', 'a') as f:
b6220b8 @pablohoffman use git describe for building version from git, and removed support f…
pablohoffman authored
88 f.write("\n__version__ = '%s'" % v.strip())
97a790d @pablohoffman improved mechanism for tagging version with hg revision
pablohoffman authored
89 version = __import__('scrapy').__version__
9206806 @pablohoffman setup.py: added support for generating version from hg revision
pablohoffman authored
90
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
91 setup_args = {
024c00a @pablohoffman title-cased project name in setup.py
pablohoffman authored
92 'name': 'Scrapy',
9206806 @pablohoffman setup.py: added support for generating version from hg revision
pablohoffman authored
93 'version': version,
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
94 'url': 'http://scrapy.org',
95 'description': 'A high-level Python Screen Scraping framework',
96 'long_description': 'Scrapy is a high level scraping and web crawling framework for writing spiders to crawl and parse web pages for all kinds of purposes, from information retrieval to monitoring or testing web sites.',
97 'author': 'Scrapy developers',
98 'maintainer': 'Pablo Hoffman',
99 'maintainer_email': 'pablo@pablohoffman.com',
100 'license': 'BSD',
101 'packages': packages,
102 'cmdclass': cmdclasses,
103 'data_files': data_files,
34554da @pablohoffman Deprecated scrapy-ctl.py command in favour of simpler "scrapy" comman…
pablohoffman authored
104 'scripts': scripts,
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
105 'classifiers': [
6e10914 @pablohoffman added pypi classifiers to setup.py
pablohoffman authored
106 'Programming Language :: Python',
107 'Programming Language :: Python :: 2.5',
108 'Programming Language :: Python :: 2.6',
109 'Programming Language :: Python :: 2.7',
110 'License :: OSI Approved :: BSD License',
111 'Operating System :: OS Independent',
112 'Development Status :: 5 - Production/Stable',
113 'Intended Audience :: Developers',
114 'Environment :: Console',
115 'Topic :: Software Development :: Libraries :: Application Frameworks',
116 'Topic :: Software Development :: Libraries :: Python Modules',
117 'Topic :: Internet :: WWW/HTTP',
118 ]
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
119 }
120
121 try:
122 from setuptools import setup
123 except ImportError:
124 from distutils.core import setup
804c027 @pablohoffman setup.py: only add lxml requirement if libxml2 is not available
pablohoffman authored
125 else:
126 setup_args['install_requires'] = ['Twisted>=2.5', 'w3lib', 'pyOpenSSL']
127 if sys.version_info < (2, 6):
128 setup_args['install_requires'] += ['simplejson']
129 try:
130 import libxml2
131 except ImportError:
132 setup_args['install_requires'] += ['lxml']
f86f62c @void Use setuptools for install, if not present fallback to distutils
void authored
133
134 setup(**setup_args)
Something went wrong with that request. Please try again.