Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source references not being locked for private indices #1635

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions poetry/packages/locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def locked_repository(
package.add_dependency(dep_name, constraint)

if "source" in info:
package.source_type = info["source"]["type"]
package.source_type = info["source"].get("type", "")
package.source_url = info["source"]["url"]
package.source_reference = info["source"]["reference"]

Expand Down Expand Up @@ -294,11 +294,12 @@ def _dump_package(self, package): # type: (poetry.packages.Package) -> dict

data["dependencies"] = dependencies

if package.source_type:
if package.source_url:
data["source"] = {
"type": package.source_type,
"url": package.source_url,
"reference": package.source_reference,
}
if package.source_type:
data["source"]["type"] = package.source_type

return data
34 changes: 34 additions & 0 deletions tests/packages/test_locker.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,37 @@ def test_reading_lock_file_should_raise_an_error_on_invalid_data(locker):
_ = locker.lock_data

assert "Unable to read the lock file" in str(e.value)


def test_locking_legacy_repository_package_should_include_source_section(root, locker):
package_a = get_package("A", "1.0.0")
package_a.source_url = "https://foo.bar"
package_a.source_reference = "legacy"
packages = [package_a]

locker.set_lock_data(root, packages)

with locker.lock.open(encoding="utf-8") as f:
content = f.read()

expected = """[[package]]
category = "main"
description = ""
name = "A"
optional = false
python-versions = "*"
version = "1.0.0"

[package.source]
reference = "legacy"
url = "https://foo.bar"

[metadata]
content-hash = "115cf985d932e9bf5f540555bbdd75decbb62cac81e399375fc19f6277f8c1d8"
python-versions = "*"

[metadata.files]
A = []
"""

assert expected == content