def list_repositories_command(args): check.inst_param(args, 'args', ListRepositoriesInput) python_file, module_name, working_directory = ( args.python_file, args.module_name, args.working_directory, ) loadable_targets = get_loadable_targets(python_file, module_name, working_directory) return ListRepositoriesResponse([ LoadableRepositorySymbol(attribute=lt.attribute, repository_name=lt.target_definition.name) for lt in loadable_targets ])
def list_repositories_command(args): check.inst_param(args, "args", ListRepositoriesInput) python_file, module_name, working_directory, attribute = ( args.python_file, args.module_name, args.working_directory, args.attribute, ) try: loadable_targets = get_loadable_targets(python_file, module_name, working_directory, attribute) return ListRepositoriesResponse([ LoadableRepositorySymbol( attribute=lt.attribute, repository_name=repository_def_from_target_def( lt.target_definition).name, ) for lt in loadable_targets ]) except Exception: # pylint: disable=broad-except return serializable_error_info_from_exc_info(sys.exc_info())
def test_out_of_process_reload_location(self, graphql_context): result = execute_dagster_graphql(graphql_context, RELOAD_REPOSITORY_LOCATION_QUERY, {"repositoryLocationName": "test"}) assert result assert result.data assert result.data["reloadRepositoryLocation"] assert result.data["reloadRepositoryLocation"][ "__typename"] == "RepositoryLocation" assert result.data["reloadRepositoryLocation"]["name"] == "test" assert result.data["reloadRepositoryLocation"]["repositories"] == [{ "name": "test_repo" }] assert result.data["reloadRepositoryLocation"][ "isReloadSupported"] is True with mock.patch( # note it where the function is *used* that needs to mocked, not # where it is defined. # see https://docs.python.org/3/library/unittest.mock.html#where-to-patch "dagster.core.host_representation.handle.sync_list_repositories_grpc" ) as cli_command_mock: with mock.patch( # note it where the function is *used* that needs to mocked, not # where it is defined. # see https://docs.python.org/3/library/unittest.mock.html#where-to-patch "dagster.core.host_representation.repository_location.sync_get_streaming_external_repositories_grpc" ) as external_repository_mock: @repository def new_repo(): return [] new_repo_data = external_repository_data_from_def(new_repo) external_repository_mock.return_value = [ ExternalRepository( new_repo_data, RepositoryHandle( "new_repo", graphql_context. repository_locations[0].location_handle), ) ] cli_command_mock.return_value = ListRepositoriesResponse( repository_symbols=[], executable_path=sys.executable, repository_code_pointer_dict={ "new_repo": CodePointer.from_python_file(__file__, "new_repo", None) }, ) result = execute_dagster_graphql( graphql_context, RELOAD_REPOSITORY_LOCATION_QUERY, {"repositoryLocationName": "test"}, ) assert cli_command_mock.call_count == 1 assert external_repository_mock.call_count == 1 assert result.data["reloadRepositoryLocation"][ "repositories"] == [{ "name": "new_repo" }]