Skip to content

Commit

Permalink
Merge pull request conda#2 from kalefranz/pr-3880
Browse files Browse the repository at this point in the history
changes to match conda-build
  • Loading branch information
Sophia Castellarin authored Nov 21, 2016
2 parents a1d4803 + d60fe71 commit 50324b6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 52 deletions.
6 changes: 3 additions & 3 deletions conda/core/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
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.package_info import NodeType
from ..models.package_info import PathType
from ..utils import on_win

try:
Expand Down Expand Up @@ -102,7 +102,7 @@ def make_link_operation(source_path_info):
link_type = LinkType.copy
prefix_placehoder = source_path_info.prefix_placeholder
file_mode = source_path_info.file_mode
elif source_path_info.no_link or source_path_info.node_type == NodeType.softlink:
elif source_path_info.no_link or source_path_info.path_type == PathType.softlink:
link_type = LinkType.copy
prefix_placehoder, file_mode = '', None
else:
Expand Down Expand Up @@ -196,7 +196,7 @@ def make_link_operation(source_path_info):
link_type = LinkType.copy
prefix_placehoder = source_path_info.prefix_placeholder
file_mode = source_path_info.file_mode
elif source_path_info.no_link or source_path_info.node_type == NodeType.softlink:
elif source_path_info.no_link or source_path_info.path_type == PathType.softlink:
link_type = LinkType.copy
prefix_placehoder, file_mode = '', None
else:
Expand Down
4 changes: 2 additions & 2 deletions conda/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
non_x86_linux_machines = non_x86_linux_machines

from conda.base.constants import DEFAULT_CHANNELS # NOQA
from .models.package_info import NodeType # NOQA
from .models.package_info import PathType # NOQA
from ._vendor.auxlib.entity import EntityEncoder # NOQA
NodeType = NodeType
PathType = PathType
EntityEncoder = EntityEncoder
get_prefix = partial(context_get_prefix, conda.base.context.context)
get_default_urls = lambda: DEFAULT_CHANNELS
Expand Down
18 changes: 9 additions & 9 deletions conda/gateways/disk/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from os.path import isfile, islink, join

from ...base.constants import FileMode, PREFIX_PLACEHOLDER, UTF8
from ...models.package_info import NodeType, PackageInfo, PathInfoV1, PathInfo
from ...models.package_info import PathType, PackageInfo, PathInfoV1, PathInfo
from ...models.record import Record
from ...exceptions import CondaUpgradeError

Expand Down Expand Up @@ -51,17 +51,17 @@ def collect_all_info_for_package(extracted_package_directory):
if isfile(file_json_path):
with open(file_json_path) as file_json:
data = json.load(file_json)
if data.get('version') != 1:
if data.get('paths_version') != 1:
raise CondaUpgradeError("""The current version of conda is too old to install this
package. (This version only supports files.json schema version 1.) Please update conda to install
this package.""")

files = (PathInfoV1(**f) for f in data['files'])
paths = (PathInfoV1(**f) for f in data['paths'])
index_json_record = read_index_json(extracted_package_directory)
noarch = read_noarch(extracted_package_directory)
icondata = read_icondata(extracted_package_directory)
return PackageInfo(files=files, index_json_record=index_json_record, noarch=noarch,
icondata=icondata, path_info_version=1)
return PackageInfo(paths=paths, index_json_record=index_json_record, noarch=noarch,
icondata=icondata, paths_version=1)
else:
files = tuple(ln for ln in (line.strip() for line in yield_lines(files_path)) if ln)

Expand All @@ -77,17 +77,17 @@ def collect_all_info_for_package(extracted_package_directory):
if f in no_link:
path_info["no_link"] = True
if islink(join(extracted_package_directory, f)):
path_info["node_type"] = NodeType.softlink
path_info["path_type"] = PathType.softlink
else:
path_info["node_type"] = NodeType.hardlink
path_info["path_type"] = PathType.hardlink
path_info_files.append(PathInfo(**path_info))

index_json_record = read_index_json(extracted_package_directory)
icondata = read_icondata(extracted_package_directory)
noarch = read_noarch(extracted_package_directory)

return PackageInfo(files=path_info_files, index_json_record=index_json_record,
icondata=icondata, noarch=noarch, path_info_version=0)
return PackageInfo(paths=path_info_files, index_json_record=index_json_record,
icondata=icondata, noarch=noarch, paths_version=0)


def read_noarch(extracted_package_directory):
Expand Down
29 changes: 12 additions & 17 deletions conda/models/package_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,13 @@ class NoarchInfo(Entity):
entry_points = ListField(string_types, required=False)


class NodeType(Enum):
class PathType(Enum):
"""
Refers to if the file in question is hard linked or soft linked. Originally designed to be used
in files.json
"""
hardlink = 1
softlink = 2

@classmethod
def __call__(cls, value, *args, **kwargs):
if isinstance(cls, value, *args, **kwargs):
return cls[value]
return super(NodeType, cls).__call__(value, *args, **kwargs)

@classmethod
def __getitem__(cls, name):
return cls._member_map_[name.replace('-', '').replace('_', '').lower()]
hardlink = 'hardlink'
softlink = 'softlink'

def __int__(self):
return self.value
Expand All @@ -44,11 +34,16 @@ def __str__(self):


