def _yes(): ''' Returns ['--yes'] if on v0.9.9.0 or later, otherwise returns an empty list ''' if 'chocolatey._yes' in __context__: return __context__['chocolatey._yes'] if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.9'): answer = ['--yes'] else: answer = [] __context__['chocolatey._yes'] = answer return answer
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' # TODO: Determine minimal version we want to support. VPC requires > 2.8.0. required_boto_version = '2.0.0' if not HAS_BOTO: return False elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): return False else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto3_version = '1.3.1' if not HAS_BOTO: return (False, 'The boto_rds module could not be loaded: ' 'boto libraries not found') elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version): return (False, 'The boto_rds module could not be loaded: ' 'boto version {0} or later must be installed.'.format(required_boto3_version)) else: return True
def install_missing(name, version=None, source=None): ''' Instructs Chocolatey to install a package if it doesn't already exist. .. versionchanged:: 2014.7.0 If the minion has Chocolatey >= 0.9.8.24 installed, this function calls :mod:`chocolatey.install <salt.modules.chocolatey.install>` instead, as ``installmissing`` is deprecated as of that version and will be removed in Chocolatey 1.0. name The name of the package to be installed. Only accepts a single argument. version Install a specific version of the package. Defaults to latest version available. source Chocolatey repository (directory, share or remote URL feed) the package comes from. Defaults to the official Chocolatey feed. CLI Example: .. code-block:: bash salt '*' chocolatey.install_missing <package name> salt '*' chocolatey.install_missing <package name> version=<package version> ''' choc_path = _find_chocolatey() if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.8.24'): log.warning('installmissing is deprecated, using install') return install(name, version=version) # chocolatey helpfully only supports a single package argument cmd = [choc_path, 'installmissing', name] if version: cmd.extend(['-Version', version]) if source: cmd.extend(['-Source', source]) # Shouldn't need this as this code should never run on v0.9.9 and newer cmd.extend(_yes()) result = __salt__['cmd.run_all'](cmd, python_shell=False) if result['retcode'] != 0: err = 'Running chocolatey failed: {0}'.format(result['stderr']) log.error(err) raise CommandExecutionError(err) return result['stdout']
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto3_version = '1.2.1' # the boto_lambda execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: return False elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version): return False else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.8.0' # the boto_ec2 execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: return False elif _LooseVersion( boto.__version__) < _LooseVersion(required_boto_version): return False else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto3_version = '1.3.1' if not HAS_BOTO: return (False, 'The boto_rds module could not be loaded: ' 'boto libraries not found') elif _LooseVersion( boto3.__version__) < _LooseVersion(required_boto3_version): return (False, 'The boto_rds module could not be loaded: ' 'boto version {0} or later must be installed.'.format( required_boto3_version)) else: return True
def test_roster_config_validate(self): try: jsonschema.validate( { 'target-1': { 'host': 'localhost', 'user': '******', 'passwd': 'foo' } }, ssh_schemas.RosterItem.serialize(), format_checker=jsonschema.FormatChecker()) except jsonschema.exceptions.ValidationError as exc: self.fail('ValidationError raised: {0}'.format(exc)) with self.assertRaises( jsonschema.exceptions.ValidationError) as excinfo: jsonschema.validate( { 'target-1:1': { 'host': 'localhost', 'user': '******', 'passwd': 'foo' } }, ssh_schemas.RosterItem.serialize(), format_checker=jsonschema.FormatChecker()) if JSONSCHEMA_VERSION < _LooseVersion('2.6.0'): self.assertIn( 'Additional properties are not allowed (\'target-1:1\' was unexpected)', excinfo.exception.message) else: self.assertIn('\'target-1:1\' does not match any of the regexes', excinfo.exception.message)
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.8.0' # the boto_ec2 execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: return False elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): return False else: __utils__['boto.assign_funcs'](__name__, 'ec2') return True
def install_missing(name, version=None, source=None): ''' Instructs Chocolatey to install a package if it doesn't already exist. .. versionchanged:: 2014.7.0 If the minion has Chocolatey >= 0.9.8.24 installed, this function calls :mod:`chocolatey.install <salt.modules.chocolatey.install>` instead, as ``installmissing`` is deprecated as of that version and will be removed in Chocolatey 1.0. name The name of the package to be installed. Only accepts a single argument. version Install a specific version of the package. Defaults to latest version available. source Chocolatey repository (directory, share or remote URL feed) the package comes from. Defaults to the official Chocolatey feed. CLI Example: .. code-block:: bash salt '*' chocolatey.install_missing <package name> salt '*' chocolatey.install_missing <package name> version=<package version> ''' choc_path = _find_chocolatey() if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.8.24'): log.warning('installmissing is deprecated, using install') return install(name, version=version) # chocolatey helpfully only supports a single package argument cmd = [choc_path, 'installmissing', name] if version: cmd.extend(['-Version', version]) if source: cmd.extend(['-Source', source]) result = __salt__['cmd.run_all'](cmd, python_shell=False) if result['retcode'] != 0: err = 'Running chocolatey failed: {0}'.format(result['stderr']) log.error(err) raise CommandExecutionError(err) return result['stdout']
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' # TODO: Determine minimal version we want to support. VPC requires > 2.8.0. required_boto_version = '2.0.0' if not HAS_BOTO: return False elif _LooseVersion( boto.__version__) < _LooseVersion(required_boto_version): return False else: global __salt__ if not __salt__: __salt__ = minion_mods(__opts__) return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.4.0' # Boto < 2.4.0 GroupOrCIDR objects have different attributes than # Boto >= 2.4.0 GroupOrCIDR objects # Differences include no group_id attribute in Boto < 2.4.0 and returning # a groupId attribute when a GroupOrCIDR object authorizes an IP range # Support for Boto < 2.4.0 can be added if needed if not HAS_BOTO: return False elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): return False else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto3_version = '1.2.1' # the boto_lambda execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: return (False, 'The boto_iot module could not be loaded: ' 'boto libraries not found') elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version): return (False, 'The boto_cognitoidentity module could not be loaded: ' 'boto version {0} or later must be installed.'.format(required_boto3_version)) else: return True
def __virtual__(): ''' Only load if boto3 libraries exist and if boto3 libraries are greater than a given version. ''' required_boto_version = '1.0.0' if not HAS_BOTO3: return (False, "The boto3.efs module cannot be loaded: " + "boto3 library not found") elif _LooseVersion(boto3.__version__) < \ _LooseVersion(required_boto_version): return (False, "The boto3.efs module cannot be loaded:" + "boto3 library version incorrect") else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto3_version = '1.2.1' # the boto_lambda execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: return (False, 'The boto_s3_bucket module could not be loaded: ' 'boto libraries not found') elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version): return (False, 'The boto_cognitoidentity module could not be loaded: ' 'boto version {0} or later must be installed.'.format(required_boto3_version)) else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.4.0' # Boto < 2.4.0 GroupOrCIDR objects have different attributes than # Boto >= 2.4.0 GroupOrCIDR objects # Differences include no group_id attribute in Boto < 2.4.0 and returning # a groupId attribute when a GroupOrCIDR object authorizes an IP range # Support for Boto < 2.4.0 can be added if needed if not HAS_BOTO: return (False, 'The boto_secgroup module could not be loaded: boto libraries not found') elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): return (False, 'The boto_secgroup module could not be loaded: boto library v2.4.0 not found') else: __utils__['boto.assign_funcs'](__name__, 'ec2', pack=__salt__) return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.8.0' # the boto_vpc execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 if not HAS_BOTO: log.debug('The boto_vpc module requires boto {0} to be installed.'.format(required_boto_version)) return False elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): log.debug('The boto_vpc module requires boto {0} to be installed. Current boto version: {1}'.format( required_boto_version, boto.__version__)) return False else: log.debug('Installed boto version: {0}'.format(boto.__version__)) return True
def update(name, source=None, pre_versions=False): ''' Instructs Chocolatey to update packages on the system. name The name of the package to update, or "all" to update everything installed on the system. source Chocolatey repository (directory, share or remote URL feed) the package comes from. Defaults to the official Chocolatey feed. pre_versions Include pre-release packages in comparison. Defaults to False. CLI Example: .. code-block:: bash salt "*" chocolatey.update all salt "*" chocolatey.update <package name> pre_versions=True ''' # chocolatey helpfully only supports a single package argument choc_path = _find_chocolatey(__context__, __salt__) if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.8.24'): log.warning('update is deprecated, using upgrade') return upgrade(name, source=source, pre_versions=pre_versions) cmd = [choc_path, 'update', name] if source: cmd.extend(['--source', source]) if salt.utils.is_true(pre_versions): cmd.append('--prerelease') cmd.extend(_yes(__context__)) result = __salt__['cmd.run_all'](cmd, python_shell=False) if result['retcode'] not in [0, 1641, 3010]: err = 'Running chocolatey failed: {0}'.format(result['stderr']) log.error(err) raise CommandExecutionError(err) return result['stdout']
def update(name, source=None, pre_versions=False): ''' Instructs Chocolatey to update packages on the system. name The name of the package to update, or "all" to update everything installed on the system. source Chocolatey repository (directory, share or remote URL feed) the package comes from. Defaults to the official Chocolatey feed. pre_versions Include pre-release packages in comparison. Defaults to False. CLI Example: .. code-block:: bash salt "*" chocolatey.update all salt "*" chocolatey.update <package name> pre_versions=True ''' # chocolatey helpfully only supports a single package argument choc_path = _find_chocolatey(__context__, __salt__) if _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.8.24'): log.warning('update is deprecated, using upgrade') return upgrade(name, source=source, pre_versions=pre_versions) cmd = [choc_path, 'update', name] if source: cmd.extend(['-source', source]) if salt.utils.is_true(pre_versions): cmd.append('-prerelease') cmd.extend(_yes(__context__)) result = __salt__['cmd.run_all'](cmd, python_shell=False) if result['retcode'] not in [0, 1641, 3010]: err = 'Running chocolatey failed: {0}'.format(result['stderr']) log.error(err) raise CommandExecutionError(err) return result['stdout']
def _get_six_source(): """Import the newest version of the six library that's available""" mod_info = None try: if _system_six and _LooseVersion and \ _LooseVersion(_system_six.__version__) >= _LooseVersion(_bundled_six.__version__): mod_info = _find_module('six') except: # Any errors finding the system library, use our bundled lib instead pass if not mod_info: try: mod_info = _find_module('ansible.module_utils.six._six') except ImportError: # zipimport module_source = _get_bundled_six_source() return module_source return mod_info[0].read()
def _checks_apyfal_version(self, config_env): """ Checks if client Apyfal version is compatible. Args: config_env (dict): environment. Raises: apyfal.exceptions.ClientConfigurationException: Apyfal version is not compatible. """ try: if _LooseVersion(config_env['apyfal_version']) < _LooseVersion( self.APYFAL_MINIMUM_VERSION): raise _exc.ClientConfigurationException( 'Apyfal version needs to be at least %s. Please upgrade it.' % self.APYFAL_MINIMUM_VERSION) # Version not available: Return, can come from REST API directly. except KeyError: return
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' required_boto_version = '2.8.0' required_boto3_version = '1.2.5' required_botocore_version = '1.5.2' # the boto_lambda execution module relies on the connect_to_region() method # which was added in boto 2.8.0 # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12 # botocore version >= 1.5.2 is required due to lambda environment variables if not HAS_BOTO: return (False, 'The boto_lambda module could not be loaded: ' 'boto libraries not found') elif _LooseVersion( boto.__version__) < _LooseVersion(required_boto_version): return (False, 'The boto_lambda module could not be loaded: ' 'boto version {0} or later must be installed.'.format( required_boto_version)) elif _LooseVersion( boto3.__version__) < _LooseVersion(required_boto3_version): return (False, 'The boto_lambda module could not be loaded: ' 'boto version {0} or later must be installed.'.format( required_boto3_version)) elif _LooseVersion(found_botocore_version) < _LooseVersion( required_botocore_version): return (False, 'The boto_apigateway module could not be loaded: ' 'botocore version {0} or later must be installed.'.format( required_botocore_version)) else: return True
def __virtual__(): ''' Only load if boto libraries exist and if boto libraries are greater than a given version. ''' # TODO: Determine minimal version we want to support. VPC requires > 2.8.0. required_boto_version = '2.0.0' # boto_s3_bucket module requires boto3 1.2.6 and botocore 1.3.23 for # idempotent ACL operations via the fix in https://github.com/boto/boto3/issues/390 required_boto3_version = '1.2.6' required_botocore_version = '1.3.23' if not HAS_BOTO: return False elif _LooseVersion(boto.__version__) < _LooseVersion(required_boto_version): return False elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version): return False elif _LooseVersion(botocore.__version__) < _LooseVersion(required_botocore_version): return False else: return True
def version(name, check_remote=False, source=None, pre_versions=False): ''' Instructs Chocolatey to check an installed package version, and optionally compare it to one available from a remote feed. name The name of the package to check. check_remote Get the version number of the latest package from the remote feed. Defaults to False. source Chocolatey repository (directory, share or remote URL feed) the package comes from. Defaults to the official Chocolatey feed. pre_versions Include pre-release packages in comparison. Defaults to False. CLI Example: .. code-block:: bash salt "*" chocolatey.version <package name> salt "*" chocolatey.version <package name> check_remote=True ''' choc_path = _find_chocolatey(__context__, __salt__) if not choc_path: err = 'Chocolatey not installed. Use chocolatey.bootstrap to install the Chocolatey package manager.' log.error(err) raise CommandExecutionError(err) use_list = _LooseVersion(chocolatey_version()) >= _LooseVersion('0.9.9') if use_list: choco_cmd = "list" else: choco_cmd = "version" cmd = [choc_path, choco_cmd, name] if not salt.utils.is_true(check_remote): cmd.append('-LocalOnly') if salt.utils.is_true(pre_versions): cmd.append('-Prerelease') if source: cmd.extend(['-Source', source]) result = __salt__['cmd.run_all'](cmd, python_shell=False) if result['retcode'] != 0: err = 'Running chocolatey failed: {0}'.format(result['stderr']) log.error(err) raise CommandExecutionError(err) ret = {} res = result['stdout'].split('\n') if use_list: res = res[:-1] # the next bit is to deal with the stupid default PowerShell formatting. # printing two value pairs is shown in columns, whereas printing six # pairs is shown in rows... if not salt.utils.is_true(check_remote): ver_re = re.compile(r'(\S+)\s+(.+)') for line in res: for name, ver in ver_re.findall(line): ret['name'] = name ret['found'] = ver else: ver_re = re.compile(r'(\S+)\s+:\s*(.*)') for line in res: for key, value in ver_re.findall(line): ret[key] = value return ret
from distutils.version import LooseVersion as _LooseVersion # pylint: disable=import-error,no-name-in-module # Import salt libs import salt.utils.compat log = logging.getLogger(__name__) # Import third party libs REQUIRED_LIBCLOUD_VERSION = '0.21.0' try: #pylint: disable=unused-import import libcloud from libcloud.dns.providers import get_driver from libcloud.dns.types import RecordType #pylint: enable=unused-import if hasattr(libcloud, '__version__') and _LooseVersion( libcloud.__version__) < _LooseVersion(REQUIRED_LIBCLOUD_VERSION): raise ImportError() logging.getLogger('libcloud').setLevel(logging.CRITICAL) HAS_LIBCLOUD = True except ImportError: HAS_LIBCLOUD = False def __virtual__(): ''' Only load if libcloud libraries exist. ''' if not HAS_LIBCLOUD: msg = ('A apache-libcloud library with version at least {0} was not ' 'found').format(REQUIRED_LIBCLOUD_VERSION) return (False, msg)
from __future__ import absolute_import # Import Python libs import logging from distutils.version import LooseVersion as _LooseVersion # pylint: disable=import-error,no-name-in-module import json import salt.ext.six as six log = logging.getLogger(__name__) # Import third party libs try: import boto # connection settings were added in 2.33.0 required_boto_version = '2.33.0' if (_LooseVersion(boto.__version__) < _LooseVersion(required_boto_version)): msg = 'boto_elb requires boto {0}.'.format(required_boto_version) logging.debug(msg) raise ImportError() import boto.ec2 from boto.ec2.elb import HealthCheck from boto.ec2.elb.attributes import AccessLogAttribute from boto.ec2.elb.attributes import ConnectionDrainingAttribute from boto.ec2.elb.attributes import ConnectionSettingAttribute from boto.ec2.elb.attributes import CrossZoneLoadBalancingAttribute logging.getLogger('boto').setLevel(logging.CRITICAL) HAS_BOTO = True except ImportError: HAS_BOTO = False
from distutils.version import LooseVersion as _LooseVersion # Import Salt Testing Libs from tests.support.unit import TestCase, skipIf # Import Salt Libs from salt.config.schemas import ssh as ssh_schemas from salt.config.schemas.minion import MinionConfiguration # Import 3rd-party libs import salt.ext.six as six try: import jsonschema import jsonschema.exceptions HAS_JSONSCHEMA = True JSONSCHEMA_VERSION = _LooseVersion(jsonschema.__version__) except ImportError: HAS_JSONSCHEMA = False JSONSCHEMA_VERSION = _LooseVersion('0') @skipIf(six.PY3, 'Tests disabled under Python 3') class RoosterEntryConfigTest(TestCase): def test_config(self): config = ssh_schemas.RosterEntryConfig() expected = { '$schema': 'http://json-schema.org/draft-04/schema#', 'title': 'Roster Entry', 'description': 'Salt SSH roster entry definition', 'type': 'object',
import salt.modules.libcloud_dns as libcloud_dns_module # Import salt libs import salt.utils import logging log = logging.getLogger(__name__) # Import third party libs REQUIRED_LIBCLOUD_VERSION = '1.0.0' try: #pylint: disable=unused-import import libcloud from libcloud.dns.providers import get_driver #pylint: enable=unused-import if _LooseVersion(libcloud.__version__) < _LooseVersion(REQUIRED_LIBCLOUD_VERSION): raise ImportError() logging.getLogger('libcloud').setLevel(logging.CRITICAL) HAS_LIBCLOUD = True except ImportError: HAS_LIBCLOUD = False def __virtual__(): ''' Only load if libcloud libraries exist. ''' if not HAS_LIBCLOUD: msg = ('A apache-libcloud library with version at least {0} was not ' 'found').format(REQUIRED_LIBCLOUD_VERSION) return (False, msg)
from distutils.version import LooseVersion as _LooseVersion from salt.utils.decorators import depends try: import boto.utils required_boto_version = '2.46.1' HAS_BOTO = (_LooseVersion(boto.__version__) >= _LooseVersion(required_boto_version)) except ImportError: HAS_BOTO = False @depends(HAS_BOTO) def get_instance_meta(): return {'instance_meta': boto.utils.get_instance_metadata()}
SINGLE = "single" AVERAGE = "average" COMPLETE = "complete" WEIGHTED = "weighted" WARD = "ward" # Does scipy implement a O(n**2) NN chain algorithm? _HAS_NN_CHAIN = hasattr(scipy.cluster.hierarchy, "_hierarchy") and \ hasattr(scipy.cluster.hierarchy._hierarchy, "nn_chain") # Prior to 0.18 scipy.cluster.hierarchical's python interface disallowed # ward clustering from a precomputed distance matrix even though it's cython # implementation allowed it and was documented to support it (scipy issue 5220) _HAS_WARD_LINKAGE_FROM_DIST = \ _LooseVersion(scipy.__version__) >= _LooseVersion("0.18") and \ _HAS_NN_CHAIN def condensedform(X, mode="upper"): X = numpy.asarray(X) assert len(X.shape) == 2 assert X.shape[0] == X.shape[1] N = X.shape[0] if mode == "upper": i, j = numpy.triu_indices(N, k=1) elif mode == "lower": i, j = numpy.tril_indices(N, k=-1) else:
import salt.utils.compat import salt.utils.odict as odict from salt.exceptions import SaltInvocationError log = logging.getLogger(__name__) # Import third party libs REQUIRED_BOTO_VERSION = '2.35.0' try: #pylint: disable=unused-import import boto import boto.route53 from boto.route53.exception import DNSServerError #pylint: enable=unused-import # create_zone params were changed in boto 2.35+ if _LooseVersion(boto.__version__) < _LooseVersion(REQUIRED_BOTO_VERSION): raise ImportError() logging.getLogger('boto').setLevel(logging.CRITICAL) HAS_BOTO = True except ImportError: HAS_BOTO = False def __virtual__(): ''' Only load if boto libraries exist. ''' if not HAS_BOTO: msg = ('A boto library with version at least {0} was not ' 'found').format(REQUIRED_BOTO_VERSION) return (False, msg)
SINGLE = "single" AVERAGE = "average" COMPLETE = "complete" WEIGHTED = "weighted" WARD = "ward" # Does scipy implement a O(n**2) NN chain algorithm? _HAS_NN_CHAIN = hasattr(scipy.cluster.hierarchy, "_hierarchy") and hasattr( scipy.cluster.hierarchy._hierarchy, "nn_chain") # Prior to 0.18 scipy.cluster.hierarchical's python interface disallowed # ward clustering from a precomputed distance matrix even though it's cython # implementation allowed it and was documented to support it (scipy issue 5220) _HAS_WARD_LINKAGE_FROM_DIST = ( _LooseVersion(scipy.__version__) >= _LooseVersion("0.18") and _HAS_NN_CHAIN) def condensedform(X, mode="upper"): X = numpy.asarray(X) assert len(X.shape) == 2 assert X.shape[0] == X.shape[1] N = X.shape[0] if mode == "upper": i, j = numpy.triu_indices(N, k=1) elif mode == "lower": i, j = numpy.tril_indices(N, k=-1) else:
"._sunburst.Sunburst", "._surface.Surface", "._table.Table", "._treemap.Treemap", "._violin.Violin", "._volume.Volume", "._waterfall.Waterfall", ], ) if sys.version_info < (3, 7): try: import ipywidgets as _ipywidgets from distutils.version import LooseVersion as _LooseVersion if _LooseVersion(_ipywidgets.__version__) >= _LooseVersion("7.0.0"): from ..graph_objs._figurewidget import FigureWidget else: raise ImportError() except Exception: from ..missing_ipywidgets import FigureWidget else: __all__.append("FigureWidget") orig_getattr = __getattr__ def __getattr__(import_name): if import_name == "FigureWidget": try: import ipywidgets from distutils.version import LooseVersion
def _parse_version(version): return _LooseVersion(version)
import salt.modules.libcloud_dns as libcloud_dns_module # Import salt libs import salt.utils import logging log = logging.getLogger(__name__) # Import third party libs REQUIRED_LIBCLOUD_VERSION = '1.0.0' try: #pylint: disable=unused-import import libcloud from libcloud.dns.providers import get_driver #pylint: enable=unused-import if hasattr(libcloud, '__version__') and _LooseVersion(libcloud.__version__) < _LooseVersion(REQUIRED_LIBCLOUD_VERSION): raise ImportError() logging.getLogger('libcloud').setLevel(logging.CRITICAL) HAS_LIBCLOUD = True except ImportError: HAS_LIBCLOUD = False def __virtual__(): ''' Only load if libcloud libraries exist. ''' if not HAS_LIBCLOUD: msg = ('A apache-libcloud library with version at least {0} was not ' 'found').format(REQUIRED_LIBCLOUD_VERSION) return (False, msg)
''' from . import ( numpy_fft, cache, ) try: import scipy.fftpack except ImportError: pass else: from distutils.version import LooseVersion as _LooseVersion has_scipy_fft = _LooseVersion(scipy.__version__) >= _LooseVersion('1.4.0') del _LooseVersion del scipy from . import scipy_fftpack if has_scipy_fft: from . import scipy_fft fft_wrap = None try: from dask.array.fft import fft_wrap except ImportError: pass if fft_wrap: from . import dask_fft
def list_repo_pkgs(*args, **kwargs): ''' Returns all available packages. Optionally, package names (and name globs) can be passed and the results will be filtered to packages matching those names. This function can be helpful in discovering the version or repo to specify in a :mod:`pkg.installed <salt.states.pkg.installed>` state. The return data will be a dictionary mapping package names to a list of version numbers, ordered from newest to oldest. If ``byrepo`` is set to ``True``, then the return dictionary will contain repository names at the top level, and each repository will map packages to lists of version numbers. For example: .. code-block:: python # With byrepo=False (default) { 'bash': ['4.4.005-2'], 'nginx': ['1.10.2-2'] } # With byrepo=True { 'core': { 'bash': ['4.4.005-2'] }, 'extra': { 'nginx': ['1.10.2-2'] } } fromrepo : None Only include results from the specified repo(s). Multiple repos can be specified, comma-separated. byrepo : False When ``True``, the return data for each package will be organized by repository. refresh : False When ``True``, the package database will be refreshed (i.e. ``pacman -Sy``) before checking for available versions. CLI Examples: .. code-block:: bash salt '*' pkg.list_repo_pkgs salt '*' pkg.list_repo_pkgs foo bar baz salt '*' pkg.list_repo_pkgs 'samba4*' fromrepo=base,updates salt '*' pkg.list_repo_pkgs 'python2-*' byrepo=True ''' kwargs = salt.utils.clean_kwargs(**kwargs) fromrepo = kwargs.pop('fromrepo', '') or '' byrepo = kwargs.pop('byrepo', False) refresh = kwargs.pop('refresh', False) if kwargs: salt.utils.invalid_kwargs(kwargs) if fromrepo: try: repos = [x.strip() for x in fromrepo.split(',')] except AttributeError: repos = [x.strip() for x in str(fromrepo).split(',')] else: repos = [] if refresh: refresh_db() out = __salt__['cmd.run_all']( ['pacman', '-Sl'], output_loglevel='trace', ignore_retcode=True, python_shell=False ) ret = {} for line in salt.utils.itertools.split(out['stdout'], '\n'): try: repo, pkg_name, pkg_ver = line.strip().split()[:3] except ValueError: continue if repos and repo not in repos: continue if args: for arg in args: if fnmatch.fnmatch(pkg_name, arg): skip_pkg = False break else: # Package doesn't match any of the passed args, skip it continue ret.setdefault(repo, {}).setdefault(pkg_name, []).append(pkg_ver) if byrepo: for reponame in ret: # Sort versions newest to oldest for pkgname in ret[reponame]: sorted_versions = sorted( [_LooseVersion(x) for x in ret[reponame][pkgname]], reverse=True ) ret[reponame][pkgname] = [x.vstring for x in sorted_versions] return ret else: byrepo_ret = {} for reponame in ret: for pkgname in ret[reponame]: byrepo_ret.setdefault(pkgname, []).extend(ret[reponame][pkgname]) for pkgname in byrepo_ret: sorted_versions = sorted( [_LooseVersion(x) for x in byrepo_ret[pkgname]], reverse=True ) byrepo_ret[pkgname] = [x.vstring for x in sorted_versions] return byrepo_ret
f""" MPI WARNING: It seems you might be running Python with MPI, but dependencies required by NetKet to enable MPI support are missing or cannot be loaded, so MPI support is disabled. NetKet will not take advantage of MPI, and every MPI rank will execute the same code independently. MPI dependencies are: - mpi4py>=3.0.1 ....... {"available" if _mpi4py_loaded else "missing"} - mpi4jax>=0.2.11 ....... {"available" if _mpi4jax_loaded else "missing"} To enable MPI support, install the missing dependencies. To learn more about MPI and NetKet consult the documentation at https://www.netket.org/docs/getting_started.html To disable this warning, set the environment variable `NETKET_MPI_WARNING=0` """ ) ) if mpi_available: _min_mpi4jax_version = "0.2.11" if not _LooseVersion(mpi4jax.__version__) >= _LooseVersion(_min_mpi4jax_version): raise ImportError( "Netket is only compatible with mpi4jax >= {}. Please update it (`pip install -U mpi4jax`).".format( _min_mpi4jax_version ) )