






'''simple docstring'''

import argparse
import os
import re

import packaging.version


SCREAMING_SNAKE_CASE__											=     'examples/'
SCREAMING_SNAKE_CASE__											=     {
    'examples': (re.compile(R'^check_min_version\("[^"]+"\)\s*$', re.MULTILINE), 'check_min_version("VERSION")\n'),
    'init': (re.compile(R'^__version__\s+=\s+"([^"]+)"\s*$', re.MULTILINE), '__version__ = "VERSION"\n'),
    'setup': (re.compile(R'^(\s*)version\s*=\s*"[^"]+",', re.MULTILINE), R'\1version="VERSION",'),
    'doc': (re.compile(R'^(\s*)release\s*=\s*"[^"]+"$', re.MULTILINE), 'release = "VERSION"\n'),
}
SCREAMING_SNAKE_CASE__											=     {
    'init': 'src/transformers/__init__.py',
    'setup': 'setup.py',
}
SCREAMING_SNAKE_CASE__											=     'README.md'







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase	,		__UpperCamelCase					)->				Union[str, Any]:







      with open(_lowercase	,		"""r"""	,		encoding="""utf-8"""	,		newline="""\n"""					) as f:
            UpperCamelCase       						=      f.read()
      UpperCamelCase						,UpperCamelCase       						=      REPLACE_PATTERNS[pattern]
      UpperCamelCase       						=      replace.replace("""VERSION"""	,		_lowercase					)
      UpperCamelCase       						=      re_pattern.sub(_lowercase	,		_lowercase					)
      with open(_lowercase	,		"""w"""	,		encoding="""utf-8"""	,		newline="""\n"""					) as f:
            f.write(_lowercase					)







def 					lowercase__				(   __UpperCamelCase					)->				Optional[Any]:







      for folder, directories, fnames in os.walk(_lowercase					):
            # Removing some of the folders with non-actively maintained examples from the walk
            if "research_projects" in directories:
                  directories.remove("""research_projects"""					)
            if "legacy" in directories:
                  directories.remove("""legacy"""					)
            for fname in fnames:
                  if fname.endswith(""".py"""					):
                        update_version_in_file(os.path.join(_lowercase	,		_lowercase					)	,		_lowercase	,		pattern="""examples"""					)







def 					lowercase__				(   __UpperCamelCase	,		__UpperCamelCase=False					)->				Any:







      for pattern, fname in REPLACE_FILES.items():
            update_version_in_file(_lowercase	,		_lowercase	,		_lowercase					)
      if not patch:
            update_version_in_examples(_lowercase					)







def 					lowercase__				(   )->				List[str]:
      UpperCamelCase       						=      """🤗 Transformers currently provides the following architectures"""
      UpperCamelCase       						=      """1. Want to contribute a new model?"""
      with open(_lowercase	,		"""r"""	,		encoding="""utf-8"""	,		newline="""\n"""					) as f:
            UpperCamelCase       						=      f.readlines()

      # Find the start of the list.
      UpperCamelCase       						=      0
      while not lines[start_index].startswith(_start_prompt					):
            start_index += 1
      start_index += 1

      UpperCamelCase       						=      start_index
      # Update the lines in the model list.
      while not lines[index].startswith(_end_prompt					):
            if lines[index].startswith("""1."""					):
                  UpperCamelCase       						=      lines[index].replace(
                      """https://huggingface.co/docs/transformers/main/model_doc"""	,		"""https://huggingface.co/docs/transformers/model_doc"""	,		)
            index += 1

      with open(_lowercase	,		"""w"""	,		encoding="""utf-8"""	,		newline="""\n"""					) as f:
            f.writelines(_lowercase					)







def 					lowercase__				(   )->				List[Any]:







      with open(REPLACE_FILES["""init"""]	,		"""r"""					) as f:
            UpperCamelCase       						=      f.read()
      UpperCamelCase       						=      REPLACE_PATTERNS["""init"""][0].search(_lowercase					).groups()[0]
      return packaging.version.parse(_lowercase					)







def 					lowercase__				(   __UpperCamelCase=False					)->				Optional[int]:
      UpperCamelCase       						=      get_version()
      if patch and default_version.is_devrelease:
            raise ValueError("""Can\'t create a patch version from the dev branch, checkout a released version!"""					)
      if default_version.is_devrelease:
            UpperCamelCase       						=      default_version.base_version
      elif patch:
            UpperCamelCase       						=      F"{default_version.major}.{default_version.minor}.{default_version.micro + 1}"
      else:
            UpperCamelCase       						=      F"{default_version.major}.{default_version.minor + 1}.0"

      # Now let's ask nicely if that's the right one.
      UpperCamelCase       						=      input(F"Which version are you releasing? [{default_version}]"					)
      if len(_lowercase					) == 0:
            UpperCamelCase       						=      default_version

      print(F"Updating version to {version}."					)
      global_version_update(_lowercase	,		patch=_lowercase					)
      if not patch:
            print("""Cleaning main README, don\'t forget to run `make fix-copies`."""					)
            clean_main_ref_in_model_list()