class PathInfo(Entity):
path = StringField()
_path = StringField()
prefix_placeholder = StringField(required=False, nullable=True)
file_mode = EnumField(FileMode, required=False, nullable=True)
no_link = BooleanField(required=False, nullable=True)
node_type = EnumField(NodeType)
path_type = EnumField(PathType)

@property
def path(self):
# because I don't have aliases as an option for entity fields yet
return self._path


class PathInfoV1(PathInfo):
Expand All @@ -58,8 +53,8 @@ class PathInfoV1(PathInfo):


class PackageInfo(Entity):
path_info_version = IntegerField()
files = ListField(PathInfo)
paths_version = IntegerField()
paths = ListField(PathInfo)
index_json_record = ComposableField(Record)
icondata = StringField(required=False, nullable=True)
noarch = ComposableField(NoarchInfo, required=False, nullable=True)
26 changes: 13 additions & 13 deletions tests/core/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from conda.core.install import (PackageInstaller, PackageUninstaller, NoarchPythonPackageInstaller,
LinkOperation)
from conda.models.dist import Dist
from conda.models.package_info import PathInfo, PackageInfo, NoarchInfo, NodeType
from conda.models.package_info import PathInfo, PackageInfo, NoarchInfo, PathType
from conda.models.record import Link, Record
from conda.utils import on_win

Expand All @@ -22,13 +22,13 @@ def setUp(self):
self.dist = Dist("channel", "dist_name")
index_json_records = Record(build=0, build_number=0, name="test_foo", version=0)
icondata = "icondata"
files = [PathInfo(path="test/path/1", file_mode=FileMode.text, node_type=NodeType.hardlink,
prefix_placeholder="/opt/anaconda1anaconda2anaconda3",),
PathInfo(path="test/path/2", no_link=True, node_type=NodeType.hardlink),
PathInfo(path="test/path/3", node_type=NodeType.softlink),
PathInfo(path="menu/test.json", node_type=NodeType.hardlink)]
paths = [PathInfo(path="test/path/1", file_mode=FileMode.text, path_type=PathType.hardlink,
prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ),
PathInfo(path="test/path/2", no_link=True, path_type=PathType.hardlink),
PathInfo(path="test/path/3", path_type=PathType.softlink),
PathInfo(path="menu/test.json", path_type=PathType.hardlink)]

self.package_info = PackageInfo(path_info_version=0, files=files, icondata=icondata,
self.package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata,
index_json_record=index_json_records)

def test_make_link_operation(self):
Expand Down Expand Up @@ -68,14 +68,14 @@ def setUp(self):
index_json_records = Record(build=0, build_number=0, name="test_foo", version=0)
icondata = "icondata"

files = [PathInfo(path="site-packages/test/1", file_mode=FileMode.text,
node_type=NodeType.hardlink,
paths = [PathInfo(path="site-packages/test/1", file_mode=FileMode.text,
path_type=PathType.hardlink,
prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ),
PathInfo(path="python-scripts/test/2", no_link=True, node_type=NodeType.hardlink),
PathInfo(path="test/path/3", node_type=NodeType.softlink),
PathInfo(path="menu/test.json", node_type=NodeType.hardlink)]
PathInfo(path="python-scripts/test/2", no_link=True, path_type=PathType.hardlink),
PathInfo(path="test/path/3", path_type=PathType.softlink),
PathInfo(path="menu/test.json", path_type=PathType.hardlink)]

self.package_info = PackageInfo(path_info_version=0, files=files, icondata=icondata,
self.package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata,
index_json_record=index_json_records)

@patch("conda.core.linked_data.get_python_version_for_prefix", return_value="2.4")
Expand Down
16 changes: 8 additions & 8 deletions tests/models/test_package_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conda.models.package_info import PackageInfo, PathInfo, NodeType, NoarchInfo
from conda.models.package_info import PackageInfo, PathInfo, PathType, NoarchInfo
from conda.base.constants import FileMode
from conda.models.record import Record
from unittest import TestCase
Expand All @@ -9,15 +9,15 @@ def test_package_info(self):
index_json_records = Record(build=0, build_number=0, name="test_foo", version=0)
icondata = "icondata"
noarch = NoarchInfo(type="python", entry_points=["test:foo"])
files = [PathInfo(path="test/path/1", file_mode=FileMode.text, node_type=NodeType.hardlink,
paths = [PathInfo(path="test/path/1", file_mode=FileMode.text, path_type=PathType.hardlink,
prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ),
PathInfo(path="test/path/2", no_link=True, node_type=NodeType.hardlink),
PathInfo(path="test/path/3", node_type=NodeType.softlink),
PathInfo(path="menu/test.json", node_type=NodeType.hardlink)]
PathInfo(path="test/path/2", no_link=True, path_type=PathType.hardlink),
PathInfo(path="test/path/3", path_type=PathType.softlink),
PathInfo(path="menu/test.json", path_type=PathType.hardlink)]

package_info = PackageInfo(path_info_version=0, files=files, icondata=icondata,
package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata,
index_json_record=index_json_records, noarch=noarch)
self.assertIsInstance(package_info.files[0], PathInfo)
self.assertIsInstance(package_info.paths[0], PathInfo)
self.assertIsInstance(package_info.index_json_record, Record)
self.assertIsInstance(package_info.noarch, NoarchInfo)
self.assertEquals(package_info.files[0].path, "test/path/1")
self.assertEquals(package_info.paths[0].path, "test/path/1")

0 comments on commit 50324b6

Please sign in to comment.