Skip to content

Commit

Permalink
Merge pull request #3235 from pypa/bugfix/3233
Browse files Browse the repository at this point in the history
Derive missing values of source from existing fields
  • Loading branch information
frostming committed Nov 17, 2018
2 parents ab09a3d + 905c8c0 commit 301e4a9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pipenv/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,18 @@ def create_pipfile(self, python=None):
data[u"requires"] = {"python_version": version[: len("2.7")]}
self.write_toml(data)

@classmethod
def populate_source(cls, source):
"""Derive missing values of source from the existing fields."""
# Only URL pararemter is mandatory, let the KeyError be thrown.
if "name" not in source:
source["name"] = get_url_name(source["url"])
if "verify_ssl" not in source:
source["verify_ssl"] = "https://" in source["url"]
if not isinstance(source["verify_ssl"], bool):
source["verify_ssl"] = source["verify_ssl"].lower() == "true"
return source

def get_or_create_lockfile(self):
from pipenv.vendor.requirementslib.models.lockfile import Lockfile as Req_Lockfile
lockfile = None
Expand All @@ -747,15 +759,7 @@ def get_or_create_lockfile(self):
elif not isinstance(sources, list):
sources = [sources,]
lockfile_dict["_meta"]["sources"] = [
{
"name": s.get("name", get_url_name(s.get("url"))),
"url": s["url"],
"verify_ssl": (
s["verify_ssl"] if isinstance(s["verify_ssl"], bool) else (
True if s["verify_ssl"].lower() == "true" else False
)
)
} for s in sources
self.populate_source(s) for s in sources
]
_created_lockfile = Req_Lockfile.from_data(
path=self.lockfile_location, data=lockfile_dict, meta_from_project=False
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,20 @@ def test_lockfile_with_empty_dict(PipenvInstance):
assert c.return_code == 0
assert 'Pipfile.lock is corrupted' in c.err
assert p.lockfile['_meta']


@pytest.mark.lock
@pytest.mark.install
def test_lock_with_incomplete_source(PipenvInstance, pypi):
with PipenvInstance(pypi=pypi, chdir=True) as p:
with open(p.pipfile_path, 'w') as f:
f.write("""
[[source]]
url = "https://test.pypi.org/simple"
[packages]
requests = "*"
""")
c = p.pipenv('install')
assert c.return_code == 0
assert p.lockfile['_meta']['sources']

0 comments on commit 301e4a9

Please sign in to comment.