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
623bfffb
Unverified
Commit
623bfffb
authored
Apr 06, 2023
by
Wagner Macedo
Committed by
GitHub
Apr 06, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only write lock file when installation is success (#7498)
(affects `poetry add` and `poetry update`)
parent
161b19cb
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
213 additions
and
131 deletions
+213
-131
src/poetry/installation/installer.py
+10
-6
src/poetry/packages/locker.py
+16
-2
tests/console/commands/self/test_add_plugins.py
+14
-14
tests/console/commands/self/test_remove_plugins.py
+2
-2
tests/console/commands/self/test_update.py
+2
-2
tests/console/commands/test_add.py
+144
-105
tests/installation/test_installer.py
+24
-0
tests/installation/test_installer_old.py
+1
-0
No files found.
src/poetry/installation/installer.py
View file @
623bfffb
...
...
@@ -291,12 +291,10 @@ class Installer:
lockfile_repo
=
LockfileRepository
()
self
.
_populate_lockfile_repo
(
lockfile_repo
,
ops
)
if
self
.
_update
:
if
self
.
_lock
and
self
.
_update
:
# If we are only in lock mode, no need to go any further
self
.
_write_lock_file
(
lockfile_repo
)
if
self
.
_lock
:
# If we are only in lock mode, no need to go any further
return
0
return
0
if
self
.
_groups
is
not
None
:
root
=
self
.
_package
.
with_dependency_groups
(
list
(
self
.
_groups
),
only
=
True
)
...
...
@@ -362,7 +360,13 @@ class Installer:
self
.
_filter_operations
(
ops
,
lockfile_repo
)
# Execute operations
return
self
.
_execute
(
ops
)
status
=
self
.
_execute
(
ops
)
if
status
==
0
and
self
.
_update
:
# Only write lock file when installation is success
self
.
_write_lock_file
(
lockfile_repo
)
return
status
def
_write_lock_file
(
self
,
repo
:
LockfileRepository
,
force
:
bool
=
False
)
->
None
:
if
self
.
_write_lock
and
(
force
or
self
.
_update
):
...
...
src/poetry/packages/locker.py
View file @
623bfffb
...
...
@@ -224,6 +224,18 @@ class Locker:
return
repository
def
set_lock_data
(
self
,
root
:
Package
,
packages
:
list
[
Package
])
->
bool
:
"""Store lock data and eventually persist to the lock file"""
lock
=
self
.
_compute_lock_data
(
root
,
packages
)
if
self
.
_should_write
(
lock
):
self
.
_write_lock_data
(
lock
)
return
True
return
False
def
_compute_lock_data
(
self
,
root
:
Package
,
packages
:
list
[
Package
]
)
->
TOMLDocument
:
package_specs
=
self
.
_lock_packages
(
packages
)
# Retrieving hashes
for
package
in
package_specs
:
...
...
@@ -254,6 +266,10 @@ class Locker:
"content-hash"
:
self
.
_content_hash
,
}
return
lock
def
_should_write
(
self
,
lock
:
TOMLDocument
)
->
bool
:
# if lock file exists: compare with existing lock data
do_write
=
True
if
self
.
is_locked
():
try
:
...
...
@@ -263,8 +279,6 @@ class Locker:
pass
else
:
do_write
=
lock
!=
lock_data
if
do_write
:
self
.
_write_lock_data
(
lock
)
return
do_write
def
_write_lock_data
(
self
,
data
:
TOMLDocument
)
->
None
:
...
...
tests/console/commands/self/test_add_plugins.py
View file @
623bfffb
...
...
@@ -49,11 +49,11 @@ Using version ^0.1.0 for poetry-plugin
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.1.0)
Writing lock file
"""
assert_plugin_add_result
(
tester
,
expected
,
"^0.1.0"
)
...
...
@@ -71,11 +71,11 @@ def test_add_with_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing poetry-plugin (0.2.0)
Writing lock file
"""
assert_plugin_add_result
(
tester
,
expected
,
"^0.2.0"
)
...
...
@@ -93,12 +93,12 @@ def test_add_with_git_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5)
• Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
"""
assert_plugin_add_result
(
...
...
@@ -119,13 +119,13 @@ def test_add_with_git_constraint_with_extras(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 3 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5)
• Installing tomlkit (0.7.0)
• Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
"""
assert_plugin_add_result
(
...
...
@@ -162,12 +162,12 @@ def test_add_with_git_constraint_with_subdirectory(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (2.0.5)
• Installing poetry-plugin (0.1.2 9cf87a2)
Writing lock file
"""
constraint
=
{
...
...
@@ -262,11 +262,11 @@ Using version ^2.3.4 for poetry-plugin
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 1 update, 0 removals
• Updating poetry-plugin (1.2.3 -> 2.3.4)
Writing lock file
"""
assert_plugin_add_result
(
tester
,
expected
,
"^2.3.4"
)
...
...
@@ -298,12 +298,12 @@ Using version ^1.2.3 for poetry-plugin
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 1 update, 0 removals
• Updating tomlkit (0.7.1 -> 0.7.2)
• Installing poetry-plugin (1.2.3)
Writing lock file
"""
assert_plugin_add_result
(
tester
,
expected
,
"^1.2.3"
)
tests/console/commands/self/test_remove_plugins.py
View file @
623bfffb
...
...
@@ -73,11 +73,11 @@ def test_remove_installed_package(tester: CommandTester):
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 0 updates, 1 removal
• Removing poetry-plugin (1.2.3)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
tests/console/commands/self/test_update.py
View file @
623bfffb
...
...
@@ -71,12 +71,12 @@ Using version ^{new_version} for poetry
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 0 installs, 2 updates, 0 removals
• Updating cleo (0.8.2 -> 1.0.0)
• Updating poetry ({__version__} -> {new_version})
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected_output
tests/console/commands/test_add.py
View file @
623bfffb
...
...
@@ -16,6 +16,8 @@ from tests.helpers import get_package
if
TYPE_CHECKING
:
from
typing
import
Any
from
cleo.testers.command_tester
import
CommandTester
from
pytest_mock
import
MockerFixture
...
...
@@ -70,11 +72,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -100,11 +102,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
assert
tester
.
command
.
installer
.
executor
.
installations_count
==
1
...
...
@@ -119,11 +121,11 @@ Package operations: 1 install, 0 updates, 0 removals
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.1.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -167,11 +169,11 @@ def test_add_equal_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.1.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -191,11 +193,11 @@ def test_add_greater_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -225,12 +227,12 @@ def test_add_constraint_with_extras(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3)
• Installing cachy (0.1.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -255,12 +257,12 @@ def test_add_constraint_dependencies(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3)
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -285,12 +287,12 @@ def test_add_git_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -321,12 +323,12 @@ def test_add_git_constraint_with_poetry(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -354,14 +356,14 @@ def test_add_git_constraint_with_extras(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals
• Installing cleo (0.6.5)
• Installing pendulum (1.4.4)
• Installing tomlkit (0.5.5)
• Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
.
strip
()
...
...
@@ -400,11 +402,11 @@ def test_add_git_constraint_with_subdirectory(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing two (2.0.0 9cf87a2)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
.
strip
()
==
expected
.
strip
()
assert
tester
.
command
.
installer
.
executor
.
installations_count
==
1
...
...
@@ -444,12 +446,12 @@ def test_add_git_ssh_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -491,12 +493,12 @@ def test_add_directory_constraint(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -532,12 +534,12 @@ def test_add_directory_with_poetry(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -564,12 +566,12 @@ def test_add_file_constraint_wheel(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -600,12 +602,12 @@ def test_add_file_constraint_sdist(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -640,12 +642,12 @@ def test_add_constraint_with_extras_option(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing msgpack-python (0.5.3)
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -680,13 +682,13 @@ def test_add_url_constraint_wheel(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
• Installing pendulum (1.4.4)
• Installing demo
\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -722,8 +724,6 @@ def test_add_url_constraint_wheel_with_extras(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals
• Installing cleo (0.6.5)
...
...
@@ -731,6 +731,8 @@ Package operations: 4 installs, 0 updates, 0 removals
• Installing tomlkit (0.5.5)
• Installing demo
\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
"""
# Order might be different, split into lines and compare the overall output.
expected
=
set
(
expected
.
splitlines
())
...
...
@@ -764,11 +766,11 @@ def test_add_constraint_with_python(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -802,11 +804,11 @@ def test_add_constraint_with_platform(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -853,11 +855,11 @@ def test_add_constraint_with_source(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -915,11 +917,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -962,11 +964,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing cachy (0.2.0)
Writing lock file
"""
assert
tester
.
io
.
fetch_error
()
==
warning
...
...
@@ -993,11 +995,11 @@ Using version ^3.13 for pyyaml
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing pyyaml (3.13)
Writing lock file
"""
assert
tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1112,11 +1114,11 @@ Using version ^1.1.2 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.1.2)
Writing lock file
"""
assert
expected
in
tester
.
io
.
fetch_output
()
...
...
@@ -1141,11 +1143,11 @@ Using version ^1.2.3b1 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.2.3b1)
Writing lock file
"""
assert
expected
in
tester
.
io
.
fetch_output
()
...
...
@@ -1164,11 +1166,11 @@ Using version ^1.2.3 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
• Installing foo (1.2.3)
Writing lock file
"""
assert
expected
in
tester
.
io
.
fetch_output
()
...
...
@@ -1212,11 +1214,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1245,11 +1247,11 @@ def test_add_equal_constraint_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.1.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1273,11 +1275,11 @@ def test_add_greater_constraint_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1309,12 +1311,12 @@ def test_add_constraint_with_extras_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3)
- Installing cachy (0.1.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1343,12 +1345,12 @@ def test_add_constraint_dependencies_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3)
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1372,12 +1374,12 @@ def test_add_git_constraint_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1407,12 +1409,12 @@ def test_add_git_constraint_with_poetry_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1439,14 +1441,14 @@ def test_add_git_constraint_with_extras_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals
- Installing cleo (0.6.5)
- Installing pendulum (1.4.4)
- Installing tomlkit (0.5.5)
- Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1478,12 +1480,12 @@ def test_add_git_ssh_constraint_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 9cf87a2)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1520,12 +1522,12 @@ def test_add_directory_constraint_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1558,12 +1560,12 @@ def test_add_directory_with_poetry_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.2 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1591,12 +1593,12 @@ def test_add_file_constraint_wheel_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1629,12 +1631,12 @@ def test_add_file_constraint_sdist_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo (0.1.0 {app.poetry.file.parent.joinpath(path).resolve().as_posix()})
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1671,12 +1673,12 @@ def test_add_constraint_with_extras_option_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing msgpack-python (0.5.3)
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1713,13 +1715,13 @@ def test_add_url_constraint_wheel_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 2 installs, 0 updates, 0 removals
- Installing pendulum (1.4.4)
- Installing demo
\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1756,8 +1758,6 @@ def test_add_url_constraint_wheel_with_extras_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 4 installs, 0 updates, 0 removals
- Installing cleo (0.6.5)
...
...
@@ -1765,6 +1765,8 @@ Package operations: 4 installs, 0 updates, 0 removals
- Installing tomlkit (0.5.5)
- Installing demo
\
(0.1.0 https://python-poetry.org/distributions/demo-0.1.0-py2.py3-none-any.whl)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1800,11 +1802,11 @@ def test_add_constraint_with_python_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1840,11 +1842,11 @@ def test_add_constraint_with_platform_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1893,11 +1895,11 @@ def test_add_constraint_with_source_old_installer(
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1959,11 +1961,11 @@ Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing cachy (0.2.0)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -1993,11 +1995,11 @@ Using version ^3.13 for pyyaml
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing pyyaml (3.13)
Writing lock file
"""
assert
old_tester
.
io
.
fetch_output
()
==
expected
...
...
@@ -2058,11 +2060,11 @@ Using version ^1.1.2 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.1.2)
Writing lock file
"""
assert
expected
in
old_tester
.
io
.
fetch_output
()
...
...
@@ -2090,11 +2092,11 @@ Using version ^1.2.3b1 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.2.3b1)
Writing lock file
"""
assert
expected
in
old_tester
.
io
.
fetch_output
()
...
...
@@ -2116,11 +2118,11 @@ Using version ^1.2.3 for foo
Updating dependencies
Resolving dependencies...
Writing lock file
Package operations: 1 install, 0 updates, 0 removals
- Installing foo (1.2.3)
Writing lock file
"""
assert
expected
in
old_tester
.
io
.
fetch_output
()
...
...
@@ -2157,7 +2159,8 @@ def test_add_keyboard_interrupt_restore_content(
tester
=
command_tester_factory
(
"add"
,
poetry
=
poetry_with_up_to_date_lockfile
)
mocker
.
patch
(
"poetry.installation.installer.Installer.run"
,
side_effect
=
KeyboardInterrupt
()
"poetry.installation.installer.Installer._execute"
,
side_effect
=
KeyboardInterrupt
(),
)
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
...
...
@@ -2200,3 +2203,39 @@ def test_add_with_dry_run_keep_files_intact(
assert
(
poetry_with_up_to_date_lockfile
.
_locker
.
lock_data
==
original_lockfile_content
)
def
test_add_should_not_change_lock_file_when_dependency_installation_fail
(
poetry_with_up_to_date_lockfile
:
Poetry
,
repo
:
TestRepository
,
command_tester_factory
:
CommandTesterFactory
,
mocker
:
MockerFixture
,
):
tester
=
command_tester_factory
(
"add"
,
poetry
=
poetry_with_up_to_date_lockfile
)
repo
.
add_package
(
get_package
(
"docker"
,
"4.3.1"
))
repo
.
add_package
(
get_package
(
"cachy"
,
"0.2.0"
))
original_pyproject_content
=
poetry_with_up_to_date_lockfile
.
file
.
read
()
original_lockfile_content
=
poetry_with_up_to_date_lockfile
.
locker
.
lock_data
def
error
(
_
:
Any
)
->
int
:
tester
.
io
.
write
(
"
\n
BuildError
\n\n
"
)
return
1
mocker
.
patch
(
"poetry.installation.installer.Installer._execute"
,
side_effect
=
error
)
tester
.
execute
(
"cachy"
)
expected
=
"""
\
Using version ^0.2.0 for cachy
Updating dependencies
Resolving dependencies...
BuildError
"""
assert
poetry_with_up_to_date_lockfile
.
file
.
read
()
==
original_pyproject_content
assert
poetry_with_up_to_date_lockfile
.
locker
.
lock_data
==
original_lockfile_content
assert
tester
.
io
.
fetch_output
()
==
expected
tests/installation/test_installer.py
View file @
623bfffb
...
...
@@ -105,6 +105,7 @@ class Locker(BaseLocker):
self
.
_lock
=
lock_path
/
"poetry.lock"
self
.
_written_data
=
None
self
.
_locked
=
False
self
.
_lock_data
=
None
self
.
_content_hash
=
self
.
_get_content_hash
()
@property
...
...
@@ -2415,6 +2416,29 @@ def test_installer_can_handle_old_lock_files(
assert
installer
.
executor
.
installations_count
==
8
def
test_installer_does_not_write_lock_file_when_installation_fails
(
installer
:
Installer
,
locker
:
Locker
,
repo
:
Repository
,
package
:
ProjectPackage
,
mocker
:
MockerFixture
,
):
repo
.
add_package
(
get_package
(
"A"
,
"1.0"
))
package
.
add_dependency
(
Factory
.
create_dependency
(
"A"
,
"~1.0"
))
locker
.
locked
(
False
)
mocker
.
patch
(
"poetry.installation.installer.Installer._execute"
,
return_value
=
1
)
result
=
installer
.
run
()
assert
result
==
1
# error
assert
locker
.
_lock_data
is
None
assert
installer
.
executor
.
installations_count
==
0
assert
installer
.
executor
.
updates_count
==
0
assert
installer
.
executor
.
removals_count
==
0
@pytest.mark.parametrize
(
"quiet"
,
[
True
,
False
])
def
test_run_with_dependencies_quiet
(
installer
:
Installer
,
...
...
tests/installation/test_installer_old.py
View file @
623bfffb
...
...
@@ -62,6 +62,7 @@ class Locker(BaseLocker):
self
.
_lock
=
lock_path
/
"poetry.lock"
self
.
_written_data
=
None
self
.
_locked
=
False
self
.
_lock_data
=
None
self
.
_content_hash
=
self
.
_get_content_hash
()
@property
...
...
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