forked from conda/conda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request conda#3927 from kalefranz/pr-3880
Populate PackageInfo model with info from paths.json
- Loading branch information
Showing
7 changed files
with
170 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,60 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from collections import namedtuple | ||
from enum import Enum | ||
from logging import getLogger | ||
|
||
from .._vendor.auxlib.entity import Entity, ListField | ||
from .record import Record | ||
from .._vendor.auxlib.entity import (BooleanField, ComposableField, Entity, EnumField, | ||
IntegerField, ListField, StringField) | ||
from ..base.constants import FileMode | ||
from ..common.compat import string_types | ||
|
||
log = getLogger(__name__) | ||
|
||
|
||
PackageInfoContents = namedtuple('PackageInfoContents', | ||
('files', 'has_prefix_files', 'no_link', 'soft_links', | ||
'index_json_record', 'icondata', 'noarch')) | ||
class NoarchInfo(Entity): | ||
type = StringField() | ||
entry_points = ListField(string_types, required=False) | ||
|
||
|
||
class PackageInfo(Entity): | ||
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 = 'hardlink' | ||
softlink = 'softlink' | ||
|
||
def __int__(self): | ||
return self.value | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
|
||
class PathInfo(Entity): | ||
_path = StringField() | ||
prefix_placeholder = StringField(required=False, nullable=True) | ||
file_mode = EnumField(FileMode, required=False, nullable=True) | ||
no_link = BooleanField(required=False, nullable=True) | ||
path_type = EnumField(PathType) | ||
|
||
file = ListField(string_types) | ||
# TODO: finish this | ||
@property | ||
def path(self): | ||
# because I don't have aliases as an option for entity fields yet | ||
return self._path | ||
|
||
|
||
class PathInfoV1(PathInfo): | ||
sha256 = StringField() | ||
size_in_bytes = IntegerField() | ||
inode_paths = ListField(string_types, required=False, nullable=True) | ||
|
||
|
||
class PackageInfo(Entity): | ||
paths_version = IntegerField() | ||
paths = ListField(PathInfo) | ||
index_json_record = ComposableField(Record) | ||
icondata = StringField(required=False, nullable=True) | ||
noarch = ComposableField(NoarchInfo, required=False, nullable=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
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 | ||
|
||
|
||
class DefaultPackageInfo(TestCase): | ||
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"]) | ||
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)] | ||
|
||
package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata, | ||
index_json_record=index_json_records, noarch=noarch) | ||
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.paths[0].path, "test/path/1") |