Skip to content

Commit

Permalink
allow packages to be specified as package=version=build (#21)
Browse files Browse the repository at this point in the history
allow packages to be specified as package=version=build
  • Loading branch information
evandam authored Jan 14, 2020
2 parents 0210423 + a804833 commit 8ba2309
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
16 changes: 11 additions & 5 deletions library/conda.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ def __init__(self, module, env):
def split_name_version(package_spec, default_version=None):
name = package_spec
version = default_version
build = None
if '=' in package_spec:
name, version = package_spec.split('=')
return {'name': name, 'version': version}
splits = package_spec.split('=')
name, version = splits[:2]
if len(splits) > 2:
build = splits[2]
return {'name': name, 'version': version, 'build': build}

def _get_conda(self, executable):
conda_exe = None
Expand Down Expand Up @@ -153,10 +157,12 @@ def install_packages(self, packages, channels):
"""Install the packages"""
pkg_strs = []
for package in packages:
pkg_str = package['name']
if package['version']:
pkg_strs.append('{name}={version}'.format(**package))
else:
pkg_strs.append(package['name'])
pkg_str += '=' + package['version']
if package['build']:
pkg_str += '=' + package['build']
pkg_strs.append(pkg_str)
return self._run_package_cmd('install',
channels,
*pkg_strs + self.env_args)
Expand Down
9 changes: 8 additions & 1 deletion molecule/default/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
roles:
- role: evandam.conda
tasks:
- name: Install jupyter with a specific build
conda:
name: jupyter=1.0.0=py37_4

- name: Install an older version of conda
conda:
name: conda
version: 4.5.0
version: 4.8.0

- name: Update conda to latest version
conda:
name: conda
state: latest

- name: Update conda again
conda:
name: conda
Expand All @@ -30,6 +35,7 @@
conda:
name: numpy
state: present

- name: Install numpy again
conda:
name: numpy
Expand All @@ -40,6 +46,7 @@
conda:
name: numpy
state: absent

- name: Remove numpy again
conda:
name: numpy
Expand Down

0 comments on commit 8ba2309

Please sign in to comment.