






"""simple docstring"""





import logging
import os
import threading
import time


try:
		import warnings
except ImportError:
		A__					: List[str]=	None

try:
		import msvcrt
except ImportError:
		A__					: Dict=	None

try:
		import fcntl
except ImportError:
		A__					: Dict=	None


# Backward compatibility
# ------------------------------------------------
try:
		TimeoutError
except NameError:
		A__					: Optional[int]=	OSError


# Data
# ------------------------------------------------
A__					: str=	[
    """Timeout""",
    """BaseFileLock""",
    """WindowsFileLock""",
    """UnixFileLock""",
    """SoftFileLock""",
    """FileLock""",
]

A__					: Union[str, Any]=	"""3.0.12"""


A__					: Any=	None







def   lowerCAmelCase_( )					->	int:
				"""simple docstring"""

				global _logger
				UpperCamelCase__         =    _logger or logging.getLogger(__name__					)
				return _logger
class    __lowerCamelCase    (  _a  ):

			def __init__(					self ,				snake_case_      )		->       Any:
							UpperCamelCase__         =    lock_file
							return None







			def __str__(					self      )		->       Optional[int]:
							UpperCamelCase__         =    F'The file lock \'{self.lock_file}\' could not be acquired.'
							return temp







class    __lowerCamelCase    :

			def __init__(					self ,				snake_case_      )		->       List[Any]:
							UpperCamelCase__         =    lock
							return None

			def __enter__(					self      )		->       int:
							return self.lock







			def __exit__(					self ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       Dict:
							self.lock.release()
							return None







class    __lowerCamelCase    :

			def __init__(					self ,				snake_case_ ,				snake_case_=-1 ,				snake_case_=None      )		->       Dict:
							UpperCamelCase__         =    max_filename_length if max_filename_length is not None else 255
							# Hash the filename if it's too long
							UpperCamelCase__         =    self.hash_filename_if_too_long(snake_case_ ,				snake_case_      )
							# The path to the lock file.
							UpperCamelCase__         =    lock_file

							# The file descriptor for the *_lock_file* as it is returned by the
							# os.open() function.
							# This file lock is only NOT None, if the object currently holds the
							# lock.
							UpperCamelCase__         =    None

							# The default timeout value.
							UpperCamelCase__         =    timeout

							# We use this lock primarily for the lock counter.
							UpperCamelCase__         =    threading.Lock()

							# The lock counter is used for implementing the nested locking
							# mechanism. Whenever the lock is acquired, the counter is increased and
							# the lock is only released, when this value is 0 again.
							UpperCamelCase__         =    0
							return None

			@property
			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
							return self._lock_file

			@property
			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[Any]:
							return self._timeout

			@timeout.setter
			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_      )		->       List[str]:
							UpperCamelCase__         =    float(snake_case_      )
							return None

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Tuple:
							raise NotImplementedError()

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       List[Any]:
							raise NotImplementedError()

			@property
			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       str:
							return self._lock_file_fd is not None

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_=None ,				snake_case_=0.05      )		->       int:
							# Use the default timeout, if no timeout is provided.
							if timeout is None:
											UpperCamelCase__         =    self.timeout

							# Increment the number right at the beginning.
							# We can still undo it, if something fails.
							with self._thread_lock:
											self._lock_counter += 1

							UpperCamelCase__         =    id(self      )
							UpperCamelCase__         =    self._lock_file
							UpperCamelCase__         =    time.time()
							try:
											while True:
															with self._thread_lock:
																			if not self.is_locked:
																							logger().debug(F'Attempting to acquire lock {lock_id} on {lock_filename}'      )
																							self._acquire()

															if self.is_locked:
																			logger().debug(F'Lock {lock_id} acquired on {lock_filename}'      )
																			break
															elif timeout >= 0 and time.time() - start_time > timeout:
																			logger().debug(F'Timeout on acquiring lock {lock_id} on {lock_filename}'      )
																			raise Timeout(self._lock_file      )
															else:
																			logger().debug(
																			    F'Lock {lock_id} not acquired on {lock_filename}, waiting {poll_intervall} seconds ...'      )
																			time.sleep(snake_case_      )
							except:  # noqa
											# Something did go wrong, so decrement the counter.
											with self._thread_lock:
															UpperCamelCase__         =    max(0 ,				self._lock_counter - 1      )

											raise
							return _Acquire_ReturnProxy(lock=self      )

			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_=False      )		->       Tuple:
							with self._thread_lock:
											if self.is_locked:
															self._lock_counter -= 1

															if self._lock_counter == 0 or force:
																			UpperCamelCase__         =    id(self      )
																			UpperCamelCase__         =    self._lock_file

																			logger().debug(F'Attempting to release lock {lock_id} on {lock_filename}'      )
																			self._release()
																			UpperCamelCase__         =    0
																			logger().debug(F'Lock {lock_id} released on {lock_filename}'      )

							return None

			def __enter__(					self      )		->       List[Any]:
							self.acquire()
							return self

			def __exit__(					self ,				snake_case_ ,				snake_case_ ,				snake_case_      )		->       Union[str, Any]:
							self.release()
							return None

			def __del__(					self      )		->       Optional[Any]:
							self.release(force=snake_case_      )
							return None







			def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_      )		->       str:
							UpperCamelCase__         =    os.path.basename(snake_case_      )
							if len(snake_case_      ) > max_length and max_length > 0:
											UpperCamelCase__         =    os.path.dirname(snake_case_      )
											UpperCamelCase__         =    str(hash(snake_case_      )      )
											UpperCamelCase__         =    filename[: max_length - len(snake_case_      ) - 8] + '...' + hashed_filename + '.lock'
											return os.path.join(snake_case_ ,				snake_case_      )
							else:
											return path







