use os.execl to "run" subcommand on Unix

see https://github.com/kennethreitz/pipenv/issues/315
This commit is contained in:
nonylene
2017-04-20 01:16:24 +09:00
parent 7b17058661
commit d5e5eca86e
+6 -18
View File
@@ -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.")