mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Merge pull request #3608 from s0undt3ch/issues/2587
Provide the information of git describe in a module when installing salt
This commit is contained in:
commit
5f0fc3a230
@ -3,25 +3,37 @@ Set up the version of Salt
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import warnings
|
||||
import subprocess
|
||||
|
||||
|
||||
__version_info__ = (0, 12, 0)
|
||||
__version__ = '.'.join(map(str, __version_info__))
|
||||
|
||||
GIT_DESCRIBE_RE = re.compile(
|
||||
GIT_DESCRIBE_REGEX = (
|
||||
r'(?P<major>[\d]{1,2}).(?P<minor>[\d]{1,2}).(?P<bugfix>[\d]{1,2})'
|
||||
r'(?:(?:.*)-(?P<noc>[\d]+)-(?P<sha>[a-z0-9]{8}))?'
|
||||
)
|
||||
|
||||
|
||||
def __get_version_info_from_git(version, version_info):
|
||||
def __get_version(version, version_info):
|
||||
'''
|
||||
If we can get a version from Git use that instead, otherwise we carry on
|
||||
If we can get a version provided at installation time or from Git, use
|
||||
that instead, otherwise we carry on.
|
||||
'''
|
||||
try:
|
||||
# Try to import the version information provided at install time
|
||||
from salt._version import __version__, __version_info__
|
||||
return __version__, __version_info__
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# This might be a 'python setup.py develop' installation type. Let's
|
||||
# discover the version information at runtime.
|
||||
import os
|
||||
import re
|
||||
import warnings
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
kwargs = dict(
|
||||
stdout=subprocess.PIPE,
|
||||
@ -39,7 +51,7 @@ def __get_version_info_from_git(version, version_info):
|
||||
if not out.strip() or err.strip():
|
||||
return version, version_info
|
||||
|
||||
match = GIT_DESCRIBE_RE.search(out.strip())
|
||||
match = re.search(GIT_DESCRIBE_REGEX, out.strip())
|
||||
if not match:
|
||||
return version, version_info
|
||||
|
||||
@ -68,18 +80,17 @@ def __get_version_info_from_git(version, version_info):
|
||||
return parsed_version, parsed_version_info
|
||||
except OSError, err:
|
||||
if err.errno != 2:
|
||||
# If the errno is not 2(The system cannot find the file specified),
|
||||
# raise the exception so it can be catch by the developers
|
||||
# If the errno is not 2(The system cannot find the file
|
||||
# specified), raise the exception so it can be catch by the
|
||||
# developers
|
||||
raise
|
||||
# Popen child exceptions are not raised
|
||||
return version, version_info
|
||||
|
||||
|
||||
# Get version information from git if available
|
||||
__version__, __version_info__ = \
|
||||
__get_version_info_from_git(__version__, __version_info__)
|
||||
# Get additional version information if available
|
||||
__version__, __version_info__ = __get_version(__version__, __version_info__)
|
||||
# This function has executed once, we're done with it. Delete it!
|
||||
del __get_version_info_from_git
|
||||
del __get_version
|
||||
|
||||
|
||||
def versions_report():
|
||||
|
47
setup.py
47
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',
|
||||
|
@ -10,6 +10,9 @@
|
||||
:license: Apache 2.0, see LICENSE for more details.
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
import re
|
||||
|
||||
# Import salt libs
|
||||
from saltunittest import TestCase, TestLoader, TextTestRunner
|
||||
import salt.version
|
||||
@ -27,7 +30,7 @@ class VersionTestCase(TestCase):
|
||||
|
||||
for vs, groups in expect:
|
||||
self.assertEqual(
|
||||
groups, salt.version.GIT_DESCRIBE_RE.search(vs).groups()
|
||||
groups, re.search(salt.version.GIT_DESCRIBE_REGEX, vs).groups()
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user