Update to genscripts rev 382. This has more fixes for py3k and the modular rewrite...
[gentoolkit.git] / setup.py
1 #!/usr/bin/env python
2
3 from __future__ import print_function
4
5
6 import re
7 import sys
8 import distutils
9 from distutils import core, log
10 from glob import glob
11
12 import os
13
14 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
15 from gentoolkit.helpers import walk
16
17 __version__ = os.getenv('VERSION', default='9999')
18
19 cwd = os.getcwd()
20
21 # Bash files that need `VERSION=""` subbed, relative to this dir:
22 bash_scripts = [os.path.join(cwd, path) for path in (
23         'bin/euse',
24         'bin/revdep-rebuild'
25 )]
26
27 # Python files that need `__version__ = ""` subbed, relative to this dir:
28 python_scripts = [os.path.join(cwd, path) for path in (
29         'bin/eclean',
30         'bin/epkginfo',
31         'bin/glsa-check',
32         'pym/gentoolkit/eclean/cli.py',
33         'pym/gentoolkit/analyse/__init__.py',
34         'pym/gentoolkit/equery/__init__.py'
35 )]
36
37
38 class set_version(core.Command):
39         """Set python __version__ and bash VERSION to our __version__."""
40         description = "hardcode scripts' version using VERSION from environment"
41         user_options = []  # [(long_name, short_name, desc),]
42
43         def initialize_options (self):
44                 pass
45
46         def finalize_options (self):
47                 pass
48
49         def run(self):
50                 ver = 'svn' if __version__ == '9999' else __version__
51                 print("Settings version to %s" % ver)
52                 def sub(files, pattern):
53                         for f in files:
54                                 updated_file = []
55                                 with open(f) as s:
56                                         for line in s:
57                                                 newline = re.sub(pattern, '"%s"' % ver, line, 1)
58                                                 if newline != line:
59                                                         log.info("%s: %s" % (f, newline))
60                                                 updated_file.append(newline)
61                                 with open(f, 'w') as s:
62                                         s.writelines(updated_file)
63                 quote = r'[\'"]{1}'
64                 bash_re = r'(?<=VERSION=)' + quote + '[^\'"]*' + quote
65                 sub(bash_scripts, bash_re)
66                 python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote
67                 sub(python_scripts, python_re)
68
69
70 def     load_test():
71         """Only return the real test class if it's actually being run so that we
72         don't depend on snakeoil just to install."""
73
74         desc = "run the test suite"
75         if 'test' in sys.argv[1:]:
76                 try:
77                         from snakeoil import distutils_extensions
78                 except ImportError:
79                         sys.stderr.write("Error: We depend on dev-python/snakeoil ")
80                         sys.stderr.write("to run tests.\n")
81                         sys.exit(1)
82                 class test(distutils_extensions.test):
83                         description = desc
84                         default_test_namespace = 'gentoolkit.test'
85         else:
86                 class test(core.Command):
87                         description = desc
88
89         return test
90
91
92 packages = [
93         str('.'.join(root.split(os.sep)[1:]))
94         for root, dirs, files in walk('pym/gentoolkit')
95         if '__init__.py' in files
96 ]
97
98 core.setup(
99         name='gentoolkit',
100         version=__version__,
101         description='Set of tools that work with and enhance portage.',
102         author='',
103         author_email='',
104         maintainer='Gentoo Portage Tools Team',
105         maintainer_email='tools-portage@gentoo.org',
106         url='http://www.gentoo.org/proj/en/portage/tools/index.xml',
107         download_url='http://distfiles.gentoo.org/distfiles/gentoolkit-%s.tar.gz'\
108                 % __version__,
109         package_dir={'': 'pym'},
110         packages=packages,
111         scripts=(glob('bin/*')),
112         data_files=(
113                 ('/etc/env.d', ['data/99gentoolkit-env']),
114                 ('/etc/revdep-rebuild', ['data/revdep-rebuild/99revdep-rebuild']),
115                 ('/etc/eclean', glob('data/eclean/*')),
116                 ('/usr/share/man/man1', glob('man/*'))
117         ),
118         cmdclass={
119                 'test': load_test(),
120                 'set_version': set_version,
121         },
122 )
123
124 # vim: set ts=4 sw=4 tw=79: