diff --git a/setup.py b/setup.py index 10fea483dbf..a145e6c8feb 100755 --- a/setup.py +++ b/setup.py @@ -8,8 +8,11 @@ from __future__ import with_statement import os import sys +from datetime import datetime from distutils.cmd import Command +from distutils.command.build import build from distutils.command.clean import clean +from distutils.command.install import install from distutils.sysconfig import get_python_lib, PREFIX # Change to salt source's directory prior to running any command @@ -109,6 +112,43 @@ class Clean(clean): break +install_version_template = """\ +# This file was auto-generated by salt's setup on \ +{date:%A, %d %B %Y @ %H:%m:%S UTC}'. + +__version__ = {version!r} +__version_info__ = {version_info!r} +""" + + +class Build(build): + def run(self): + # Run build.run function + build.run(self) + # If our install attribute is present and set to True, we'll go ahead + # and write our install time _version.py file. + if getattr(self.distribution, 'running_salt_install', False): + version_file_path = os.path.join( + self.build_lib, 'salt', '_version.py' + ) + open(version_file_path, 'w').write( + install_version_template.format( + date=datetime.utcnow(), + version=__version__, + version_info=__version_info__ + ) + ) + + +class Install(install): + def run(self): + # Let's set the running_salt_install attribute so we can add + # _version.py in the build command + self.distribution.running_salt_install = True + # Run install.run + install.run(self) + + NAME = 'salt' VER = __version__ DESC = ('Portable, distributed, remote execution and ' @@ -134,7 +174,12 @@ setup_kwargs = {'name': NAME, 'author': 'Thomas S Hatch', 'author_email': 'thatch45@gmail.com', 'url': 'http://saltstack.org', - 'cmdclass': {'test': TestCommand, 'clean': Clean}, + 'cmdclass': { + 'test': TestCommand, + 'clean': Clean, + 'build': Build, + 'install': Install + }, 'classifiers': ['Programming Language :: Python', 'Programming Language :: Cython', 'Programming Language :: Python :: 2.6',