from semver import VersionInfo __version__ = VersionInfo( major=1, minor=1, patch=1, )
def run(self, **kwargs): version = VersionInfo.parse(self.version) self.version = str( VersionInfo(major=version.major, minor=version.minor, patch=version.patch, prerelease=version.prerelease)) if not (self.getData('mac') or self.getData('windows') or self.getData('unix')): return try: import PyInstaller.__main__ except: print('Installing PyInstaller...') os.system('pip3 install pyinstaller') import PyInstaller.__main__ mods = [] for x in self.data['resources']['modules']: mods.append('--hidden-import') mods.append(x) datafiles = [] for x in self.data['resources']['data_files']: for g in glob.glob(self.data['short_name'] + os.sep + x): datafiles.append('--add-data') datafiles.append(g + os.pathsep + "." + os.sep + os.sep.join( g.replace(self.data['short_name'] + os.sep, '').split(os.sep)[:-1])) typ = '--nowindowed' if self.getData('type') == 1 else '--noconsole' if sys.platform.startswith('dar') and 'icns' in self.data['resources']: ico = ["--icon", self.data['resources']['icns']] if sys.platform.startswith('win') and 'ico' in self.data['resources']: ico = ["--icon", self.data['resources']['ico']] else: ico = [] osname = "macos" if sys.platform.startswith('darwin') else sys.platform options = [ self.data['short_name'] + os.sep + '__main__.py', '--onefile', '--name', self.data['short_name'] + '-' + self.version + '-' + osname, '--distpath', '.' + os.sep + 'dist' + os.sep + 'pyinstaller', *(self.getData('options') if 'options' in self.data2 else []), *mods, *datafiles, typ, *ico, '--osx-bundle-identifier', self.getData('bundle_id') ] print(options) PyInstaller.__main__.run(options) print('removing *.spec files') for specfile in glob.glob('*.spec'): os.remove(specfile) # MAC APP BUNDLE============== for appbundle in glob.glob('dist/pyinstaller/*.app'): print(appbundle) shutil.rmtree( appbundle) # We don't want the .app file PyInstaller made! print( '\n\n\u001b[4m\u001b[1;36mGenerating Mac .app bundle...\u001b[0m') if self.getData('mac') and sys.platform.startswith('dar'): os.chdir('dist') os.mkdir(self.data['name']) os.chdir(self.data['name']) os.mkdir('Contents') os.chdir('Contents') os.mkdir('MacOS') os.mkdir('Resources') infoPlist = open('Info.plist', 'w+') infoPlist.write( self.getResource('resources' + os.sep + 'info.plist.xml').read( ).format(**self.data, execname=self.data['name'].replace('_', ''), **self.data['build'], version=self.version, bundle_id=self.getData('bundle_id'))) infoPlist.close() os.rename( './../../pyinstaller/' + self.data["short_name"] + "-" + self.version + "-macos", 'MacOS/' + self.data['name'].replace('_', '')) if self.getData('type') == 1: os.rename('MacOS/' + self.data['name'].replace('_', ''), 'MacOS/main') with open('MacOS/' + self.data['name'].replace('_', ''), 'w+') as f: f.write( f'#!/bin/bash\n' 'DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"\n' 'open -a Terminal ${DIR}/main') # with open('MacOS/runner', 'w+') as f: # f.write(f'#!/bin/bash\n' # 'DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"\n' # '${DIR}/main') st = os.stat('MacOS/' + self.data['name'].replace('_', '')) os.chmod('MacOS/' + self.data['name'].replace('_', ''), st.st_mode | stat.S_IEXEC) if "icns" in self.data['resources'] and os.path.isfile( "./../../../" + self.data['resources']["icns"]): shutil.copy('./../../../' + self.data['resources']["icns"], 'Resources/icon.icns') os.chdir('./../../..') os.rename('./dist/' + self.data['name'], './dist/pyinstaller/' + self.data['name'] + ".app") else: print( 'not generating mac .app bundle because on {} not mac.'.format( sys.platform)) # ============== Generate Installer Package =============================================== print( '\n\n\u001b[4m\u001b[1;36mGenerating Installer Package...\u001b[0m' ) if not (self.getData('windows') or self.getData('unix') or self.getData('mac')): pass elif sys.platform.startswith('darwin'): # MAC try: import dmgbuild except ModuleNotFoundError: print('Installing dmgbuild') os.system('pip3 install dmgbuild') import dmgbuild del dmgbuild if not os.path.isdir('build'): os.mkdir('build') open('build' + os.sep + 'settings.py', 'w+').write( self.getResource('resources' + os.sep + 'settings.py.template').read(). format(**self.data, version=self.version, icns="" if not "icns" in self.data['resources'] else self.data['resources']['icns'], keywo=", ".join(self.data['keywords']), ddimage=self.prefix + 'resources' + os.sep + 'dragdrop.png')) os.system( f'dmgbuild -s .{os.sep}build{os.sep}settings.py "{self.data["name"]} Installer" ./dist/pyinstaller/{self.data["short_name"] + "-" + self.version + "-macos"}.dmg' ) else: print(f'Installer creation not yet supported for {sys.platform}!')
def test_oci(sandbox): # pylint: disable=redefined-outer-name image = sandbox container_id = RobotNamer().generate() # A non existing process should not have a state print("...Case 1. Check status of non-existing bundle.") state = Client.oci.state("mycontainer") assert state is None # This will use sudo print("...Case 2: Create OCI image from bundle") result = Client.oci.create(bundle=image, container_id=container_id) print(result) assert result["status"] == "created" print("...Case 3. Execute command to non running bundle.") result = Client.oci.execute( container_id=container_id, sudo=True, command=["ls", "/"] ) print(result) print(Client.version_info()) if Client.version_info() >= VersionInfo(3, 2, 0, "1"): assert result["return_code"] == 255 else: assert "bin" in result print("...Case 4. Start container return value 0.") state = Client.oci.start(container_id, sudo=True) assert state == 0 print("...Case 5. Execute command to running bundle.") result = Client.oci.execute( container_id=container_id, sudo=True, command=["ls", "/"] ) print(result) assert "bin" in result print("...Case 6. Check status of existing bundle.") state = Client.oci.state(container_id, sudo=True) assert state["status"] == "running" print("...Case 7. Pause running container return value 0.") state = Client.oci.pause(container_id, sudo=True) assert state == 0 # State was still reported as running if Client.version_info() >= VersionInfo(3, 2, 0, "1"): print("...check status of paused bundle.") state = Client.oci.state(container_id, sudo=True) assert state["status"] == "paused" print("...Case 8. Resume paused container return value 0.") state = Client.oci.resume(container_id, sudo=True) assert state == 0 print("...check status of resumed bundle.") state = Client.oci.state(container_id, sudo=True) assert state["status"] == "running" print("...Case 9. Kill container.") state = Client.oci.kill(container_id, sudo=True) assert state == 0 # Clean up the image (should still use sudo) # Bug in singularity that kill doesn't kill completely - this returns # 255. When testsupdated to 3.1.* add signal=K to run result = Client.oci.delete(container_id, sudo=True) assert result in [0, 255]
def createSandbox(sandbox, srcWorkspace=None, forceCreate=False, mcsMode=None): ''' Set up a run-time sandbox in which to run GCAM. This involves copying from or linking to files and directories in `workspace`, which defaults to the value of config parameter GCAM.SandboxRefWorkspace. :param sandbox: (str) the directory to create :param srcWorkspace: (str) the workspace to link to or copy from :param forceCreate: (bool) if True, delete and recreate the sandbox :param mcsMode: ('gensim', 'trial', or None) perform setup appropriate for pygcam-mcs trials. :return: none ''' from semver import VersionInfo if not srcWorkspace: srcWorkspace = getParam('GCAM.RefWorkspace') if mcsMode == 'gensim' \ else getParam('GCAM.SandboxRefWorkspace') # MCS "new" sub-command creates its ref workspace; for non-MCS # we do it here, on demand, i.e., if it doesn't exist already. if not mcsMode: copyWorkspace(srcWorkspace) if mcsMode and getParamAsBoolean('GCAM.CopyAllFiles'): # Not prohibited; just a disk-hogging, suboptimal choice _logger.warn('GCAM.CopyAllFiles = True while running MCS') _logger.info("Setting up sandbox '%s'", sandbox) if os.path.lexists(sandbox) and os.path.samefile(sandbox, srcWorkspace): raise SetupException( "The run sandbox is the same as the run workspace; no setup performed" ) if forceCreate: # avoid deleting the current directory with pushd('..'): removeTreeSafely(sandbox, ignore_errors=True) mkdirs(sandbox) # also makes sandbox and sandbox/exe logPath = pathjoin(sandbox, 'exe', 'logs') mkdirs(logPath) # Need to mkdir("exe/restart") for gcam-v5.1.2 (and beyond?) if parse_version_info() >= VersionInfo(5, 1, 2): restartDir = pathjoin(sandbox, 'exe', 'restart') mkdirs(restartDir) filesToCopy, filesToLink = _getFilesToCopyAndLink( 'GCAM.SandboxFilesToLink') for filename in filesToCopy: _workspaceLinkOrCopy(filename, srcWorkspace, sandbox, copyFiles=True) for filename in filesToLink: _workspaceLinkOrCopy(filename, srcWorkspace, sandbox, copyFiles=False) outputDir = pathjoin(sandbox, 'output') if mcsMode: from .mcs.util import createOutputDir # link {sandbox}/dyn-xml to ../dyn-xml dynXmlDir = pathjoin('..', DYN_XML_NAME) dynXmlAbsPath = pathjoin(os.path.dirname(sandbox), DYN_XML_NAME) mkdirs(dynXmlAbsPath) createOutputDir(outputDir) # deals with link and tmp dir... else: # link {sandbox}/dyn-xml to {refWorkspace}/dyn-xml dynXmlDir = pathjoin(srcWorkspace, DYN_XML_NAME) # Create a local output dir mkdirs(outputDir) dynXmlLink = pathjoin(sandbox, DYN_XML_NAME) _remakeSymLink(dynXmlDir, dynXmlLink) # static xml files are always linked to reference workspace localXmlDir = pathjoin(srcWorkspace, LOCAL_XML_NAME) localXmlLink = pathjoin(sandbox, LOCAL_XML_NAME) _remakeSymLink(localXmlDir, localXmlLink)
def test_should_be_able_to_use_integers_as_prerelease_build(): v = VersionInfo(1, 2, 3, 4, 5) assert isinstance(v.prerelease, str) assert isinstance(v.build, str) assert VersionInfo(1, 2, 3, 4, 5) == VersionInfo(1, 2, 3, '4', '5')
def test_check_get_singularity_version_info(): """Check that the version_info is correct""" from spython.utils import get_singularity_version_info with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "2.3.1"): version = get_singularity_version_info() assert version == VersionInfo(2, 3, 1) assert version > VersionInfo(2, 3, 0) assert version < VersionInfo(3, 0, 0) with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "singularity version 3.2.1-1"): version = get_singularity_version_info() assert version == VersionInfo(3, 2, 1, "1") assert version > VersionInfo(2, 0, 0) assert version < VersionInfo(3, 3, 0) assert version > VersionInfo(3, 2, 0) assert version < VersionInfo(3, 2, 1) with ScopedEnvVar("SPYTHON_SINGULARITY_VERSION", "2.6.1-pull/124.1d068a7"): version = get_singularity_version_info() assert version == VersionInfo(2, 6, 1, "pull", "124.1d068a7") assert version > VersionInfo(2, 6, 0) assert version < VersionInfo(2, 7, 0)
# (C) Datadog, Inc. 2019-present # All rights reserved # Licensed under Simplified BSD License (see LICENSE) import re import psycopg2 import semver from semver import VersionInfo V8_3 = VersionInfo(**semver.parse("8.3.0")) V9 = VersionInfo(**semver.parse("9.0.0")) V9_1 = VersionInfo(**semver.parse("9.1.0")) V9_2 = VersionInfo(**semver.parse("9.2.0")) V9_4 = VersionInfo(**semver.parse("9.4.0")) V9_6 = VersionInfo(**semver.parse("9.6.0")) V10 = VersionInfo(**semver.parse("10.0.0")) def get_raw_version(db): cursor = db.cursor() cursor.execute('SHOW SERVER_VERSION;') raw_version = cursor.fetchone()[0] return raw_version def is_aurora(db): cursor = db.cursor() try: cursor.execute('select AURORA_VERSION();') return True except psycopg2.errors.UndefinedFunction:
def version(): return VersionInfo(major=1, minor=2, patch=3, prerelease='alpha.1.2', build='build.11.e0f985a')
("1.0.0-rc.1", "patch", "1.0.0"), # same as "major" ("1.0.0-rc.1", "minor", "1.0.0"), # same as "major" ], ) def test_next_version_with_versioninfo(version, part, expected): ver = VersionInfo.parse(version) next_version = ver.next_version(part) assert isinstance(next_version, VersionInfo) assert str(next_version) == expected @pytest.mark.parametrize( "version, expected", [ ( VersionInfo(major=1, minor=2, patch=3, prerelease=None, build=None), "VersionInfo(major=1, minor=2, patch=3, prerelease=None, build=None)", ), ( VersionInfo( major=1, minor=2, patch=3, prerelease="r.1", build=None), "VersionInfo(major=1, minor=2, patch=3, prerelease='r.1', build=None)", ), ( VersionInfo( major=1, minor=2, patch=3, prerelease="dev.1", build=None), "VersionInfo(major=1, minor=2, patch=3, prerelease='dev.1', build=None)", ), ( VersionInfo( major=1, minor=2, patch=3, prerelease="dev.1", build="b.1"),
def version(): return VersionInfo(major=1, minor=2, patch=3, prerelease="alpha.1.2", build="build.11.e0f985a")
# Copyright 2020 Cole Wilson and other contributors # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. import sys from semver import VersionInfo try: rl = VersionInfo(sys.argv[1].split('/')[-1]).prerelease.replace('v','') != None except: rl = False # Prerelease checker given GitHub tag. if "dev" in sys.argv[1]: print('prerel=true') if "rc" in sys.argv[1]: print('prerel=true') elif "beta" in sys.argv[1]: print('prerel=true') elif "alpha" in sys.argv[1]: print('prerel=true') elif "test" in sys.argv[1]: print('prerel=true') elif rl: print('prerel=true') else: print('prerel=false')
import pytest from semver import VersionInfo from cachemachine.rubintag import RubinPartialTag, RubinTagType TAGSTR_TO_TAGOBJ = [ ( "r21_0_1", RubinPartialTag( tag="r21_0_1", image_type=RubinTagType.RELEASE, display_name="Release r21.0.1", semantic_version=VersionInfo(major=21, minor=0, patch=1, prerelease=None, build=None), cycle=None, ), ), ( "r22_0_0_rc1", RubinPartialTag( tag="r22_0_0_rc1", image_type=RubinTagType.RELEASE_CANDIDATE, display_name="Release Candidate r22.0.0-rc1", semantic_version=VersionInfo(major=22, minor=0, patch=0, prerelease="rc1", build=None),
import utilities from srctools import Property from srctools.logger import get_logger logger = get_logger() overwriteDict: dict = {} configPath: Path = Path( './config.cfg' if utilities.frozen() else './../config.cfg') assetsPath: str = './assets/' if utilities.frozen() else './../assets/' """ The path to the assets folder (finishes with /) """ tmpFolderPath: str = './tmp/' if utilities.frozen() else './../tmp/' """ The path to the tmp folder (finishes with /) """ pluginsPath: str = './plugins' if utilities.frozen() else './../plugins' version: VersionInfo = VersionInfo(major=1, minor=0, patch=0, prerelease='pre2', build='beta4') """current app version""" default_config = { 'config_type': 'BEE2.4 Manipulator Config File', 'usePrereleases': False if utilities.frozen() else True, 'steamDir': None, 'portal2Dir': None, 'beePath': utilities.__getbee(), 'beeVersion': None, 'logWindowVisibility': False, 'logLevel': 'info', 'l18nFolderPath': './langs' if utilities.frozen() else './../langs', 'databasePath': './assets/database.json'
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. # SPDX-License-Identifier: Apache-2.0 from unittest import TestCase from semver import VersionInfo from dazl.damlsdk.artifacts import load_artifacts, get_artifact_url, ArtifactLocation ZERO_VERSION = VersionInfo(0, 0, 0) DUMMY_ARTIFACT = ArtifactLocation('com.something', 'somewhere', ZERO_VERSION) DUMMY_NATIVE_ARTIFACT = ArtifactLocation('com.something', 'somewhere', ZERO_VERSION, native=True) DUMMY_TAR_GZ_ARTIFACT = ArtifactLocation('com.something', 'somewhere', ZERO_VERSION, 'tar.gz') DUMMY_NATIVE_TAR_GZ_ARTIFACT = ArtifactLocation('com.something', 'somewhere', ZERO_VERSION, 'tar.gz', native=True) class TestArtifacts(TestCase): def test_artifacts_yaml_can_parse(self): """ Verify that the artifacts manifest is syntactically correct. """ load_artifacts() def test_artifacts_yaml_are_valid(self): """ Verify that all artifacts resolve to correct URLs. """ repository = load_artifacts() for platform in ('osx', 'linux'): for name, artifact in repository.artifacts.items():
def createProtected(tree, fraction, landClasses=None, otherArable=False, regions=None, unprotectFirst=False): """ Modify an lxml tree representing a GCAM input file to protect a `fraction` of `landClasses` in `regions`. :param tree: a tree representing a parsed GCAM land_input XML file :param fraction: the fraction of land in the given land classes to protect :param landClasses: a string or a list of strings, or None. If None, all standard unmanaged land classes are modified. :param otherArable: (bool) if True, land class 'OtherArableLand' is included in default land classes. :param regions: a string or a list of strings, or None. If None, all regions are modified. :param unprotectFirst: (bool) if True, make all land "unprotected" before protecting. :return: None """ version = parse_version_info() if version >= VersionInfo(5, 0, 0): raise PygcamException( "Called landProtection.createProtected on GCAM version >= 5.0. Use landProtectionUpdate.protectLand instead." ) _logger.debug( 'createProtected: fraction=%.2f, landClasses=%s, regions=%s, unprotect=%s', fraction, landClasses, regions, unprotectFirst) def multiplyValues(nodes, factor): for n in nodes: newValue = float(n.text) * factor n.text = str(newValue) # Remove any existing land protection, if so requested if unprotectFirst: unProtectLand(tree, landClasses=landClasses, otherArable=otherArable, regions=regions) regionXpath = (_makeRegionXpath(regions) if regions else '') + '//LandAllocatorRoot' landRoots = tree.xpath(regionXpath) if not landClasses: landClasses = UnmanagedLandClasses + (['OtherArableLand'] if otherArable else []) unmgdXpath = _makeLandClassXpath(landClasses) protectedXpath = _makeLandClassXpath(landClasses, protected=True) allocXpath = ".//allocation|.//landAllocation" for landRoot in landRoots: # ensure that we're not protecting an already-protected land class in these regions nodes = landRoot.xpath(protectedXpath) if len(nodes) > 0: node = nodes[0] regNodes = list(node.iterancestors(tag='region')) region = regNodes[0].get('name') raise FileFormatError( 'Error: Land class %s is already protected in region %s' % (node.tag, region)) nodes = landRoot.xpath(unmgdXpath) for node in nodes: landnode = ET.SubElement(landRoot, 'LandNode') new = copy.deepcopy(node) newName = 'Protected' + node.get('name') new.set('name', newName) landnode.set('name', newName) landnode.set('fraction', "%.4f" % fraction) landnode.append(new) originalAreas = node.xpath(allocXpath) protectedAreas = new.xpath(allocXpath) multiplyValues(originalAreas, 1 - fraction) multiplyValues(protectedAreas, fraction)
import wx import wx.py.dispatcher as dispatcher from semver import VersionInfo from pluginSystem import Plugin, Events, RegisterHandler as RegisterHandlerType @Plugin(name='MenuBar Menu Example', version=VersionInfo(1, 0, 0) ) class MenuExample: exampleMenu: wx.Menu async def load(self): # create a menu object self.exampleMenu = wx.Menu() # add an item to it, and save it exampleItem = self.exampleMenu.Append(18, 'Example Item', 'This is the example item description') # bind the press of that item to a function self.exampleMenu.Bind(wx.EVT_MENU, self.pressed, exampleItem) # listen for the RegisterMenus event with the registerMenu method as callback dispatcher.connect( self.registerHandler, Events.RegisterEvent ) def pressed(self, evt: wx.CommandEvent): wx.GenericMessageDialog( parent=wx.GetTopLevelWindows()[0], caption='Pressed!', message='The example item was pressed!' ).ShowModal()
def run(self, plugins={}, **kwargs): self.data['release-notes'] = input('Release Notes: ') version = VersionInfo.parse(self.data['latest_build']) version = str( VersionInfo(major=version.major, minor=version.minor, patch=version.patch, prerelease=version.prerelease)) runs = {} if self.options == []: for x in self.data['release']: if x in plugins['release']: runs[x] = plugins['release'][x]['order'] for x in self.data['build']: if x in plugins['build']: if plugins['build'][x]['release']: runs[x] = plugins['build'][x]['order'] for x in self.data: if x in plugins['core']: if plugins['core'][x]['release']: runs[x] = plugins['core'][x]['order'] else: for x in self.options: if x in self.data['release'] and x in plugins['release']: runs[x] = plugins['release'][x]['order'] elif x in self.data['build']: if plugins['build'][x]['release']: runs[x] = plugins['build'][x]['order'] elif x in self.data: if plugins['core'][x]['release']: runs[x] = plugins['core'][x]['order'] else: print('sailboat: error: {} is not a valid release plugin.'. format(x)) return runstemp = [] for x in runs: runstemp.append(f"{runs[x]}::{x}") runstemp.sort() runs = [] for x in runstemp: order, name = x.split('::') runs.append(name) input( f'Press enter to release version {version} the following ways:\n\t- ' + '\n\t- '.join(runs) + '\n\n>>>') dones = [] lorder = 0 for release_plugin in runs: if release_plugin in dones: continue print(self.section(release_plugin + ":")) if release_plugin in self.data['release']: dist = plugins['release'][release_plugin]['dist'] elif release_plugin in self.data['build']: dist = plugins['build'][release_plugin]['dist'] else: dist = plugins['core'][release_plugin]['dist'] temp = pkg_resources.load_entry_point(dist, 'sailboat_plugins', release_plugin) temp = temp(data=self.data, options=[self.options], name=release_plugin, prefix=self.prefix, version=version) temp.release() if temp._type == 'core': self.dat = temp.data else: self.data[temp._type][release_plugin] = temp.data[ temp._type][release_plugin] dones.append(release_plugin) lorder = order print() self.data['latest_release'] = version
def test_should_compare_prerelease_and_build_with_numbers(): assert VersionInfo(major=1, minor=9, patch=1, prerelease=1, build=1) < \ VersionInfo(major=1, minor=9, patch=1, prerelease=2, build=1) assert VersionInfo(1, 9, 1, 1, 1) < VersionInfo(1, 9, 1, 2, 1) assert VersionInfo('2') < VersionInfo(10) assert VersionInfo('2') < VersionInfo('10')
manifest = configparser.ConfigParser() manifest.read(bundle_path / "manifest.raucm") bundle_version = manifest["update"]["version"] # Obtain system version system_version = distro.version() print( f"Checking update: {system_version} -> {bundle_version}, admin: {admin}, downgrade bundle: {downgrade_enabled}" ) try: system_semver = VersionInfo.parse(system_version) except ValueError: print("System version invalid. Using 0.0.0 instead") system_semver = VersionInfo(0, 0, 0) try: bundle_semver = VersionInfo.parse(bundle_version) except ValueError: print("Bundle version invalid. Using 0.0.0 instead") bundle_semver = VersionInfo(0, 0, 0) if bundle_semver == system_semver and not admin: print("Same version install not allowed !!!") exit(2) if bundle_semver < system_semver and not admin and not downgrade_enabled: print("Downgrades not allowed") exit(1)
def test_should_compare_prerelease_with_numbers_and_letters(): v1 = VersionInfo(major=1, minor=9, patch=1, prerelease='1unms', build=None) v2 = VersionInfo(major=1, minor=9, patch=1, prerelease=None, build='1asd') assert v1 < v2 assert compare("1.9.1-1unms", "1.9.1+1") == -1
def update_skip_according_to_db(data): if type(data['tests']) is list: return def kernel_match(kernel1, kernel2): if kernel1 in custom_kernels: kernel1 = custom_kernels[kernel1] # regex issue with strings like "3.10-100+$" so use string compare for exact match. if (kernel1.strip('()') == kernel2 or re.search("^%s$" % kernel1, kernel2)): return True return False rm = MlxRedmine() nic = get_config_value('NIC') current_fw_ver = get_current_fw(nic) current_nic = DeviceType.get(get_current_nic_type(nic)) if args.test_kernel: current_kernel = args.test_kernel else: current_kernel = os.uname()[2] flow_steering_mode = get_flow_steering_mode(nic) simx_mode = check_simx(nic) custom_kernels = data.get('custom_kernels', {}) print("nic: %s" % current_nic) print("fw: %s" % current_fw_ver) print("flow steering: %s" % flow_steering_mode) print("kernel: %s" % current_kernel) if simx_mode: print("simx mode") for t in TESTS: name = t.name if data['tests'][name] is None: data['tests'][name] = {} ignore_for_linust = data['tests'][name].get('ignore_for_linust', 0) ignore_for_upstream = data['tests'][name].get('ignore_for_upstream', 0) simx_ignore = data['tests'][name].get('simx_ignore', 0) if ignore_for_linust and ignore_for_upstream: raise RuntimeError("%s: Do not ignore on both for_linust and for_upstream." % name) if ignore_for_linust and 'linust' in current_kernel: t.set_ignore("Ignore on for-linust kernel") continue if ignore_for_upstream and 'upstream' in current_kernel: t.set_ignore("Ignore on for-upstream kernel") continue ignore_fs = data['tests'][name].get('ignore_flow_steering', '') if ignore_fs and (not flow_steering_mode or ignore_fs == flow_steering_mode): t.set_ignore("Ignore flow steering mode %s" % ignore_fs) continue if simx_mode and simx_ignore: t.set_ignore("Ignore for SimX mode with reason %s" % simx_ignore) continue ignore_not_supported = data['tests'][name].get('ignore_not_supported', 0) if ignore_not_supported is True: t.set_ignore("Not supported") continue elif type(ignore_not_supported) == list: for kernel in ignore_not_supported: if kernel_match(kernel, current_kernel): t.set_ignore("Not supported") break if t.ignore: continue if 'el' in current_kernel: min_kernel = data['tests'][name].get('min_kernel_rhel', None) else: min_kernel = data['tests'][name].get('min_kernel', None) kernels = data['tests'][name].get('kernels', []) if kernels and not min_kernel: raise RuntimeError("%s: Specifying kernels without min_kernel is not allowed." % name) if min_kernel: kernels += custom_kernels.values() ok = False for kernel in kernels: if kernel_match(kernel, current_kernel): ok = True break if not ok: a = VersionInfo(min_kernel) b = VersionInfo(current_kernel) if b < a: t.set_ignore("Unsupported kernel version. Minimum %s" % min_kernel) continue for nic in data['tests'][name].get('ignore_nic', []): if nic == current_nic: t.set_ignore("Unsupported nic %s" % nic) break if t.ignore: continue bugs_list = [] # issue number key with list of kernels issue_keys = [x for x in data['tests'][name].keys() if isinstance(x, int)] for issue in issue_keys: for kernel in data['tests'][name][issue]: if kernel_match(kernel, current_kernel): bugs_list.append(issue) ignore_kernel = data['tests'][name].get('ignore_kernel', {}) for kernel in ignore_kernel: if kernel_match(kernel, current_kernel): bugs_list += ignore_kernel[kernel] for fw in data['tests'][name].get('ignore_fw', {}): if not current_fw_ver or re.search("^%s$" % fw, current_fw_ver): bugs_list += data['tests'][name]['ignore_fw'][fw] ignore_smfs = data['tests'][name].get('ignore_smfs', []) if ignore_smfs and (not flow_steering_mode or flow_steering_mode == 'smfs'): for kernel in ignore_smfs: if kernel_match(kernel, current_kernel): bugs_list.extend(ignore_smfs[kernel]) if simx_mode: simx_ignore_issues = data['tests'][name].get('simx_ignore_issue', []) bugs_list.extend(simx_ignore_issues) for bug in bugs_list: try: task = rm.get_issue(bug) t.issues.append(task) except ValueError: t.set_skip("Cannot fetch RM #%s" % bug) continue if rm.is_issue_wont_fix_or_release_notes(task): WONT_FIX[name] = "%s RM #%s: %s" % (task['status']['name'], bug, task['subject']) if rm.is_issue_open(task): t.set_skip("RM #%s: %s" % (bug, task['subject'])) break sys.stdout.write('.') sys.stdout.flush() print()
# This Source Code Form is subject to the terms of the # Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed # with this file, You can obtain one at http://mozilla.org/MPL/2.0/. from spython.utils import get_installdir from spython.main.base.generate import RobotNamer from spython.main import Client import shutil import os import pytest from semver import VersionInfo pytestmark = pytest.mark.skipif( Client.version_info() < VersionInfo(3, 0, 0), reason="OCI command group introduced in singularity 3", ) @pytest.fixture def sandbox(tmp_path): image = Client.build( "docker://busybox:1.30.1", image=str(tmp_path / "sandbox"), sandbox=True, sudo=False, ) assert os.path.exists(image)
def runGCAM(scenario, workspace=None, refWorkspace=None, scenariosDir=None, groupDir='', configFile=None, forceCreate=False, noRun=False, noWrapper=False): """ :param scenario: (str) the scenario to run :param workspace: (str) path to the workspace to run in, or None, in which case the model is run in {GCAM.SandboxDir}/{scenario} if scenario is given otherwise, the default scenario in the configuration.xml in the GCAM.RefWorkspace is run. :param refWorkspace: (str) a workspace to copy files from to create the sandbox, if the workspace is not given, or doesn't exist. :param scenariosDir: (str) the directory in which the config.xml file for the given scenario is found. Defaults to GCAM.ScenariosDir, if given, or "." :param groupDir: (str) the name of the scenario group if group sub-directories are to be used when computing the location of the scenario's config.xml. :param configFile: (str) if scenario is not given, the name of a configuration file to run. If scenario is given, this parameter is ignored. :param forceCreate: (bool) if True, recreate the sandbox even if it already exists. :param noRun: (bool) if True, don't run the model, just create the sandbox and display the command that would be executed. :param noWrapper: (bool) if True, don't run GCAM inside a "wrapper" that reads output and kills the model run as soon as an error is detected. :return: none :raises ProgramExecutionError: if GCAM exits with non-zero status """ import platform if platform.system() == 'Darwin': linkToMacJava() workspace = workspace or (pathjoin(getParam('GCAM.SandboxDir'), scenario) if scenario else getParam('GCAM.RefWorkspace')) if not os.path.lexists(workspace) or forceCreate: createSandbox(workspace, srcWorkspace=refWorkspace, forceCreate=forceCreate) exeDir = getExeDir(workspace, chdir=True) setJavaPath(exeDir) # required for Windows; a no-op otherwise version = parse_version_info() # These features didn't exist in version 4.2 if version > VersionInfo( 4, 2, 0) and not (getParamAsBoolean('GCAM.RunQueriesInGCAM') or getParamAsBoolean('GCAM.InMemoryDatabase') ): # this implies RunQueriesInGCAM # Write a "no-op" XMLDBDriver.properties file writeXmldbDriverProperties(inMemory=False, outputDir=exeDir) if scenario: # Translate scenario name into config file path, assuming that for scenario # FOO, the configuration file is {scenariosDir}/{groupDir}/FOO/config.xml scenariosDir = unixPath(scenariosDir or getParam('GCAM.ScenariosDir') or '.', abspath=True) configFile = pathjoin(scenariosDir, groupDir, scenario, "config.xml") else: configFile = unixPath(configFile or pathjoin(exeDir, 'configuration.xml'), abspath=True) gcamPath = unixPath(getParam('GCAM.Executable'), abspath=True) gcamArgs = [ gcamPath, '-C%s' % configFile ] # N.B. GCAM (< 4.2) doesn't allow space between -C and filename command = ' '.join(gcamArgs) if noRun: print(command) else: _logger.info('Running: %s', command) noWrapper = IsWindows or noWrapper # never use the wrapper on Windows exitCode = subprocess.call( gcamArgs, shell=False) if noWrapper else _gcamWrapper(gcamArgs) if exitCode != 0: raise ProgramExecutionError(command, exitCode)
def test_parse_javac_non_semver_format_version(self): version_output = "javac 1.8.0_292\n" version = parse_javac_version_output(version_output) self.assertEqual(version, VersionInfo(8, 0, 0))
def test_should_not_allow_to_compare_invalid_versionstring(s): v = VersionInfo(major=3, minor=4, patch=5, prerelease="pre.2", build="build.4") with pytest.raises(ValueError): v < s with pytest.raises(ValueError): s > v