Skip to content

Commit

Permalink
add extra properties to Dist; fixes to test_plan.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Nov 29, 2016
1 parent a3f0ef3 commit 313293e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conda/core/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ def run_script(prefix, dist, action='post-link', env_prefix=None):
args = [shell_path, path]
env = os.environ.copy()
name, version, _, _ = dist.quad
build_number = dist.build_number()
build_number = dist.build_number
env[str('ROOT_PREFIX')] = sys.prefix
env[str('PREFIX')] = str(env_prefix or prefix)
env[str('PKG_NAME')] = name
Expand Down
29 changes: 22 additions & 7 deletions conda/models/dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ def __init__(self, channel, dist_name=None, with_features_depends=None):
def full_name(self):
return self.__str__()

@property
def name(self):
return self.quad[0]

@property
def version(self):
return self.quad[1]

@property
def build_string(self):
return self.quad[2]

@property
def build(self):
return self.build_string

@property
def build_number(self):
n = ensure_text_type(self.quad[2].rsplit('_')[-1])
n = int(n) if n.isdigit() else 0
return int(n)

@property
def pair(self):
return self.channel or DEFAULTS, self.dist_name
Expand All @@ -54,13 +76,6 @@ def quad(self):
parts = self.dist_name.rsplit('-', 2) + ['', '']
return parts[0], parts[1], parts[2], self.channel or DEFAULTS

def build_number(self):
n = self.quad[2].rsplit('_')[-1]
if hasattr(n, 'decode'):
n = n.decode(UTF8)
n = int(n) if n.isdigit() else 0
return int(n)

def __str__(self):
base = "%s::%s" % (self.channel, self.dist_name) if self.channel else self.dist_name
if self.with_features_depends:
Expand Down
29 changes: 19 additions & 10 deletions tests/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def test_display_actions():
reset_context(())
actions = defaultdict(list, {"FETCH": [Dist('sympy-0.7.2-py27_0'), Dist("numpy-1.7.1-py27_0")]})
# The older test index doesn't have the size metadata
index[Dist.from_string('sympy-0.7.2-py27_0.tar.bz2')]['size'] = 4374752
index[Dist.from_string("numpy-1.7.1-py27_0.tar.bz2")]['size'] = 5994338
d = Dist.from_string('sympy-0.7.2-py27_0.tar.bz2')
index[d] = Record.from_objects(index[d], size=4374752)
d = Dist.from_string("numpy-1.7.1-py27_0.tar.bz2")
index[d] = Record.from_objects(index[d], size=5994338)

with captured() as c:
display_actions(actions, index)
Expand Down Expand Up @@ -283,8 +285,10 @@ def test_display_actions_show_channel_urls():
actions = defaultdict(list, {"FETCH": ['sympy-0.7.2-py27_0',
"numpy-1.7.1-py27_0"]})
# The older test index doesn't have the size metadata
index[Dist('sympy-0.7.2-py27_0.tar.bz2')]['size'] = 4374752
index[Dist("numpy-1.7.1-py27_0.tar.bz2")]['size'] = 5994338
d = Dist('sympy-0.7.2-py27_0.tar.bz2')
index[d] = Record.from_objects(d, size=4374752)
d = Dist('numpy-1.7.1-py27_0.tar.bz2')
index[d] = Record.from_objects(d, size=5994338)

with captured() as c:
display_actions(actions, index)
Expand All @@ -294,8 +298,8 @@ def test_display_actions_show_channel_urls():
package | build
---------------------------|-----------------
sympy-0.7.2 | py27_0 4.2 MB <unknown>
numpy-1.7.1 | py27_0 5.7 MB <unknown>
sympy-0.7.2 | py27_0 4.2 MB defaults
numpy-1.7.1 | py27_0 5.7 MB defaults
------------------------------------------------------------
Total: 9.9 MB
Expand Down Expand Up @@ -417,8 +421,10 @@ def test_display_actions_show_channel_urls():

actions['LINK'], actions['UNLINK'] = actions['UNLINK'], actions['LINK']

index[Dist('cython-0.19.1-py33_0.tar.bz2')]['channel'] = 'my_channel'
index[Dist('dateutil-1.5-py33_0.tar.bz2')]['channel'] = 'my_channel'
d = Dist('cython-0.19.1-py33_0.tar.bz2')
index[d] = Record.from_objects(d, channel='my_channel')
d = Dist('dateutil-1.5-py33_0.tar.bz2')
index[d] = Record.from_objects(d, channel='my_channel')

with captured() as c:
display_actions(actions, index)
Expand Down Expand Up @@ -601,8 +607,11 @@ def test_display_actions_link_type():
os.environ['CONDA_SHOW_CHANNEL_URLS'] = 'True'
reset_context(())

index[Dist('cython-0.19.1-py33_0.tar.bz2')]['channel'] = 'my_channel'
index[Dist('dateutil-1.5-py33_0.tar.bz2')]['channel'] = 'my_channel'
d = Dist('cython-0.19.1-py33_0.tar.bz2')
index[d] = Record.from_objects(index[d], channel='my_channel')

d = Dist('dateutil-1.5-py33_0.tar.bz2')
index[d] = Record.from_objects(index[d], channel='my_channel')

actions = defaultdict(list, {'LINK': ['cython-0.19.1-py33_0 3', 'dateutil-1.5-py33_0 3',
'numpy-1.7.1-py33_0 3', 'python-3.3.2-0 3', 'readline-6.2-0 3', 'sqlite-3.7.13-0 3', 'tk-8.5.13-0 3', 'zlib-1.2.7-0 3']})
Expand Down

0 comments on commit 313293e

Please sign in to comment.