def find_dependencies_command(**kwargs): pack_name = kwargs.get('pack_folder_name', '') id_set_path = kwargs.get('id_set_path') verbose = kwargs.get('verbose') PackDependencies.find_dependencies(pack_name=pack_name, id_set_path=id_set_path, debug_file_path=verbose)
def run_find_dependencies(mocker, repo_path, pack_name): with ChangeCWD(repo_path): # Circle froze on 3.7 dut to high usage of processing power. # pool = Pool(processes=cpu_count() * 2) is the line that in charge of the multiprocessing initiation, # so changing `cpu_count` return value to 1 still gives you multiprocessing but with only 2 processors, # and not the maximum amount. import demisto_sdk.commands.common.update_id_set as uis mocker.patch.object(uis, 'cpu_count', return_value=1) PackDependencies.find_dependencies(pack_name, silent_mode=True)
def find_dependencies_command(**kwargs): pack_name = kwargs.get('pack_folder_name', '') id_set_path = kwargs.get('id_set_path') verbose = kwargs.get('verbose') update_pack_metadata = not kwargs.get('no_update') try: PackDependencies.find_dependencies( pack_name=pack_name, id_set_path=id_set_path, debug_file_path=verbose, update_pack_metadata=update_pack_metadata, ) except ValueError as exp: print_error(str(exp))
def validate_pack_dependencies(self, id_set_path=None): click.secho( f'\n================= Running pack dependencies validation on {self.pack}=================', fg="bright_cyan") core_pack_list = tools.get_remote_file( 'Tests/Marketplace/core_packs_list.json') or [] first_level_dependencies = PackDependencies.find_dependencies( self.pack, id_set_path=id_set_path, silent_mode=True, exclude_ignored_dependencies=False, update_pack_metadata=False) for core_pack in core_pack_list: first_level_dependencies.pop(core_pack, None) if not first_level_dependencies: return True dependency_result = json.dumps(first_level_dependencies, indent=4) click.echo( click.style(f"Found dependencies result for {self.pack} pack:", bold=True)) click.echo(click.style(dependency_result, bold=True)) non_supported_pack = first_level_dependencies.get('NonSupported', {}) deprecated_pack = first_level_dependencies.get('DeprecatedContent', {}) if (non_supported_pack.get('mandatory')) or ( deprecated_pack.get('mandatory')): error_message, error_code = Errors.invalid_package_dependencies( self.pack) if self._add_error((error_message, error_code), file_path=self.pack_path): return False return True
def handle_dependencies(self, pack_name: str, id_set_path: str, logger: logging.Logger) -> None: """Updates pack's dependencies using the find_dependencies command. Args: pack_name (str): The pack's name. id_set_path (str): the id_set file path. logger (logging.Logger): System logger already initialized. """ calculated_dependencies = PackDependencies.find_dependencies( pack_name, id_set_path=id_set_path, update_pack_metadata=False, silent_mode=True, complete_data=True) # If it is a core pack, check that no new mandatory packs (that are not core packs) were added # They can be overridden in the user metadata to be not mandatory so we need to check there as well if pack_name in CORE_PACKS_LIST: mandatory_dependencies = [ k for k, v in calculated_dependencies.items() if v.get('mandatory', False) is True and k not in CORE_PACKS_LIST and k not in self.dependencies.keys() ] if mandatory_dependencies: logger.error( f'New mandatory dependencies {mandatory_dependencies} were ' f'found in the core pack {pack_name}') self.dependencies.update(calculated_dependencies)
def validate_pack_dependencies(self, id_set_path=None): try: click.secho( f'\nRunning pack dependencies validation on {self.pack}\n', fg="bright_cyan") core_pack_list = tools.get_remote_file( 'Tests/Marketplace/core_packs_list.json') or [] first_level_dependencies = PackDependencies.find_dependencies( self.pack, id_set_path=id_set_path, silent_mode=True, exclude_ignored_dependencies=False, update_pack_metadata=False, skip_id_set_creation=self.skip_id_set_creation) if not first_level_dependencies: if not self.suppress_print: click.secho( "Unable to find id_set.json file - skipping dependencies check", fg="yellow") return True for core_pack in core_pack_list: first_level_dependencies.pop(core_pack, None) if not first_level_dependencies: return True dependency_result = json.dumps(first_level_dependencies, indent=4) click.echo( click.style(f"Found dependencies result for {self.pack} pack:", bold=True)) click.echo(click.style(dependency_result, bold=True)) non_supported_pack = first_level_dependencies.get( 'NonSupported', {}) deprecated_pack = first_level_dependencies.get( 'DeprecatedContent', {}) if (non_supported_pack.get('mandatory')) or ( deprecated_pack.get('mandatory')): error_message, error_code = Errors.invalid_package_dependencies( self.pack) if self._add_error((error_message, error_code), file_path=self.pack_path): return False return True except ValueError as e: if "Couldn't find any items for pack" in str(e): error_message, error_code = Errors.invalid_id_set() if self._add_error((error_message, error_code), file_path=self.pack_path): return False return True else: raise
def validate_pack_dependencies(self): try: click.secho(f'\nRunning pack dependencies validation on {self.pack}\n', fg="bright_cyan") core_pack_list = get_core_pack_list() first_level_dependencies = PackDependencies.find_dependencies( self.pack, id_set_path=self.id_set_path, silent_mode=True, exclude_ignored_dependencies=False, update_pack_metadata=False, skip_id_set_creation=self.skip_id_set_creation, use_pack_metadata=True ) if not first_level_dependencies: if not self.suppress_print: click.secho("No first level dependencies found", fg="yellow") return True for core_pack in core_pack_list: first_level_dependencies.pop(core_pack, None) if not first_level_dependencies: if not self.suppress_print: click.secho("Found first level dependencies only on core packs", fg="yellow") return True dependency_result = json.dumps(first_level_dependencies, indent=4) click.echo(click.style(f"Found dependencies result for {self.pack} pack:", bold=True)) click.echo(click.style(dependency_result, bold=True)) if self.pack in core_pack_list: if not self.validate_core_pack_dependencies(first_level_dependencies): return False non_supported_pack = first_level_dependencies.get('NonSupported', {}) deprecated_pack = first_level_dependencies.get('DeprecatedContent', {}) if not self.is_invalid_package_dependencies(non_supported_pack, deprecated_pack): return False return True except ValueError as e: if "Couldn't find any items for pack" in str(e): error_message, error_code = Errors.invalid_id_set() if self._add_error((error_message, error_code), file_path=self.pack_path): return False return True else: raise
def find_dependencies_command(**kwargs): pack_name = kwargs.get('pack_folder_name', '') id_set_path = kwargs.get('id_set_path') PackDependencies.find_dependencies(pack_name=pack_name, id_set_path=id_set_path)