1
- from __future__ import print_function
2
-
3
1
import argparse
4
2
import logging
5
3
import os
6
4
import platform
7
5
import shutil
8
6
import subprocess
9
7
import sys
10
-
11
- try :
12
- from urllib .request import Request , urlopen
13
- except ImportError :
14
- from urllib2 import Request , urlopen
8
+ from urllib .request import Request , urlopen
15
9
16
10
17
11
def parse_args (bootstrap ):
@@ -47,6 +41,10 @@ def parse_args(bootstrap):
47
41
"packages" )
48
42
parser .add_argument ("--use_local" , dest = "use_local" , action = 'store_true' ,
49
43
help = "Use locally built conda packages (for testing)." )
44
+ parser .add_argument ("--mache_fork" , dest = "mache_fork" ,
45
+ help = "Point to a mache fork (and branch) for testing" )
46
+ parser .add_argument ("--mache_branch" , dest = "mache_branch" ,
47
+ help = "Point to a mache branch (and fork) for testing" )
50
48
parser .add_argument ("--update_spack" , dest = "update_spack" ,
51
49
action = 'store_true' ,
52
50
help = "If the shared spack environment should be "
@@ -78,6 +76,10 @@ def parse_args(bootstrap):
78
76
79
77
args = parser .parse_args (sys .argv [1 :])
80
78
79
+ if (args .mache_fork is None ) != (args .mache_branch is None ):
80
+ raise ValueError ('You must supply both or neither of '
81
+ '--mache_fork and --mache_branch' )
82
+
81
83
return args
82
84
83
85
@@ -92,9 +94,9 @@ def get_conda_base(conda_base, config, shared=False, warn=False):
92
94
conda_base = os .path .abspath (
93
95
os .path .join (conda_exe , '..' , '..' ))
94
96
if warn :
95
- print ('\n Warning: --conda path not supplied. Using conda '
96
- 'installed at:\n '
97
- ' {}\n ' . format ( conda_base ) )
97
+ print (f '\n Warning: --conda path not supplied. Using conda '
98
+ f 'installed at:\n '
99
+ f ' { conda_base } \n ' )
98
100
else :
99
101
raise ValueError ('No conda base provided with --conda and '
100
102
'none could be inferred.' )
@@ -118,9 +120,9 @@ def get_spack_base(spack_base, config):
118
120
def check_call (commands , env = None , logger = None ):
119
121
print_command = '\n ' .join (commands .split (' && ' ))
120
122
if logger is None :
121
- print ('\n Running:\n {}\n ' . format ( print_command ) )
123
+ print (f '\n Running:\n { print_command } \n ' )
122
124
else :
123
- logger .info ('\n running:\n {}\n ' . format ( print_command ) )
125
+ logger .info (f '\n running:\n { print_command } \n ' )
124
126
125
127
if logger is None :
126
128
process = subprocess .Popen (commands , env = env , executable = '/bin/bash' ,
@@ -154,8 +156,8 @@ def install_miniconda(conda_base, activate_base, logger):
154
156
system = 'MacOSX'
155
157
else :
156
158
system = 'Linux'
157
- miniconda = 'Mambaforge-{}-x86_64.sh' . format ( system )
158
- url = 'https://github.com/conda-forge/miniforge/releases/latest/download/{}' . format ( miniconda ) # noqa: E501
159
+ miniconda = f 'Mambaforge-{ system } -x86_64.sh'
160
+ url = f 'https://github.com/conda-forge/miniforge/releases/latest/download/{ miniconda } ' # noqa: E501
159
161
print (url )
160
162
req = Request (url , headers = {'User-Agent' : 'Mozilla/5.0' })
161
163
f = urlopen (req )
@@ -164,31 +166,30 @@ def install_miniconda(conda_base, activate_base, logger):
164
166
outfile .write (html )
165
167
f .close ()
166
168
167
- command = '/bin/bash {} -b -p {}' . format ( miniconda , conda_base )
169
+ command = f '/bin/bash { miniconda } -b -p { conda_base } '
168
170
check_call (command , logger = logger )
169
171
os .remove (miniconda )
170
172
171
173
backup_bashrc ()
172
174
173
175
print ('Doing initial setup\n ' )
174
176
175
- commands = '{} && ' \
176
- 'conda config --add channels conda-forge && ' \
177
- 'conda config --set channel_priority strict' \
178
- '' .format (activate_base )
177
+ commands = f'{ activate_base } && ' \
178
+ f'conda config --add channels conda-forge && ' \
179
+ f'conda config --set channel_priority strict'
179
180
180
181
check_call (commands , logger = logger )
181
182
182
- commands = '{ } && ' \
183
- 'conda remove -y boa' . format ( activate_base )
183
+ commands = f' { activate_base } && ' \
184
+ f 'conda remove -y boa'
184
185
try :
185
186
check_call (commands , logger = logger )
186
187
except subprocess .CalledProcessError :
187
188
pass
188
189
189
- commands = '{ } && ' \
190
- 'mamba update -y --all && ' \
191
- 'mamba init' . format ( activate_base )
190
+ commands = f' { activate_base } && ' \
191
+ f 'mamba update -y --all && ' \
192
+ f 'mamba init'
192
193
193
194
check_call (commands , logger = logger )
194
195
@@ -200,7 +201,7 @@ def backup_bashrc():
200
201
files = ['.bashrc' , '.bash_profile' ]
201
202
for filename in files :
202
203
src = os .path .join (home_dir , filename )
203
- dst = os .path .join (home_dir , '{ }.conda_bak'. format ( filename ) )
204
+ dst = os .path .join (home_dir , f' { filename } .conda_bak' )
204
205
if os .path .exists (src ):
205
206
shutil .copyfile (src , dst )
206
207
@@ -209,14 +210,14 @@ def restore_bashrc():
209
210
home_dir = os .path .expanduser ('~' )
210
211
files = ['.bashrc' , '.bash_profile' ]
211
212
for filename in files :
212
- src = os .path .join (home_dir , '{ }.conda_bak'. format ( filename ) )
213
+ src = os .path .join (home_dir , f' { filename } .conda_bak' )
213
214
dst = os .path .join (home_dir , filename )
214
215
if os .path .exists (src ):
215
216
shutil .move (src , dst )
216
217
217
218
218
219
def get_logger (name , log_filename ):
219
- print ('Logging to: {}\n ' . format ( log_filename ) )
220
+ print (f 'Logging to: { log_filename } \n ' )
220
221
try :
221
222
os .remove (log_filename )
222
223
except OSError :
0 commit comments