





import os
from datetime import datetime as dt

from github import Github


SCREAMING_SNAKE_CASE_						       =	[
    """good first issue""",
    """feature request""",
    """wip""",
]



def        __lowercase       (				)			->       Optional[Any]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						Github(os.environ["""GITHUB_TOKEN"""]     )
      SCREAMING_SNAKE_CASE		=						g.get_repo("""huggingface/accelerate"""     )
      SCREAMING_SNAKE_CASE		=						repo.get_issues(state="""open"""     )

      for issue in open_issues:
            SCREAMING_SNAKE_CASE		=						sorted([comment for comment in issue.get_comments()]			,						key=lambda _SCREAMING_SNAKE_CASE     : i.created_at			,						reverse=_SCREAMING_SNAKE_CASE     )
            SCREAMING_SNAKE_CASE		=						comments[0] if len(_SCREAMING_SNAKE_CASE     ) > 0 else None
            SCREAMING_SNAKE_CASE		=						dt.utcnow()
            SCREAMING_SNAKE_CASE		=						(current_time - issue.updated_at).days
            SCREAMING_SNAKE_CASE		=						(current_time - issue.created_at).days
            if (
                last_comment is not None
                and last_comment.user.login == "github-actions[bot]"
                and days_since_updated > 7
                and days_since_creation >= 30
                and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()     )
            ):
                  # Close issue since it has been 7 days of inactivity since bot mention.
                  issue.edit(state="""closed"""     )
            elif (
                days_since_updated > 23
                and days_since_creation >= 30
                and not any(label.name.lower() in LABELS_TO_EXEMPT for label in issue.get_labels()     )
            ):
                  # Add stale comment
                  issue.create_comment(
                      """This issue has been automatically marked as stale because it has not had """
                      """recent activity. If you think this still needs to be addressed """
                      """please comment on this thread.\n\nPlease note that issues that do not follow the """
                      """[contributing guidelines](https://github.com/huggingface/accelerate/blob/main/CONTRIBUTING.md) """
                      """are likely to be ignored."""     )


if __name__ == "__main__":
      main()









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

import pytest
import zstandard as zstd

from datasets.download.download_config import DownloadConfig
from datasets.utils.file_utils import (
    OfflineModeIsEnabled,
    cached_path,
    fsspec_get,
    fsspec_head,
    ftp_get,
    ftp_head,
    get_from_cache,
    http_get,
    http_head,
)


SCREAMING_SNAKE_CASE_						       =	"""\
    Text data.
    Second line of data."""

SCREAMING_SNAKE_CASE_						       =	"""file"""



