mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Clear pipfile cache when it seems like we might be mutating
This commit is contained in:
@@ -291,6 +291,7 @@ def ensure_pipfile(validate=True, skip_requirements=False):
|
||||
if validate and project.virtualenv_exists and not PIPENV_SKIP_VALIDATION:
|
||||
# Ensure that Pipfile is using proper casing.
|
||||
p = project.parsed_pipfile
|
||||
p.clear_pipfile_cache()
|
||||
changed = ensure_proper_casing(pfile=p)
|
||||
# Write changes out to disk.
|
||||
if changed:
|
||||
|
||||
+11
-2
@@ -294,6 +294,9 @@ class Project(object):
|
||||
|
||||
@property
|
||||
def parsed_pipfile(self):
|
||||
"""Parse Pipfile into a TOMLFile and cache it
|
||||
|
||||
(call clear_pipfile_cache() afterwards if mutating)"""
|
||||
# Open the pipfile, read it into memory.
|
||||
with open(self.pipfile_location) as f:
|
||||
contents = f.read()
|
||||
@@ -302,9 +305,12 @@ class Project(object):
|
||||
if cache_key not in _cache.pipfile_cache:
|
||||
parsed = self._parse_pipfile(contents)
|
||||
_cache.pipfile_cache[cache_key] = parsed
|
||||
# deepcopy likely unnecessary but why not avoid bugs?
|
||||
return _cache.pipfile_cache[cache_key]
|
||||
|
||||
def clear_pipfile_cache(self):
|
||||
"""Clear pipfile cache (e.g., so we can mutate parsed pipfile)"""
|
||||
_cache.pipfile_cache.clear()
|
||||
|
||||
def _parse_pipfile(self, contents):
|
||||
# If any outline tables are present...
|
||||
if ('[packages.' in contents) or ('[dev-packages.' in contents):
|
||||
@@ -338,8 +344,10 @@ class Project(object):
|
||||
def _pipfile(self):
|
||||
"""Pipfile divided by PyPI and external dependencies."""
|
||||
pfile = self.parsed_pipfile
|
||||
# mutation time!
|
||||
self.clear_pipfile_cache()
|
||||
for section in ('packages', 'dev-packages'):
|
||||
p_section = pfile.get(section, {})
|
||||
p_section = dict(pfile.get(section, {}))
|
||||
for key in list(p_section.keys()):
|
||||
# Normalize key name to PEP 423.
|
||||
norm_key = pep423_name(key)
|
||||
@@ -370,6 +378,7 @@ class Project(object):
|
||||
p['pipenv'] = settings
|
||||
# Write the changes to disk.
|
||||
self.write_toml(p)
|
||||
self.clear_pipfile_cache()
|
||||
|
||||
@property
|
||||
def _lockfile(self):
|
||||
|
||||
Reference in New Issue
Block a user