summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2012-11-12 07:54:03 -0800
committerBrian Dolbec <dolsen@gentoo.org>2012-11-12 07:54:03 -0800
commitcbe03f36f0b55f968301ec82e98db1151acb92e5 (patch)
tree8be29d84adaae598d11d0a7b2c4a138ae825e430
parentinitial EPREFIX enabling. not fully tested. (diff)
downloadmirrorselect-cbe03f36f0b55f968301ec82e98db1151acb92e5.tar.gz
mirrorselect-cbe03f36f0b55f968301ec82e98db1151acb92e5.tar.bz2
mirrorselect-cbe03f36f0b55f968301ec82e98db1151acb92e5.zip
Initial setup.py copied/edited from gentoolkits setup.py
-rwxr-xr-xsetup.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/setup.py b/setup.py
new file mode 100755
index 0000000..db82dd7
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python
+# coding: utf-8
+
+from __future__ import print_function
+
+
+import re
+import sys
+from distutils import core, log
+from glob import glob
+
+import os
+import io
+
+
+__version__ = os.getenv('VERSION', default='9999')
+
+cwd = os.getcwd()
+
+# establish the eprefix, initially set so eprefixify can
+# set it on install
+EPREFIX = "@GENTOO_PORTAGE_EPREFIX@"
+
+# check and set it if it wasn't
+if "GENTOO_PORTAGE_EPREFIX" in EPREFIX:
+ EPREFIX = ''
+
+
+# Python files that need `version = ""` subbed, relative to this dir:
+python_scripts = [os.path.join(cwd, path) for path in (
+ 'mirrorselect/version.py'
+)]
+
+
+class set_version(core.Command):
+ """Set python version to our __version__."""
+ description = "hardcode scripts' version using VERSION from environment"
+ user_options = [] # [(long_name, short_name, desc),]
+
+ def initialize_options (self):
+ pass
+
+ def finalize_options (self):
+ pass
+
+ def run(self):
+ ver = 'git' if __version__ == '9999' else __version__
+ print("Setting version to %s" % ver)
+ def sub(files, pattern):
+ for f in files:
+ updated_file = []
+ with io.open(f, 'r', 1, 'utf_8') as s:
+ for line in s:
+ newline = re.sub(pattern, '"%s"' % ver, line, 1)
+ if newline != line:
+ log.info("%s: %s" % (f, newline))
+ updated_file.append(newline)
+ with io.open(f, 'w', 1, 'utf_8') as s:
+ s.writelines(updated_file)
+ quote = r'[\'"]{1}'
+ python_re = r'(?<=^version = )' + quote + '[^\'"]*' + quote
+ sub(python_scripts, python_re)
+
+
+def load_test():
+ """Only return the real test class if it's actually being run so that we
+ don't depend on snakeoil just to install."""
+
+ desc = "run the test suite"
+ if 'test' in sys.argv[1:]:
+ try:
+ from snakeoil import distutils_extensions
+ except ImportError:
+ sys.stderr.write("Error: We depend on dev-python/snakeoil ")
+ sys.stderr.write("to run tests.\n")
+ sys.exit(1)
+ class test(distutils_extensions.test):
+ description = desc
+ default_test_namespace = 'mirrorselect.test'
+ else:
+ class test(core.Command):
+ description = desc
+
+ return test
+
+packages = [
+ str('.'.join(root.split(os.sep)[1:]))
+ for root, dirs, files in os.walk('mirrorselect')
+ if '__init__.py' in files
+]
+
+test_data = {
+ 'mirrorselect': [
+ ]
+}
+
+core.setup(
+ name='mirrorselect',
+ version=__version__,
+ description='Tool for selecting Gentoo source and rsync mirrors.',
+ author='',
+ author_email='',
+ maintainer='Gentoo Portage Tools Team',
+ maintainer_email='tools-portage@gentoo.org',
+ url='http://www.gentoo.org/proj/en/portage/tools/index.xml',
+ download_url='http://distfiles.gentoo.org/distfiles/mirrorselect-%s.tar.gz'\
+ % __version__,
+ package_dir={'': 'mirrorselect'},
+ packages=packages,
+ package_data = test_data,
+ scripts=(glob('bin/*')),
+ data_files=(
+ (os.path.join(os.sep, EPREFIX.lstrip(os.sep), 'usr/share/man/man8'), 'mirrorselect.8'),
+ ),
+ cmdclass={
+ 'test': load_test(),
+ 'set_version': set_version,
+ },
+)