setup.py
author rptlab
Mon, 11 Mar 2013 17:25:34 +0000
changeset 11 a0a1adbc7b13
parent 2 src/setup.py@01c9ffc7734a
child 17 b0a98a6ac6a2
permissions -rw-r--r--
move towards standard filesystem layout

#!/usr/bin/env python
#Copyright ReportLab Europe Ltd. 2000-2012
#see license.txt for license details
#history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/rl_addons/pyRXP/setup.py
if __name__=='__main__': #NO RUNTESTS
	import os, sys, shutil, re
	pkgDir=os.path.dirname(sys.argv[0])
	if not pkgDir:
		pkgDir=os.getcwd()
	elif not os.path.isabs(pkgDir):
		pkgDir=os.path.abspath(pkgDir)
	from distutils.core import setup, Extension

	def raiseConfigError(msg):
		import exceptions 
		class ConfigError(exceptions.Exception): 
			pass 
		raise ConfigError(msg)

	LIBS = []
	LIBRARIES=[]
	EXT_MODULES = []

	#building pyRXP
	if sys.platform=="win32":
		LIBS=['wsock32']
	elif sys.platform=="sunos5":
		LIBS=['nsl', 'socket', 'dl']
	elif sys.platform=="aix4":
		LIBS=['nsl_r', 'dl']
	else:
		LIBS=[]

	rxpFiles = ('xmlparser.c', 'url.c', 'charset.c', 'string16.c', 'ctype16.c', 
				'dtd.c', 'input.c', 'stdio16.c', 'system.c', 'hash.c', 
				'version.c', 'namespaces.c', 'http.c', 'nf16check.c', 'nf16data.c')
	pyRXPDir = os.path.join(pkgDir,'src')
	RXPLIBSOURCES=[]
	pyRXP_c = os.path.join(pyRXPDir,'pyRXP.c')
	VERSION = re.search(r'^#\s*define\s+VERSION\s*"([^"]+)"',open(pyRXP_c,'r').read(),re.MULTILINE)
	VERSION = VERSION and VERSION.group(1) or 'unknown'
	RXPDIR=os.path.join(pyRXPDir,'rxp')
	RXPLIBSOURCES= [os.path.join(RXPDIR,f) for f in rxpFiles]
	EXT_MODULES =	[Extension( 'pyRXP',
								[pyRXP_c]+RXPLIBSOURCES,
								include_dirs=[RXPDIR],
								define_macros=[('CHAR_SIZE', 8),],
								library_dirs=[],
								# libraries to link against
								libraries=LIBS,
								),
					]
	# We copy the rxp source - we need to build it a second time for uRXP
	# with different compile time flags
	RXPUDIR=os.path.join(pkgDir,'build','_pyRXPU')
	if os.path.exists(RXPUDIR):
		shutil.rmtree(RXPUDIR)
	os.makedirs(RXPUDIR)
	uRXPLIBSOURCES=[]
	for f in rxpFiles:
		uRXP_file = os.path.join(RXPUDIR,f.replace('.','U.'))
		try:
			shutil.copy2(os.path.join(RXPDIR,f),uRXP_file)
		except:
			print RXPDIR, f, uRXP_file
			raise
		uRXPLIBSOURCES.append(uRXP_file)
	pyRXPU_c = os.path.join(RXPUDIR,'pyRXPU.c')
	shutil.copy2(pyRXP_c,pyRXPU_c)
	uRXPLIBSOURCES.append(pyRXPU_c)
	EXT_MODULES.append(Extension('pyRXPU',
					uRXPLIBSOURCES,
					include_dirs=[RXPDIR],
					define_macros=[('CHAR_SIZE', 16),],
					library_dirs=[],
					# libraries to link against
					libraries=LIBS,
					))


	setup(	name = "pyRXP",
			version = VERSION,
			description = "Python RXP interface - fast validating XML parser",
			author = "Robin Becker",
			author_email = "robin@reportlab.com",
			url = "http://www.reportlab.com",
			packages = [],
			ext_modules = EXT_MODULES,
			#license = open(os.path.join('rxp','COPYING')).read(),
            classifiers = [
				'Development Status :: 5 - Production/Stable',
				'Intended Audience :: Developers',
				'License :: OSI Approved :: ReportLab BSD derived',
				'Programming Language :: Python',
				'Programming Language :: C',
				'Operating System :: Unix',
				'Operating System :: POSIX',
				'Operating System :: Microsoft :: Windows',
				'Topic :: Software Development :: Libraries :: Python Modules',
				'Topic :: Text Processing :: Markup :: XML',
                ]
			)