From 4a10ae945119df4f4bbc1f35ccf61c6e003f4d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Rinc=C3=B3n?= Date: Fri, 11 Aug 2023 16:43:46 +0200 Subject: [PATCH] Refactor ugly class member into parametes --- conans/client/graph/graph_binaries.py | 47 +++++++++++++-------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/conans/client/graph/graph_binaries.py b/conans/client/graph/graph_binaries.py index 3c4588a6ea4..9cc718dfc68 100644 --- a/conans/client/graph/graph_binaries.py +++ b/conans/client/graph/graph_binaries.py @@ -48,20 +48,20 @@ def _evaluate_clean_pkg_folder_dirty(node, package_layout): # check through all the selected remotes: # - if not --update: get the first package found # - if --update: get the latest remote searching in all of them - def _get_package_from_remotes(self, node): + def _get_package_from_remotes(self, node, remotes, update): results = [] pref = node.pref - for r in self._selected_remotes: + for r in remotes: try: info = node.conanfile.info latest_pref = self._remote_manager.get_latest_package_reference(pref, r, info) results.append({'pref': latest_pref, 'remote': r}) - if len(results) > 0 and not self._update: + if len(results) > 0 and not update: break except NotFoundException: pass - if not self._selected_remotes and self._update: + if not remotes and update: node.conanfile.output.warning("Can't update, there are no remotes defined") if len(results) > 0: @@ -95,14 +95,14 @@ def _evaluate_is_cached(self, node): return True self._evaluated[pref] = [node] - def _process_compatible_packages(self, node): + def _process_compatible_packages(self, node, remotes, update): conanfile = node.conanfile original_binary = node.binary original_package_id = node.package_id compatibles = self._compatibility.compatibles(conanfile) existing = compatibles.pop(original_package_id, None) # Skip main package_id - if existing: # Skip the check if same packge_id + if existing: # Skip the check if same package_id conanfile.output.info(f"Compatible package ID {original_package_id} equal to " "the default package ID") @@ -113,7 +113,7 @@ def _process_compatible_packages(self, node): f"{conanfile.info.dump_diff(compatible_package)}") node._package_id = package_id # Modifying package id under the hood, FIXME node.binary = None # Invalidate it - self._process_compatible_node(node) + self._process_compatible_node(node, remotes, update) if node.binary in (BINARY_CACHE, BINARY_DOWNLOAD, BINARY_UPDATE): conanfile.output.info("Main binary package '%s' missing. Using " "compatible package '%s'" % (original_package_id, package_id)) @@ -129,15 +129,15 @@ def _process_compatible_packages(self, node): node.binary = original_binary node._package_id = original_package_id - def _evaluate_node(self, node, build_mode): + def _evaluate_node(self, node, build_mode, remotes, update): assert node.binary is None, "Node.binary should be None" assert node.package_id is not None, "Node.package_id shouldn't be None" assert node.prev is None, "Node.prev should be None" - self._process_node(node, build_mode) + self._process_node(node, build_mode, remotes, update) if node.binary == BINARY_MISSING \ and not build_mode.should_build_missing(node.conanfile) and not node.should_build: - self._process_compatible_packages(node) + self._process_compatible_packages(node, remotes, update) if node.binary == BINARY_MISSING and build_mode.allowed(node.conanfile): node.should_build = True @@ -148,7 +148,7 @@ def _evaluate_node(self, node, build_mode): # BINARY_BUILD IS NOT A VIABLE fallback for invalid node.binary = BINARY_INVALID - def _process_node(self, node, build_mode): + def _process_node(self, node, build_mode, remotes, update): # Check that this same reference hasn't already been checked if self._evaluate_is_cached(node): return @@ -193,9 +193,9 @@ def _process_node(self, node, build_mode): else: node.binary = BINARY_MISSING elif cache_latest_prev is None: # This binary does NOT exist in the cache - self._evaluate_download(node) + self._evaluate_download(node, remotes, update) else: # This binary already exists in the cache, maybe can be updated - self._evaluate_in_cache(cache_latest_prev, node) + self._evaluate_in_cache(cache_latest_prev, node, remotes, update) # The INVALID should only prevail if a compatible package, due to removal of # settings in package_id() was not found @@ -203,7 +203,7 @@ def _process_node(self, node, build_mode): if node.conanfile.info.invalid and node.conanfile.info.invalid[0] == BINARY_INVALID: node.binary = BINARY_INVALID - def _process_compatible_node(self, node): + def _process_compatible_node(self, node, remotes, update): """ simplified checking of compatible_packages, that should be found existing, but will never be built, for example. They cannot be editable either at this point. """ @@ -226,9 +226,9 @@ def _process_compatible_node(self, node): break if cache_latest_prev is None: # This binary does NOT exist in the cache - self._evaluate_download(node) + self._evaluate_download(node, remotes, update) else: # This binary already exists in the cache, maybe can be updated - self._evaluate_in_cache(cache_latest_prev, node) + self._evaluate_in_cache(cache_latest_prev, node, remotes, update) def _process_locked_node(self, node, build_mode, locked_prev): # Check that this same reference hasn't already been checked @@ -256,20 +256,20 @@ def _process_locked_node(self, node, build_mode, locked_prev): # TODO: Check in remotes for download - def _evaluate_download(self, node): + def _evaluate_download(self, node, remotes, update): try: - self._get_package_from_remotes(node) + self._get_package_from_remotes(node, remotes, update) except NotFoundException: node.binary = BINARY_MISSING else: node.binary = BINARY_DOWNLOAD - def _evaluate_in_cache(self, cache_latest_prev, node): + def _evaluate_in_cache(self, cache_latest_prev, node, remotes, update): assert cache_latest_prev.revision - if self._update: + if update: output = node.conanfile.output try: - self._get_package_from_remotes(node) + self._get_package_from_remotes(node, remotes, update) except NotFoundException: output.warning("Can't update, no package in remote") except NoRemoteAvailable: @@ -306,9 +306,6 @@ def _evaluate_package_id(self, node): def evaluate_graph(self, deps_graph, build_mode, lockfile, remotes, update, build_mode_test=None, tested_graph=None): - self._selected_remotes = remotes or [] # TODO: A bit dirty interfaz, pass as arg instead - self._update = update # TODO: Dirty, fix it - if tested_graph is None: main_mode = BuildMode(build_mode) test_mode = None # Should not be used at all @@ -343,7 +340,7 @@ def evaluate_graph(self, deps_graph, build_mode, lockfile, remotes, update, buil if locked_prev: self._process_locked_node(node, build_mode, locked_prev) continue - self._evaluate_node(node, build_mode) + self._evaluate_node(node, build_mode, remotes, update) self._skip_binaries(deps_graph)