Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: scripts/slave/recipe_modules/conda/api.py

Issue 1511383003: Add recipe to build CIPD package with relocatable Conda environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: add mathplot lib, depends on Qt :( Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Functions to work with Miniconda python environment.
6
7 See http://conda.pydata.org/miniconda.html
8 """
9
10 from recipe_engine import recipe_api
11
12
13 class CondaEnv(object):
14 def __init__(self, module_api, version, path):
15 self._module_api = module_api
16 self.version = version
17 self.path = path
18
19 def install(self, pkg):
20 """Installs a conda package into the environment."""
21 return self._call(['install', pkg])
22
23 def convert_to_cipd_package(self, package_name, output_file):
24 """Packages Conda environment as CIPD package.
25
26 It also destroys it in the process (by irreversibly mutating it to be
27 prefix independent, as much as possible). It is not possible to install
28 new packages into the environment once it has been mutated.
29
30 Args:
31 package_name: name of the CIPD package, 'infra/conda_python/linux-amd64'.
32 output_file: path to put *.cipd package to.
33 """
34 self._call(['clean', '--tarballs', '--index-cache', '--packages'])
35 self._module_api.m.python(
36 'make conda env location independent',
37 self._module_api.resource('butcher_conda.py'),
38 args=[self.path])
39 self._module_api.m.cipd.build(
40 input_dir=self.path,
41 output_package=output_file,
42 package_name=package_name,
43 install_mode='copy')
44
45 def _call(self, cmd):
46 if self._module_api.m.platform.is_win:
47 conda_exe = self.path.join('Scripts', 'conda.exe')
48 else:
49 conda_exe = self.path.join('bin', 'conda')
50 return self._module_api.m.step(
51 ' '.join(['conda'] + cmd),
52 [conda_exe] + cmd + ['--yes'],
53 env={'PYTHONPATH': ''})
54
55
56 class CondaApi(recipe_api.RecipeApi):
57 def install(self, version, path):
58 """Downloads Miniconda installer for given version and executes it.
59
60 Args:
61 version: version of Miniconda to install, e.g. 'Miniconda2-3.18.3'.
62 path: prefix to install Miniconda into.
63
64 Returns:
65 Instance of CondaEnv.
66 """
67 # Construct URL to installer. See https://repo.continuum.io/miniconda/.
68 os = {
69 'linux': 'Linux',
70 'mac': 'MacOSX',
71 'win': 'Windows',
72 }[self.m.platform.name]
73 arch = {
74 32: 'x86',
75 64: 'x86_64',
76 }[self.m.platform.bits]
77 ext = '.exe' if self.m.platform.is_win else '.sh'
78 url = (
79 'https://repo.continuum.io/miniconda/%s-%s-%s%s' %
80 (version, os, arch, ext))
81
82 # Fetch installer into temp directory and install Conda to 'path'.
83 # We acknowledge the license agreement.
84 tmp = self.m.path.mkdtemp('conda')
85 installer = tmp.join(url[url.rfind('/')+1:])
86 try:
87 self.m.url.fetch_to_file(
88 url=url,
89 path=installer,
90 step_name='fetch miniconda installer',
91 attempts=5)
92 if self.m.platform.is_win:
93 install_cmd = [installer, '/S', '/D=' + str(path)]
94 else:
95 install_cmd = ['/bin/bash', installer, '-b', '-p', path]
96 self.m.step('install miniconda', install_cmd, env={'PYTHONPATH': ''})
97 return CondaEnv(self, version, path)
98 finally:
99 self.m.file.rmtree('remove miniconda installer', tmp)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698