Loading CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ - Added the `version` command to automatically bump the package's version. - Added a standalone installer to install `poetry` isolated. - Added support for classifiers in `pyproject.toml`. - Added the `script` command. ### Changed Loading docs/docs/cli.md +19 −0 Original line number Diff line number Diff line Loading @@ -253,6 +253,25 @@ poetry run python -V Note that this command has no option. ## script The `script` executes one of the scripts defined in `pyproject.toml`. So, if you have a script defined like this: ```toml [tool.poetry.scripts] my-script = "my_module:main" ``` You can execute it like so: ```bash poetry script my-script ``` Note that this command has no option. ## check The `check` command validate the structure of the `pyproject.toml` file Loading poetry/console/application.py +4 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ from .commands import NewCommand from .commands import PublishCommand from .commands import RemoveCommand from .commands import RunCommand from .commands import ScriptCommand from .commands import ShowCommand from .commands import UpdateCommand from .commands import VersionCommand Loading Loading @@ -57,7 +58,7 @@ class Application(BaseApplication): o = ConsoleOutput() name = i.get_first_argument() if name == 'run': if name in ['run', 'script']: self._skip_io_configuration = True i = RawArgvInput() Loading @@ -66,7 +67,7 @@ class Application(BaseApplication): def do_run(self, i, o): name = self.get_command_name(i) if name != 'run': if name not in ['run', 'script']: return super().do_run(i, o) command = self.find(name) Loading Loading @@ -98,6 +99,7 @@ class Application(BaseApplication): PublishCommand(), RemoveCommand(), RunCommand(), ScriptCommand(), ShowCommand(), UpdateCommand(), VersionCommand(), Loading poetry/console/commands/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ from .new import NewCommand from .publish import PublishCommand from .remove import RemoveCommand from .run import RunCommand from .script import ScriptCommand from .show import ShowCommand from .update import UpdateCommand from .version import VersionCommand poetry/console/commands/script.py 0 → 100644 +54 −0 Original line number Diff line number Diff line import sys from .venv_command import VenvCommand class ScriptCommand(VenvCommand): """ Executes a script defined in <comment>pyproject.toml</comment> script { script-name : The name of the script to execute } { args?* : The command and arguments/options to pass to the script. } """ def handle(self): script = self.argument('script-name') argv = [script] + self.argument('args') scripts = self.poetry.config.get('scripts') if not scripts: raise RuntimeError('No scripts defined in pyproject.toml') if script not in scripts: raise ValueError('Script {} is not defined'.format(script)) module, callable_ = scripts[script].split(':') cmd = ['python', '-c'] cmd += [ '"import sys; ' 'from importlib import import_module; ' 'sys.argv = {!r}; ' 'import_module(\'{}\').{}()"'.format( argv, module, callable_ ) ] self.venv.run(*cmd, shell=True, call=True) def merge_application_definition(self, merge_args=True): if self._application is None \ or (self._application_definition_merged and (self._application_definition_merged_with_args or not merge_args)): return if merge_args: current_arguments = self._definition.get_arguments() self._definition.set_arguments(self._application.get_definition().get_arguments()) self._definition.add_arguments(current_arguments) self._application_definition_merged = True if merge_args: self._application_definition_merged_with_args = True Loading
CHANGELOG.md +1 −0 Original line number Diff line number Diff line Loading @@ -8,6 +8,7 @@ - Added the `version` command to automatically bump the package's version. - Added a standalone installer to install `poetry` isolated. - Added support for classifiers in `pyproject.toml`. - Added the `script` command. ### Changed Loading
docs/docs/cli.md +19 −0 Original line number Diff line number Diff line Loading @@ -253,6 +253,25 @@ poetry run python -V Note that this command has no option. ## script The `script` executes one of the scripts defined in `pyproject.toml`. So, if you have a script defined like this: ```toml [tool.poetry.scripts] my-script = "my_module:main" ``` You can execute it like so: ```bash poetry script my-script ``` Note that this command has no option. ## check The `check` command validate the structure of the `pyproject.toml` file Loading
poetry/console/application.py +4 −2 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ from .commands import NewCommand from .commands import PublishCommand from .commands import RemoveCommand from .commands import RunCommand from .commands import ScriptCommand from .commands import ShowCommand from .commands import UpdateCommand from .commands import VersionCommand Loading Loading @@ -57,7 +58,7 @@ class Application(BaseApplication): o = ConsoleOutput() name = i.get_first_argument() if name == 'run': if name in ['run', 'script']: self._skip_io_configuration = True i = RawArgvInput() Loading @@ -66,7 +67,7 @@ class Application(BaseApplication): def do_run(self, i, o): name = self.get_command_name(i) if name != 'run': if name not in ['run', 'script']: return super().do_run(i, o) command = self.find(name) Loading Loading @@ -98,6 +99,7 @@ class Application(BaseApplication): PublishCommand(), RemoveCommand(), RunCommand(), ScriptCommand(), ShowCommand(), UpdateCommand(), VersionCommand(), Loading
poetry/console/commands/__init__.py +1 −0 Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ from .new import NewCommand from .publish import PublishCommand from .remove import RemoveCommand from .run import RunCommand from .script import ScriptCommand from .show import ShowCommand from .update import UpdateCommand from .version import VersionCommand
poetry/console/commands/script.py 0 → 100644 +54 −0 Original line number Diff line number Diff line import sys from .venv_command import VenvCommand class ScriptCommand(VenvCommand): """ Executes a script defined in <comment>pyproject.toml</comment> script { script-name : The name of the script to execute } { args?* : The command and arguments/options to pass to the script. } """ def handle(self): script = self.argument('script-name') argv = [script] + self.argument('args') scripts = self.poetry.config.get('scripts') if not scripts: raise RuntimeError('No scripts defined in pyproject.toml') if script not in scripts: raise ValueError('Script {} is not defined'.format(script)) module, callable_ = scripts[script].split(':') cmd = ['python', '-c'] cmd += [ '"import sys; ' 'from importlib import import_module; ' 'sys.argv = {!r}; ' 'import_module(\'{}\').{}()"'.format( argv, module, callable_ ) ] self.venv.run(*cmd, shell=True, call=True) def merge_application_definition(self, merge_args=True): if self._application is None \ or (self._application_definition_merged and (self._application_definition_merged_with_args or not merge_args)): return if merge_args: current_arguments = self._definition.get_arguments() self._definition.set_arguments(self._application.get_definition().get_arguments()) self._definition.add_arguments(current_arguments) self._application_definition_merged = True if merge_args: self._application_definition_merged_with_args = True