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 5513ae1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
10 changes: 10 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
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 5513ae1

Please sign in to comment.