48
48
except ImportError :
49
49
import ruamel_json as json
50
50
51
- files = ".constructor-build.info" , "urls" , "urls.txt" , "env.txt"
51
+ files = (
52
+ "pkgs/.constructor-build.info" ,
53
+ "pkgs/urls" ,
54
+ "pkgs/urls.txt" ,
55
+ "conda-meta/initial-state.explicit.txt" ,
56
+ )
52
57
53
58
54
59
def write_index_cache (info , dst_dir , used_packages ):
@@ -135,8 +140,28 @@ def system_info():
135
140
return out
136
141
137
142
138
- def write_files (info , dst_dir ):
139
- with open (join (dst_dir , ".constructor-build.info" ), "w" ) as fo :
143
+ def write_files (info : dict , workspace : str ):
144
+ """
145
+ Prepare files on disk to be shipped as part of the pre-conda payload, mostly
146
+ configuration and metadata files:
147
+
148
+ - `conda-meta/initial-state.explicit.txt`: Lockfile to provision the base environment.
149
+ - `conda-meta/history`: Prepared history file with the right requested specs in input file.
150
+ - `pkgs/urls` and `pkgs/urls.txt`: Direct URLs of packages used, with and without MD5 hashes.
151
+ - `pkgs/cache/*.json`: Trimmed repodata to mock offline channels in use.
152
+ - `pkgs/channels.txt`: Channels in use.
153
+ - `pkgs/shortcuts.txt`: Which packages should have their shortcuts created, if any.
154
+
155
+ If extra envs are requested, this will also write:
156
+
157
+ - Their corresponding `envs/<env-name>/conda-meta/` files.
158
+ - Their corresponding `pkgs/channels.txt` and `pkgs/shortcuts.txt` under
159
+ `pkgs/envs/<env-name>`.
160
+ """
161
+ os .makedirs (join (workspace , "conda-meta" ), exist_ok = True )
162
+ pkgs_dir = join (workspace , "pkgs" )
163
+ os .makedirs (pkgs_dir , exist_ok = True )
164
+ with open (join (pkgs_dir , ".constructor-build.info" ), "w" ) as fo :
140
165
json .dump (system_info (), fo )
141
166
142
167
all_urls = info ["_urls" ].copy ()
@@ -146,15 +171,15 @@ def write_files(info, dst_dir):
146
171
final_urls_md5s = tuple ((get_final_url (info , url ), md5 ) for url , md5 in info ["_urls" ])
147
172
all_final_urls_md5s = tuple ((get_final_url (info , url ), md5 ) for url , md5 in all_urls )
148
173
149
- with open (join (dst_dir , "urls" ), "w" ) as fo :
174
+ with open (join (pkgs_dir , "urls" ), "w" ) as fo :
150
175
for url , md5 in all_final_urls_md5s :
151
176
maybe_different_url = ensure_transmuted_ext (info , url )
152
177
if maybe_different_url != url : # transmuted, no md5
153
178
fo .write (f"{ maybe_different_url } \n " )
154
179
else :
155
180
fo .write (f"{ url } #{ md5 } \n " )
156
181
157
- with open (join (dst_dir , "urls.txt" ), "w" ) as fo :
182
+ with open (join (pkgs_dir , "urls.txt" ), "w" ) as fo :
158
183
for url , _ in all_final_urls_md5s :
159
184
fo .write ("%s\n " % url )
160
185
@@ -163,33 +188,36 @@ def write_files(info, dst_dir):
163
188
all_dists += env_info ["_dists" ]
164
189
all_dists = list ({dist : None for dist in all_dists }) # de-duplicate
165
190
166
- write_index_cache (info , dst_dir , all_dists )
191
+ write_index_cache (info , pkgs_dir , all_dists )
167
192
168
193
# base environment conda-meta
169
- write_conda_meta (info , dst_dir , final_urls_md5s )
194
+ write_conda_meta (info , join ( workspace , "conda-meta" ) , final_urls_md5s )
170
195
171
- write_repodata_record (info , dst_dir )
196
+ write_repodata_record (info , pkgs_dir )
172
197
173
198
# base environment file used with conda install --file
174
199
# (list of specs/dists to install)
175
- write_env_txt (info , dst_dir , final_urls_md5s )
200
+ write_initial_state_explicit_txt (info , join ( workspace , "conda-meta" ) , final_urls_md5s )
176
201
177
202
for fn in files :
178
- os .chmod (join (dst_dir , fn ), 0o664 )
203
+ os .chmod (join (workspace , fn ), 0o664 )
179
204
180
205
for env_name , env_info in info .get ("_extra_envs_info" , {}).items ():
181
206
env_config = info ["extra_envs" ][env_name ]
182
- env_dst_dir = os .path .join (dst_dir , "envs" , env_name )
207
+ env_pkgs = os .path .join (workspace , "pkgs" , "envs" , env_name )
208
+ env_conda_meta = os .path .join (workspace , "envs" , env_name , "conda-meta" )
209
+ os .makedirs (env_pkgs , exist_ok = True )
210
+ os .makedirs (env_conda_meta , exist_ok = True )
183
211
# environment conda-meta
184
212
env_urls_md5 = tuple ((get_final_url (info , url ), md5 ) for url , md5 in env_info ["_urls" ])
185
213
user_requested_specs = env_config .get ("user_requested_specs" , env_config .get ("specs" , ()))
186
- write_conda_meta (info , env_dst_dir , env_urls_md5 , user_requested_specs )
214
+ write_conda_meta (info , env_conda_meta , env_urls_md5 , user_requested_specs )
187
215
# environment installation list
188
- write_env_txt (info , env_dst_dir , env_urls_md5 )
216
+ write_initial_state_explicit_txt (info , env_conda_meta , env_urls_md5 )
189
217
# channels
190
- write_channels_txt (info , env_dst_dir , env_config )
218
+ write_channels_txt (info , env_pkgs , env_config )
191
219
# shortcuts
192
- write_shortcuts_txt (info , env_dst_dir , env_config )
220
+ write_shortcuts_txt (info , env_pkgs , env_config )
193
221
194
222
195
223
def write_conda_meta (info , dst_dir , final_urls_md5s , user_requested_specs = None ):
@@ -212,9 +240,7 @@ def write_conda_meta(info, dst_dir, final_urls_md5s, user_requested_specs=None):
212
240
builder .append ("# update specs: %s" % update_specs )
213
241
builder .append ("\n " )
214
242
215
- if not isdir (join (dst_dir , "conda-meta" )):
216
- os .makedirs (join (dst_dir , "conda-meta" ))
217
- with open (join (dst_dir , "conda-meta" , "history" ), "w" ) as fh :
243
+ with open (join (dst_dir , "history" ), "w" ) as fh :
218
244
fh .write ("\n " .join (builder ))
219
245
220
246
@@ -245,7 +271,7 @@ def write_repodata_record(info, dst_dir):
245
271
json .dump (rr_json , rf , indent = 2 , sort_keys = True )
246
272
247
273
248
- def write_env_txt (info , dst_dir , urls ):
274
+ def write_initial_state_explicit_txt (info , dst_dir , urls ):
249
275
"""
250
276
urls is an iterable of tuples with url and md5 values
251
277
"""
@@ -257,7 +283,7 @@ def write_env_txt(info, dst_dir, urls):
257
283
@EXPLICIT
258
284
"""
259
285
).lstrip ()
260
- with open (join (dst_dir , "env .txt" ), "w" ) as envf :
286
+ with open (join (dst_dir , "initial-state.explicit .txt" ), "w" ) as envf :
261
287
envf .write (header )
262
288
for url , md5 in urls :
263
289
maybe_different_url = ensure_transmuted_ext (info , url )
0 commit comments