fix most pylints

master
jerger 1 year ago
parent c1c25a016f
commit a3d97a0d04

@ -30,7 +30,7 @@ pylint:
stage: lint
allow_failure: true
script:
- pylint -d C0301 dda_python_terraform/*.py
- pylint -d C0112,C0115,C0301,R0913,R0903,R0902,R0914,R1705,R1732,W0622 dda_python_terraform/*.py
test-0.13.7:

@ -1,3 +1,4 @@
"""Module providing wrapper for terraform."""
from .terraform import (
IsFlagged,
IsNotFlagged,

@ -1,3 +1,4 @@
"""Module providing wrapper for terraform."""
import json
import logging
import os
@ -30,8 +31,9 @@ CommandOutput = Tuple[Optional[int], Optional[str], Optional[str]]
class TerraformCommandError(subprocess.CalledProcessError):
"""Class representing a terraform error"""
def __init__(self, ret_code: int, cmd: str, out: Optional[str], err: Optional[str]):
super(TerraformCommandError, self).__init__(ret_code, cmd)
super().__init__(ret_code, cmd)
self.out = out
self.err = err
logger.error("Error with command %s. Reason: %s", self.cmd, self.err)
@ -76,7 +78,7 @@ class Terraform:
self.working_dir = working_dir
self.state = state
self.targets = [] if targets is None else targets
self.variables = dict() if variables is None else variables
self.variables = {} if variables is None else variables
self.parallelism = parallelism
self.terraform_bin_path = (
terraform_bin_path if terraform_bin_path else "terraform"
@ -313,15 +315,15 @@ class Terraform:
if self.is_env_vars_included:
environ_vars = os.environ.copy()
p = subprocess.Popen(
proc = subprocess.Popen(
cmds, stdout=stdout, stderr=stderr, cwd=working_folder, env=environ_vars
)
if not synchronous:
return None, None, None
out, err = p.communicate()
ret_code = p.returncode
out, err = proc.communicate()
ret_code = proc.returncode
logger.info("output: %s", out)
if ret_code == 0:
@ -486,8 +488,6 @@ class Terraform:
}
def _generate_cmd_options(self, **kwargs) -> List[str]:
"""
"""
result = []
for option, value in kwargs.items():
@ -501,13 +501,12 @@ class Terraform:
if isinstance(value, dict):
if "backend-config" in option:
for bk, bv in value.items():
result += [f"-backend-config={bk}={bv}"]
for backend_key, backend_value in value.items():
result += [f"-backend-config={backend_key}={backend_value}"]
continue
# since map type sent in string won't work, create temp var file for
# variables, and clean it up later
elif option == "var":
if option == "var":
# We do not create empty var-files if there is no var passed.
# An empty var-file would result in an error: An argument or block definition is required here
if value:
@ -546,10 +545,12 @@ class Terraform:
class VariableFiles:
"""Class representing a terraform var files"""
def __init__(self):
self.files = []
def create(self, variables: Dict[str, str]) -> str:
"""create var file in temp"""
with tempfile.NamedTemporaryFile(
"w+t", suffix=".tfvars.json", delete=False
) as temp:
@ -562,7 +563,8 @@ class VariableFiles:
return file_name
def clean_up(self):
for f in self.files:
os.unlink(f.name)
"""cleanup the var file"""
for fle in self.files:
os.unlink(fle.name)
self.files = []

@ -1,3 +1,4 @@
"""Helper Module providing wrapper for terraform state."""
import json
import logging
import os
@ -7,6 +8,7 @@ logger = logging.getLogger(__name__)
class Tfstate:
"""Class representing a terraform state"""
def __init__(self, data: Optional[Dict[str, str]] = None):
self.tfstate_file: Optional[str] = None
self.native_data = data
@ -21,8 +23,8 @@ class Tfstate:
"""
logger.debug("read data from %s", file_path)
if os.path.exists(file_path):
with open(file_path) as f:
json_data = json.load(f)
with open(file_path, encoding="utf-8") as fle:
json_data = json.load(fle)
tf_state = Tfstate(json_data)
tf_state.tfstate_file = file_path

Loading…
Cancel
Save