Skip to content

Commit

Permalink
add --dev option to poetry install to install specific dev depend…
Browse files Browse the repository at this point in the history
…ency
  • Loading branch information
finswimmer committed Jan 30, 2021
1 parent a104970 commit ecaf7eb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ by passing the `--dev-only` option. Note that `--no-dev` takes priority if both
poetry install --dev-only
```

If not all development dependencies should be installed, but only a specific list, you can do this py passing
the `--dev` option. This option can be used multiple times. If only development dependencies should be used, you
can use this option together with the `--dev-only` option.

```bash
poetry install --dev black
poetry install --dev black --dev isort
poetry install --dev-only --dev black
```

If you want to remove old dependencies no longer present in the lock file, use the
`--remove-untracked` option.

Expand Down Expand Up @@ -156,6 +166,7 @@ option is passed.

* `--no-dev`: Do not install dev dependencies.
* `--dev-only`: Only install dev dependencies.
* `--dev`: Only install listed development dependencies.
* `--no-root`: Do not install the root package (your project).
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
* `--remove-untracked`: Remove dependencies not presented in the lock file
Expand Down
8 changes: 8 additions & 0 deletions poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class InstallCommand(InstallerCommand):
options = [
option("no-dev", None, "Do not install the development dependencies."),
option("dev-only", None, "Only install the development dependencies."),
option(
"dev",
None,
"Only install listed development dependencies.",
flag=False,
multiple=True,
),
option(
"no-root", None, "Do not install the root package (the current project)."
),
Expand Down Expand Up @@ -66,6 +73,7 @@ def handle(self): # type: () -> int
self._installer.extras(extras)
self._installer.dev_mode(not self.option("no-dev"))
self._installer.dev_only(self.option("dev-only"))
self._installer.dev_dependencies(self.option("dev"))
self._installer.dry_run(self.option("dry-run"))
self._installer.remove_untracked(self.option("remove-untracked"))
self._installer.verbose(self._io.is_verbose())
Expand Down
14 changes: 14 additions & 0 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def __init__(

self._extras = []

self._dev_dependencies = []

if executor is None:
executor = Executor(self._env, self._pool, config, self._io)

Expand Down Expand Up @@ -150,6 +152,11 @@ def dev_only(self, dev_only=False): # type: (bool) -> Installer

return self

def dev_dependencies(self, dev_dependencies): # type: (List[str]) -> Installer
self._dev_dependencies = dev_dependencies

return self

def is_dev_only(self): # type: () -> bool
return self._dev_only

Expand Down Expand Up @@ -291,6 +298,13 @@ def _do_install(self, local_repo): # type: (Repository) -> int
root = root.clone()
del root.requires[:]

if self._dev_dependencies:
root.dev_requires = [
package
for package in root.dev_requires
if package.name in self._dev_dependencies
]

if self._io.is_verbose():
self._io.write_line("")
self._io.write_line(
Expand Down

0 comments on commit ecaf7eb

Please sign in to comment.