3 from __future__ import print_function
9 from distutils import core, log
15 sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
17 __version__ = os.getenv('VERSION', default='9999')
21 # Load EPREFIX from Portage, fall back to the empty string if it fails
23 from portage.const import EPREFIX
28 # Bash files that need `VERSION=""` subbed, relative to this dir:
29 bash_scripts = [os.path.join(cwd, path) for path in (
31 'bin/revdep-rebuild.sh'
34 # Python files that need `__version__ = ""` subbed, relative to this dir:
35 python_scripts = [os.path.join(cwd, path) for path in (
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'
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),]
52 def initialize_options (self):
55 def finalize_options (self):
59 ver = 'svn' if __version__ == '9999' else __version__
60 print("Settings version to %s" % ver)
61 def sub(files, pattern):
64 with io.open(f, 'r', 1, 'utf_8') as s:
66 newline = re.sub(pattern, '"%s"' % ver, line, 1)
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)
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)
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."""
83 desc = "run the test suite"
84 if 'test' in sys.argv[1:]:
86 from snakeoil import distutils_extensions
88 sys.stderr.write("Error: We depend on dev-python/snakeoil ")
89 sys.stderr.write("to run tests.\n")
91 class test(distutils_extensions.test):
93 default_test_namespace = 'gentoolkit.test'
95 class test(core.Command):
101 str('.'.join(root.split(os.sep)[1:]))
102 for root, dirs, files in os.walk('pym/gentoolkit')
103 if '__init__.py' in files
108 'test/eclean/Packages',
109 'test/eclean/testdistfiles.tar.gz',
110 'test/eclean/distfiles.exclude'
117 description='Set of tools that work with and enhance portage.',
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'\
125 package_dir={'': 'pym'},
127 package_data = test_data,
128 scripts=(glob('bin/*')),
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/*')),
137 'set_version': set_version,
141 # vim: set ts=4 sw=4 tw=79: