Skip to content

Commit

Permalink
beginning work to make Record immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Nov 29, 2016
1 parent 08d71a7 commit dfce753
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
10 changes: 6 additions & 4 deletions conda/core/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ def add_http_value_to_dict(resp, http_key, d, dict_key):


def add_unknown(index, priorities):
# TODO: discuss with @mcg1969 and document
priorities = {p[0]: p[1] for p in itervalues(priorities)}
maxp = max(itervalues(priorities)) + 1 if priorities else 1
for dist, info in iteritems(package_cache()):
Expand All @@ -356,7 +357,7 @@ def add_unknown(index, priorities):
continue
try:
with open(join(info['dirs'][0], 'info', 'index.json')) as fi:
meta = Record(**json.load(fi))
meta = json.load(fi)
except IOError:
continue
if info['urls']:
Expand All @@ -383,13 +384,14 @@ def add_unknown(index, priorities):
})
meta.setdefault('depends', [])
log.debug("adding cached pkg to index: %s" % dist)
index[dist] = meta
index[dist] = Record(**meta)


def add_pip_dependency(index):
for info in itervalues(index):
# TODO: discuss with @mcg1969 and document
for dist, info in iteritems(index):
if info['name'] == 'python' and info['version'].startswith(('2.', '3.')):
info['depends'] = info['depends'] + ('pip',)
index[dist] = Record.from_objects(info, depends=info['depends'] + ('pip',))


def create_cache_dir():
Expand Down
25 changes: 12 additions & 13 deletions conda/core/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from ..gateways.disk.delete import rm_rf
from ..gateways.disk.read import collect_all_info_for_package, yield_lines
from ..gateways.disk.update import _PaddingError, update_prefix
from ..models.record import Link
from ..models.record import Link, Record
from ..models.package_info import PathType
from ..utils import on_win

Expand Down Expand Up @@ -164,21 +164,20 @@ def _create_meta(self, dest_short_paths, requested_link_type, url):
Create the conda metadata, in a given prefix, for a given package.
"""
package_info = self.package_info
meta_dict = self.index.get(self.dist, {})
meta_dict['url'] = url
record_from_index = self.index.get(self.dist, {})
new_info = dict()
new_info['url'] = url

# alt_files_path is a hack for python_noarch
alt_files_path = join(self.prefix, 'conda-meta', self.dist.to_filename('.files'))
meta_dict['files'] = (list(yield_lines(alt_files_path)) if isfile(alt_files_path)
else dest_short_paths)
meta_dict['link'] = Link(source=self.extracted_package_dir, type=requested_link_type)
if 'icon' in meta_dict:
meta_dict['icondata'] = package_info.icondata

meta = package_info.index_json_record
meta.update(meta_dict)

return meta
new_info['files'] = (list(yield_lines(alt_files_path)) if isfile(alt_files_path)
else dest_short_paths)
new_info['link'] = Link(source=self.extracted_package_dir, type=requested_link_type)
if 'icon' in record_from_index:
new_info['icondata'] = package_info.icondata

record_from_package = package_info.index_json_record
return Record.from_objects(new_info, record_from_index, record_from_package)


class NoarchPythonPackageInstaller(PackageInstaller):
Expand Down
8 changes: 4 additions & 4 deletions conda/models/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

from logging import getLogger

from .._vendor.auxlib.entity import (BooleanField, ComposableField, DictSafeMixin, Entity,
EnumField, IntegerField, ListField, StringField, MapField)
from ..base.constants import Arch, Platform, LinkType
from .._vendor.auxlib.entity import BooleanField, ComposableField, DictSafeMixin, Entity, \
EnumField, ImmutableEntity, IntegerField, ListField, MapField, StringField
from ..base.constants import Arch, LinkType, Platform
from ..common.compat import string_types

log = getLogger(__name__)
Expand Down Expand Up @@ -46,7 +46,7 @@ class Link(DictSafeMixin, Entity):
# version = StringField()


class Record(DictSafeMixin, Entity):
class Record(DictSafeMixin, ImmutableEntity):
arch = EnumField(Arch, required=False, nullable=True)
build = StringField()
build_number = IntegerField()
Expand Down

0 comments on commit dfce753

Please sign in to comment.