__init__.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # __init__.py
  2. # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors
  3. #
  4. # This module is part of GitPython and is released under
  5. # the BSD License: http://www.opensource.org/licenses/bsd-license.php
  6. # flake8: noqa
  7. # @PydevCodeAnalysisIgnore
  8. from git.exc import * # @NoMove @IgnorePep8
  9. import inspect
  10. import os
  11. import sys
  12. import os.path as osp
  13. from typing import Optional
  14. from git.types import PathLike
  15. __version__ = '3.1.31'
  16. # { Initialization
  17. def _init_externals() -> None:
  18. """Initialize external projects by putting them into the path"""
  19. if __version__ == '3.1.31' and "PYOXIDIZER" not in os.environ:
  20. sys.path.insert(1, osp.join(osp.dirname(__file__), "ext", "gitdb"))
  21. try:
  22. import gitdb
  23. except ImportError as e:
  24. raise ImportError("'gitdb' could not be found in your PYTHONPATH") from e
  25. # END verify import
  26. # } END initialization
  27. #################
  28. _init_externals()
  29. #################
  30. # { Imports
  31. try:
  32. from git.config import GitConfigParser # @NoMove @IgnorePep8
  33. from git.objects import * # @NoMove @IgnorePep8
  34. from git.refs import * # @NoMove @IgnorePep8
  35. from git.diff import * # @NoMove @IgnorePep8
  36. from git.db import * # @NoMove @IgnorePep8
  37. from git.cmd import Git # @NoMove @IgnorePep8
  38. from git.repo import Repo # @NoMove @IgnorePep8
  39. from git.remote import * # @NoMove @IgnorePep8
  40. from git.index import * # @NoMove @IgnorePep8
  41. from git.util import ( # @NoMove @IgnorePep8
  42. LockFile,
  43. BlockingLockFile,
  44. Stats,
  45. Actor,
  46. rmtree,
  47. )
  48. except GitError as exc:
  49. raise ImportError("%s: %s" % (exc.__class__.__name__, exc)) from exc
  50. # } END imports
  51. __all__ = [name for name, obj in locals().items() if not (name.startswith("_") or inspect.ismodule(obj))]
  52. # { Initialize git executable path
  53. GIT_OK = None
  54. def refresh(path: Optional[PathLike] = None) -> None:
  55. """Convenience method for setting the git executable path."""
  56. global GIT_OK
  57. GIT_OK = False
  58. if not Git.refresh(path=path):
  59. return
  60. if not FetchInfo.refresh():
  61. return
  62. GIT_OK = True
  63. # } END initialize git executable path
  64. #################
  65. try:
  66. refresh()
  67. except Exception as exc:
  68. raise ImportError("Failed to initialize: {0}".format(exc)) from exc
  69. #################