4848except ImportError :
4949 import ruamel_json as json
5050
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+ )
5257
5358
5459def write_index_cache (info , dst_dir , used_packages ):
@@ -135,8 +140,28 @@ def system_info():
135140 return out
136141
137142
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 :
140165 json .dump (system_info (), fo )
141166
142167 all_urls = info ["_urls" ].copy ()
@@ -146,15 +171,15 @@ def write_files(info, dst_dir):
146171 final_urls_md5s = tuple ((get_final_url (info , url ), md5 ) for url , md5 in info ["_urls" ])
147172 all_final_urls_md5s = tuple ((get_final_url (info , url ), md5 ) for url , md5 in all_urls )
148173
149- with open (join (dst_dir , "urls" ), "w" ) as fo :
174+ with open (join (pkgs_dir , "urls" ), "w" ) as fo :
150175 for url , md5 in all_final_urls_md5s :
151176 maybe_different_url = ensure_transmuted_ext (info , url )
152177 if maybe_different_url != url : # transmuted, no md5
153178 fo .write (f"{ maybe_different_url } \n " )
154179 else :
155180 fo .write (f"{ url } #{ md5 } \n " )
156181
157- with open (join (dst_dir , "urls.txt" ), "w" ) as fo :
182+ with open (join (pkgs_dir , "urls.txt" ), "w" ) as fo :
158183 for url , _ in all_final_urls_md5s :
159184 fo .write ("%s\n " % url )
160185
@@ -163,33 +188,36 @@ def write_files(info, dst_dir):
163188 all_dists += env_info ["_dists" ]
164189 all_dists = list ({dist : None for dist in all_dists }) # de-duplicate
165190
166- write_index_cache (info , dst_dir , all_dists )
191+ write_index_cache (info , pkgs_dir , all_dists )
167192
168193 # 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 )
170195
171- write_repodata_record (info , dst_dir )
196+ write_repodata_record (info , pkgs_dir )
172197
173198 # base environment file used with conda install --file
174199 # (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 )
176201
177202 for fn in files :
178- os .chmod (join (dst_dir , fn ), 0o664 )
203+ os .chmod (join (workspace , fn ), 0o664 )
179204
180205 for env_name , env_info in info .get ("_extra_envs_info" , {}).items ():
181206 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 )
183211 # environment conda-meta
184212 env_urls_md5 = tuple ((get_final_url (info , url ), md5 ) for url , md5 in env_info ["_urls" ])
185213 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 )
187215 # 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 )
189217 # channels
190- write_channels_txt (info , env_dst_dir , env_config )
218+ write_channels_txt (info , env_pkgs , env_config )
191219 # shortcuts
192- write_shortcuts_txt (info , env_dst_dir , env_config )
220+ write_shortcuts_txt (info , env_pkgs , env_config )
193221
194222
195223def 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):
212240 builder .append ("# update specs: %s" % update_specs )
213241 builder .append ("\n " )
214242
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 :
218244 fh .write ("\n " .join (builder ))
219245
220246
@@ -245,7 +271,7 @@ def write_repodata_record(info, dst_dir):
245271 json .dump (rr_json , rf , indent = 2 , sort_keys = True )
246272
247273
248- def write_env_txt (info , dst_dir , urls ):
274+ def write_initial_state_explicit_txt (info , dst_dir , urls ):
249275 """
250276 urls is an iterable of tuples with url and md5 values
251277 """
@@ -257,7 +283,7 @@ def write_env_txt(info, dst_dir, urls):
257283 @EXPLICIT
258284 """
259285 ).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 :
261287 envf .write (header )
262288 for url , md5 in urls :
263289 maybe_different_url = ensure_transmuted_ext (info , url )
0 commit comments