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
23
24"""Python implementation of the Git file formats and protocols."""
25
26import sys
27from typing import Callable, Optional, TypeVar
28
29if sys.version_info >= (3, 10):
30 from typing import ParamSpec
31else:
32 from typing_extensions import ParamSpec
33
34__version__ = (0, 23, 3)
35
36__all__ = ["__version__", "replace_me"]
37
38P = ParamSpec("P")
39R = TypeVar("R")
40
41try:
42 from dissolve import replace_me
43except ImportError:
44 # if dissolve is not installed, then just provide a basic implementation
45 # of its replace_me decorator
46 def replace_me(
47 since: Optional[str] = None, remove_in: Optional[str] = None
48 ) -> Callable[[Callable[P, R]], Callable[P, R]]:
49 def decorator(func: Callable[P, R]) -> Callable[P, R]:
50 import functools
51 import warnings
52
53 m = f"{func.__name__} is deprecated"
54 if since is not None and remove_in is not None:
55 m += f" since {since} and will be removed in {remove_in}"
56 elif since is not None:
57 m += f" since {since}"
58 elif remove_in is not None:
59 m += f" and will be removed in {remove_in}"
60 else:
61 m += " and will be removed in a future version"
62
63 @functools.wraps(func)
64 def _wrapped_func(*args: P.args, **kwargs: P.kwargs) -> R:
65 warnings.warn(
66 m,
67 DeprecationWarning,
68 stacklevel=2,
69 )
70 return func(*args, **kwargs)
71
72 return _wrapped_func
73
74 return decorator