FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
GitCode-API/gitcode_api/_base_resource.py at main · Trenza1ore/GitCode-API · GitHub
Trenza1ore
/
GitCode-API
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
7
Code
Issues
0
Pull requests
0
Discussions
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
GitCode-API
/
gitcode_api
/
_base_resource.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (45 loc) · 2.19 KB
Breadcrumbs
GitCode-API
/
gitcode_api
/
_base_resource.py
Copy path
File metadata and controls
60 lines (45 loc) · 2.19 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Resource base classe for the GitCode SDK."""
from
functools
import
cached_property
,
lru_cache
_UTILITY_METHODS
=
{
"methods"
,
"method_signature"
}
_DATA_MODEL_PATH
=
"gitcode_api._models."
class
BaseResource
:
"""Resource group base class."""
def
__del__
(
self
)
->
None
:
"""Attempt to clear the lru cache."""
self
.
method_signature
.
cache_clear
()
@
cached_property
def
methods
(
self
)
->
tuple
[
str
, ...]:
"""Public callable names on this resource group in stable SDK order.
Ordering uses :func:`sorted` with a key derived from each name's
underscore-separated segments (for example two-part names are ordered
as if ``second_first``). This is not plain lexicographic order on the
full method string. Excludes ``methods``, names starting with ``_``,
and non-callables. The result is cached on first access.
:returns: Tuple of method names in that order.
"""
def
_is_valid_func
(
name
:
str
):
return
not
(
name
.
startswith
(
"_"
)
or
name
in
_UTILITY_METHODS
)
and
callable
(
getattr
(
self
,
name
))
def
_sort_helper
(
method_name
:
str
):
name_parts
=
method_name
.
split
(
"_"
)
num_part
=
len
(
name_parts
)
if
num_part
==
2
:
return
f"
{
name_parts
[
1
]
}
_
{
name_parts
[
0
]
}
"
if
num_part
==
3
:
return
f"{{
{
name_parts
[
0
]
}
_"
return
"_"
+
method_name
return
tuple
(
sorted
(
(
func
for
func
in
dir
(
self
)
if
_is_valid_func
(
func
)),
key
=
_sort_helper
,
)
)
@
lru_cache
(
maxsize
=
50
)
def
method_signature
(
self
,
method_name
:
str
)
->
str
:
"""Return signature for a method in this resource group, result is cached.
For example ``client.pulls.method_signature("list_issues")`` would return:
list_issues(*, number: Union[int, str], owner: Optional[str] = None, repo: Optional[str] = None) -> List[Issue]
:param method_name: Attribute name of a callable on this resource.
:returns: Formatted signature.
"""
import
inspect
return
method_name
+
str
(
inspect
.
signature
(
getattr
(
self
,
method_name
))).
replace
(
_DATA_MODEL_PATH
,
""
)
Back
|
FazBrowse Home
|
New Git URL