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