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