Commit 06a2bd17 by Sébastien Eustace

Merge run and script

parent 1dd12f7d
......@@ -13,6 +13,7 @@
### Changed
- Improved the `show` command to make it easier to check if packages are properly installed.
- The `script` command has been deprecated, use `run` instead.
- Expanded version constraints now keep the original version's precision.
### Fixed
......
......@@ -289,11 +289,7 @@ The `run` command executes the given command inside the project's virtualenv.
poetry run python -V
```
Note that this command has no option.
## script
The `script` executes one of the scripts defined in `pyproject.toml`.
It can also executes one of the scripts defined in `pyproject.toml`.
So, if you have a script defined like this:
......@@ -305,7 +301,7 @@ my-script = "my_module:main"
You can execute it like so:
```bash
poetry script my-script
poetry run my-script
```
Note that this command has no option.
......
......@@ -11,11 +11,47 @@ class RunCommand(VenvCommand):
def handle(self):
args = self.argument('args')
script = args[0]
scripts = self.poetry.local_config.get('scripts')
if scripts and script in scripts:
return self.run_script(scripts[script], args)
venv = self.venv
return venv.execute(*args)
def run_script(self, script, args):
module, callable_ = script.split(':')
src_in_sys_path = 'sys.path.append(\'src\'); ' \
if self._module.is_in_src() else ''
cmd = ['python', '-c']
cmd += [
'"import sys; '
'from importlib import import_module; '
'sys.argv = {!r}; {}'
'import_module(\'{}\').{}()"'.format(
args, src_in_sys_path, module, callable_
)
]
return self.venv.run(*cmd, shell=True, call=True)
@property
def _module(self):
from ...masonry.utils.module import Module
poetry = self.poetry
package = poetry.package
path = poetry.file.parent
module = Module(
package.name, path.as_posix()
)
return module
def merge_application_definition(self, merge_args=True):
if self._application is None \
or (self._application_definition_merged
......
import sys
from ...masonry.utils.module import Module
from .venv_command import VenvCommand
class ScriptCommand(VenvCommand):
"""
Executes a script defined in <comment>pyproject.toml</comment>
Executes a script defined in <comment>pyproject.toml</comment>. (<error>Deprecated</error>)
script
{ script-name : The name of the script to execute }
......@@ -14,6 +11,9 @@ class ScriptCommand(VenvCommand):
"""
def handle(self):
self.line('<warning>script is deprecated use run instead.</warning>')
self.line('')
script = self.argument('script-name')
argv = [script] + self.argument('args')
......@@ -44,6 +44,8 @@ class ScriptCommand(VenvCommand):
@property
def _module(self):
from ...masonry.utils.module import Module
poetry = self.poetry
package = poetry.package
path = poetry.file.parent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment