From d5e5eca86ea0b4c2c81e03e39c1c096e12ff60da Mon Sep 17 00:00:00 2001 From: nonylene Date: Thu, 20 Apr 2017 01:16:24 +0900 Subject: [PATCH 1/3] use os.execl to "run" subcommand on Unix see https://github.com/kennethreitz/pipenv/issues/315 --- pipenv/cli.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 62a4165a..2fb415f9 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -984,39 +984,27 @@ def shell(three=None, python=False, compat=False, shell_args=None): )) @click.argument('command') @click.argument('args', nargs=-1) -@click.option('--no-interactive', is_flag=True, default=False, help="Run the command in non-interactive mode.") @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -def run(command, args, no_interactive=False, three=None, python=False): +def run(command, args, three=None, python=False): # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False) - # Automatically enable --no-interactive, when applicable. - if not sys.stdout.isatty(): - no_interactive = True + command_path = which(command) - # Spawn the new process, and interact with it. try: - c = pexpect.spawn(which(command), list(args)) - except pexpect.exceptions.ExceptionPexpect: - click.echo(crayons.red('The command ({0}) was not found within the virtualenv!'.format(which(command)))) + c = os.execl(command_path, command_path, *args) + except FileNotFoundError: + click.echo(crayons.red('The command ({0}) was not found within the virtualenv!'.format(command_path))) sys.exit(1) # Windows! except AttributeError: import subprocess - p = subprocess.Popen([which(command)] + list(args), shell=True, universal_newlines=True) + p = subprocess.Popen([command_path] + list(args), shell=True, universal_newlines=True) p.communicate() sys.exit(p.returncode) - # Interact with the new shell. - if no_interactive: - c.wait() - else: - c.interact() - c.close() - sys.exit(c.exitstatus) - @click.command(help="Checks PEP 508 markers provided in Pipfile.") @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") From ac96188f2d252c1941198b7fc868edaf8446b75a Mon Sep 17 00:00:00 2001 From: nonylene Date: Thu, 20 Apr 2017 01:47:38 +0900 Subject: [PATCH 2/3] Use subprocess on Windows os.execl has strange behavior on Windows. --- pipenv/cli.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 2fb415f9..3da5938f 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -992,18 +992,18 @@ def run(command, args, three=None, python=False): command_path = which(command) - try: - c = os.execl(command_path, command_path, *args) - except FileNotFoundError: + if not os.path.exists(command_path): click.echo(crayons.red('The command ({0}) was not found within the virtualenv!'.format(command_path))) sys.exit(1) - # Windows! - except AttributeError: + if os.name == 'nt': + # Windows! import subprocess p = subprocess.Popen([command_path] + list(args), shell=True, universal_newlines=True) p.communicate() sys.exit(p.returncode) + else: + os.execl(command_path, command_path, *args) @click.command(help="Checks PEP 508 markers provided in Pipfile.") From 2fe5d2efd609a3eb5af99d361c1e02c31de6402f Mon Sep 17 00:00:00 2001 From: nonylene Date: Thu, 20 Apr 2017 02:32:03 +0900 Subject: [PATCH 3/3] change comment position --- pipenv/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 3da5938f..96753462 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -996,8 +996,8 @@ def run(command, args, three=None, python=False): click.echo(crayons.red('The command ({0}) was not found within the virtualenv!'.format(command_path))) sys.exit(1) + # Windows! if os.name == 'nt': - # Windows! import subprocess p = subprocess.Popen([command_path] + list(args), shell=True, universal_newlines=True) p.communicate()