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
dad75f6c
Unverified
Commit
dad75f6c
authored
Oct 15, 2018
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for optional scripts
parent
48ed586b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
64 additions
and
21 deletions
+64
-21
CHANGELOG.md
+1
-0
poetry/console/commands/run.py
+3
-0
poetry/json/schemas/poetry-schema.json
+35
-0
poetry/masonry/builders/builder.py
+6
-1
poetry/poetry.py
+16
-0
tests/masonry/builders/fixtures/complete/pyproject.toml
+1
-0
tests/masonry/builders/test_complete.py
+1
-0
tests/masonry/builders/test_sdist.py
+1
-20
No files found.
CHANGELOG.md
View file @
dad75f6c
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
-
Added a cache version system.
-
Added a cache version system.
-
Added a
`--lock`
option to
`update`
to only update the lock file without executing operations.
-
Added a
`--lock`
option to
`update`
to only update the lock file without executing operations.
-
Added support for the
`Project-URL`
metadata.
-
Added support for the
`Project-URL`
metadata.
-
Added support for optional scripts.
### Changed
### Changed
...
...
poetry/console/commands/run.py
View file @
dad75f6c
...
@@ -20,6 +20,9 @@ class RunCommand(EnvCommand):
...
@@ -20,6 +20,9 @@ class RunCommand(EnvCommand):
return
self
.
env
.
execute
(
*
args
)
return
self
.
env
.
execute
(
*
args
)
def
run_script
(
self
,
script
,
args
):
def
run_script
(
self
,
script
,
args
):
if
isinstance
(
script
,
dict
):
script
=
script
[
"callable"
]
module
,
callable_
=
script
.
split
(
":"
)
module
,
callable_
=
script
.
split
(
":"
)
src_in_sys_path
=
"sys.path.append('src'); "
if
self
.
_module
.
is_in_src
()
else
""
src_in_sys_path
=
"sys.path.append('src'); "
if
self
.
_module
.
is_in_src
()
else
""
...
...
poetry/json/schemas/poetry-schema.json
View file @
dad75f6c
...
@@ -371,6 +371,41 @@
...
@@ -371,6 +371,41 @@
]
]
}
}
},
},
"scripts"
:
{
"type"
:
"object"
,
"patternProperties"
:
{
"^[a-zA-Z-_.0-9]+$"
:
{
"oneOf"
:
[
{
"$ref"
:
"#/definitions/script"
},
{
"$ref"
:
"#/definitions/extra-script"
}
]
}
}
},
"script"
:
{
"type"
:
"string"
,
"description"
:
"A simple script pointing to a callable object."
},
"extra-script"
:
{
"type"
:
"object"
,
"description"
:
"A script that should be installed only if extras are activated."
,
"properties"
:
{
"callable"
:
{
"$ref"
:
"#/definitions/script"
},
"extras"
:
{
"type"
:
"array"
,
"description"
:
"The required extras for this script."
,
"items"
:
{
"type"
:
"string"
}
}
}
},
"repository"
:
{
"repository"
:
{
"type"
:
"object"
,
"type"
:
"object"
,
"properties"
:
{
"properties"
:
{
...
...
poetry/masonry/builders/builder.py
View file @
dad75f6c
...
@@ -138,7 +138,12 @@ class Builder(object):
...
@@ -138,7 +138,12 @@ class Builder(object):
# Scripts -> Entry points
# Scripts -> Entry points
for
name
,
ep
in
self
.
_poetry
.
local_config
.
get
(
"scripts"
,
{})
.
items
():
for
name
,
ep
in
self
.
_poetry
.
local_config
.
get
(
"scripts"
,
{})
.
items
():
result
[
"console_scripts"
]
.
append
(
"{} = {}"
.
format
(
name
,
ep
))
extras
=
""
if
isinstance
(
ep
,
dict
):
extras
=
"[{}]"
.
format
(
", "
.
join
(
ep
[
"extras"
]))
ep
=
ep
[
"callable"
]
result
[
"console_scripts"
]
.
append
(
"{} = {}{}"
.
format
(
name
,
ep
,
extras
))
# Plugins -> entry points
# Plugins -> entry points
plugins
=
self
.
_poetry
.
local_config
.
get
(
"plugins"
,
{})
plugins
=
self
.
_poetry
.
local_config
.
get
(
"plugins"
,
{})
...
...
poetry/poetry.py
View file @
dad75f6c
...
@@ -215,4 +215,20 @@ class Poetry:
...
@@ -215,4 +215,20 @@ class Poetry:
"Consider specifying a more explicit one."
"Consider specifying a more explicit one."
)
)
# Checking for scripts with extras
if
"scripts"
in
config
:
scripts
=
config
[
"scripts"
]
for
name
,
script
in
scripts
.
items
():
if
not
isinstance
(
script
,
dict
):
continue
extras
=
script
[
"extras"
]
for
extra
in
extras
:
if
extra
not
in
config
[
"extras"
]:
result
[
"errors"
]
.
append
(
'Script "{}" requires extra "{}" which is not defined.'
.
format
(
name
,
extra
)
)
return
result
return
result
tests/masonry/builders/fixtures/complete/pyproject.toml
View file @
dad75f6c
...
@@ -37,3 +37,4 @@ time = ["pendulum"]
...
@@ -37,3 +37,4 @@ time = ["pendulum"]
[tool.poetry.scripts]
[tool.poetry.scripts]
my-script
=
"my_package:main"
my-script
=
"my_package:main"
my-2nd-script
=
"my_package:main2"
my-2nd-script
=
"my_package:main2"
extra-script
=
{callable
=
"my_package.extra:main"
,
extras
=
["time"]
}
tests/masonry/builders/test_complete.py
View file @
dad75f6c
...
@@ -107,6 +107,7 @@ def test_complete():
...
@@ -107,6 +107,7 @@ def test_complete():
decode
(
entry_points
.
decode
())
decode
(
entry_points
.
decode
())
==
"""
\
==
"""
\
[console_scripts]
[console_scripts]
extra-script=my_package.extra:main[time]
my-2nd-script=my_package:main2
my-2nd-script=my_package:main2
my-script=my_package:main
my-script=my_package:main
...
...
tests/masonry/builders/test_sdist.py
View file @
dad75f6c
...
@@ -121,6 +121,7 @@ def test_make_setup():
...
@@ -121,6 +121,7 @@ def test_make_setup():
assert
ns
[
"install_requires"
]
==
[
"cachy[msgpack]>=0.2.0,<0.3.0"
,
"cleo>=0.6,<0.7"
]
assert
ns
[
"install_requires"
]
==
[
"cachy[msgpack]>=0.2.0,<0.3.0"
,
"cleo>=0.6,<0.7"
]
assert
ns
[
"entry_points"
]
==
{
assert
ns
[
"entry_points"
]
==
{
"console_scripts"
:
[
"console_scripts"
:
[
"extra-script = my_package.extra:main[time]"
,
"my-2nd-script = my_package:main2"
,
"my-2nd-script = my_package:main2"
,
"my-script = my_package:main"
,
"my-script = my_package:main"
,
]
]
...
@@ -222,26 +223,6 @@ def test_make_pkg_info_multi_constraints_dependency():
...
@@ -222,26 +223,6 @@ def test_make_pkg_info_multi_constraints_dependency():
]
]
def
test_find_files_to_add
():
poetry
=
Poetry
.
create
(
project
(
"complete"
))
builder
=
SdistBuilder
(
poetry
,
NullEnv
(),
NullIO
())
result
=
builder
.
find_files_to_add
()
assert
sorted
(
result
)
==
sorted
(
[
Path
(
"LICENSE"
),
Path
(
"README.rst"
),
Path
(
"my_package/__init__.py"
),
Path
(
"my_package/data1/test.json"
),
Path
(
"my_package/sub_pkg1/__init__.py"
),
Path
(
"my_package/sub_pkg2/__init__.py"
),
Path
(
"my_package/sub_pkg2/data2/data.json"
),
Path
(
"pyproject.toml"
),
]
)
def
test_find_packages
():
def
test_find_packages
():
poetry
=
Poetry
.
create
(
project
(
"complete"
))
poetry
=
Poetry
.
create
(
project
(
"complete"
))
...
...
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