


"""simple docstring"""


import json
import os
from pathlib import Path
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple, Union

import sentencepiece

from ...tokenization_utils import BatchEncoding, PreTrainedTokenizer
from ...utils import logging


_snake_case          =							logging.get_logger(__name__)

_snake_case          =							"▁"

_snake_case          =							{
    "vocab_file": "vocab.json",
    "spm_file": "sentencepiece.bpe.model",
    "tokenizer_config_file": "tokenizer_config.json",
}

_snake_case          =							{
    "vocab_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/vocab.json",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/vocab.json",
    },
    "spm_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/sentencepiece.bpe.model",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/sentencepiece.bpe.model",
    },
    "tokenizer_config_file": {
        "facebook/m2m100_418M": "https://huggingface.co/facebook/m2m100_418M/resolve/main/tokenizer_config.json",
        "facebook/m2m100_1.2B": "https://huggingface.co/facebook/m2m100_1.2B/resolve/main/tokenizer_config.json",
    },
}

_snake_case          =							{
    "facebook/m2m100_418M": 1024,
}

# fmt: off
_snake_case          =							{
    "m2m100": ["af", "am", "ar", "ast", "az", "ba", "be", "bg", "bn", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "en", "es", "et", "fa", "ff", "fi", "fr", "fy", "ga", "gd", "gl", "gu", "ha", "he", "hi", "hr", "ht", "hu", "hy", "id", "ig", "ilo", "is", "it", "ja", "jv", "ka", "kk", "km", "kn", "ko", "lb", "lg", "ln", "lo", "lt", "lv", "mg", "mk", "ml", "mn", "mr", "ms", "my", "ne", "nl", "no", "ns", "oc", "or", "pa", "pl", "ps", "pt", "ro", "ru", "sd", "si", "sk", "sl", "so", "sq", "sr", "ss", "su", "sv", "sw", "ta", "th", "tl", "tn", "tr", "uk", "ur", "uz", "vi", "wo", "xh", "yi", "yo", "zh", "zu"],
    "wmt21": ["en", "ha", "is", "ja", "cs", "ru", "zh", "de"]
}



