






"""simple docstring"""





import posixpath
from pathlib import Path
from unittest.mock import patch

import pytest
from fsspec.implementations.local import AbstractFileSystem, LocalFileSystem, stringify_path
from fsspec.registry import _registry as _fsspec_registry







class 		_a       (						lowercase_   ):





   '''simple docstring'''






   UpperCamelCase__      					=    """mock"""





   def __init__(   self			,				*UpperCAmelCase_			,				UpperCAmelCase_			,				**UpperCAmelCase_)	-> List[Any]:




          '''simple docstring'''




          super().__init__()
          lowercase__:    Any        =      LocalFileSystem(*UpperCAmelCase_			,				**UpperCAmelCase_)
          lowercase__:    Union[str, Any]        =      Path(UpperCAmelCase_).resolve().as_posix() + "/"





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> Optional[int]:




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.mkdir(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> int:




          '''simple docstring'''




          lowercase__:    Any        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.makedirs(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_)	-> List[str]:




          '''simple docstring'''




          lowercase__:    List[str]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.rmdir(UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_=True			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> int:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          lowercase__:    Optional[int]        =      self._fs.ls(UpperCAmelCase_			,				detail=UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)
          if detail:
                 return [{**info, "name": info["name"][len(self.local_root_dir) :]} for info in out]
          else:
                 return [name[len(self.local_root_dir) :] for name in out]





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    Optional[int]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          lowercase__:    Optional[int]        =      dict(self._fs.info(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_))
          lowercase__:    Any        =      out["name"][len(self.local_root_dir) :]
          return out





   def __lowercase    (   self			,				UpperCAmelCase_			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          lowercase__:    Optional[int]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.cp_file(UpperCAmelCase_			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> int:




          '''simple docstring'''




          lowercase__:    Any        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.rm_file(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> List[Any]:




          '''simple docstring'''




          lowercase__:    str        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.rm(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> str:




          '''simple docstring'''




          lowercase__:    Optional[Any]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs._open(UpperCAmelCase_			,				*UpperCAmelCase_			,				**UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_)	-> Any:




          '''simple docstring'''




          lowercase__:    Union[str, Any]        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.created(UpperCAmelCase_)





   def __lowercase    (   self			,				UpperCAmelCase_)	-> str:




          '''simple docstring'''




          lowercase__:    Dict        =      posixpath.join(self.local_root_dir			,				self._strip_protocol(UpperCAmelCase_))
          return self._fs.modified(UpperCAmelCase_)





   @classmethod
   def __lowercase    (   cls			,				UpperCAmelCase_)	-> Dict:




          '''simple docstring'''




          lowercase__:    List[Any]        =      stringify_path(UpperCAmelCase_)
          if path.startswith("mock://"):
                 lowercase__:    Dict        =      path[7:]
          return path







class 		_a       (						lowercase_   ):





   '''simple docstring'''






   UpperCamelCase__      					=    """tmp"""
   UpperCamelCase__      					=    None





   def __init__(   self			,				*UpperCAmelCase_			,				**UpperCAmelCase_)	-> Any:




          '''simple docstring'''




          assert self.tmp_dir is not None, "TmpDirFileSystem.tmp_dir is not set"
          super().__init__(*UpperCAmelCase_			,				**UpperCAmelCase_			,				local_root_dir=self.tmp_dir			,				auto_mkdir=UpperCAmelCase_)





   @classmethod
   def __lowercase    (   cls			,				UpperCAmelCase_)	-> Union[str, Any]:




          '''simple docstring'''




          lowercase__:    int        =      stringify_path(UpperCAmelCase_)
          if path.startswith("tmp://"):
                 lowercase__:    int        =      path[6:]
          return path







@pytest.fixture
def     A(  ):
       """simple docstring"""





       lowercase__:    Optional[int]        =      MockFileSystem
       lowercase__:    List[str]        =      TmpDirFileSystem
       yield
       del _fsspec_registry["mock"]
       del _fsspec_registry["tmp"]






@pytest.fixture
def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__:    Optional[Any]        =      tmp_path_factory.mktemp("mockfs"		)
       return MockFileSystem(local_root_dir=snake_case_						,       auto_mkdir=snake_case_		)







@pytest.fixture
def     A(  snake_case_						,       snake_case_		):
       """simple docstring"""





       lowercase__:    str        =      tmp_path_factory.mktemp("tmpfs"		)
       with patch.object(snake_case_						,       "tmp_dir"						,       snake_case_		):
              yield TmpDirFileSystem()














"""simple docstring"""





# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ..utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


UpperCamelCase			=      {
    """agents""": ["""Agent""", """AzureOpenAiAgent""", """HfAgent""", """LocalAgent""", """OpenAiAgent"""],
    """base""": ["""PipelineTool""", """RemoteTool""", """Tool""", """launch_gradio_demo""", """load_tool"""],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  UpperCamelCase			=      ["""DocumentQuestionAnsweringTool"""]
  UpperCamelCase			=      ["""ImageCaptioningTool"""]
  UpperCamelCase			=      ["""ImageQuestionAnsweringTool"""]
  UpperCamelCase			=      ["""ImageSegmentationTool"""]
  UpperCamelCase			=      ["""SpeechToTextTool"""]
  UpperCamelCase			=      ["""TextClassificationTool"""]
  UpperCamelCase			=      ["""TextQuestionAnsweringTool"""]
  UpperCamelCase			=      ["""TextSummarizationTool"""]
  UpperCamelCase			=      ["""TextToSpeechTool"""]
  UpperCamelCase			=      ["""TranslationTool"""]

if TYPE_CHECKING:
  from .agents import Agent, AzureOpenAiAgent, HfAgent, LocalAgent, OpenAiAgent
  from .base import PipelineTool, RemoteTool, Tool, launch_gradio_demo, load_tool

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .document_question_answering import DocumentQuestionAnsweringTool
    from .image_captioning import ImageCaptioningTool
    from .image_question_answering import ImageQuestionAnsweringTool
    from .image_segmentation import ImageSegmentationTool
    from .speech_to_text import SpeechToTextTool
    from .text_classification import TextClassificationTool
    from .text_question_answering import TextQuestionAnsweringTool
    from .text_summarization import TextSummarizationTool
    from .text_to_speech import TextToSpeechTool
    from .translation import TranslationTool
else:
  import sys

  UpperCamelCase			=      _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)






