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