properly handle command-line arguments with spaces
This commit is contained in:
parent
df415ebbe3
commit
2123571f3c
|
@ -1,5 +1,5 @@
|
|||
__software__ = 'PyVenv'
|
||||
__version__ = '0.1.4'
|
||||
__version__ = '0.1.5'
|
||||
|
||||
|
||||
from .env import PythonEnvironment
|
||||
|
|
|
@ -96,13 +96,11 @@ def cli_run(ctx, command):
|
|||
if len(command) == 0:
|
||||
return click.echo('Script or module name not provided')
|
||||
|
||||
cmd = ' '.join(command)
|
||||
|
||||
if Path(command[0]).is_file():
|
||||
ctx.obj.run_script(cmd)
|
||||
ctx.obj.run_script(command)
|
||||
|
||||
else:
|
||||
ctx.obj.run_module(cmd)
|
||||
ctx.obj.run_module(command)
|
||||
|
||||
|
||||
@cli.command('import')
|
||||
|
|
|
@ -250,23 +250,36 @@ class PythonEnvironment(EnvBuilder):
|
|||
|
||||
|
||||
def run_module(self, module, *args, **kwargs):
|
||||
text = f'-m {module}'
|
||||
if isinstance(module, (list, tuple)):
|
||||
module = ['-m', *module]
|
||||
|
||||
for arg in args:
|
||||
text += f' {arg}'
|
||||
elif isinstance(module, str):
|
||||
module = f'-m {module}'
|
||||
|
||||
return self.run_python(text)
|
||||
else:
|
||||
raise TypeError(f'command must be a list, tuple, or str, not {type(module).__name__}')
|
||||
|
||||
return self.run_python(module, *args, **kwargs)
|
||||
|
||||
|
||||
def run_python(self, command, **kwargs):
|
||||
if not self.executable.exists():
|
||||
raise FileNotFoundError('Cannot find python executable. Was the environment created?')
|
||||
|
||||
return Process(f'{self.executable} {command}', **kwargs)
|
||||
if isinstance(command, (list, tuple)):
|
||||
command = [self.executable, *command]
|
||||
|
||||
elif isinstance(command, str):
|
||||
command = f'{self.executable} {command}'
|
||||
|
||||
else:
|
||||
raise TypeError(f'command must be a list, tuple, or str, not {type(command).__name__}')
|
||||
|
||||
return Process(command, **kwargs)
|
||||
|
||||
|
||||
def run_script(self, script):
|
||||
return self.run_python(script)
|
||||
def run_script(self, script, *args, **kwargs):
|
||||
return self.run_python(script, *args, **kwargs)
|
||||
|
||||
|
||||
def save_config(self):
|
||||
|
|
Loading…
Reference in a new issue