1
2
3
4
5 """
6 Common code for setup.py files. Details about the Trove classifiers are
7 available at
8 U{http://pypi.python.org/pypi?%3Aaction=list_classifiers}.
9 """
10
11 arg_keys = """
12 name
13 version
14 author
15 author_email
16 description: Summary
17 download_url: Download-url
18 long_description: Description
19 keywords: Keywords
20 url: Home-page
21 license
22 classifiers: Classifier
23 platforms: Platform
24 """
25
26 import sys
27 if not hasattr(sys, "version_info") or sys.version_info < (2, 3):
28 from distutils.core import setup
29 _setup = setup
31 for key in [
32
33
34 "classifiers", "download_url",
35
36 "install_requires", "zip_safe", "test_suite",
37 ]:
38 if kwargs.has_key(key):
39 del kwargs[key]
40
41
42
43 if kwargs["packages"] is None:
44 del kwargs["packages"]
45 else:
46 del kwargs["py_modules"]
47 apply(_setup, (), kwargs)
48 else:
49 from setuptools import setup, find_packages
50
51 -def run_setup( pkg_info_text, srcdir = 'src', *orig_args, **orig_kwargs ):
52 list_keys = set( [ 'Classifier' ] )
53 pkg_info = {}
54 for line in pkg_info_text.split( '\n' ):
55 if line.strip() != '':
56 if line.startswith( ' '*8 ):
57 pkg_info[ key ] += line[ 7 : ]
58 else:
59 key, value = line.split( ': ', 1 )
60 if key in list_keys:
61 try:
62 pkg_info[ key ].append( value )
63 except:
64 pkg_info[ key ] = [ value ]
65 else:
66 pkg_info[ key ] = value
67
68 args_nontranslations = set()
69 args_translations = {}
70 for line in arg_keys.split( '\n' ):
71 if line.strip() != '':
72 splitted = line.split( ': ', 1 )
73 dest_name = splitted[ 0 ]
74 if len( splitted ) == 2:
75 source_name = splitted[ 1 ]
76 args_translations[ source_name ] = dest_name
77 else:
78 args_nontranslations.add( dest_name )
79
80 args = {}
81 for key, value in pkg_info.iteritems():
82 dest_name = None
83 try:
84 dest_name = args_translations[ key ]
85 except KeyError:
86 key = key.lower().replace('-','_')
87 if key in args_nontranslations:
88 dest_name = key
89 if dest_name is not None:
90 args[ dest_name ] = value
91
92
93 args.update( orig_kwargs )
94 args.update( {
95 'package_dir': {'':srcdir},
96 'packages': find_packages(srcdir),
97 'zip_safe': True,
98 } )
99
100 setup( *orig_args, **args )
101