def 					lowercase__				(   )->				str:
      UpperCamelCase       						=      get_version()
      UpperCamelCase       						=      F"{current_version.major}.{current_version.minor + 1}.0.dev0"
      UpperCamelCase       						=      current_version.base_version

      # Check with the user we got that right.
      UpperCamelCase       						=      input(F"Which version are we developing now? [{dev_version}]"					)
      if len(_lowercase					) == 0:
            UpperCamelCase       						=      dev_version

      print(F"Updating version to {version}."					)
      global_version_update(_lowercase					)
      print("""Cleaning main README, don\'t forget to run `make fix-copies`."""					)
      clean_main_ref_in_model_list()


if __name__ == "__main__":
     SCREAMING_SNAKE_CASE__											=     argparse.ArgumentParser()
     parser.add_argument('--post_release', action='store_true', help='Whether this is pre or post release.')
     parser.add_argument('--patch', action='store_true', help='Whether or not this is a patch release.')
     SCREAMING_SNAKE_CASE__											=     parser.parse_args()
     if not args.post_release:
          pre_release_work(patch=args.patch)
     elif args.patch:
          print('Nothing to do after a patch :-)')
     else:
          post_release_work()








'''simple docstring'''

# Copyright 2022 The HuggingFace 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.

import argparse
import os
import platform

import numpy as np
import psutil
import torch

from accelerate import __version__ as version
from accelerate.commands.config import default_config_file, load_config_from_file

from ..utils import is_npu_available, is_xpu_available







def 					lowercase__				(   __UpperCamelCase=None					)->				Union[str, Any]:
      if subparsers is not None:
            UpperCamelCase       						=      subparsers.add_parser("""env"""					)
      else:
            UpperCamelCase       						=      argparse.ArgumentParser("""Accelerate env command"""					)

      parser.add_argument(
          """--config_file"""	,		default=__UpperCamelCase	,		help="""The config file to use for the default values in the launching script."""					)

      if subparsers is not None:
            parser.set_defaults(func=__UpperCamelCase					)
      return parser







def 					lowercase__				(   __UpperCamelCase					)->				List[str]:
      UpperCamelCase       						=      torch.__version__
      UpperCamelCase       						=      torch.cuda.is_available()
      UpperCamelCase       						=      is_xpu_available()
      UpperCamelCase       						=      is_npu_available()

      UpperCamelCase       						=      """Not found"""
      # Get the default from the config file.
      if args.config_file is not None or os.path.isfile(__UpperCamelCase					):
            UpperCamelCase       						=      load_config_from_file(args.config_file					).to_dict()

      UpperCamelCase       						=      {
          """`Accelerate` version""": version,
          """Platform""": platform.platform(),
          """Python version""": platform.python_version(),
          """Numpy version""": np.__version__,
          """PyTorch version (GPU?)""": F"{pt_version} ({pt_cuda_available})",
          """PyTorch XPU available""": str(__UpperCamelCase					),
          """PyTorch NPU available""": str(__UpperCamelCase					),
          """System RAM""": F"{psutil.virtual_memory().total / 1024 ** 3:.2f} GB",
      }
      if pt_cuda_available:
            UpperCamelCase       						=      torch.cuda.get_device_name()

      print("""\nCopy-and-paste the text below in your GitHub issue\n"""					)
      print("""\n""".join([F"- {prop}: {val}" for prop, val in info.items()]					)					)

      print("""- `Accelerate` default config:""" if args.config_file is None else """- `Accelerate` config passed:"""					)
      UpperCamelCase       						=      (
          """\n""".join([F"\t- {prop}: {val}" for prop, val in accelerate_config.items()]					)
          if isinstance(__UpperCamelCase	,		__UpperCamelCase					)
          else F"\t{accelerate_config}"
      )
      print(__UpperCamelCase					)

      UpperCamelCase       						=      accelerate_config

      return info







def 					lowercase__				(   )->				int:
      UpperCamelCase       						=      env_command_parser()
      UpperCamelCase       						=      parser.parse_args()
      env_command(__UpperCamelCase					)
      return 0


if __name__ == "__main__":
     raise SystemExit(main())
