Commit d2485b8f by Ryan Opel Committed by finswimmer

Add option to install only dev dependencies

Add an option to poetry install to install only dev dependencies,
e.g. poetry install --dev-only.

Fixes https://github.com/python-poetry/poetry/issues/2572
parent a106cb21
...@@ -109,6 +109,13 @@ the `--no-dev` option. ...@@ -109,6 +109,13 @@ the `--no-dev` option.
poetry install --no-dev poetry install --no-dev
``` ```
Conversely, you can specify to the command that you only want to install the development dependencies
by passing the `--dev-only` option. Note that `--no-dev` takes priority if both options are passed.
```bash
poetry install --dev-only
```
If you want to remove old dependencies no longer present in the lock file, use the If you want to remove old dependencies no longer present in the lock file, use the
`--remove-untracked` option. `--remove-untracked` option.
...@@ -142,9 +149,13 @@ If you want to skip this installation, use the `--no-root` option. ...@@ -142,9 +149,13 @@ If you want to skip this installation, use the `--no-root` option.
poetry install --no-root poetry install --no-root
``` ```
Installation of your project's package is also skipped when the `--dev-only`
option is passed.
### Options ### Options
* `--no-dev`: Do not install dev dependencies. * `--no-dev`: Do not install dev dependencies.
* `--dev-only`: Only install dev dependencies.
* `--no-root`: Do not install the root package (your project). * `--no-root`: Do not install the root package (your project).
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose). * `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
* `--remove-untracked`: Remove dependencies not presented in the lock file * `--remove-untracked`: Remove dependencies not presented in the lock file
......
...@@ -10,6 +10,7 @@ class InstallCommand(InstallerCommand): ...@@ -10,6 +10,7 @@ class InstallCommand(InstallerCommand):
options = [ options = [
option("no-dev", None, "Do not install the development dependencies."), option("no-dev", None, "Do not install the development dependencies."),
option("dev-only", None, "Only install the development dependencies."),
option( option(
"no-root", None, "Do not install the root package (the current project)." "no-root", None, "Do not install the root package (the current project)."
), ),
...@@ -64,6 +65,7 @@ dependencies and not including the current project, run the command with the ...@@ -64,6 +65,7 @@ dependencies and not including the current project, run the command with the
self._installer.extras(extras) self._installer.extras(extras)
self._installer.dev_mode(not self.option("no-dev")) self._installer.dev_mode(not self.option("no-dev"))
self._installer.dev_only(self.option("dev-only"))
self._installer.dry_run(self.option("dry-run")) self._installer.dry_run(self.option("dry-run"))
self._installer.remove_untracked(self.option("remove-untracked")) self._installer.remove_untracked(self.option("remove-untracked"))
self._installer.verbose(self._io.is_verbose()) self._installer.verbose(self._io.is_verbose())
...@@ -73,7 +75,7 @@ dependencies and not including the current project, run the command with the ...@@ -73,7 +75,7 @@ dependencies and not including the current project, run the command with the
if return_code != 0: if return_code != 0:
return return_code return return_code
if self.option("no-root"): if self.option("no-root") or self.option("dev-only"):
return 0 return 0
try: try:
......
...@@ -47,6 +47,7 @@ class Installer: ...@@ -47,6 +47,7 @@ class Installer:
self._verbose = False self._verbose = False
self._write_lock = True self._write_lock = True
self._dev_mode = True self._dev_mode = True
self._dev_only = False
self._execute_operations = True self._execute_operations = True
self._lock = False self._lock = False
...@@ -136,6 +137,14 @@ class Installer: ...@@ -136,6 +137,14 @@ class Installer:
def is_dev_mode(self): # type: () -> bool def is_dev_mode(self): # type: () -> bool
return self._dev_mode return self._dev_mode
def dev_only(self, dev_only=False): # type: (bool) -> Installer
self._dev_only = dev_only
return self
def is_dev_only(self): # type: () -> bool
return self._dev_only
def update(self, update=True): # type: (bool) -> Installer def update(self, update=True): # type: (bool) -> Installer
self._update = update self._update = update
...@@ -270,6 +279,9 @@ class Installer: ...@@ -270,6 +279,9 @@ class Installer:
if not self.is_dev_mode(): if not self.is_dev_mode():
root = root.clone() root = root.clone()
del root.dev_requires[:] del root.dev_requires[:]
elif self.is_dev_only():
root = root.clone()
del root.requires[:]
if self._io.is_verbose(): if self._io.is_verbose():
self._io.write_line("") self._io.write_line("")
......
...@@ -267,7 +267,10 @@ def test_run_update_after_removing_dependencies( ...@@ -267,7 +267,10 @@ def test_run_update_after_removing_dependencies(
assert 1 == installer.executor.removals_count assert 1 == installer.executor.removals_count
def test_run_install_no_dev(installer, locker, repo, package, installed): def _configure_run_install_dev(locker, repo, package, installed):
"""
Perform common test setup for `test_run_install_*dev*()` methods.
"""
locker.locked(True) locker.locked(True)
locker.mock_lock_data( locker.mock_lock_data(
{ {
...@@ -323,7 +326,34 @@ def test_run_install_no_dev(installer, locker, repo, package, installed): ...@@ -323,7 +326,34 @@ def test_run_install_no_dev(installer, locker, repo, package, installed):
package.add_dependency(Factory.create_dependency("B", "~1.1")) package.add_dependency(Factory.create_dependency("B", "~1.1"))
package.add_dependency(Factory.create_dependency("C", "~1.2", category="dev")) package.add_dependency(Factory.create_dependency("C", "~1.2", category="dev"))
def test_run_install_no_dev(installer, locker, repo, package, installed):
_configure_run_install_dev(locker, repo, package, installed)
installer.dev_mode(False)
installer.run()
assert 0 == installer.executor.installations_count
assert 0 == installer.executor.updates_count
assert 1 == installer.executor.removals_count
def test_run_install_dev_only(installer, locker, repo, package, installed):
_configure_run_install_dev(locker, repo, package, installed)
installer.dev_only(True)
installer.run()
assert 0 == installer.executor.installations_count
assert 0 == installer.executor.updates_count
assert 2 == installer.executor.removals_count
def test_run_install_no_dev_and_dev_only(installer, locker, repo, package, installed):
_configure_run_install_dev(locker, repo, package, installed)
installer.dev_mode(False) installer.dev_mode(False)
installer.dev_only(True)
installer.run() installer.run()
assert 0 == installer.executor.installations_count assert 0 == installer.executor.installations_count
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment