diff --git a/setup.py b/setup.py index 8c10d51..de97e8c 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ # Always prefer setuptools over distutils -from codecs import open +from codecs import open as codecs_open from os import path import sys @@ -12,12 +12,16 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README.md file -with open(path.join(here, 'README.md'), encoding='utf-8') as f: +with codecs_open(path.join(here, 'README.md'), encoding='utf-8') as f: long_description = f.read() version = {} -with open("spotinst_sdk2/version.py") as fp: - exec(fp.read(), version) +with codecs_open("spotinst_sdk2/version.py", encoding='utf-8') as fp: + for line in fp: + if line.startswith("__version__"): + delim = '"' if '"' in line else "'" + version['__version__'] = line.split(delim)[1] + break setup( name='spotinst-sdk2', @@ -53,46 +57,46 @@ keywords='spotinst spot instances aws azure ec2 cloud infrastructure development elastigroup', packages=[ - "spotinst_sdk2", - "spotinst_sdk2.clients", - "spotinst_sdk2.clients.admin", - "spotinst_sdk2.clients.elastigroup", - "spotinst_sdk2.clients.functions", - "spotinst_sdk2.clients.hpc", - "spotinst_sdk2.clients.mcs", - "spotinst_sdk2.clients.mrscaler", - "spotinst_sdk2.clients.ocean", - "spotinst_sdk2.clients.ocean_cd", - "spotinst_sdk2.clients.subscription", - "spotinst_sdk2.clients.setup", - "spotinst_sdk2.clients.managed_instance", - "spotinst_sdk2.clients.stateful_node", + "spotinst_sdk2", + "spotinst_sdk2.clients", + "spotinst_sdk2.clients.admin", + "spotinst_sdk2.clients.elastigroup", + "spotinst_sdk2.clients.functions", + "spotinst_sdk2.clients.hpc", + "spotinst_sdk2.clients.mcs", + "spotinst_sdk2.clients.mrscaler", + "spotinst_sdk2.clients.ocean", + "spotinst_sdk2.clients.ocean_cd", + "spotinst_sdk2.clients.subscription", + "spotinst_sdk2.clients.setup", + "spotinst_sdk2.clients.managed_instance", + "spotinst_sdk2.clients.stateful_node", "spotinst_sdk2.models", - "spotinst_sdk2.models.admin", - "spotinst_sdk2.models.elastigroup", - "spotinst_sdk2.models.elastigroup.aws", - "spotinst_sdk2.models.elastigroup.azure_v3", - "spotinst_sdk2.models.elastigroup.gcp", - "spotinst_sdk2.models.functions", - "spotinst_sdk2.models.hpc", - "spotinst_sdk2.models.hpc.aws", - "spotinst_sdk2.models.mrscaler", - "spotinst_sdk2.models.mrscaler.aws", - "spotinst_sdk2.models.ocean", - "spotinst_sdk2.models.ocean.aws", - "spotinst_sdk2.models.ocean.azure", - "spotinst_sdk2.models.ocean.gcp", - "spotinst_sdk2.models.ocean.ecs", - "spotinst_sdk2.models.ocean.rightsizing", - "spotinst_sdk2.models.ocean_cd", - "spotinst_sdk2.models.ocean_cd", - "spotinst_sdk2.models.setup", - "spotinst_sdk2.models.setup.azure", - "spotinst_sdk2.models.setup.gcp", - "spotinst_sdk2.models.subscription", - "spotinst_sdk2.models.managed_instance", - "spotinst_sdk2.models.managed_instance.aws", - "spotinst_sdk2.models.stateful_node" + "spotinst_sdk2.models.admin", + "spotinst_sdk2.models.elastigroup", + "spotinst_sdk2.models.elastigroup.aws", + "spotinst_sdk2.models.elastigroup.azure_v3", + "spotinst_sdk2.models.elastigroup.gcp", + "spotinst_sdk2.models.functions", + "spotinst_sdk2.models.hpc", + "spotinst_sdk2.models.hpc.aws", + "spotinst_sdk2.models.mrscaler", + "spotinst_sdk2.models.mrscaler.aws", + "spotinst_sdk2.models.ocean", + "spotinst_sdk2.models.ocean.aws", + "spotinst_sdk2.models.ocean.azure", + "spotinst_sdk2.models.ocean.gcp", + "spotinst_sdk2.models.ocean.ecs", + "spotinst_sdk2.models.ocean.rightsizing", + "spotinst_sdk2.models.ocean_cd", + "spotinst_sdk2.models.ocean_cd", + "spotinst_sdk2.models.setup", + "spotinst_sdk2.models.setup.azure", + "spotinst_sdk2.models.setup.gcp", + "spotinst_sdk2.models.subscription", + "spotinst_sdk2.models.managed_instance", + "spotinst_sdk2.models.managed_instance.aws", + "spotinst_sdk2.models.stateful_node" ], install_requires=['requests', 'PyYaml'], diff --git a/spotinst_sdk2/client.py b/spotinst_sdk2/client.py index 7994400..91c4307 100644 --- a/spotinst_sdk2/client.py +++ b/spotinst_sdk2/client.py @@ -4,13 +4,12 @@ import logging import requests - +from .version import __version__ VAR_SPOTINST_LOG_LEVEL = 'SPOTINST_LOG_LEVEL' -version = {} -with open(os.path.join(os.path.dirname(__file__), "./version.py")) as fp: - exec(fp.read(), version) + +version = {'__version__': __version__} _SpotinstClient__spotinst_sdk_python_agent_name = 'spotinst-sdk-python' _SpotinstClient__spotinst_sdk_user_agent = '{}/{}'.format( @@ -406,7 +405,7 @@ def print_output(self, output, level="debug"): if level == "info": self.logger.info(output) if level == "warn": - self.logger.warn(output) + self.logger.warning(output) if level == "error": self.logger.error(output) if level == "critical": diff --git a/spotinst_sdk2/session.py b/spotinst_sdk2/session.py index ccf54b6..df6aec5 100644 --- a/spotinst_sdk2/session.py +++ b/spotinst_sdk2/session.py @@ -45,7 +45,7 @@ def load_credentials(self, profile, credentials_file): VAR_SPOTINST_SHARED_CREDENTIALS_FILE, DEFAULT_CREDENTIALS_FILE) - with open(credentials_file, 'r') as credentials_file: + with open(credentials_file, 'r', encoding='utf-8') as credentials_file: self.__load_credentials_yaml(profile, credentials_file) if not self.auth_token: self.__load_credentials_ini(profile, credentials_file) @@ -60,7 +60,7 @@ def __load_credentials_yaml(self, profile, credentials_file): if config: self.account_id = config.get(profile, {}).get("account", None) self.auth_token = config.get(profile, {}).get("token", None) - except: + except (yaml.YAMLError, KeyError): return def __load_credentials_ini(self, profile, credentials_file): @@ -70,5 +70,5 @@ def __load_credentials_ini(self, profile, credentials_file): if config[profile]: self.account_id = config[profile]["account"] self.auth_token = config[profile]["token"] - except: + except (configparser.NoSectionError, configparser.NoOptionError): return diff --git a/spotinst_sdk2/version.py b/spotinst_sdk2/version.py index 9bf346d..c170b8d 100644 --- a/spotinst_sdk2/version.py +++ b/spotinst_sdk2/version.py @@ -1,2 +1 @@ -__version__ = '3.19.0' - +__version__ = '3.20.0'