Skip to content

Commit

Permalink
Merge pull request #349 from wdpypere/pass_tests
Browse files Browse the repository at this point in the history
make sure vsc-base passes latest vsc-install tests
  • Loading branch information
alvarosimon authored Nov 22, 2023
2 parents baf1113 + cb5e2e0 commit 2ae8e60
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 45 deletions.
1 change: 0 additions & 1 deletion lib/vsc/utils/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,3 @@ def run(self):
You should override this method when you subclass Daemon. It will be called after the process has been
daemonized by start() or restart().
"""
pass
1 change: 0 additions & 1 deletion lib/vsc/utils/optcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def _call(self, **kwargs): # pylint: disable=unused-argument

class NoneCompleter(Completer):
"""Generates empty completion list. For compatibility reasons."""
pass


class ListCompleter(Completer):
Expand Down
87 changes: 45 additions & 42 deletions lib/vsc/utils/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,20 @@ def _start_in_path(self):
try:
self._cwd_before_startpath = os.getcwd() # store it some one can return to it
os.chdir(self.startpath)
except OSError:
self.log.raiseException("_start_in_path: failed to change path from %s to startpath %s" %
(self._cwd_before_startpath, self.startpath))
except OSError as exc:
msg = (
f"_start_in_path: failed to change path from {self._cwd_before_startpath} "
f"to startpath {self.startpath}")
self.log.exception(msg)
raise OSError(msg) from exc
else:
self.log.raiseException("_start_in_path: provided startpath %s exists but is no directory" %
self.startpath)
msg = f"_start_in_path: provided startpath {self.startpath} exists but is no directory"
self.log.error(msg)
raise ValueError(msg)
else:
self.log.raiseException(f"_start_in_path: startpath {self.startpath} does not exist")
msg = f"_start_in_path: startpath {self.startpath} does not exist"
self.log.error(msg)
raise ValueError(msg)

def _return_to_previous_start_in_path(self):
"""Change to original path before the change to startpath"""
Expand All @@ -322,15 +328,22 @@ def _return_to_previous_start_in_path(self):
self.log.warning(("_return_to_previous_start_in_path: current diretory %s does not match "
"startpath %s"), currentpath, self.startpath)
os.chdir(self._cwd_before_startpath)
except OSError:
self.log.raiseException(("_return_to_previous_start_in_path: failed to change path from current %s "
"to previous path %s"), currentpath, self._cwd_before_startpath)
except OSError as exc:
msg = (
f"_return_to_previous_start_in_path: failed to change path from current {currentpath} "
f"to previous path {self._cwd_before_startpath}")
self.log.exception(msg)
raise OSError(msg) from exc
else:
self.log.raiseException(("_return_to_previous_start_in_path: provided previous cwd path %s exists "
"but is no directory") % self._cwd_before_startpath)
msg = (
f"_return_to_previous_start_in_path: provided previous cwd path {self._cwd_before_startpath} "
"exists but is not a directory.")
self.log.error(msg)
raise ValueError(msg)
else:
self.log.raiseException("_return_to_previous_start_in_path: previous cwd path %s does not exist" %
self._cwd_before_startpath)
msg = f"_return_to_previous_start_in_path: previous cwd path {self._cwd_before_startpath} does not exist"
self.log.error(msg)
raise ValueError(msg)

def _make_popen_named_args(self, others=None):
"""Create the named args for Popen"""
Expand Down Expand Up @@ -397,9 +410,12 @@ def _wait_for_process(self):
try:
self._process_exitcode = self._process.wait()
self._process_output = self._read_process(-1) # -1 is read all
except Exception:
self.log.raiseException("_wait_for_process: problem during wait exitcode %s output %s" %
(self._process_exitcode, self._process_output))
except Exception as exc:
msg = (
f"_wait_for_process: problem during wait exitcode {self._process_exitcode} "
f"output {self._process_output}")
self.log.exception(msg)
raise OSError(msg) from exc

def _cleanup_process(self):
"""Cleanup any leftovers from the process"""
Expand Down Expand Up @@ -702,22 +718,27 @@ def _make_popen_named_args(self, others=None):
if os.path.isfile(self.filename):
self.log.warning("_make_popen_named_args: going to overwrite existing file %s", self.filename)
elif os.path.isdir(self.filename):
self.log.raiseException(("_make_popen_named_args: writing to filename %s impossible. "
"Path exists and is a directory.") % self.filename)
msg = (f"_make_popen_named_args: writing to filename {self.filename} impossible. "
"Path exists and is a directory.")
self.log.error(msg)
raise ValueError(msg)
else:
self.log.raiseException("_make_popen_named_args: path exists and is not a file or directory %s" %
self.filename)
msg = f"_make_popen_named_args: path exists and is not a file or directory {self.filename}"
self.log.error(msg)
raise ValueError(msg)
else:
dirname = os.path.dirname(self.filename)
if dirname and not os.path.isdir(dirname):
try:
os.makedirs(dirname)
except OSError:
self.log.raiseException(("_make_popen_named_args: dirname %s for file %s does not exists. "
"Creating it failed.") % (dirname, self.filename))
msg = (f"_make_popen_named_args: dirname {dirname} for file {self.filename} "
f"does not exists. Creating it failed.")
self.log.exception(msg)
raise OSError(msg) from OSError

try:
self.filehandle = open(self.filename, 'w') # pylint: disable=consider-using-with
self.filehandle = open(self.filename, 'w', encoding='utf8') # pylint: disable=consider-using-with
except OSError:
self.log.raiseException(f"_make_popen_named_args: failed to open filehandle for file {self.filename}")

Expand Down Expand Up @@ -829,7 +850,7 @@ def _parse_qa(self, qa, qa_reg, no_qa):

def escape_special(string):
specials = r'.*+?(){}[]|\$^'
return re.sub(r"([%s])" % ''.join([r'\%s' % x for x in specials]), r"\\\1", string)
return re.sub(r"([%s])" % ''.join([rf'\{x}' for x in specials]), r"\\\1", string)

SPLIT = '[\\s\n]+'
REG_SPLIT = re.compile(r"" + SPLIT)
Expand Down Expand Up @@ -951,54 +972,36 @@ def _loop_process_output(self, output):

class RunNoShellQA(RunNoShell, RunQA):
"""Question/Answer processing"""
pass


class RunAsyncLoop(RunLoop, RunAsync):
"""Async read in loop"""
pass

class RunNoShellAsyncLoop(RunNoShellLoop, RunNoShellAsync):
"""Async read in loop"""
pass


class RunAsyncLoopLog(RunLoopLog, RunAsync):
"""Async read, log to logger"""
pass


class RunNoShellAsyncLoopLog(RunNoShellLoopLog, RunNoShellAsync):
"""Async read, log to logger"""
pass

class RunQALog(RunLoopLog, RunQA):
"""Async loop QA with LoopLog"""
pass


class RunNoShellQALog(RunNoShellLoopLog, RunNoShellQA):
"""Async loop QA with LoopLog"""
pass


class RunQAStdout(RunLoopStdout, RunQA):
"""Async loop QA with LoopLogStdout"""
pass


class RunNoShellQAStdout(RunNoShellLoopStdout, RunNoShellQA):
"""Async loop QA with LoopLogStdout"""
pass


class RunAsyncLoopStdout(RunLoopStdout, RunAsync):
"""Async read, flush to stdout"""
pass

class RunNoShellAsyncLoopStdout(RunNoShellLoopStdout, RunNoShellAsync):
"""Async read, flush to stdout"""
pass


# convenient names
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from vsc.install.shared_setup import ag, kh, jt, sdw

PACKAGE = {
'version': '3.5.9',
'version': '3.5.10',
'author': [sdw, jt, ag, kh],
'maintainer': [sdw, jt, ag, kh],
'install_requires': [
Expand Down

0 comments on commit 2ae8e60

Please sign in to comment.