Skip to content

Commit

Permalink
Refactor code to satisfy pylint
Browse files Browse the repository at this point in the history
With updating pylint to its latest version, we also need to apply some
minor code fixes. The biggest problem was duplicate code issues, which
we needed to disable throughout all files because it's currently not
possible to disable just certain code blocks and functions.
  • Loading branch information
anzoman authored and sstanovnik committed May 13, 2021
1 parent 9091f6d commit b5856c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .sanity-config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ disable=print-statement,
unused-argument,
too-few-public-methods,
too-many-return-statements,
too-many-branches
too-many-branches,
duplicate-code

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down
19 changes: 8 additions & 11 deletions src/opera/executor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ def copy(source, target):


def write(dest_dir, content, suffix=None):
dest = tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=suffix)
dest.write(content.encode("utf-8"))
dest.close()
return dest.name
with tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=suffix) as dest:
dest.write(content.encode("utf-8"))
return dest.name


def run_in_directory(dest_dir, cmd, env):
fstdout = tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=".stdout")
fstderr = tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=".stderr")
result = subprocess.run(cmd, cwd=dest_dir, stdout=fstdout, stderr=fstderr, # nosec
env=dict(os.environ, **env), check=False)
fstdout.close()
fstderr.close()
return result.returncode, fstdout.name, fstderr.name
with tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=".stdout") as fstdout, \
tempfile.NamedTemporaryFile(dir=dest_dir, delete=False, suffix=".stderr") as fstderr:
result = subprocess.run(cmd, cwd=dest_dir, stdout=fstdout, stderr=fstderr, # nosec
env=dict(os.environ, **env), check=False)
return result.returncode, fstdout.name, fstderr.name
4 changes: 2 additions & 2 deletions src/opera/parser/tosca/csar.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def __init__(self, csar_file: Path):
"""csar_file is guaranteed to exist, be absolute, and be a file."""
super().__init__(str(csar_file.name))
self.csar_file = csar_file
self.backing_zip = ZipFile(csar_file, mode="r")
self.backing_zip = ZipFile(csar_file, mode="r") # pylint: disable=consider-using-with

def package_csar(self, output_file, service_template=None, csar_format="zip") -> str:
raise NotImplementedError("Repackaging a packaged CSAR is not implemented.")
Expand All @@ -269,7 +269,7 @@ def members(self) -> List[PurePath]:
return [PurePath(zi.filename) for zi in self.backing_zip.infolist()]

def open_member(self, path: PurePath) -> IO:
return self.backing_zip.open(str(path), mode="r")
return self.backing_zip.open(str(path), mode="r") # pylint: disable=consider-using-with

def _member_exists(self, member: PurePath) -> bool:
try:
Expand Down

0 comments on commit b5856c4

Please sign in to comment.