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 (
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'
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),]
51 def initialize_options (self):
54 def finalize_options (self):
58 ver = 'svn' if __version__ == '9999' else __version__
59 print("Settings version to %s" % ver)
60 def sub(files, pattern):
63 with io.open(f, 'r', 1, 'utf_8') as s:
65 newline = re.sub(pattern, '"%s"' % ver, line, 1)
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)
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)
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."""
82 desc = "run the test suite"
83 if 'test' in sys.argv[1:]:
85 from snakeoil import distutils_extensions
87 sys.stderr.write("Error: We depend on dev-python/snakeoil ")
88 sys.stderr.write("to run tests.\n")
90 class test(distutils_extensions.test):
92 default_test_namespace = 'gentoolkit.test'
94 class test(core.Command):
100 str('.'.join(root.split(os.sep)[1:]))
101 for root, dirs, files in os.walk('pym/gentoolkit')
102 if '__init__.py' in files
107 'test/eclean/Packages',
108 'test/eclean/testdistfiles.tar.gz',
109 'test/eclean/distfiles.exclude'
116 description='Set of tools that work with and enhance portage.',
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'\
124 package_dir={'': 'pym'},
126 package_data = test_data,
127 scripts=(glob('bin/*')),
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/*')),
136 'set_version': set_version,
140 # vim: set ts=4 sw=4 tw=79: