mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #56378 from Ch3LL/wheel_version
Include _version.py if building wheel
This commit is contained in:
commit
e72a8d2cbc
7 changed files with 162 additions and 8 deletions
|
@ -241,7 +241,10 @@ class SaltStackVersion(object):
|
|||
if bugfix is None and not self.new_version(major=major):
|
||||
bugfix = 0
|
||||
elif isinstance(bugfix, string_types):
|
||||
bugfix = int(bugfix)
|
||||
if not bugfix:
|
||||
bugfix = None
|
||||
else:
|
||||
bugfix = int(bugfix)
|
||||
|
||||
if mbugfix is None:
|
||||
mbugfix = 0
|
||||
|
@ -269,6 +272,8 @@ class SaltStackVersion(object):
|
|||
self.pre_type = pre_type
|
||||
self.pre_num = pre_num
|
||||
self.name = self.VNAMES.get((major, minor), None)
|
||||
if self.new_version(major):
|
||||
self.name = self.VNAMES.get((major,), None)
|
||||
self.noc = noc
|
||||
self.sha = sha
|
||||
|
||||
|
@ -362,6 +367,23 @@ class SaltStackVersion(object):
|
|||
self.sha])
|
||||
return tuple(info)
|
||||
|
||||
@property
|
||||
def full_info_all_versions(self):
|
||||
'''
|
||||
Return the full info regardless
|
||||
of which versioning scheme we
|
||||
are using.
|
||||
'''
|
||||
info = [self.major,
|
||||
self.minor,
|
||||
self.bugfix,
|
||||
self.mbugfix,
|
||||
self.pre_type,
|
||||
self.pre_num,
|
||||
self.noc,
|
||||
self.sha]
|
||||
return tuple(info)
|
||||
|
||||
@property
|
||||
def string(self):
|
||||
if self.new_version(self.major):
|
||||
|
@ -477,8 +499,16 @@ class SaltStackVersion(object):
|
|||
parts.extend([
|
||||
'major={0}'.format(self.major),
|
||||
'minor={0}'.format(self.minor),
|
||||
'bugfix={0}'.format(self.bugfix)
|
||||
])
|
||||
])
|
||||
|
||||
if self.new_version(self.major):
|
||||
if not self.minor:
|
||||
parts.remove(''.join([x for x in parts if re.search('^minor*', x)]))
|
||||
else:
|
||||
parts.extend([
|
||||
'bugfix={0}'.format(self.bugfix)
|
||||
])
|
||||
|
||||
if self.mbugfix:
|
||||
parts.append('minor-bugfix={0}'.format(self.mbugfix))
|
||||
if self.pre_type:
|
||||
|
|
28
setup.py
28
setup.py
|
@ -38,6 +38,11 @@ from setuptools.command.develop import develop
|
|||
from setuptools.command.install import install
|
||||
from setuptools.command.sdist import sdist
|
||||
from setuptools.command.egg_info import egg_info
|
||||
try:
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
HAS_BDIST_WHEEL = True
|
||||
except ImportError:
|
||||
HAS_BDIST_WHEEL = False
|
||||
# pylint: enable=E0611
|
||||
|
||||
try:
|
||||
|
@ -256,7 +261,7 @@ class WriteSaltVersion(Command):
|
|||
open(self.distribution.salt_version_hardcoded_path, 'w').write(
|
||||
INSTALL_VERSION_TEMPLATE.format(
|
||||
date=DATE,
|
||||
full_version_info=salt_version.full_info
|
||||
full_version_info=salt_version.full_info_all_versions
|
||||
)
|
||||
)
|
||||
# pylint: enable=E0602
|
||||
|
@ -642,6 +647,14 @@ class Clean(clean):
|
|||
os.remove(to_remove_filename)
|
||||
|
||||
|
||||
if HAS_BDIST_WHEEL:
|
||||
class BDistWheel(bdist_wheel):
|
||||
|
||||
def finalize_options(self):
|
||||
bdist_wheel.finalize_options(self)
|
||||
self.distribution.build_wheel = True
|
||||
|
||||
|
||||
INSTALL_VERSION_TEMPLATE = '''\
|
||||
# This file was auto-generated by salt's setup
|
||||
|
||||
|
@ -679,11 +692,16 @@ class Build(build):
|
|||
def run(self):
|
||||
# Run build.run function
|
||||
build.run(self)
|
||||
salt_build_ver_file = os.path.join(self.build_lib, 'salt', '_version.py')
|
||||
|
||||
if getattr(self.distribution, 'with_salt_version', False):
|
||||
# Write the hardcoded salt version module salt/_version.py
|
||||
self.distribution.salt_version_hardcoded_path = os.path.join(
|
||||
self.build_lib, 'salt', '_version.py'
|
||||
)
|
||||
self.distribution.salt_version_hardcoded_path = salt_build_ver_file
|
||||
self.run_command('write_salt_version')
|
||||
|
||||
if getattr(self.distribution, 'build_wheel', False):
|
||||
# we are building a wheel package. need to include _version.py
|
||||
self.distribution.salt_version_hardcoded_path = salt_build_ver_file
|
||||
self.run_command('write_salt_version')
|
||||
|
||||
if getattr(self.distribution, 'running_salt_install', False):
|
||||
|
@ -908,6 +926,8 @@ class SaltDistribution(distutils.dist.Distribution):
|
|||
'install_lib': InstallLib})
|
||||
if IS_WINDOWS_PLATFORM:
|
||||
self.cmdclass.update({'download-windows-dlls': DownloadWindowsDlls})
|
||||
if HAS_BDIST_WHEEL:
|
||||
self.cmdclass["bdist_wheel"] = BDistWheel
|
||||
|
||||
self.license = 'Apache Software License 2.0'
|
||||
self.packages = self.discover_packages()
|
||||
|
|
1
tests/integration/setup/__init__.py
Normal file
1
tests/integration/setup/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# -*- coding: utf-8 -*-
|
48
tests/integration/setup/test_bdist.py
Normal file
48
tests/integration/setup/test_bdist.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
tests.integration.setup.test_bdist
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, print_function, unicode_literals
|
||||
import os
|
||||
import re
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
from tests.support.unit import skipIf
|
||||
from tests.support.helpers import skip_if_not_root, VirtualEnv
|
||||
from tests.support.case import ModuleCase
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.path
|
||||
import salt.utils.platform
|
||||
from salt.modules.virtualenv_mod import KNOWN_BINARY_NAMES
|
||||
|
||||
|
||||
@skip_if_not_root
|
||||
@skipIf(salt.utils.path.which_bin(KNOWN_BINARY_NAMES) is None, 'virtualenv not installed')
|
||||
class BdistSetupTest(ModuleCase):
|
||||
'''
|
||||
Tests for building and installing bdist_wheel packages
|
||||
'''
|
||||
def test_wheel_build(self):
|
||||
'''
|
||||
test building a bdist_wheel package
|
||||
'''
|
||||
# Let's create the testing virtualenv
|
||||
with VirtualEnv() as venv:
|
||||
ret = self.run_function('cmd.run', ['{0} setup.py bdist_wheel --dist-dir={1}'.format(venv.venv_python, venv.venv_dir)], cwd=RUNTIME_VARS.CODE_DIR)
|
||||
|
||||
for _file in os.listdir(venv.venv_dir):
|
||||
if _file.endswith('whl'):
|
||||
whl = os.path.join(venv.venv_dir, _file)
|
||||
break
|
||||
|
||||
ret = self.run_function('pip.install', pkgs=whl, bin_env=venv.venv_dir)
|
||||
|
||||
# Let's ensure the version is correct
|
||||
pip_ver = self.run_function('pip.list', bin_env=venv.venv_dir).get('salt')
|
||||
whl_ver = [x for x in whl.split('/')[-1:][0].split('-') if re.search(r'^\d.\d*', x)][0]
|
||||
assert pip_ver == whl_ver.replace('_', '-')
|
|
@ -143,6 +143,9 @@ TEST_SUITES_UNORDERED = {
|
|||
'returners':
|
||||
{'display_name': 'Returners',
|
||||
'path': 'integration/returners'},
|
||||
'setup':
|
||||
{'display_name': 'Setup',
|
||||
'path': 'integration/setup'},
|
||||
'ssh-int':
|
||||
{'display_name': 'SSH Integration',
|
||||
'path': 'integration/ssh'},
|
||||
|
@ -399,6 +402,13 @@ class SaltTestsuiteParser(SaltCoverageTestingParser):
|
|||
action='store_true',
|
||||
help='Run spm integration tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'--setup',
|
||||
dest='setup',
|
||||
default=False,
|
||||
action='store_true',
|
||||
help='Run setup integration tests'
|
||||
)
|
||||
self.test_selection_group.add_option(
|
||||
'-l',
|
||||
'--loader',
|
||||
|
|
|
@ -159,6 +159,7 @@ class BadTestModuleNamesTestCase(TestCase):
|
|||
'integration.scheduler.test_maxrunning',
|
||||
'integration.scheduler.test_helpers',
|
||||
'integration.scheduler.test_run_job',
|
||||
'integration.setup.test_bdist',
|
||||
'integration.shell.test_spm',
|
||||
'integration.shell.test_cp',
|
||||
'integration.shell.test_syndic',
|
||||
|
|
|
@ -42,7 +42,8 @@ class VersionTestCase(TestCase):
|
|||
('v4518.1', (4518, 1, '', 0, 0, None), '4518.1'),
|
||||
('v3000rc1', (3000, 'rc', 1, 0, None), '3000rc1'),
|
||||
('v3000rc1-n/a-abcdefff', (3000, 'rc', 1, -1, 'abcdefff'), None),
|
||||
('3000-n/a-1e7bc8f', (3000, '', 0, -1, '1e7bc8f'), None)
|
||||
('3000-n/a-1e7bc8f', (3000, '', 0, -1, '1e7bc8f'), None),
|
||||
('3000.1-n/a-1e7bc8f', (3000, 1, '', 0, -1, '1e7bc8f'), None),
|
||||
|
||||
)
|
||||
|
||||
|
@ -221,6 +222,25 @@ class VersionTestCase(TestCase):
|
|||
assert saltstack_version.full_info, full_info
|
||||
assert len(saltstack_version.full_info) == len(full_info)
|
||||
|
||||
def test_full_info_all_versions(self):
|
||||
'''
|
||||
Test full_info_all_versions property method
|
||||
'''
|
||||
expect = (
|
||||
('v2014.1.4.1rc3-n/a-abcdefff', (2014, 1, 4, 1, 'rc', 3, -1, 'abcdefff')),
|
||||
('v3.4.1.1', (3, 4, 1, 1, '', 0, 0, None)),
|
||||
('v3000', (3000, None, None, 0, '', 0, 0, None)),
|
||||
('v3000.0', (3000, 0, None, 0, '', 0, 0, None)),
|
||||
('v4518.1', (4518, 1, None, 0, '', 0, 0, None)),
|
||||
('v3000rc1', (3000, None, None, 0, 'rc', 2, 0, None)),
|
||||
('v3000rc1-n/a-abcdefff', (3000, None, None, 0, 'rc', 1, -1, 'abcdefff')),
|
||||
)
|
||||
|
||||
for vstr, full_info in expect:
|
||||
saltstack_version = SaltStackVersion.parse(vstr)
|
||||
assert saltstack_version.full_info_all_versions, full_info
|
||||
assert len(saltstack_version.full_info_all_versions) == len(full_info)
|
||||
|
||||
def test_discover_version(self):
|
||||
'''
|
||||
Test call to __discover_version
|
||||
|
@ -275,3 +295,27 @@ class VersionTestCase(TestCase):
|
|||
assert ver.info == (maj_ver, min_ver, 0, 0)
|
||||
else:
|
||||
assert ver.info == (maj_ver, min_ver, bug_fix, 0)
|
||||
|
||||
def test_bugfix_string(self):
|
||||
'''
|
||||
test when bugfix is an empty string
|
||||
'''
|
||||
ret = SaltStackVersion(3000, 1, '', 0, 0, None)
|
||||
assert ret.info == (3000, 1)
|
||||
assert ret.minor == 1
|
||||
assert ret.bugfix is None
|
||||
|
||||
def test_version_repr(self):
|
||||
'''
|
||||
Test SaltStackVersion repr for both date
|
||||
and new versioning scheme
|
||||
'''
|
||||
expect = (
|
||||
((3000, 1, None, None, '', 0, 0, None), "<SaltStackVersion name='Neon' major=3000 minor=1>"),
|
||||
((3000, 0, None, None, '', 0, 0, None), "<SaltStackVersion name='Neon' major=3000>"),
|
||||
((2019, 2, 3, None, '', 0, 0, None), "<SaltStackVersion name='Fluorine' major=2019 minor=2 bugfix=3>"),
|
||||
((2019, 2, 3, None, 'rc', 1, 0, None), "<SaltStackVersion name='Fluorine' major=2019 minor=2 bugfix=3 rc=1>")
|
||||
)
|
||||
|
||||
for ver, repr_ret in expect:
|
||||
assert repr(SaltStackVersion(*ver)) == repr_ret
|
||||
|
|
Loading…
Add table
Reference in a new issue