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
594697d5
Commit
594697d5
authored
Mar 08, 2021
by
Sébastien Eustace
Committed by
Arun Babu Neelicattu
Mar 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a `plugin show` command
parent
f5df3af9
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
278 additions
and
5 deletions
+278
-5
docs/docs/cli.md
+3
-3
docs/docs/plugins.md
+1
-1
poetry/console/application.py
+1
-0
poetry/console/commands/plugin/show.py
+95
-0
poetry/plugins/plugin_manager.py
+6
-1
tests/console/commands/plugin/test_show.py
+172
-0
No files found.
docs/docs/cli.md
View file @
594697d5
...
@@ -566,12 +566,12 @@ poetry plugin add poetry-plugin --dry-run
...
@@ -566,12 +566,12 @@ poetry plugin add poetry-plugin --dry-run
* `
--dry-run
`: Outputs the operations but will not execute anything (implicitly enables --verbose).
* `
--dry-run
`: Outputs the operations but will not execute anything (implicitly enables --verbose).
### `
plugin
list
`
### `
plugin
show
`
The `
plugin
list
` command lists all the currently installed plugins.
The `
plugin
show
` command lists all the currently installed plugins.
```bash
```bash
poetry plugin
list
poetry plugin
show
```
```
### `
plugin remove
`
### `
plugin remove
`
...
...
docs/docs/plugins.md
View file @
594697d5
...
@@ -199,7 +199,7 @@ poetry plugin remove poetry-plugin
...
@@ -199,7 +199,7 @@ poetry plugin remove poetry-plugin
You can also list all currently installed plugins by running:
You can also list all currently installed plugins by running:
```
shell
```
shell
poetry plugin
list
poetry plugin
show
```
```
### With `pipx inject`
### With `pipx inject`
...
...
poetry/console/application.py
View file @
594697d5
...
@@ -72,6 +72,7 @@ COMMANDS = [
...
@@ -72,6 +72,7 @@ COMMANDS = [
"env use"
,
"env use"
,
# Plugin commands
# Plugin commands
"plugin add"
,
"plugin add"
,
"plugin show"
,
# Self commands
# Self commands
"self update"
,
"self update"
,
]
]
...
...
poetry/console/commands/plugin/show.py
0 → 100644
View file @
594697d5
from
collections
import
defaultdict
from
typing
import
TYPE_CHECKING
from
typing
import
DefaultDict
from
typing
import
Dict
from
typing
import
List
from
typing
import
Union
from
poetry.console.commands.command
import
Command
if
TYPE_CHECKING
:
from
poetry.core.packages.package
import
Package
class
PluginShowCommand
(
Command
):
name
=
"plugin show"
description
=
"Shows information about the currently installed plugins."
def
handle
(
self
)
->
int
:
from
poetry.plugins.application_plugin
import
ApplicationPlugin
from
poetry.plugins.plugin_manager
import
PluginManager
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.utils.env
import
EnvManager
from
poetry.utils.helpers
import
canonicalize_name
plugins
:
DefaultDict
[
str
,
Dict
[
str
,
Union
[
"Package"
,
List
[
str
]]]]
=
defaultdict
(
lambda
:
{
"package"
:
None
,
"plugins"
:
[],
"application_plugins"
:
[],
}
)
entry_points
=
(
PluginManager
(
"application.plugin"
)
.
get_plugin_entry_points
()
+
PluginManager
(
"plugin"
)
.
get_plugin_entry_points
()
)
system_env
=
EnvManager
.
get_system_env
()
installed_repository
=
InstalledRepository
.
load
(
system_env
,
with_dependencies
=
True
)
packages_by_name
=
{
pkg
.
name
:
pkg
for
pkg
in
installed_repository
.
packages
}
for
entry_point
in
entry_points
:
plugin
=
entry_point
.
load
()
category
=
"plugins"
if
issubclass
(
plugin
,
ApplicationPlugin
):
category
=
"application_plugins"
package
=
packages_by_name
[
canonicalize_name
(
entry_point
.
name
)]
plugins
[
package
.
pretty_name
][
"package"
]
=
package
plugins
[
package
.
pretty_name
][
category
]
.
append
(
entry_point
)
for
name
,
info
in
plugins
.
items
():
package
=
info
[
"package"
]
self
.
line
(
""
)
self
.
line
(
" • <c1>{}</c1> (<c2>{}</c2>){}"
.
format
(
name
,
package
.
version
,
" "
+
package
.
description
if
package
.
description
else
""
,
)
)
provide_line
=
" "
if
info
[
"plugins"
]:
provide_line
+=
" <info>{}</info> plugin{}"
.
format
(
len
(
info
[
"plugins"
]),
"s"
if
len
(
info
[
"plugins"
])
>
1
else
""
)
if
info
[
"application_plugins"
]:
if
info
[
"plugins"
]:
provide_line
+=
" and"
provide_line
+=
" <info>{}</info> application plugin{}"
.
format
(
len
(
info
[
"application_plugins"
]),
"s"
if
len
(
info
[
"application_plugins"
])
>
1
else
""
,
)
self
.
line
(
provide_line
)
if
package
.
requires
:
self
.
line
(
""
)
self
.
line
(
" <info>Dependencies</info>"
)
for
dependency
in
package
.
requires
:
self
.
line
(
" - {} (<c2>{}</c2>)"
.
format
(
dependency
.
pretty_name
,
dependency
.
pretty_constraint
)
)
return
0
poetry/plugins/plugin_manager.py
View file @
594697d5
import
logging
import
logging
from
typing
import
List
import
entrypoints
import
entrypoints
from
.application_plugin
import
ApplicationPlugin
from
.application_plugin
import
ApplicationPlugin
...
@@ -23,11 +25,14 @@ class PluginManager(object):
...
@@ -23,11 +25,14 @@ class PluginManager(object):
if
self
.
_disable_plugins
:
if
self
.
_disable_plugins
:
return
return
plugin_entrypoints
=
entrypoints
.
get_group_all
(
"poetry.{}"
.
format
(
self
.
_type
)
)
plugin_entrypoints
=
self
.
get_plugin_entry_points
(
)
for
entrypoint
in
plugin_entrypoints
:
for
entrypoint
in
plugin_entrypoints
:
self
.
_load_plugin_entrypoint
(
entrypoint
)
self
.
_load_plugin_entrypoint
(
entrypoint
)
def
get_plugin_entry_points
(
self
)
->
List
[
entrypoints
.
EntryPoint
]:
return
entrypoints
.
get_group_all
(
"poetry.{}"
.
format
(
self
.
_type
))
def
add_plugin
(
self
,
plugin
):
# type: (Plugin) -> None
def
add_plugin
(
self
,
plugin
):
# type: (Plugin) -> None
if
not
isinstance
(
plugin
,
(
Plugin
,
ApplicationPlugin
)):
if
not
isinstance
(
plugin
,
(
Plugin
,
ApplicationPlugin
)):
raise
ValueError
(
raise
ValueError
(
...
...
tests/console/commands/plugin/test_show.py
0 → 100644
View file @
594697d5
import
pytest
from
entrypoints
import
EntryPoint
as
_EntryPoint
from
poetry.__version__
import
__version__
from
poetry.core.packages.package
import
Package
from
poetry.factory
import
Factory
from
poetry.plugins.application_plugin
import
ApplicationPlugin
from
poetry.plugins.plugin
import
Plugin
from
poetry.repositories.installed_repository
import
InstalledRepository
from
poetry.repositories.pool
import
Pool
from
poetry.utils.env
import
EnvManager
class
EntryPoint
(
_EntryPoint
):
def
load
(
self
):
if
"ApplicationPlugin"
in
self
.
object_name
:
return
ApplicationPlugin
return
Plugin
@pytest.fixture
()
def
tester
(
command_tester_factory
):
return
command_tester_factory
(
"plugin show"
)
@pytest.fixture
()
def
installed
():
repository
=
InstalledRepository
()
repository
.
add_package
(
Package
(
"poetry"
,
__version__
))
return
repository
def
configure_sources_factory
(
repo
):
def
_configure_sources
(
poetry
,
sources
,
config
,
io
):
pool
=
Pool
()
pool
.
add_repository
(
repo
)
poetry
.
set_pool
(
pool
)
return
_configure_sources
@pytest.fixture
(
autouse
=
True
)
def
setup_mocks
(
mocker
,
env
,
repo
,
installed
):
mocker
.
patch
.
object
(
EnvManager
,
"get_system_env"
,
return_value
=
env
)
mocker
.
patch
.
object
(
InstalledRepository
,
"load"
,
return_value
=
installed
)
mocker
.
patch
.
object
(
Factory
,
"configure_sources"
,
side_effect
=
configure_sources_factory
(
repo
)
)
def
test_show_displays_installed_plugins
(
app
,
tester
,
installed
,
mocker
):
mocker
.
patch
(
"entrypoints.get_group_all"
,
side_effect
=
[
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:ApplicationPlugin"
,
"FirstApplicationPlugin"
,
)
],
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:Plugin"
,
"FirstPlugin"
,
)
],
],
)
installed
.
add_package
(
Package
(
"poetry-plugin"
,
"1.2.3"
))
tester
.
execute
(
""
)
expected
=
"""
• poetry-plugin (1.2.3)
1 plugin and 1 application plugin
"""
assert
tester
.
io
.
fetch_output
()
==
expected
def
test_show_displays_installed_plugins_with_multiple_plugins
(
app
,
tester
,
installed
,
mocker
):
mocker
.
patch
(
"entrypoints.get_group_all"
,
side_effect
=
[
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:ApplicationPlugin"
,
"FirstApplicationPlugin"
,
),
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:ApplicationPlugin"
,
"SecondApplicationPlugin"
,
),
],
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:Plugin"
,
"FirstPlugin"
,
),
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:Plugin"
,
"SecondPlugin"
,
),
],
],
)
installed
.
add_package
(
Package
(
"poetry-plugin"
,
"1.2.3"
))
tester
.
execute
(
""
)
expected
=
"""
• poetry-plugin (1.2.3)
2 plugins and 2 application plugins
"""
assert
tester
.
io
.
fetch_output
()
==
expected
def
test_show_displays_installed_plugins_with_dependencies
(
app
,
tester
,
installed
,
mocker
):
mocker
.
patch
(
"entrypoints.get_group_all"
,
side_effect
=
[
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:ApplicationPlugin"
,
"FirstApplicationPlugin"
,
)
],
[
EntryPoint
(
"poetry-plugin"
,
"poetry_plugin.plugins:Plugin"
,
"FirstPlugin"
,
)
],
],
)
plugin
=
Package
(
"poetry-plugin"
,
"1.2.3"
)
plugin
.
add_dependency
(
Factory
.
create_dependency
(
"foo"
,
">=1.2.3"
))
plugin
.
add_dependency
(
Factory
.
create_dependency
(
"bar"
,
"<4.5.6"
))
installed
.
add_package
(
plugin
)
tester
.
execute
(
""
)
expected
=
"""
• poetry-plugin (1.2.3)
1 plugin and 1 application plugin
Dependencies
- foo (>=1.2.3)
- bar (<4.5.6)
"""
assert
tester
.
io
.
fetch_output
()
==
expected
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