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
20589be5
Unverified
Commit
20589be5
authored
Jul 06, 2021
by
Sébastien Eustace
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update the `install` command to support groups
parent
4b8384cd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
13 deletions
+140
-13
poetry/console/commands/install.py
+78
-5
poetry/installation/installer.py
+3
-3
tests/console/commands/test_install.py
+19
-0
tests/installation/test_installer.py
+38
-3
tests/installation/test_installer_old.py
+2
-2
No files found.
poetry/console/commands/install.py
View file @
20589be5
...
@@ -9,8 +9,38 @@ class InstallCommand(InstallerCommand):
...
@@ -9,8 +9,38 @@ class InstallCommand(InstallerCommand):
description
=
"Installs the project dependencies."
description
=
"Installs the project dependencies."
options
=
[
options
=
[
option
(
"no-dev"
,
None
,
"Do not install the development dependencies."
),
option
(
option
(
"dev-only"
,
None
,
"Only install the development dependencies."
),
"without"
,
None
,
"The dependency groups to ignore for installation."
,
flag
=
False
,
multiple
=
True
,
),
option
(
"with"
,
None
,
"The optional dependency groups to include for installation."
,
flag
=
False
,
multiple
=
True
,
),
option
(
"default"
,
None
,
"Only install the default dependencies."
),
option
(
"only"
,
None
,
"The only dependency groups to install."
,
flag
=
False
,
multiple
=
True
,
),
option
(
"no-dev"
,
None
,
"Do not install the development dependencies. (<warning>Deprecated</warning>)"
,
),
option
(
"dev-only"
,
None
,
"Only install the development dependencies. (<warning>Deprecated</warning>)"
,
),
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)."
),
),
...
@@ -66,8 +96,51 @@ dependencies and not including the current project, run the command with the
...
@@ -66,8 +96,51 @@ dependencies and not including the current project, run the command with the
extras
.
append
(
extra
)
extras
.
append
(
extra
)
self
.
_installer
.
extras
(
extras
)
self
.
_installer
.
extras
(
extras
)
self
.
_installer
.
dev_mode
(
not
self
.
option
(
"no-dev"
))
self
.
_installer
.
dev_only
(
self
.
option
(
"dev-only"
))
excluded_groups
=
[]
included_groups
=
[]
only_groups
=
[]
if
self
.
option
(
"no-dev"
):
self
.
line
(
"<warning>The `<fg=yellow;options=bold>--no-dev</>` option is deprecated,"
"use the `<fg=yellow;options=bold>--without dev</>` notation instead.</warning>"
)
excluded_groups
.
append
(
"dev"
)
elif
self
.
option
(
"dev-only"
):
self
.
line
(
"<warning>The `<fg=yellow;options=bold>--dev-only</>` option is deprecated,"
"use the `<fg=yellow;options=bold>--only dev</>` notation instead.</warning>"
)
only_groups
.
append
(
"dev"
)
excluded_groups
.
extend
(
[
group
.
strip
()
for
groups
in
self
.
option
(
"without"
)
for
group
in
groups
.
split
(
","
)
]
)
included_groups
.
extend
(
[
group
.
strip
()
for
groups
in
self
.
option
(
"with"
)
for
group
in
groups
.
split
(
","
)
]
)
only_groups
.
extend
(
[
group
.
strip
()
for
groups
in
self
.
option
(
"only"
)
for
group
in
groups
.
split
(
","
)
]
)
if
self
.
option
(
"default"
):
only_groups
.
append
(
"default"
)
self
.
_installer
.
only_groups
(
only_groups
)
self
.
_installer
.
without_groups
(
excluded_groups
)
self
.
_installer
.
with_groups
(
included_groups
)
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
())
...
@@ -77,7 +150,7 @@ dependencies and not including the current project, run the command with the
...
@@ -77,7 +150,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"
)
or
self
.
option
(
"
dev-
only"
):
if
self
.
option
(
"no-root"
)
or
self
.
option
(
"only"
):
return
0
return
0
try
:
try
:
...
...
poetry/installation/installer.py
View file @
20589be5
...
@@ -286,10 +286,10 @@ class Installer:
...
@@ -286,10 +286,10 @@ class Installer:
if
self
.
_without_groups
or
self
.
_with_groups
or
self
.
_only_groups
:
if
self
.
_without_groups
or
self
.
_with_groups
or
self
.
_only_groups
:
if
self
.
_with_groups
:
if
self
.
_with_groups
:
# Default dependencies and opt-in optional dependencies
# Default dependencies and opt
ed
-in optional dependencies
root
=
self
.
_package
.
with
out
_dependency_groups
(
self
.
_with_groups
)
root
=
self
.
_package
.
with_dependency_groups
(
self
.
_with_groups
)
elif
self
.
_without_groups
:
elif
self
.
_without_groups
:
# Default dependencies without elected groups
# Default dependencies without
s
elected groups
root
=
self
.
_package
.
without_dependency_groups
(
self
.
_without_groups
)
root
=
self
.
_package
.
without_dependency_groups
(
self
.
_without_groups
)
else
:
else
:
# Only selected groups
# Only selected groups
...
...
tests/console/commands/test_install.py
0 → 100644
View file @
20589be5
import
pytest
@pytest.fixture
def
tester
(
command_tester_factory
):
return
command_tester_factory
(
"install"
)
def
test_group_options_are_passed_to_the_installer
(
tester
,
mocker
):
"""
Group options are passed properly to the installer.
"""
mocker
.
patch
.
object
(
tester
.
command
.
installer
,
"run"
,
return_value
=
1
)
tester
.
execute
(
"--with foo,bar --without baz --without bim --only bam"
)
assert
tester
.
command
.
installer
.
_with_groups
==
[
"foo"
,
"bar"
]
assert
tester
.
command
.
installer
.
_without_groups
==
[
"baz"
,
"bim"
]
assert
tester
.
command
.
installer
.
_only_groups
==
[
"bam"
]
tests/installation/test_installer.py
View file @
20589be5
...
@@ -15,6 +15,7 @@ from cleo.io.outputs.buffered_output import BufferedOutput
...
@@ -15,6 +15,7 @@ from cleo.io.outputs.buffered_output import BufferedOutput
from
cleo.io.outputs.output
import
Verbosity
from
cleo.io.outputs.output
import
Verbosity
from
deepdiff
import
DeepDiff
from
deepdiff
import
DeepDiff
from
poetry.core.packages.dependency_group
import
DependencyGroup
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.package
import
Package
from
poetry.core.packages.project_package
import
ProjectPackage
from
poetry.core.packages.project_package
import
ProjectPackage
from
poetry.core.toml.file
import
TOMLFile
from
poetry.core.toml.file
import
TOMLFile
...
@@ -277,7 +278,9 @@ def test_run_update_after_removing_dependencies(
...
@@ -277,7 +278,9 @@ def test_run_update_after_removing_dependencies(
assert
1
==
installer
.
executor
.
removals_count
assert
1
==
installer
.
executor
.
removals_count
def
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
):
def
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
,
with_optional_group
=
False
):
"""
"""
Perform common test setup for `test_run_install_*dev*()` methods.
Perform common test setup for `test_run_install_*dev*()` methods.
"""
"""
...
@@ -334,13 +337,16 @@ def _configure_run_install_dev(locker, repo, package, installed):
...
@@ -334,13 +337,16 @@ def _configure_run_install_dev(locker, repo, package, installed):
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
"~1.0"
))
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
"~1.0"
))
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"
,
groups
=
[
"dev"
]))
group
=
DependencyGroup
(
"dev"
,
optional
=
with_optional_group
)
group
.
add_dependency
(
Factory
.
create_dependency
(
"C"
,
"~1.2"
,
groups
=
[
"dev"
]))
package
.
add_dependency_group
(
group
)
def
test_run_install_no_group
(
installer
,
locker
,
repo
,
package
,
installed
):
def
test_run_install_no_group
(
installer
,
locker
,
repo
,
package
,
installed
):
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
)
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
)
installer
.
with_groups
([
"dev"
])
installer
.
with
out
_groups
([
"dev"
])
installer
.
run
()
installer
.
run
()
assert
0
==
installer
.
executor
.
installations_count
assert
0
==
installer
.
executor
.
installations_count
...
@@ -359,6 +365,35 @@ def test_run_install_group_only(installer, locker, repo, package, installed):
...
@@ -359,6 +365,35 @@ def test_run_install_group_only(installer, locker, repo, package, installed):
assert
2
==
installer
.
executor
.
removals_count
assert
2
==
installer
.
executor
.
removals_count
def
test_run_install_with_optional_group_not_selected
(
installer
,
locker
,
repo
,
package
,
installed
):
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
,
with_optional_group
=
True
)
installer
.
run
()
assert
0
==
installer
.
executor
.
installations_count
assert
0
==
installer
.
executor
.
updates_count
assert
1
==
installer
.
executor
.
removals_count
def
test_run_install_with_optional_group_selected
(
installer
,
locker
,
repo
,
package
,
installed
):
_configure_run_install_dev
(
locker
,
repo
,
package
,
installed
,
with_optional_group
=
True
)
installer
.
with_groups
([
"dev"
])
installer
.
run
()
assert
0
==
installer
.
executor
.
installations_count
assert
0
==
installer
.
executor
.
updates_count
assert
0
==
installer
.
executor
.
removals_count
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"managed_reserved_package_names"
,
"managed_reserved_package_names"
,
[
[
...
...
tests/installation/test_installer_old.py
View file @
20589be5
...
@@ -227,7 +227,7 @@ def test_run_update_after_removing_dependencies(
...
@@ -227,7 +227,7 @@ def test_run_update_after_removing_dependencies(
assert
len
(
removals
)
==
1
assert
len
(
removals
)
==
1
def
test_run_install_no_
dev
(
installer
,
locker
,
repo
,
package
,
installed
):
def
test_run_install_no_
group
(
installer
,
locker
,
repo
,
package
,
installed
):
locker
.
locked
(
True
)
locker
.
locked
(
True
)
locker
.
mock_lock_data
(
locker
.
mock_lock_data
(
{
{
...
@@ -283,7 +283,7 @@ def test_run_install_no_dev(installer, locker, repo, package, installed):
...
@@ -283,7 +283,7 @@ 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"
,
groups
=
[
"dev"
]))
package
.
add_dependency
(
Factory
.
create_dependency
(
"C"
,
"~1.2"
,
groups
=
[
"dev"
]))
installer
.
with_groups
([
"dev"
])
installer
.
with
out
_groups
([
"dev"
])
installer
.
run
()
installer
.
run
()
installs
=
installer
.
installer
.
installs
installs
=
installer
.
installer
.
installs
...
...
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