class   _a      (      SCREAMING_SNAKE_CASE_ ):
    a_    :				Optional[int]             =    VOCAB_FILES_NAMES
    a_    :				List[str]             =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    a_    :				List[str]             =    PRETRAINED_VOCAB_FILES_MAP
    a_    :				Optional[Any]             =    ['input_ids', 'attention_mask']

    a_    :				List[int]             =    []
    a_    :				List[int]             =    []
    def __init__( self							:					str							,					SCREAMING_SNAKE_CASE__							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					Dict							,					SCREAMING_SNAKE_CASE__							:					List[Any]=None							,					SCREAMING_SNAKE_CASE__							:					List[str]=None							,					SCREAMING_SNAKE_CASE__							:					Tuple="<s>"							,					SCREAMING_SNAKE_CASE__							:					Any="</s>"							,					SCREAMING_SNAKE_CASE__							:					List[str]="</s>"							,					SCREAMING_SNAKE_CASE__							:					str="<pad>"							,					SCREAMING_SNAKE_CASE__							:					List[str]="<unk>"							,					SCREAMING_SNAKE_CASE__							:					str="m2m100"							,					SCREAMING_SNAKE_CASE__							:					Optional[Dict[str, Any]] = None							,					SCREAMING_SNAKE_CASE__							:					int=8							,					**SCREAMING_SNAKE_CASE__							:					Optional[int]							,					):
          lowerCamelCase__           =		{} if sp_model_kwargs is None else sp_model_kwargs

          lowerCamelCase__           =		language_codes
          lowerCamelCase__           =		FAIRSEQ_LANGUAGE_CODES[language_codes]
          lowerCamelCase__           =		{lang_code: F'__{lang_code}__' for lang_code in fairseq_language_code}

          lowerCamelCase__           =		kwargs.get('additional_special_tokens'							,					[]				)
          kwargs["additional_special_tokens"] += [
              self.get_lang_token(SCREAMING_SNAKE_CASE__				)
              for lang_code in fairseq_language_code
              if self.get_lang_token(SCREAMING_SNAKE_CASE__				) not in kwargs["additional_special_tokens"]
          ]

          super().__init__(
              src_lang=SCREAMING_SNAKE_CASE__							,					tgt_lang=SCREAMING_SNAKE_CASE__							,					bos_token=SCREAMING_SNAKE_CASE__							,					eos_token=SCREAMING_SNAKE_CASE__							,					sep_token=SCREAMING_SNAKE_CASE__							,					unk_token=SCREAMING_SNAKE_CASE__							,					pad_token=SCREAMING_SNAKE_CASE__							,					language_codes=SCREAMING_SNAKE_CASE__							,					sp_model_kwargs=self.sp_model_kwargs							,					num_madeup_words=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__							,					)

          lowerCamelCase__           =		vocab_file
          lowerCamelCase__           =		load_json(SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		{v: k for k, v in self.encoder.items()}
          lowerCamelCase__           =		spm_file
          lowerCamelCase__           =		load_spm(SCREAMING_SNAKE_CASE__							,					self.sp_model_kwargs				)

          lowerCamelCase__           =		len(self.encoder				)

          lowerCamelCase__           =		{
              self.get_lang_token(SCREAMING_SNAKE_CASE__				): self.encoder_size + i for i, lang_code in enumerate(SCREAMING_SNAKE_CASE__				)
          }
          lowerCamelCase__           =		{lang_code: self.encoder_size + i for i, lang_code in enumerate(SCREAMING_SNAKE_CASE__				)}
          lowerCamelCase__           =		{v: k for k, v in self.lang_token_to_id.items()}

          lowerCamelCase__           =		src_lang if src_lang is not None else 'en'
          lowerCamelCase__           =		tgt_lang
          lowerCamelCase__           =		self.get_lang_id(self._src_lang				)
          self.set_src_lang_special_tokens(self._src_lang				)

          lowerCamelCase__           =		num_madeup_words
    @property
    def      _UpperCamelCase       ( self							:					Union[str, Any]				):
          return len(self.encoder				) + len(self.lang_token_to_id				)
    @property
    def      _UpperCamelCase       ( self							:					List[str]				):
          return self._src_lang
    @src_lang.setter
    def      _UpperCamelCase       ( self							:					Dict							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		new_src_lang
          self.set_src_lang_special_tokens(self._src_lang				)
    def      _UpperCamelCase       ( self							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          return self.sp_model.encode(SCREAMING_SNAKE_CASE__							,					out_type=SCREAMING_SNAKE_CASE__				)
    def      _UpperCamelCase       ( self							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					List[Any]				):
          if token in self.lang_token_to_id:
                return self.lang_token_to_id[token]
          return self.encoder.get(SCREAMING_SNAKE_CASE__							,					self.encoder[self.unk_token]				)
    def      _UpperCamelCase       ( self							:					Optional[int]							,					SCREAMING_SNAKE_CASE__							:					int				):
          if index in self.id_to_lang_token:
                return self.id_to_lang_token[index]
          return self.decoder.get(SCREAMING_SNAKE_CASE__							,					self.unk_token				)
    def      _UpperCamelCase       ( self							:					Optional[int]							,					SCREAMING_SNAKE_CASE__							:					List[str]				):
          lowerCamelCase__           =		[]
          lowerCamelCase__           =		''
          for token in tokens:
                # make sure that special tokens are not decoded using sentencepiece model
                if token in self.all_special_tokens:
                      out_string += self.sp_model.decode(SCREAMING_SNAKE_CASE__				) + token
                      lowerCamelCase__           =		[]
                else:
                      current_sub_tokens.append(SCREAMING_SNAKE_CASE__				)
          out_string += self.sp_model.decode(SCREAMING_SNAKE_CASE__				)
          return out_string.strip()
    def      _UpperCamelCase       ( self							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					List[int]							,					SCREAMING_SNAKE_CASE__							:					Optional[List[int]] = None							,					SCREAMING_SNAKE_CASE__							:					bool = False				):

          if already_has_special_tokens:
                return super().get_special_tokens_mask(
                    token_ids_a=SCREAMING_SNAKE_CASE__							,					token_ids_a=SCREAMING_SNAKE_CASE__							,					already_has_special_tokens=SCREAMING_SNAKE_CASE__				)

          lowerCamelCase__           =		[1] * len(self.prefix_tokens				)
          lowerCamelCase__           =		[1] * len(self.suffix_tokens				)
          if token_ids_a is None:
                return prefix_ones + ([0] * len(SCREAMING_SNAKE_CASE__				)) + suffix_ones
          return prefix_ones + ([0] * len(SCREAMING_SNAKE_CASE__				)) + ([0] * len(SCREAMING_SNAKE_CASE__				)) + suffix_ones
    def      _UpperCamelCase       ( self							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					List[int]							,					SCREAMING_SNAKE_CASE__							:					Optional[List[int]] = None				):
          if token_ids_a is None:
                return self.prefix_tokens + token_ids_a + self.suffix_tokens
          # We don't expect to process pairs, but leave the pair logic for API consistency
          return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens
    def      _UpperCamelCase       ( self							:					str				):
          lowerCamelCase__           =		{self.convert_ids_to_tokens(SCREAMING_SNAKE_CASE__				): i for i in range(self.vocab_size				)}
          vocab.update(self.added_tokens_encoder				)
          return vocab
    def __getstate__( self							:					int				):
          lowerCamelCase__           =		self.__dict__.copy()
          lowerCamelCase__           =		None
          return state
    def __setstate__( self							:					Dict							,					SCREAMING_SNAKE_CASE__							:					Dict				):
          lowerCamelCase__           =		d

          # for backward compatibility
          if not hasattr(self							,					'sp_model_kwargs'				):
                lowerCamelCase__           =		{}

          lowerCamelCase__           =		load_spm(self.spm_file							,					self.sp_model_kwargs				)
    def      _UpperCamelCase       ( self							:					Union[str, Any]							,					SCREAMING_SNAKE_CASE__							:					str							,					SCREAMING_SNAKE_CASE__							:					Optional[str] = None				):
          lowerCamelCase__           =		Path(SCREAMING_SNAKE_CASE__				)
          if not save_dir.is_dir():
                raise OSError(F'{save_directory} should be a directory'				)
          lowerCamelCase__           =		save_dir / (
              (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['vocab_file']
          )
          lowerCamelCase__           =		save_dir / (
              (filename_prefix + '-' if filename_prefix else '') + self.vocab_files_names['spm_file']
          )

          save_json(self.encoder							,					SCREAMING_SNAKE_CASE__				)

          if os.path.abspath(self.spm_file				) != os.path.abspath(SCREAMING_SNAKE_CASE__				) and os.path.isfile(self.spm_file				):
                copyfile(self.spm_file							,					SCREAMING_SNAKE_CASE__				)
          elif not os.path.isfile(self.spm_file				):
                with open(SCREAMING_SNAKE_CASE__							,					'wb'				) as fi:
                      lowerCamelCase__           =		self.sp_model.serialized_model_proto()
                      fi.write(SCREAMING_SNAKE_CASE__				)

          return (str(SCREAMING_SNAKE_CASE__				), str(SCREAMING_SNAKE_CASE__				))
    def      _UpperCamelCase       ( self							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					List[str]							,					SCREAMING_SNAKE_CASE__							:					str = "en"							,					SCREAMING_SNAKE_CASE__							:					Optional[List[str]] = None							,					SCREAMING_SNAKE_CASE__							:					str = "ro"							,					**SCREAMING_SNAKE_CASE__							:					str							,					):
          lowerCamelCase__           =		src_lang
          lowerCamelCase__           =		tgt_lang
          self.set_src_lang_special_tokens(self.src_lang				)
          return super().prepare_seqaseq_batch(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)
    def      _UpperCamelCase       ( self							:					str							,					SCREAMING_SNAKE_CASE__							:					int							,					SCREAMING_SNAKE_CASE__							:					Optional[str]							,					SCREAMING_SNAKE_CASE__							:					Optional[str]							,					**SCREAMING_SNAKE_CASE__							:					List[str]				):
          if src_lang is None or tgt_lang is None:
                raise ValueError('Translation requires a `src_lang` and a `tgt_lang` for this model'				)
          lowerCamelCase__           =		src_lang
          lowerCamelCase__           =		self(SCREAMING_SNAKE_CASE__							,					add_special_tokens=SCREAMING_SNAKE_CASE__							,					**SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		self.get_lang_id(SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		tgt_lang_id
          return inputs
    def      _UpperCamelCase       ( self							:					Optional[int]				):
          self.set_src_lang_special_tokens(self.src_lang				)
    def      _UpperCamelCase       ( self							:					Tuple				):
          self.set_tgt_lang_special_tokens(self.tgt_lang				)
    def      _UpperCamelCase       ( self							:					Dict							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		self.get_lang_token(SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		self.lang_token_to_id[lang_token]
          lowerCamelCase__           =		[self.cur_lang_id]
          lowerCamelCase__           =		[self.eos_token_id]
    def      _UpperCamelCase       ( self							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		self.get_lang_token(SCREAMING_SNAKE_CASE__				)
          lowerCamelCase__           =		self.lang_token_to_id[lang_token]
          lowerCamelCase__           =		[self.cur_lang_id]
          lowerCamelCase__           =		[self.eos_token_id]
    def      _UpperCamelCase       ( self							:					Union[str, Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          return self.lang_code_to_token[lang]


    def      _UpperCamelCase       ( self							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
          lowerCamelCase__           =		self.get_lang_token(SCREAMING_SNAKE_CASE__				)
          return self.lang_token_to_id[lang_token]






def   snake_case						(				_a:     str		,   _a:     Dict[str, Any]							)->		sentencepiece.SentencePieceProcessor:
      '''simple docstring'''


      lowerCamelCase__           =		sentencepiece.SentencePieceProcessor(**_a							)
      spm.Load(str(_a							)							)
      return spm



def   snake_case						(				_a:     str							)->		Union[Dict, List]:
      '''simple docstring'''


      with open(_a		,   'r'							) as f:
            return json.load(_a							)






def   snake_case						(				_a:     str		,   _a:     str							)->		None:
      '''simple docstring'''


      with open(_a		,   'w'							) as f:
            json.dump(_a		,   _a		,   indent=2							)







"""simple docstring"""


import collections
import json
import math
import os
import re
import time
from fnmatch import fnmatch
from typing import Dict

import requests
from slack_sdk import WebClient


_snake_case          =							WebClient(token=os.environ["CI_SLACK_BOT_TOKEN"])



def   snake_case						(				_a:     Any							)->		Optional[Any]:
      '''simple docstring'''


      lowerCamelCase__           =		test_results.split(' '							)

      lowerCamelCase__           =		0
      lowerCamelCase__           =		0

      # When the output is short enough, the output is surrounded by = signs: "== OUTPUT =="
      # When it is too long, those signs are not present.
      lowerCamelCase__           =		expressions[-2] if '=' in expressions[-1] else expressions[-1]

      for i, expression in enumerate(_a							):
            if "failed" in expression:
                  failed += int(expressions[i - 1]							)
            if "passed" in expression:
                  success += int(expressions[i - 1]							)

      return failed, success, time_spent



def   snake_case						(				_a:     Optional[int]							)->		Optional[int]:
      '''simple docstring'''


      lowerCamelCase__           =		{}
      lowerCamelCase__           =		None
      lowerCamelCase__           =		False
      for line in failures_short_lines.split('\n'							):
            if re.search(R'_ \[doctest\]'		,   _a							):
                  lowerCamelCase__           =		True
                  lowerCamelCase__           =		line.split(' '							)[2]
            elif in_error and not line.split(' '							)[0].isdigit():
                  lowerCamelCase__           =		line
                  lowerCamelCase__           =		False

      return failures



class   _a      :
    def __init__( self							:					Optional[Any]							,					SCREAMING_SNAKE_CASE__							:					str							,					SCREAMING_SNAKE_CASE__							:					Dict				):
          lowerCamelCase__           =		title

          lowerCamelCase__           =		doc_test_results['time_spent'].split(','				)[0]
          lowerCamelCase__           =		doc_test_results['success']
          lowerCamelCase__           =		doc_test_results['failures']
          lowerCamelCase__           =		self.n_success + self.n_failures

          # Failures and success of the modeling tests
          lowerCamelCase__           =		doc_test_results
    @property
    def      _UpperCamelCase       ( self							:					List[str]				):
          lowerCamelCase__           =		[self._time_spent]
          lowerCamelCase__           =		0

          for time in time_spent:
                lowerCamelCase__           =		time.split(':'				)

                # Time can be formatted as xx:xx:xx, as .xx, or as x.xx if the time spent was less than a minute.
                if len(SCREAMING_SNAKE_CASE__				) == 1:
                      lowerCamelCase__           =		[0, 0, time_parts[0]]

                lowerCamelCase__    ,  lowerCamelCase__    ,  lowerCamelCase__           =		int(time_parts[0]				), int(time_parts[1]				), float(time_parts[2]				)
                total_secs += hours * 36_00 + minutes * 60 + seconds

          lowerCamelCase__    ,  lowerCamelCase__    ,  lowerCamelCase__           =		total_secs // 36_00, (total_secs % 36_00) // 60, total_secs % 60
          return F'{int(SCREAMING_SNAKE_CASE__				)}h{int(SCREAMING_SNAKE_CASE__				)}m{int(SCREAMING_SNAKE_CASE__				)}s'
    @property
    def      _UpperCamelCase       ( self							:					Dict				):
          return {"type": "header", "text": {"type": "plain_text", "text": self.title}}
    @property
    def      _UpperCamelCase       ( self							:					Dict				):
          return {
              "type": "section",
              "text": {
                  "type": "plain_text",
                  "text": F'🌞 There were no failures: all {self.n_tests} tests passed. The suite ran in {self.time}.',
                  "emoji": True,
              },
              "accessory": {
                  "type": "button",
                  "text": {"type": "plain_text", "text": "Check Action results", "emoji": True},
                  "url": F'https://github.com/huggingface/transformers/actions/runs/{os.environ["GITHUB_RUN_ID"]}',
              },
          }
    @property
    def      _UpperCamelCase       ( self							:					Any				):
          return {
              "type": "section",
              "text": {
                  "type": "plain_text",
                  "text": (
                      F'There were {self.n_failures} failures, out of {self.n_tests} tests.\nThe suite ran in'
                      F' {self.time}.'
                  ),
                  "emoji": True,
              },
              "accessory": {
                  "type": "button",
                  "text": {"type": "plain_text", "text": "Check Action results", "emoji": True},
                  "url": F'https://github.com/huggingface/transformers/actions/runs/{os.environ["GITHUB_RUN_ID"]}',
              },
          }
    @property
    def      _UpperCamelCase       ( self							:					Union[str, Any]				):
          lowerCamelCase__           =		40
          lowerCamelCase__           =		{k: v['failed'] for k, v in doc_test_results.items() if isinstance(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__				)}

          lowerCamelCase__           =		''
          for category, failures in category_failures.items():
                if len(SCREAMING_SNAKE_CASE__				) == 0:
                      continue

                if report != "":
                      report += "\n\n"

                report += F'*{category} failures*:'.ljust(line_length // 2				).rjust(line_length // 2				) + "\n"
                report += "`"
                report += "`\n`".join(SCREAMING_SNAKE_CASE__				)
                report += "`"

          return {
              "type": "section",
              "text": {
                  "type": "mrkdwn",
                  "text": F'The following examples had failures:\n\n\n{report}\n',
              },
          }
    @property
    def      _UpperCamelCase       ( self							:					str				):
          lowerCamelCase__           =		[self.header]

          if self.n_failures > 0:
                blocks.append(self.failures				)

          if self.n_failures > 0:
                blocks.extend([self.category_failures]				)

          if self.n_failures == 0:
                blocks.append(self.no_failures				)

          return json.dumps(SCREAMING_SNAKE_CASE__				)
    @staticmethod
    def      _UpperCamelCase       ( ):
          lowerCamelCase__           =		[
              {
                  'type': 'section',
                  'text': {
                      'type': 'plain_text',
                      'text': 'There was an issue running the tests.',
                  },
                  'accessory': {
                      'type': 'button',
                      'text': {'type': 'plain_text', 'text': 'Check Action results', 'emoji': True},
                      'url': F'https://github.com/huggingface/transformers/actions/runs/{os.environ["GITHUB_RUN_ID"]}',
                  },
              }
          ]

          print('Sending the following payload'				)
          print(json.dumps({'blocks': json.loads(SCREAMING_SNAKE_CASE__				)}				)				)

          client.chat_postMessage(
              channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']							,					text='There was an issue running the tests.'							,					blocks=SCREAMING_SNAKE_CASE__							,					)
    def      _UpperCamelCase       ( self							:					Optional[int]				):
          print('Sending the following payload'				)
          print(json.dumps({'blocks': json.loads(self.payload				)}				)				)

          lowerCamelCase__           =		F'{self.n_failures} failures out of {self.n_tests} tests,' if self.n_failures else 'All tests passed.'

          lowerCamelCase__           =		client.chat_postMessage(
              channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']							,					blocks=self.payload							,					text=SCREAMING_SNAKE_CASE__							,					)
    def      _UpperCamelCase       ( self							:					Optional[Any]							,					SCREAMING_SNAKE_CASE__							:					Dict							,					SCREAMING_SNAKE_CASE__							:					List[Any]							,					SCREAMING_SNAKE_CASE__							:					Tuple							,					SCREAMING_SNAKE_CASE__							:					Tuple				):
          lowerCamelCase__           =		''
          for key, value in failures.items():
                lowerCamelCase__           =		value[:2_00] + ' [Truncated]' if len(SCREAMING_SNAKE_CASE__				) > 2_50 else value
                failures_text += F'*{key}*\n_{value}_\n\n'

          lowerCamelCase__           =		job_name
          lowerCamelCase__           =		{'type': 'section', 'text': {'type': 'mrkdwn', 'text': text}}

          if job_link is not None:
                lowerCamelCase__           =		{
                    'type': 'button',
                    'text': {'type': 'plain_text', 'text': 'GitHub Action job', 'emoji': True},
                    'url': job_link,
                }

          return [
              {"type": "header", "text": {"type": "plain_text", "text": title.upper(), "emoji": True}},
              content,
              {"type": "section", "text": {"type": "mrkdwn", "text": failures_text}},
          ]


    def      _UpperCamelCase       ( self							:					Optional[int]				):
          if self.thread_ts is None:
                raise ValueError('Can only post reply if a post has been made.'				)

          lowerCamelCase__           =		self.doc_test_results.pop('job_link'				)
          self.doc_test_results.pop('failures'				)
          self.doc_test_results.pop('success'				)
          self.doc_test_results.pop('time_spent'				)

          lowerCamelCase__           =		sorted(self.doc_test_results.items()							,					key=lambda SCREAMING_SNAKE_CASE__				: t[0]				)
          for job, job_result in sorted_dict:
                if len(job_result['failures']				):
                      lowerCamelCase__           =		F'*Num failures* :{len(job_result["failed"]				)} \n'
                      lowerCamelCase__           =		job_result['failures']
                      lowerCamelCase__           =		self.get_reply_blocks(SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__							,					SCREAMING_SNAKE_CASE__							,					text=SCREAMING_SNAKE_CASE__				)

                      print('Sending the following reply'				)
                      print(json.dumps({'blocks': blocks}				)				)

                      client.chat_postMessage(
                          channel=os.environ['CI_SLACK_CHANNEL_ID_DAILY']							,					text=F'Results for {job}'							,					blocks=SCREAMING_SNAKE_CASE__							,					thread_ts=self.thread_ts['ts']							,					)

                      time.sleep(1				)





def   snake_case						(				)->		Optional[Any]:
      '''simple docstring'''


      lowerCamelCase__           =		os.environ['GITHUB_RUN_ID']
      lowerCamelCase__           =		F'https://api.github.com/repos/huggingface/transformers/actions/runs/{run_id}/jobs?per_page=100'
      lowerCamelCase__           =		requests.get(_a							).json()
      lowerCamelCase__           =		{}

      try:
            jobs.update({job['name']: job['html_url'] for job in result['jobs']}							)
            lowerCamelCase__           =		math.ceil((result['total_count'] - 100) / 100							)

            for i in range(_a							):
                  lowerCamelCase__           =		requests.get(url + F'&page={i + 2}'							).json()
                  jobs.update({job['name']: job['html_url'] for job in result['jobs']}							)

            return jobs
      except Exception as e:
            print('Unknown error, could not fetch links.'		,   _a							)

      return {}



def   snake_case						(				_a:     str							)->		Dict:
      '''simple docstring'''


      lowerCamelCase__           =		{}

      if os.path.exists(_a							):
            lowerCamelCase__           =		os.listdir(_a							)
            for file in files:
                  try:
                        with open(os.path.join(_a		,   _a							)		,   encoding='utf-8'							) as f:
                              lowerCamelCase__           =		f.read()
                  except UnicodeDecodeError as e:
                        raise ValueError(F'Could not open {os.path.join(_a		,   _a							)}.'							) from e

      return _artifact



def   snake_case						(				)->		Optional[int]:
      '''simple docstring'''


      class   _a      :
          def __init__( self							:					Tuple							,					SCREAMING_SNAKE_CASE__							:					str				):
                lowerCamelCase__           =		name
                lowerCamelCase__           =		[]
          def __str__( self							:					Dict				):
                return self.name


          def      _UpperCamelCase       ( self							:					Union[str, Any]							,					SCREAMING_SNAKE_CASE__							:					str				):
                self.paths.append({'name': self.name, 'path': path}				)





      lowerCamelCase__           =		{}

      lowerCamelCase__           =		filter(os.path.isdir		,   os.listdir()							)
      for directory in directories:
            lowerCamelCase__           =		directory
            if artifact_name not in _available_artifacts:
                  lowerCamelCase__           =		Artifact(_a							)

                  _available_artifacts[artifact_name].add_path(_a							)

      return _available_artifacts


if __name__ == "__main__":
   _snake_case          =							get_job_links()
   _snake_case          =							retrieve_available_artifacts()

   _snake_case          =							collections.OrderedDict(
       [
           ("*.py", "API Examples"),
           ("*.md", "MD Examples"),
       ]
   )

   # This dict will contain all the information relative to each doc test category:
   # - failed: list of failed tests
   # - failures: dict in the format 'test': 'error_message'
   _snake_case          =							{
       v: {
           "failed": [],
           "failures": {},
       }
       for v in docs.values()
   }

   # Link to the GitHub Action job
   _snake_case          =							github_actions_job_links.get("run_doctests")

   _snake_case          =							available_artifacts["doc_tests_gpu_test_reports"].paths[0]
   _snake_case          =							retrieve_artifact(artifact_path["name"])
   if "stats" in artifact:
      _snake_case      ,					_snake_case      ,					_snake_case          =							handle_test_results(artifact["stats"])
      _snake_case          =							failed
      _snake_case          =							success
      _snake_case          =							time_spent[1:-1] + ", "

      _snake_case          =							extract_first_line_failure(artifact["failures_short"])
      for line in artifact["summary_short"].split("\n"):
         if re.search("FAILED", line):
            _snake_case          =							line.replace("FAILED ", "")
            _snake_case          =							line.split()[0].replace("\n", "")

            if "::" in line:
               _snake_case      ,					_snake_case          =							line.split("::")
            else:
               _snake_case      ,					_snake_case          =							line, line

            for file_regex in docs.keys():
               if fnmatch(file_path, file_regex):
                  _snake_case          =							docs[file_regex]
                  doc_test_results[category]["failed"].append(test)

                  _snake_case          =							all_failures[test] if test in all_failures else "N/A"
                  _snake_case          =							failure
                  break

   _snake_case          =							Message("🤗 Results of the doc tests.", doc_test_results)
   message.post()
   message.post_reply()



