__init__.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # __init__.py -- The git module of dulwich
  2. # Copyright (C) 2007 James Westby <jw+debian@jameswestby.net>
  3. # Copyright (C) 2008 Jelmer Vernooij <jelmer@jelmer.uk>
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
  6. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  7. # General Public License as published by the Free Software Foundation; version 2.0
  8. # or (at your option) any later version. You can redistribute it and/or
  9. # modify it under the terms of either of these two licenses.
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. #
  17. # You should have received a copy of the licenses; if not, see
  18. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  19. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  20. # License, Version 2.0.
  21. #
  22. """Python implementation of the Git file formats and protocols."""
  23. import sys
  24. from typing import Callable, Optional, TypeVar, Union
  25. if sys.version_info >= (3, 10):
  26. from typing import ParamSpec
  27. else:
  28. from typing_extensions import ParamSpec
  29. __version__ = (0, 24, 1)
  30. __all__ = ["__version__", "replace_me"]
  31. P = ParamSpec("P")
  32. R = TypeVar("R")
  33. F = TypeVar("F", bound=Callable[..., object])
  34. try:
  35. from dissolve import replace_me
  36. except ImportError:
  37. # if dissolve is not installed, then just provide a basic implementation
  38. # of its replace_me decorator
  39. def replace_me(
  40. since: Optional[Union[str, tuple[int, ...]]] = None,
  41. remove_in: Optional[Union[str, tuple[int, ...]]] = None,
  42. ) -> Callable[[F], F]:
  43. """Decorator to mark functions as deprecated.
  44. Args:
  45. since: Version when the function was deprecated
  46. remove_in: Version when the function will be removed
  47. Returns:
  48. Decorator function
  49. """
  50. def decorator(func: F) -> F:
  51. import functools
  52. import warnings
  53. m = f"{func.__name__} is deprecated" # type: ignore[attr-defined]
  54. since_str = str(since) if since is not None else None
  55. remove_in_str = str(remove_in) if remove_in is not None else None
  56. if since_str is not None and remove_in_str is not None:
  57. m += f" since {since_str} and will be removed in {remove_in_str}"
  58. elif since_str is not None:
  59. m += f" since {since_str}"
  60. elif remove_in_str is not None:
  61. m += f" and will be removed in {remove_in_str}"
  62. else:
  63. m += " and will be removed in a future version"
  64. @functools.wraps(func)
  65. def _wrapped_func(*args, **kwargs): # type: ignore[no-untyped-def]
  66. warnings.warn(
  67. m,
  68. DeprecationWarning,
  69. stacklevel=2,
  70. )
  71. return func(*args, **kwargs) # type: ignore[operator]
  72. return _wrapped_func # type: ignore[return-value]
  73. return decorator