diff --git a/pipenv/core.py b/pipenv/core.py index 8c48d7fa..3b304625 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -906,16 +906,19 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None): # Actually create the virtualenv. nospin = environments.PIPENV_NOSPIN - c = vistir.misc.run( - cmd, verbose=False, return_object=True, - spinner_name=environments.PIPENV_SPINNER, combine_stderr=False, - block=False, nospin=nospin, env=pip_config, - ) - click.echo(crayons.blue("{0}".format(c.out)), err=True) - if c.returncode != 0: - raise exceptions.VirtualenvCreationException( - extra=[crayons.blue("{0}".format(c.err)),] + with create_spinner("Creating virtual environment...") as sp: + c = vistir.misc.run( + cmd, verbose=False, return_object=True, write_to_stdout=False, + combine_stderr=False, block=True, nospin=True, env=pip_config, ) + click.echo(crayons.blue("{0}".format(c.out)), err=True) + if c.returncode != 0: + sp.fail(environments.PIPENV_SPINNER_FAIL_TEXT.format("Failed creating virtual environment")) + raise exceptions.VirtualenvCreationException( + extra=[crayons.blue("{0}".format(c.err)),] + ) + else: + sp.green.ok(environments.PIPENV_SPINNER_OK_TEXT.format("Successfully created virtual environment!")) # Associate project directory with the environment. # This mimics Pew's "setproject". diff --git a/pipenv/environment.py b/pipenv/environment.py index 7a7fd2ea..0f161473 100644 --- a/pipenv/environment.py +++ b/pipenv/environment.py @@ -193,7 +193,7 @@ class Environment(object): elif any([sys.prefix == self.prefix, not self.is_venv]): return sys.path cmd_args = [self.python, "-c", "import json, sys; print(json.dumps(sys.path))"] - path, _ = vistir.misc.run(cmd_args, return_object=False, nospin=True, block=True, combine_stderr=False) + path, _ = vistir.misc.run(cmd_args, return_object=False, nospin=True, block=True, combine_stderr=False, write_to_stdout=False) path = json.loads(path.strip()) return path @@ -206,7 +206,7 @@ class Environment(object): """ command = [self.python, "-c" "import sys; print(sys.prefix)"] - c = vistir.misc.run(command, return_object=True, block=True, nospin=True) + c = vistir.misc.run(command, return_object=True, block=True, nospin=True, write_to_stdout=False) sys_prefix = vistir.compat.Path(vistir.misc.to_text(c.out).strip()).as_posix() return sys_prefix @@ -413,7 +413,7 @@ class Environment(object): c = None with self.activated(): script = vistir.cmdparse.Script.parse(cmd) - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd, write_to_stdout=False) return c def run_py(self, cmd, cwd=os.curdir): @@ -432,7 +432,7 @@ class Environment(object): else: script = vistir.cmdparse.Script.parse([self.python, "-c"] + list(cmd)) with self.activated(): - c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd) + c = vistir.misc.run(script._parts, return_object=True, nospin=True, cwd=cwd, write_to_stdout=False) return c def run_activate_this(self): diff --git a/pipenv/vendor/vistir/misc.py b/pipenv/vendor/vistir/misc.py index 870fa38b..74108d6f 100644 --- a/pipenv/vendor/vistir/misc.py +++ b/pipenv/vendor/vistir/misc.py @@ -106,7 +106,7 @@ def _spawn_subprocess(script, env=None, block=True, cwd=None, combine_stderr=Tru from distutils.spawn import find_executable if not env: - env = {} + env = os.environ.copy() command = find_executable(script.command) options = { "env": env, @@ -148,15 +148,16 @@ def _create_subprocess( spinner=None, combine_stderr=False, display_limit=200, - start_text="" + start_text="", + write_to_stdout=True ): if not env: - env = {} + env = os.environ.copy() try: c = _spawn_subprocess(cmd, env=env, block=block, cwd=cwd, - combine_stderr=combine_stderr) + combine_stderr=combine_stderr) except Exception as exc: - print("Error %s while executing command %s", exc, " ".join(cmd._parts)) + sys.stderr.write("Error %s while executing command %s", exc, " ".join(cmd._parts)) raise if not block: c.stdin.close() @@ -193,9 +194,7 @@ def _create_subprocess( err_line = fs_str("{0}".format(stderr_line)) if verbose and err_line is not None: if spinner: - spinner._hide_cursor() - spinner.write_err(err_line) - spinner._show_cursor() + spinner.hide_and_write(err_line, target=spinner.stderr) else: sys.stderr.write(err_line) sys.stderr.flush() @@ -206,12 +205,12 @@ def _create_subprocess( display_line = "{0}...".format(stdout_line[:display_limit]) if verbose and display_line is not None: if spinner: - spinner._hide_cursor() - spinner.write_err(display_line) - spinner._show_cursor() + target = spinner.stdout if write_to_stdout else spinner.stderr + spinner.hide_and_write(display_line, target=target) else: - sys.stderr.write(display_line) - sys.stderr.flush() + target = sys.stdout if write_to_stdout else sys.stderr + target.write(display_line) + target.flush() if spinner: spinner.text = to_native_string("{0} {1}".format(spinner_orig_text, display_line)) continue diff --git a/pipenv/vendor/vistir/spin.py b/pipenv/vendor/vistir/spin.py index acb428a5..c6ae5884 100644 --- a/pipenv/vendor/vistir/spin.py +++ b/pipenv/vendor/vistir/spin.py @@ -93,6 +93,18 @@ class DummySpinner(object): self._close_output_buffer() return 0 + def hide_and_write(self, text, target=None): + if not target: + target = self.stdout + from .misc import decode_for_output + if text is None or isinstance(text, six.string_types) and text == "None": + pass + target.write(decode_for_output("\r")) + self._hide_cursor(target=target) + target.write(decode_for_output("{0}\n".format(text))) + target.write(CLEAR_LINE) + self._show_cursor(target=target) + def write(self, text=None): if not self.write_to_stdout: return self.write_err(text) @@ -189,6 +201,18 @@ class VistirSpinner(base_obj): err = err or not self.write_to_stdout self._freeze(_text, err=err) + def hide_and_write(self, text, target=None): + if not target: + target = self.stdout + from .misc import decode_for_output + if text is None or isinstance(text, six.string_types) and text == "None": + pass + target.write(decode_for_output("\r")) + self._hide_cursor(target=target) + target.write(decode_for_output("{0}\n".format(text))) + target.write(CLEAR_LINE) + self._show_cursor(target=target) + def write(self, text): if not self.write_to_stdout: return self.write_err(text)