Skip to content

Commit

Permalink
Fix locked VCS dependencies always being updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater authored and abn committed Apr 14, 2021
1 parent fa9cd5f commit b9eb246
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 9 deletions.
7 changes: 6 additions & 1 deletion poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,12 @@ def _install_git(self, operation):

git = Git()
git.clone(package.source_url, src_dir)
git.checkout(package.source_reference, src_dir)

reference = package.source_resolved_reference
if not reference:
reference = package.source_reference

git.checkout(reference, src_dir)

# Now we just need to install from the source directory
package._source_url = str(src_dir)
Expand Down
11 changes: 4 additions & 7 deletions poetry/installation/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,6 @@ def _do_install(self, local_repo):

pool.add_repository(repo)

# We whitelist all packages to be sure
# that the latest ones are picked up
whitelist = []
for pkg in locked_repository.packages:
whitelist.append(pkg.name)

solver = Solver(
root,
pool,
Expand All @@ -303,9 +297,12 @@ def _do_install(self, local_repo):
NullIO(),
remove_untracked=self._remove_untracked,
)
# Everything is resolved at this point, so we no longer need
# to load deferred dependencies (i.e. VCS, URL and path dependencies)
solver.provider.load_deferred(False)

with solver.use_environment(self._env):
ops = solver.solve(use_latest=whitelist)
ops = solver.solve(use_latest=self._whitelist)

# We need to filter operations so that packages
# not compatible with the current system,
Expand Down
7 changes: 6 additions & 1 deletion poetry/installation/pip_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,12 @@ def install_git(self, package):

git = Git()
git.clone(package.source_url, src_dir)
git.checkout(package.source_reference, src_dir)

reference = package.source_resolved_reference
if not reference:
reference = package.source_reference

git.checkout(reference, src_dir)

# Now we just need to install from the source directory
pkg = Package(package.name, package.version)
Expand Down
64 changes: 64 additions & 0 deletions tests/installation/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from clikit.io import NullIO

from poetry.core.packages import ProjectPackage
from poetry.core.packages.package import Package
from poetry.core.toml.file import TOMLFile
from poetry.factory import Factory
from poetry.installation import Installer as BaseInstaller
Expand Down Expand Up @@ -1860,3 +1861,66 @@ def test_installer_can_handle_old_lock_files(

# colorama will be added
assert 8 == installer.executor.installations_count


def test_installer_should_use_the_locked_version_of_git_dependencies(
installer, locker, package, repo
):
locker.locked(True)
locker.mock_lock_data(
{
"package": [
{
"name": "demo",
"version": "0.1.1",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
"dependencies": {"pendulum": ">=1.4.4"},
"source": {
"type": "git",
"url": "https://github.com/demo/demo.git",
"reference": "master",
"resolved_reference": "123456",
},
},
{
"name": "pendulum",
"version": "1.4.4",
"category": "main",
"optional": False,
"platform": "*",
"python-versions": "*",
"checksum": [],
"dependencies": {},
},
],
"metadata": {
"python-versions": "*",
"platform": "*",
"content-hash": "123456789",
"hashes": {"demo": [], "pendulum": []},
},
}
)

package.add_dependency(
Factory.create_dependency(
"demo", {"git": "https://github.com/demo/demo.git", "branch": "master"}
)
)

repo.add_package(get_package("pendulum", "1.4.4"))

installer.run()

assert installer.executor.installations[-1] == Package(
"demo",
"0.1.1",
source_type="git",
source_url="https://github.com/demo/demo.git",
source_reference="master",
source_resolved_reference="123456",
)

0 comments on commit b9eb246

Please sign in to comment.