Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace poetry plugin commands with more generic poetry self commands #5450

Merged
merged 12 commits into from
May 30, 2022
187 changes: 140 additions & 47 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -710,53 +710,6 @@ To only remove a specific package from a cache, you have to specify the cache en
poetry cache clear pypi:requests:2.24.0
```

## plugin

The `plugin` namespace regroups sub commands to manage Poetry plugins.

### `plugin add`

The `plugin add` command installs Poetry plugins and make them available at runtime.

For example, to install the `poetry-plugin` plugin, you can run:

```bash
poetry plugin add poetry-plugin
```

The package specification formats supported by the `plugin add` command are the same as the ones supported
by the [`add` command](#add).

If you just want to check what would happen by installing a plugin, you can use the `--dry-run` option

```bash
poetry plugin add poetry-plugin --dry-run
```

#### Options

* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables --verbose).

### `plugin show`

The `plugin show` command lists all the currently installed plugins.

```bash
poetry plugin show
```

### `plugin remove`

The `plugin remove` command removes installed plugins.

```bash
poetry plugin remove poetry-plugin
```

#### Options

* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables --verbose).

## source

The `source` namespace regroups sub commands to manage repository sources for a Poetry project.
Expand Down Expand Up @@ -851,3 +804,143 @@ The `list` command displays all the available Poetry commands.
```bash
poetry list
```

## self

The `self` namespace regroups sub commands to manage the Poetry installation itself.

{{% note %}}
Use of these commands will create the required `pyproject.toml` and `poetry.lock` files in your
[configuration directory]({{< relref "configuration" >}}).
{{% /note %}}

### `self add`

The `self add` command installs Poetry plugins and make them available at runtime. Additionally, it can
also be used to upgrade Poetry's own dependencies or inject additional packages into the runtime
environment

{{% note %}}
The `self add` command works exactly like the [`add` command](#add). However, is different in that the packages
managed are for Poetry's runtime environment.

The package specification formats supported by the `self add` command are the same as the ones supported
by the [`add` command](#add).
{{% /note %}}

For example, to install the `poetry-plugin-export` plugin, you can run:

```bash
poetry self add poetry-plugin-export
```

To update to the latest `poetry-core` version, you can run:

```bash
poetry self add poetry-core@latest
```

To add a keyring provider `artifacts-keyring`, you can run:

```bash
poetry self add artifacts-keyring
```

### Options

* `--editable (-e)`: Add vcs/path dependencies as editable.
* `--extras (-E)`: Extras to activate for the dependency. (multiple values allowed)
* `--allow-prereleases`: Accept prereleases.
* `--source`: Name of the source to use to install the package.
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).

### `self update`

The `self update` command updates Poetry version in its current runtime environment.

{{% note %}}
The `self update` command works exactly like the [`update` command](#update). However,
is different in that the packages managed are for Poetry's runtime environment.
{{% /note %}}

```bash
poetry self update
```

### Options

* `--preview`: Allow the installation of pre-release versions.
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).

### `self lock`

The `self lock` command reads this Poetry installation's system `pyproject.toml` file. The system
dependencies are locked in the corresponding `poetry.lock` file.

```bash
poetry self lock
```

### Options

* `--check`: Verify that `poetry.lock` is consistent with `pyproject.toml`
* `--no-update`: Do not update locked versions, only refresh lock file.

### `self show`

The `self show` command behaves similar to the show command, but
working within Poetry's runtime environment. This lists all packages installed within
the Poetry install environment.

To show only additional packages that have been added via self add and their
dependencies use `self show --addons`.

```bash
poetry self show
```

### Options

* `--addons`: List only add-on packages installed.
* `--tree`: List the dependencies as a tree.
* `--latest (-l)`: Show the latest version.
* `--outdated (-o)`: Show the latest version but only for packages that are outdated.

### `self show plugins`

The `self show plugins` command lists all the currently installed plugins.

```bash
poetry self show plugins
```

### `self remove`

The `self remove` command removes an installed addon package.

```bash
poetry self remove poetry-plugin-export
```

#### Options

* `--dry-run`: Outputs the operations but will not execute anything (implicitly enables --verbose).

### `self install`

The `self install` command ensures all additional packages specified are installed in the current
runtime environment.

{{% note %}}
The `self install` command works similar to the [`install` command](#install). However,
is different in that the packages managed are for Poetry's runtime environment.
{{% /note %}}

```bash
poetry self install --sync
```

### Options

* `--sync`: Synchronize the environment with the locked packages and the specified groups.
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
14 changes: 7 additions & 7 deletions docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,30 +191,30 @@ Installed plugin packages are automatically loaded when Poetry starts up.

You have multiple ways to install plugins for Poetry

### The `plugin add` command
### The `self add` command

This is the easiest way and should account for all the ways Poetry can be installed.

```bash
poetry plugin add poetry-plugin
poetry self add poetry-plugin
```

The `plugin add` command will ensure that the plugin is compatible with the current version of Poetry
The `self add` command will ensure that the plugin is compatible with the current version of Poetry
and install the needed packages for the plugin to work.

The package specification formats supported by the `plugin add` command are the same as the ones supported
The package specification formats supported by the `self add` command are the same as the ones supported
by the [`add` command]({{< relref "cli#add" >}}).

If you no longer need a plugin and want to uninstall it, you can use the `plugin remove` command.
If you no longer need a plugin and want to uninstall it, you can use the `self remove` command.

```shell
poetry plugin remove poetry-plugin
poetry self remove poetry-plugin
```

You can also list all currently installed plugins by running:

```shell
poetry plugin show
poetry self show
```

### With `pipx inject`
Expand Down
18 changes: 13 additions & 5 deletions src/poetry/console/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ def _load() -> type[Command]:
"plugin remove",
"plugin show",
# Self commands
"self add",
"self install",
"self lock",
"self remove",
"self update",
"self show",
"self show plugins",
# Source commands
"source add",
"source remove",
Expand All @@ -104,7 +110,7 @@ def __init__(self) -> None:
dispatcher = EventDispatcher()
dispatcher.add_listener(COMMAND, self.register_command_loggers)
dispatcher.add_listener(COMMAND, self.configure_env)
dispatcher.add_listener(COMMAND, self.configure_installer)
dispatcher.add_listener(COMMAND, self.configure_installer_for_event)
self.set_event_dispatcher(dispatcher)

command_loader = CommandLoader({name: load_command(name) for name in COMMANDS})
Expand Down Expand Up @@ -296,8 +302,9 @@ def configure_env(

command.set_env(env)

def configure_installer(
self, event: ConsoleCommandEvent, event_name: str, _: Any
@classmethod
def configure_installer_for_event(
cls, event: ConsoleCommandEvent, event_name: str, _: Any
) -> None:
from poetry.console.commands.installer_command import InstallerCommand

Expand All @@ -310,9 +317,10 @@ def configure_installer(
if command.installer is not None:
return

self._configure_installer(command, event.io)
cls.configure_installer_for_command(command, event.io)

def _configure_installer(self, command: InstallerCommand, io: IO) -> None:
@staticmethod
def configure_installer_for_command(command: InstallerCommand, io: IO) -> None:
from poetry.installation.installer import Installer

poetry = command.poetry
Expand Down
25 changes: 16 additions & 9 deletions src/poetry/console/commands/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ class AddCommand(InstallerCommand, InitCommand):
),
option("lock", None, "Do not perform operations (only update the lockfile)."),
]
help = """\
The add command adds required packages to your <comment>pyproject.toml</> and installs\
them.

examples = """\
If you do not specify a version constraint, poetry will choose a suitable one based on\
the available package versions.

Expand All @@ -91,6 +88,12 @@ class AddCommand(InstallerCommand, InitCommand):
- A file path (<b>../my-package/my-package.whl</b>)
- A directory (<b>../my-package/</b>)
- A url (<b>https://example.com/packages/my-package-0.1.0.tar.gz</b>)
"""
help = f"""\
The add command adds required packages to your <comment>pyproject.toml</> and installs\
them.

{examples}
"""

loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"]
Expand Down Expand Up @@ -275,15 +278,19 @@ def get_existing_packages_from_input(

return existing_packages

@property
def _hint_update_packages(self) -> str:
return (
"\nIf you want to update it to the latest compatible version, you can use"
" `poetry update package`.\nIf you prefer to upgrade it to the latest"
" available version, you can use `poetry add package@latest`.\n"
)

def notify_about_existing_packages(self, existing_packages: list[str]) -> None:
self.line(
"The following packages are already present in the pyproject.toml and will"
" be skipped:\n"
)
for name in existing_packages:
self.line(f" • <c1>{name}</c1>")
self.line(
"\nIf you want to update it to the latest compatible version, you can use"
" `poetry update package`.\nIf you prefer to upgrade it to the latest"
" available version, you can use `poetry add package@latest`.\n"
)
self.line(self._hint_update_packages)
2 changes: 1 addition & 1 deletion src/poetry/console/commands/group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def activated_groups(self) -> set[str]:
for key in {"with", "without", "only"}:
groups[key] = {
group.strip()
for groups in self.option(key)
for groups in self.option(key, "")
for group in groups.split(",")
}

Expand Down
Loading