@pytest.fixture(scope="""session"""     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       Union[str, Any]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						tmp_path_factory.mktemp("""data"""     ) / (FILE_PATH + """.zstd""")
      SCREAMING_SNAKE_CASE		=						bytes(_SCREAMING_SNAKE_CASE			,						"""utf-8"""     )
      with zstd.open(_SCREAMING_SNAKE_CASE			,						"""wb"""     ) as f:
            f.write(_SCREAMING_SNAKE_CASE     )
      return path



@pytest.fixture
def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       List[Any]:


      '''simple docstring'''


      with open(os.path.join(tmpfs.local_root_dir			,						_SCREAMING_SNAKE_CASE     )			,						"""w"""     ) as f:
            f.write(_SCREAMING_SNAKE_CASE     )
      return FILE_PATH



@pytest.mark.parametrize("""compression_format"""			,						["""gzip""", """xz""", """zstd"""]     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )			->       Tuple:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						{"""gzip""": gz_file, """xz""": xz_file, """zstd""": zstd_path}
      SCREAMING_SNAKE_CASE		=						input_paths[compression_format]
      SCREAMING_SNAKE_CASE		=						tmp_path / """cache"""
      SCREAMING_SNAKE_CASE		=						DownloadConfig(cache_dir=_SCREAMING_SNAKE_CASE			,						extract_compressed_file=_SCREAMING_SNAKE_CASE     )
      SCREAMING_SNAKE_CASE		=						cached_path(_SCREAMING_SNAKE_CASE			,						download_config=_SCREAMING_SNAKE_CASE     )
      with open(_SCREAMING_SNAKE_CASE     ) as f:
            SCREAMING_SNAKE_CASE		=						f.read()
      with open(_SCREAMING_SNAKE_CASE     ) as f:
            SCREAMING_SNAKE_CASE		=						f.read()
      assert extracted_file_content == expected_file_content



@pytest.mark.parametrize("""default_extracted"""			,						[True, False]     )
@pytest.mark.parametrize("""default_cache_dir"""			,						[True, False]     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE			,						_SCREAMING_SNAKE_CASE     )			->       List[str]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						"""custom_cache"""
      SCREAMING_SNAKE_CASE		=						"""custom_extracted_dir"""
      SCREAMING_SNAKE_CASE		=						tmp_path / """custom_extracted_path"""
      if default_extracted:
            SCREAMING_SNAKE_CASE		=						("""downloads""" if default_cache_dir else custom_cache_dir, """extracted""")
      else:
            monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_DIR"""			,						_SCREAMING_SNAKE_CASE     )
            monkeypatch.setattr("""datasets.config.EXTRACTED_DATASETS_PATH"""			,						str(_SCREAMING_SNAKE_CASE     )     )
            SCREAMING_SNAKE_CASE		=						custom_extracted_path.parts[-2:] if default_cache_dir else (custom_cache_dir, custom_extracted_dir)

      SCREAMING_SNAKE_CASE		=						xz_file
      SCREAMING_SNAKE_CASE		=						(
          DownloadConfig(extract_compressed_file=_SCREAMING_SNAKE_CASE     )
          if default_cache_dir
          else DownloadConfig(cache_dir=tmp_path / custom_cache_dir			,						extract_compressed_file=_SCREAMING_SNAKE_CASE     )
      )
      SCREAMING_SNAKE_CASE		=						cached_path(_SCREAMING_SNAKE_CASE			,						download_config=_SCREAMING_SNAKE_CASE     )
      assert Path(_SCREAMING_SNAKE_CASE     ).parent.parts[-2:] == expected



def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						str(Path(_SCREAMING_SNAKE_CASE     ).resolve()     )
      assert cached_path(_SCREAMING_SNAKE_CASE     ) == text_file
      # relative path
      SCREAMING_SNAKE_CASE		=						str(Path(_SCREAMING_SNAKE_CASE     ).resolve().relative_to(Path(os.getcwd()     )     )     )
      assert cached_path(_SCREAMING_SNAKE_CASE     ) == text_file



def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       Dict:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						str(tmp_path.resolve() / """__missing_file__.txt"""     )
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            cached_path(_SCREAMING_SNAKE_CASE     )
      # relative path
      SCREAMING_SNAKE_CASE		=						"""./__missing_file__.txt"""
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            cached_path(_SCREAMING_SNAKE_CASE     )



def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       str:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						get_from_cache(F"""tmp://{tmpfs_file}"""     )
      with open(_SCREAMING_SNAKE_CASE     ) as f:
            SCREAMING_SNAKE_CASE		=						f.read()
      assert output_file_content == FILE_CONTENT



@patch("""datasets.config.HF_DATASETS_OFFLINE"""			,						_SCREAMING_SNAKE_CASE     )
def        __lowercase       (				)			->       Dict:


      '''simple docstring'''


      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            cached_path("""https://huggingface.co"""     )



@patch("""datasets.config.HF_DATASETS_OFFLINE"""			,						_SCREAMING_SNAKE_CASE     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       Union[str, Any]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						tmp_path_factory.mktemp("""data"""     ) / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            http_get("""https://huggingface.co"""			,						temp_file=_SCREAMING_SNAKE_CASE     )
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            http_head("""https://huggingface.co"""     )



@patch("""datasets.config.HF_DATASETS_OFFLINE"""			,						_SCREAMING_SNAKE_CASE     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       Optional[int]:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						tmp_path_factory.mktemp("""data"""     ) / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            ftp_get("""ftp://huggingface.co"""			,						temp_file=_SCREAMING_SNAKE_CASE     )
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            ftp_head("""ftp://huggingface.co"""     )



@patch("""datasets.config.HF_DATASETS_OFFLINE"""			,						_SCREAMING_SNAKE_CASE     )
def        __lowercase       (				_SCREAMING_SNAKE_CASE     )			->       int:


      '''simple docstring'''


      SCREAMING_SNAKE_CASE		=						tmp_path_factory.mktemp("""data"""     ) / """file.html"""
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            fsspec_get("""s3://huggingface.co"""			,						temp_file=_SCREAMING_SNAKE_CASE     )
      with pytest.raises(_SCREAMING_SNAKE_CASE     ):
            fsspec_head("""s3://huggingface.co"""     )


