Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
python-poetry
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
python-poetry
Commits
c824c630
Unverified
Commit
c824c630
authored
Apr 03, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the script command
parent
0f25e1b5
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
5 deletions
+93
-5
CHANGELOG.md
+1
-0
docs/docs/cli.md
+19
-0
poetry/console/application.py
+4
-2
poetry/console/commands/__init__.py
+1
-0
poetry/console/commands/script.py
+54
-0
poetry/packages/locker.py
+0
-2
poetry/utils/venv.py
+14
-1
No files found.
CHANGELOG.md
View file @
c824c630
...
@@ -8,6 +8,7 @@
...
@@ -8,6 +8,7 @@
-
Added the
`version`
command to automatically bump the package's version.
-
Added the
`version`
command to automatically bump the package's version.
-
Added a standalone installer to install
`poetry`
isolated.
-
Added a standalone installer to install
`poetry`
isolated.
-
Added support for classifiers in
`pyproject.toml`
.
-
Added support for classifiers in
`pyproject.toml`
.
-
Added the
`script`
command.
### Changed
### Changed
...
...
docs/docs/cli.md
View file @
c824c630
...
@@ -253,6 +253,25 @@ poetry run python -V
...
@@ -253,6 +253,25 @@ poetry run python -V
Note that this command has no option.
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
## check
The `
check
` command validate the structure of the `
pyproject.toml
` file
The `
check
` command validate the structure of the `
pyproject.toml
` file
...
...
poetry/console/application.py
View file @
c824c630
...
@@ -19,6 +19,7 @@ from .commands import NewCommand
...
@@ -19,6 +19,7 @@ from .commands import NewCommand
from
.commands
import
PublishCommand
from
.commands
import
PublishCommand
from
.commands
import
RemoveCommand
from
.commands
import
RemoveCommand
from
.commands
import
RunCommand
from
.commands
import
RunCommand
from
.commands
import
ScriptCommand
from
.commands
import
ShowCommand
from
.commands
import
ShowCommand
from
.commands
import
UpdateCommand
from
.commands
import
UpdateCommand
from
.commands
import
VersionCommand
from
.commands
import
VersionCommand
...
@@ -57,7 +58,7 @@ class Application(BaseApplication):
...
@@ -57,7 +58,7 @@ class Application(BaseApplication):
o
=
ConsoleOutput
()
o
=
ConsoleOutput
()
name
=
i
.
get_first_argument
()
name
=
i
.
get_first_argument
()
if
name
==
'run'
:
if
name
in
[
'run'
,
'script'
]
:
self
.
_skip_io_configuration
=
True
self
.
_skip_io_configuration
=
True
i
=
RawArgvInput
()
i
=
RawArgvInput
()
...
@@ -66,7 +67,7 @@ class Application(BaseApplication):
...
@@ -66,7 +67,7 @@ class Application(BaseApplication):
def
do_run
(
self
,
i
,
o
):
def
do_run
(
self
,
i
,
o
):
name
=
self
.
get_command_name
(
i
)
name
=
self
.
get_command_name
(
i
)
if
name
!=
'run'
:
if
name
not
in
[
'run'
,
'script'
]
:
return
super
()
.
do_run
(
i
,
o
)
return
super
()
.
do_run
(
i
,
o
)
command
=
self
.
find
(
name
)
command
=
self
.
find
(
name
)
...
@@ -98,6 +99,7 @@ class Application(BaseApplication):
...
@@ -98,6 +99,7 @@ class Application(BaseApplication):
PublishCommand
(),
PublishCommand
(),
RemoveCommand
(),
RemoveCommand
(),
RunCommand
(),
RunCommand
(),
ScriptCommand
(),
ShowCommand
(),
ShowCommand
(),
UpdateCommand
(),
UpdateCommand
(),
VersionCommand
(),
VersionCommand
(),
...
...
poetry/console/commands/__init__.py
View file @
c824c630
...
@@ -9,6 +9,7 @@ from .new import NewCommand
...
@@ -9,6 +9,7 @@ from .new import NewCommand
from
.publish
import
PublishCommand
from
.publish
import
PublishCommand
from
.remove
import
RemoveCommand
from
.remove
import
RemoveCommand
from
.run
import
RunCommand
from
.run
import
RunCommand
from
.script
import
ScriptCommand
from
.show
import
ShowCommand
from
.show
import
ShowCommand
from
.update
import
UpdateCommand
from
.update
import
UpdateCommand
from
.version
import
VersionCommand
from
.version
import
VersionCommand
poetry/console/commands/script.py
0 → 100644
View file @
c824c630
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
poetry/packages/locker.py
View file @
c824c630
...
@@ -15,8 +15,6 @@ class Locker:
...
@@ -15,8 +15,6 @@ class Locker:
_relevant_keys
=
[
_relevant_keys
=
[
'name'
,
'name'
,
'version'
,
'version'
,
'python-versions'
,
'platform'
,
'dependencies'
,
'dependencies'
,
'dev-dependencies'
,
'dev-dependencies'
,
'source'
,
'source'
,
...
...
poetry/utils/venv.py
View file @
c824c630
...
@@ -201,18 +201,25 @@ class Venv:
...
@@ -201,18 +201,25 @@ class Venv:
return
value
return
value
def
run
(
self
,
bin
:
str
,
*
args
,
**
kwargs
)
->
str
:
def
run
(
self
,
bin
:
str
,
*
args
,
**
kwargs
):
"""
"""
Run a command inside the virtual env.
Run a command inside the virtual env.
"""
"""
cmd
=
[
bin
]
+
list
(
args
)
cmd
=
[
bin
]
+
list
(
args
)
shell
=
kwargs
.
get
(
'shell'
,
False
)
shell
=
kwargs
.
get
(
'shell'
,
False
)
call
=
kwargs
.
pop
(
'call'
,
False
)
if
shell
:
if
shell
:
cmd
=
' '
.
join
(
cmd
)
cmd
=
' '
.
join
(
cmd
)
try
:
try
:
if
not
self
.
is_venv
():
if
not
self
.
is_venv
():
if
call
:
return
subprocess
.
call
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
output
=
subprocess
.
check_output
(
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
**
kwargs
...
@@ -228,6 +235,12 @@ class Venv:
...
@@ -228,6 +235,12 @@ class Venv:
self
.
unset_env
(
'PYTHONHOME'
)
self
.
unset_env
(
'PYTHONHOME'
)
self
.
unset_env
(
'__PYVENV_LAUNCHER__'
)
self
.
unset_env
(
'__PYVENV_LAUNCHER__'
)
if
call
:
return
subprocess
.
call
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
)
output
=
subprocess
.
check_output
(
output
=
subprocess
.
check_output
(
cmd
,
stderr
=
subprocess
.
STDOUT
,
cmd
,
stderr
=
subprocess
.
STDOUT
,
**
kwargs
**
kwargs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment