@@ -60,13 +60,12 @@ def _get_reference(specification):
6060 return specification .get ('registry' )
6161
6262
63- # def compose(dependencies, search_paths): #uncomment this and search_paths.pop(0) to
64- def _get_available_crates (search_paths ):
63+ def _get_available_crates (search_path ):
6564 """
6665 Create a list of crates available from a directory
6766
68- :param search_paths: List of local registry sources to search for packages
69- :type search_paths: List[ Path]
67+ :param search_path: Local registry source to search for packages
68+ :type search_path: Path
7069
7170 :returns: Collection of packages available within a directory and their versions
7271 :rtype: dict
@@ -79,43 +78,43 @@ def _get_available_crates(search_paths):
7978 pkgs_metadata = {}
8079
8180 # Iterate over all the paths provided
82- for search_path in search_paths :
83- for manifest_path in search_path .glob ('*/Cargo.toml' ):
84- manifest = load_manifest (manifest_path )
85- pkgname = manifest .get ('package' , {}).get ('name' )
86- version = manifest .get ('package' , {}).get ('version' )
81+ for manifest_path in search_path .glob ('*/Cargo.toml' ):
82+ manifest = load_manifest (manifest_path )
83+ pkgname = manifest .get ('package' , {}).get ('name' )
84+ version = manifest .get ('package' , {}).get ('version' )
8785
88- versions [pkgname ].add (version )
86+ versions [pkgname ].add (version )
8987
90- # We are assuming here there won't be duplicated crates+version within the same search_path
91- # Should we throw a warning?
92- pkgs_metadata [f"{ pkgname } +{ version } " ] = (manifest_path .parent , manifest )
88+ # We are assuming here there won't be duplicated crates+version within the same search_path
89+ # Should we throw a warning?
90+ pkgs_metadata [f"{ pkgname } +{ version } " ] = (manifest_path .parent , manifest )
9391
9492 return versions , pkgs_metadata
9593
9694
97- # Untested: what if we provide multiple crates_path for a single category?
98- # How do we prioritize between these?
99- def compose (dependencies , ws_crates_paths , system_crates_paths , online_build = True ):
95+ def compose (dependencies , search_paths , online_build = True ):
10096 """
10197 Compose a collection of crates which may satisfy given dependencies.
10298
10399 :param dependencies: List of dependency tuples
104100 (import name, specifications)
105101 :type dependencies: tuple
106102
107- :param ws_crates_path: Directory where the crate dependencies local to our project are stored
108- :type ws_crates_path: path
103+ :param search_paths: List of local registry sources to search for packages
104+ :type search_paths: list
109105
110- :param system_crates_path: Directory where our platform saves IMMUTABLE crates
111- :type system_crates_path: path
106+ :param online_build: Decide if we throw error when we need a dep from cargo
107+ :type online_build: bool (defaults True)
112108
113109 :returns: Collection of packages which may satisfy the required
114110 dependencies.
115111 :rtype: dict
116112 """
117- ws_crates , workspace_crates_metadata = _get_available_crates (ws_crates_paths )
118- platform_crates , platform_crates_metadata = _get_available_crates (system_crates_paths )
113+ dependency_paths_registered = []
114+ for user_path in search_paths :
115+ crates_and_metadata = _get_available_crates (user_path )
116+ dependency_paths_registered .append (crates_and_metadata )
117+
119118 composition = {}
120119 solved_specifiers = {}
121120
@@ -139,19 +138,11 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
139138 continue
140139
141140 candidate = None
142- # Priority mechanism, attempt to get first a candidate that solves the expected dependency
143- # specification from the local workspace. If not available, try to solve with machine
144- # installed packages. Otherwise, just default to crates.io
145- # TO-DO: if we do nothing about the latter ones, cargo will default to crates.io
146- if ws_crates [name ] and (solved_version := solve_dependency (version_spec , ws_crates [name ])):
147- candidate = workspace_crates_metadata [f"{ name } +{ solved_version } " ]
148- local_crate = True
149- elif platform_crates [name ] and (solved_version := solve_dependency (version_spec , platform_crates [name ])):
150- candidate = platform_crates_metadata [f"{ name } +{ solved_version } " ]
151- local_crate = False
152- else :
153- # Do nothing, cargo will handle this scenario
154- pass
141+ # Priority mechanism, check the dependency paths in the order provided by the user of pallet-patcher
142+ for crates , metadada in dependency_paths_registered :
143+ if crates [name ] and (solved_version := solve_dependency (version_spec , crates [name ])):
144+ candidate = metadada [f"{ name } +{ solved_version } " ]
145+ break
155146
156147 # Do not search again for versions specifiers that we already looked up
157148 solved_specifiers [name + str (version_spec )] = True
@@ -165,15 +156,9 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
165156 # Otherwise cargo should just pull from crates.io
166157 # Default case: this won't throw and error, it will pull whatever it's missing from crates.io
167158 print (f"ERROR: { name } does not have any candidates available to meet requirements { specifications } " )
168- if not ws_crates [name ] and not platform_crates [name ]:
169- print ("Not any local packages available" )
170- elif not ws_crates [name ]:
171- print (f"Available system: { platform_crates [name ]} " )
172- elif not platform_crates [name ]:
173- print (f"Available local: { ws_crates [name ]} " )
174- else :
175- print (f"Available local: { ws_crates [name ]} " , f"Available system: { platform_crates [name ]} " )
176- continue
159+ for crates , _ in dependency_paths_registered :
160+ print (f"Available in path provided: { crates [name ]} " )
161+ return {}
177162
178163 reference = _get_reference (specifications )
179164 # Add the dependencies of the pkg to the list of packages that we need to find afterwards
@@ -184,7 +169,7 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
184169
185170 # We also add the raw pkgname to the composition, because patches don't support
186171 # Adding pkgname+version as part of the patch name
187- composition [name + "~" + solved_version ] = (reference , location , local_crate , name )
172+ composition [name + "~" + solved_version ] = (reference , location , name )
188173
189174 return composition
190175
@@ -206,7 +191,7 @@ def get_cargo_arguments(composition, default_registry=None):
206191 if not default_registry :
207192 default_registry = 'crates-io'
208193 arguments = set ()
209- for versioned_name , (reference , candidate , crate_local , pkgname ) in composition .items ():
194+ for versioned_name , (reference , candidate , pkgname ) in composition .items ():
210195 # I'm not sure how this will work with user custom references here
211196 if not reference :
212197 reference = default_registry
@@ -221,16 +206,6 @@ def get_cargo_arguments(composition, default_registry=None):
221206 arguments .add (f"--config={ section } .package='{ pkgname } '" )
222207 arguments .add (f"--config={ section } .path='{ candidate } '" )
223208
224- # I added the crate_local variable so we can treat
225- # dependencies in the system folder differently than dependencies
226- # in our local path. HOWEVER, it seems we can not treat those
227- # differently, unless we modify the original Cargo.toml, specifying
228- # That we get those from a different registry
229- # if crate_local:
230- # pass
231- # else:
232- # pass
233-
234209 return sorted (arguments )
235210
236211
@@ -251,7 +226,7 @@ def get_cargo_config(composition, default_registry=None):
251226 if not default_registry :
252227 default_registry = 'crates-io'
253228 sections = set ()
254- for versioned_name , (reference , candidate , crate_local , pkgname ) in composition .items ():
229+ for versioned_name , (reference , candidate , pkgname ) in composition .items ():
255230 if reference is None :
256231 reference = default_registry
257232 elif candidate .as_uri () == reference :
0 commit comments