3 from __future__ import print_function
9 from distutils import core, log
14 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
16 __version__ = os.getenv('VERSION', default='9999')
20 # Load EPREFIX from Portage, fall back to the empty string if it fails
22 from portage.const import EPREFIX
23 except AttributeError:
27 # Bash files that need `VERSION=""` subbed, relative to this dir:
28 bash_scripts = [os.path.join(cwd, path) for path in (
33 # Python files that need `__version__ = ""` subbed, relative to this dir:
34 python_scripts = [os.path.join(cwd, path) for path in (
38 'pym/gentoolkit/eclean/cli.py',
39 'pym/gentoolkit/analyse/__init__.py',
40 'pym/gentoolkit/equery/__init__.py'
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),]
49 def initialize_options (self):
52 def finalize_options (self):
56 ver = 'svn' if __version__ == '9999' else __version__
57 print("Settings version to %s" % ver)
58 def sub(files, pattern):
63 newline = re.sub(pattern, '"%s"' % ver, line, 1)
65 log.info("%s: %s" % (f, newline))
66 updated_file.append(newline)
67 with open(f, 'w') as s:
68 s.writelines(updated_file)
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)
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."""
80 desc = "run the test suite"
81 if 'test' in sys.argv[1:]:
83 from snakeoil import distutils_extensions
85 sys.stderr.write("Error: We depend on dev-python/snakeoil ")
86 sys.stderr.write("to run tests.\n")
88 class test(distutils_extensions.test):
90 default_test_namespace = 'gentoolkit.test'
92 class test(core.Command):
99 str('.'.join(root.split(os.sep)[1:]))
100 for root, dirs, files in os.walk('pym/gentoolkit')
101 if '__init__.py' in files
107 description='Set of tools that work with and enhance portage.',
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'\
115 package_dir={'': 'pym'},
117 scripts=(glob('bin/*')),
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/*'))
126 'set_version': set_version,
130 # vim: set ts=4 sw=4 tw=79: