@@ -24,13 +24,12 @@ def _get_reference(specification):
2424 return specification .get ('registry' )
2525
2626
27- # def compose(dependencies, search_paths): #uncomment this and search_paths.pop(0) to
28- def _get_available_crates (search_paths ):
27+ def _get_available_crates (search_path ):
2928 """
3029 Create a list of crates available from a directory
3130
32- :param search_paths: List of local registry sources to search for packages
33- :type search_paths: List[ Path]
31+ :param search_path: Local registry source to search for packages
32+ :type search_path: Path
3433
3534 :returns: Collection of packages available within a directory and their versions
3635 :rtype: dict
@@ -43,43 +42,43 @@ def _get_available_crates(search_paths):
4342 pkgs_metadata = {}
4443
4544 # Iterate over all the paths provided
46- for search_path in search_paths :
47- for manifest_path in search_path .glob ('*/Cargo.toml' ):
48- manifest = load_manifest (manifest_path )
49- pkgname = manifest .get ('package' , {}).get ('name' )
50- version = manifest .get ('package' , {}).get ('version' )
45+ for manifest_path in search_path .glob ('*/Cargo.toml' ):
46+ manifest = load_manifest (manifest_path )
47+ pkgname = manifest .get ('package' , {}).get ('name' )
48+ version = manifest .get ('package' , {}).get ('version' )
5149
52- versions [pkgname ].add (version )
50+ versions [pkgname ].add (version )
5351
54- # We are assuming here there won't be duplicated crates+version within the same search_path
55- # Should we throw a warning?
56- pkgs_metadata [f"{ pkgname } +{ version } " ] = (manifest_path .parent , manifest )
52+ # We are assuming here there won't be duplicated crates+version within the same search_path
53+ # Should we throw a warning?
54+ pkgs_metadata [f"{ pkgname } +{ version } " ] = (manifest_path .parent , manifest )
5755
5856 return versions , pkgs_metadata
5957
6058
61- # Untested: what if we provide multiple crates_path for a single category?
62- # How do we prioritize between these?
63- def compose (dependencies , ws_crates_paths , system_crates_paths , online_build = True ):
59+ def compose (dependencies , search_paths , online_build = True ):
6460 """
6561 Compose a collection of crates which may satisfy given dependencies.
6662
6763 :param dependencies: List of dependency tuples
6864 (import name, specifications)
6965 :type dependencies: tuple
7066
71- :param ws_crates_path: Directory where the crate dependencies local to our project are stored
72- :type ws_crates_path: path
67+ :param search_paths: List of local registry sources to search for packages
68+ :type search_paths: list
7369
74- :param system_crates_path: Directory where our platform saves IMMUTABLE crates
75- :type system_crates_path: path
70+ :param online_build: Decide if we throw error when we need a dep from cargo
71+ :type online_build: bool (defaults True)
7672
7773 :returns: Collection of packages which may satisfy the required
7874 dependencies.
7975 :rtype: dict
8076 """
81- ws_crates , workspace_crates_metadata = _get_available_crates (ws_crates_paths )
82- platform_crates , platform_crates_metadata = _get_available_crates (system_crates_paths )
77+ dependency_paths_registered = []
78+ for user_path in search_paths :
79+ crates_and_metadata = _get_available_crates (user_path )
80+ dependency_paths_registered .append (crates_and_metadata )
81+
8382 composition = {}
8483 solved_specifiers = {}
8584
@@ -103,19 +102,11 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
103102 continue
104103
105104 candidate = None
106- # Priority mechanism, attempt to get first a candidate that solves the expected dependency
107- # specification from the local workspace. If not available, try to solve with machine
108- # installed packages. Otherwise, just default to crates.io
109- # TO-DO: if we do nothing about the latter ones, cargo will default to crates.io
110- if ws_crates [name ] and (solved_version := solve_dependency (version_spec , ws_crates [name ])):
111- candidate = workspace_crates_metadata [f"{ name } +{ solved_version } " ]
112- local_crate = True
113- elif platform_crates [name ] and (solved_version := solve_dependency (version_spec , platform_crates [name ])):
114- candidate = platform_crates_metadata [f"{ name } +{ solved_version } " ]
115- local_crate = False
116- else :
117- # Do nothing, cargo will handle this scenario
118- pass
105+ # Priority mechanism, check the dependency paths in the order provided by the user of pallet-patcher
106+ for crates , metadada in dependency_paths_registered :
107+ if crates [name ] and (solved_version := solve_dependency (version_spec , crates [name ])):
108+ candidate = metadada [f"{ name } +{ solved_version } " ]
109+ break
119110
120111 # Do not search again for versions specifiers that we already looked up
121112 solved_specifiers [name + str (version_spec )] = True
@@ -129,15 +120,9 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
129120 # Otherwise cargo should just pull from crates.io
130121 # Default case: this won't throw and error, it will pull whatever it's missing from crates.io
131122 print (f"ERROR: { name } does not have any candidates available to meet requirements { specifications } " )
132- if not ws_crates [name ] and not platform_crates [name ]:
133- print ("Not any local packages available" )
134- elif not ws_crates [name ]:
135- print (f"Available system: { platform_crates [name ]} " )
136- elif not platform_crates [name ]:
137- print (f"Available local: { ws_crates [name ]} " )
138- else :
139- print (f"Available local: { ws_crates [name ]} " , f"Available system: { platform_crates [name ]} " )
140- continue
123+ for crates , _ in dependency_paths_registered :
124+ print (f"Available in path provided: { crates [name ]} " )
125+ return {}
141126
142127 reference = _get_reference (specifications )
143128 # Add the dependencies of the pkg to the list of packages that we need to find afterwards
@@ -148,7 +133,7 @@ def compose(dependencies, ws_crates_paths, system_crates_paths, online_build = T
148133
149134 # We also add the raw pkgname to the composition, because patches don't support
150135 # Adding pkgname+version as part of the patch name
151- composition [name + "~" + solved_version ] = (reference , location , local_crate , name )
136+ composition [name + "~" + solved_version ] = (reference , location , name )
152137
153138 return composition
154139
@@ -170,7 +155,7 @@ def get_cargo_arguments(composition, default_registry=None):
170155 if not default_registry :
171156 default_registry = 'crates-io'
172157 arguments = set ()
173- for versioned_name , (reference , candidate , crate_local , pkgname ) in composition .items ():
158+ for versioned_name , (reference , candidate , pkgname ) in composition .items ():
174159 # I'm not sure how this will work with user custom references here
175160 if not reference :
176161 reference = default_registry
@@ -185,16 +170,6 @@ def get_cargo_arguments(composition, default_registry=None):
185170 arguments .add (f"--config={ section } .package='{ pkgname } '" )
186171 arguments .add (f"--config={ section } .path='{ candidate } '" )
187172
188- # I added the crate_local variable so we can treat
189- # dependencies in the system folder differently than dependencies
190- # in our local path. HOWEVER, it seems we can not treat those
191- # differently, unless we modify the original Cargo.toml, specifying
192- # That we get those from a different registry
193- # if crate_local:
194- # pass
195- # else:
196- # pass
197-
198173 return sorted (arguments )
199174
200175
@@ -215,7 +190,7 @@ def get_cargo_config(composition, default_registry=None):
215190 if not default_registry :
216191 default_registry = 'crates-io'
217192 sections = set ()
218- for versioned_name , (reference , candidate , crate_local , pkgname ) in composition .items ():
193+ for versioned_name , (reference , candidate , pkgname ) in composition .items ():
219194 if reference is None :
220195 reference = default_registry
221196 elif candidate .as_uri () == reference :
0 commit comments