class    __lowerCamelCase    (  _a  ):

			def __init__(					self ,				snake_case_ ,				snake_case_=-1 ,				snake_case_=None      )		->       Dict:
							from .file_utils import relative_to_absolute_path

							super().__init__(snake_case_ ,				timeout=snake_case_ ,				max_filename_length=snake_case_      )
							UpperCamelCase__         =    '\\\\?\\' + relative_to_absolute_path(self.lock_file      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Dict:
							UpperCamelCase__         =    os.O_RDWR | os.O_CREAT | os.O_TRUNC

							try:
											UpperCamelCase__         =    os.open(self._lock_file ,				snake_case_      )
							except OSError:
											pass
							else:
											try:
															msvcrt.locking(snake_case_ ,				msvcrt.LK_NBLCK ,				1      )
											except OSError:
															os.close(snake_case_      )
											else:
															UpperCamelCase__         =    fd
							return None







			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
							UpperCamelCase__         =    self._lock_file_fd
							UpperCamelCase__         =    None
							msvcrt.locking(snake_case_ ,				msvcrt.LK_UNLCK ,				1      )
							os.close(snake_case_      )

							try:
											os.remove(self._lock_file      )
							# Probably another instance of the application
							# that acquired the file lock.
							except OSError:
											pass
							return None







class    __lowerCamelCase    (  _a  ):

			def __init__(					self ,				snake_case_ ,				snake_case_=-1 ,				snake_case_=None      )		->       int:
							UpperCamelCase__         =    os.statvfs(os.path.dirname(snake_case_      )      ).f_namemax
							super().__init__(snake_case_ ,				timeout=snake_case_ ,				max_filename_length=snake_case_      )

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[Any]:
							UpperCamelCase__         =    os.O_RDWR | os.O_CREAT | os.O_TRUNC
							UpperCamelCase__         =    os.open(self._lock_file ,				snake_case_      )

							try:
											fcntl.flock(snake_case_ ,				fcntl.LOCK_EX | fcntl.LOCK_NB      )
							except OSError:
											os.close(snake_case_      )
							else:
											UpperCamelCase__         =    fd
							return None







			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
							# Do not remove the lockfile:
							#
							#   https://github.com/benediktschmitt/py-filelock/issues/31
							#   https://stackoverflow.com/questions/17708885/flock-removing-locked-file-without-race-condition
							UpperCamelCase__         =    self._lock_file_fd
							UpperCamelCase__         =    None
							fcntl.flock(snake_case_ ,				fcntl.LOCK_UN      )
							os.close(snake_case_      )
							return None







class    __lowerCamelCase    (  _a  ):

			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Any:
							UpperCamelCase__         =    os.O_WRONLY | os.O_CREAT | os.O_EXCL | os.O_TRUNC
							try:
											UpperCamelCase__         =    os.open(self._lock_file ,				snake_case_      )
							except OSError:
											pass
							else:
											UpperCamelCase__         =    fd
							return None







			def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Tuple:
							os.close(self._lock_file_fd      )
							UpperCamelCase__         =    None

							try:
											os.remove(self._lock_file      )
							# The file is already deleted and that's what we want.
							except OSError:
											pass
							return None







A__					: Union[str, Any]=	None

if msvcrt:
		A__					: List[Any]=	WindowsFileLock
elif fcntl:
		A__					: Optional[Any]=	UnixFileLock
else:
		A__					: Dict=	SoftFileLock

		if warnings is not None:
				warnings.warn("""only soft file lock is available""")












"""simple docstring"""





import doctest
import logging
import os
import unittest
from pathlib import Path
from typing import List, Union

import transformers
from transformers.testing_utils import require_tf, require_torch, slow


A__					: Union[str, Any]=	logging.getLogger()
@unittest.skip("""Temporarily disable the doc tests."""  )
@require_torch
@require_tf
@slow
class    __lowerCamelCase    (  unittest.TestCase  ):

   def 						SCREAMING_SNAKE_CASE__ (					self ,				snake_case_ ,				snake_case_ = None ,				snake_case_ = None ,				snake_case_ = None ,				snake_case_ = True ,				)		->       Tuple:
       UpperCamelCase__         =    [file for file in os.listdir(snake_case_      ) if os.path.isfile(os.path.join(snake_case_ ,				snake_case_      )      )]

       if identifier is not None:
           UpperCamelCase__         =    [file for file in files if identifier in file]

       if n_identifier is not None:
           if isinstance(snake_case_ ,				snake_case_      ):
               for n_ in n_identifier:
                   UpperCamelCase__         =    [file for file in files if n_ not in file]
           else:
               UpperCamelCase__         =    [file for file in files if n_identifier not in file]

       UpperCamelCase__         =    ignore_files or []
       ignore_files.append('__init__.py'      )
       UpperCamelCase__         =    [file for file in files if file not in ignore_files]

       for file in files:
           # Open all files
           print('Testing' ,				snake_case_      )

           if only_modules:
               UpperCamelCase__         =    file.split('.'      )[0]
               try:
                   UpperCamelCase__         =    getattr(snake_case_ ,				snake_case_      )
                   UpperCamelCase__         =    doctest.DocTestSuite(snake_case_      )
                   UpperCamelCase__         =    unittest.TextTestRunner().run(snake_case_      )
                   self.assertIs(len(result.failures      ) ,				0      )
               except AttributeError:
                   logger.info(F'{module_identifier} is not a module.'      )
           else:
               UpperCamelCase__         =    doctest.testfile(str('..' / directory / file      ) ,				optionflags=doctest.ELLIPSIS      )
               self.assertIs(result.failed ,				0      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'modeling'
       UpperCamelCase__         =    [
           'modeling_ctrl.py',
           'modeling_tf_ctrl.py',
       ]
       self.analyze_directory(snake_case_ ,				identifier=snake_case_ ,				ignore_files=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[int]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'tokenization'
       self.analyze_directory(snake_case_ ,				identifier=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Optional[Any]:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    'configuration'
       self.analyze_directory(snake_case_ ,				identifier=snake_case_      )

   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       str:
       UpperCamelCase__         =    Path('src/transformers'      )
       UpperCamelCase__         =    ['configuration', 'modeling', 'tokenization']
       self.analyze_directory(snake_case_ ,				n_identifier=snake_case_      )







   def 						SCREAMING_SNAKE_CASE__ (					self      )		->       Union[str, Any]:
       UpperCamelCase__         =    Path('docs/source'      )
       UpperCamelCase__         =    ['favicon.ico']
       self.analyze_directory(snake_case_ ,				ignore_files=snake_case_ ,				only_modules=snake_case_      )




