Skip to content

Commit

Permalink
allow .conda packages to use cached .tar.bz2 entries for otherwise si…
Browse files Browse the repository at this point in the history
…milar packages
  • Loading branch information
msarahan committed May 13, 2019
1 parent daa9cac commit f87945e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
12 changes: 8 additions & 4 deletions conda/core/package_cache_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,19 @@ def make_actions_for_record(pref_or_spec):
sha256 = pref_or_spec.get("sha256")
size = pref_or_spec.get("size")
md5 = pref_or_spec.get("md5")
legacy_bz2_size = pref_or_spec.get("legacy_bz2_size")
legacy_bz2_md5 = pref_or_spec.get("legacy_bz2_md5")

def pcrec_matches(pcrec):
matches = True
if sha256 is not None and pcrec.sha256 is not None:
matches = sha256 == pcrec.sha256
# sha256 is overkill for things that are already in the package cache.
# It's just a quick match.
# if sha256 is not None and pcrec.sha256 is not None:
# matches = sha256 == pcrec.sha256
if size is not None and pcrec.size is not None:
matches = size == pcrec.size
matches = pcrec.size in (size, legacy_bz2_size)
if matches and md5 is not None and pcrec is not None:
matches = md5 == pcrec.md5
matches = pcrec.md5 in (md5, legacy_bz2_md5)
return matches

if md5:
Expand Down
42 changes: 23 additions & 19 deletions conda/core/subdir_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,25 +361,29 @@ def _process_raw_repodata_str(self, raw_repodata_str):
k[:-6] + _tar_bz2 for k in iterkeys(conda_packages)
)

for fn, info in concatv(
iteritems(conda_packages),
((k, legacy_packages[k]) for k in use_these_legacy_keys),
):
info['fn'] = fn
info['url'] = join_url(channel_url, fn)
if add_pip and info['name'] == 'python' and info['version'].startswith(('2.', '3.')):
info['depends'].append('pip')
info.update(meta_in_common)
if info.get('record_version', 0) > 1:
log.debug("Ignoring record_version %d from %s",
info["record_version"], info['url'])
continue
package_record = PackageRecord(**info)

_package_records.append(package_record)
_names_index[package_record.name].append(package_record)
for ftr_name in package_record.track_features:
_track_features_index[ftr_name].append(package_record)
for group, copy_legacy_md5 in ((iteritems(conda_packages), True),
(((k, legacy_packages[k]) for k in use_these_legacy_keys), False)):
for fn, info in group:
info['fn'] = fn
info['url'] = join_url(channel_url, fn)
if copy_legacy_md5:
counterpart = fn.replace('.conda', '.tar.bz2')
if counterpart in legacy_packages:
info['legacy_bz2_md5'] = legacy_packages[counterpart].get('md5')
info['legacy_bz2_size'] = legacy_packages[counterpart].get('size')
if add_pip and info['name'] == 'python' and info['version'].startswith(('2.', '3.')):
info['depends'].append('pip')
info.update(meta_in_common)
if info.get('record_version', 0) > 1:
log.debug("Ignoring record_version %d from %s",
info["record_version"], info['url'])
continue
package_record = PackageRecord(**info)

_package_records.append(package_record)
_names_index[package_record.name].append(package_record)
for ftr_name in package_record.track_features:
_track_features_index[ftr_name].append(package_record)

self._internal_state = _internal_state
return _internal_state
Expand Down
3 changes: 3 additions & 0 deletions conda/models/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ class PackageRecord(DictSafeMixin, Entity):
fn = FilenameField(aliases=('filename',))

md5 = StringField(default=None, required=False, nullable=True, default_in_dump=False)
legacy_bz2_md5 = StringField(default=None, required=False, nullable=True,
default_in_dump=False)
legacy_bz2_size = IntegerField(required=False, nullable=True, default_in_dump=False)
url = StringField(default=None, required=False, nullable=True, default_in_dump=False)
sha256 = StringField(default=None, required=False, nullable=True, default_in_dump=False)

Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_package_cache_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"depends": [
"vc >=14.1,<15.0a0"
],
"legacy_bz2_md5": "a46cf10ba0eece37dffcec2d45a1f4ec",
"legacy_bz2_size": 131285,
"license": "zlib",
"license_family": "Other",
"md5": "edad165fc3d25636d4f0a61c42873fbc",
Expand Down

0 comments on commit f87945e

Please sign in to comment.