gitcode-api 1.2.0__py3-none-any.whl → 1.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gitcode_api/__main__.py CHANGED
@@ -1,3 +1,5 @@
1
+ """Run the package CLI via ``python -m gitcode_api``."""
2
+
1
3
  from .cli import main
2
4
 
3
5
  if __name__ == "__main__":
@@ -7,7 +7,7 @@ _DATA_MODEL_PATH = "gitcode_api._models."
7
7
 
8
8
 
9
9
  class BaseResource:
10
- """Resource group base class"""
10
+ """Resource group base class."""
11
11
 
12
12
  def __del__(self) -> None:
13
13
  """Attempt to clear the lru cache."""
gitcode_api/_client.py CHANGED
@@ -144,6 +144,7 @@ class GitCode(SyncAPIClient):
144
144
  self.oauth = OAuthResource(self)
145
145
 
146
146
  def __enter__(self) -> "GitCode":
147
+ """Enter synchronous context and return this client."""
147
148
  return self
148
149
 
149
150
 
@@ -246,4 +247,5 @@ class AsyncGitCode(AsyncAPIClient):
246
247
  self.oauth = AsyncOAuthResource(self)
247
248
 
248
249
  async def __aenter__(self) -> "AsyncGitCode":
250
+ """Enter asynchronous context and return this client."""
249
251
  return self
gitcode_api/_models.py CHANGED
@@ -73,6 +73,7 @@ class APIObject(Mapping[str, Any]):
73
73
  data: MutableMapping[str, Any] = field(init=False, repr=False)
74
74
 
75
75
  def __init__(self, data: Mapping[str, Any]):
76
+ """Initialize from API response data."""
76
77
  payload = dict(data)
77
78
  object.__setattr__(self, "data", payload)
78
79
  type_hints = get_type_hints(self.__class__)
@@ -95,24 +96,30 @@ class APIObject(Mapping[str, Any]):
95
96
  object.__setattr__(self, model_field.name, value)
96
97
 
97
98
  def __getitem__(self, key: str) -> Any:
99
+ """Return the value for ``key`` from the backing mapping."""
98
100
  return _wrap_value(self.data[key])
99
101
 
100
102
  def __iter__(self) -> Iterator[str]:
103
+ """Iterate keys of the backing mapping."""
101
104
  return iter(self.data)
102
105
 
103
106
  def __len__(self) -> int:
107
+ """Return the number of keys in the backing mapping."""
104
108
  return len(self.data)
105
109
 
106
110
  def __getattr__(self, name: str) -> Any:
111
+ """Resolve unknown attributes from the backing mapping."""
107
112
  try:
108
113
  return _wrap_value(self.data[name])
109
114
  except KeyError as exc:
110
115
  raise AttributeError(name) from exc
111
116
 
112
117
  def get(self, key: str, default: Any = None) -> Any:
118
+ """Return the value for ``key``, or ``default`` if missing."""
113
119
  return _wrap_value(self.data.get(key, default))
114
120
 
115
121
  def to_dict(self) -> Dict[str, Any]:
122
+ """Return a shallow copy of the backing mapping."""
116
123
  return dict(self.data)
117
124
 
118
125
 
gitcode_api/cli.py CHANGED
@@ -174,7 +174,7 @@ def _write_output(value: Any, *, output_file: Optional[str], compact: bool) -> N
174
174
 
175
175
 
176
176
  def _invocation_parent_parser() -> argparse.ArgumentParser:
177
- """Flags for real API calls (attached only to leaf METHOD parsers, not top-level usage)."""
177
+ """Parser with flags for real API calls (attached only to leaf METHOD parsers, not top-level usage)."""
178
178
  parser = argparse.ArgumentParser(add_help=False)
179
179
  parser.add_argument("--api-key", help=f"GitCode access token. Defaults to {DEFAULT_TOKEN_ENV}.")
180
180
  parser.add_argument("--owner", help="Default repository owner.")
@@ -191,6 +191,7 @@ def _root_banner() -> str:
191
191
 
192
192
 
193
193
  def build_parser() -> argparse.ArgumentParser:
194
+ """Build main parser."""
194
195
  common = _invocation_parent_parser()
195
196
  epilog = """\
196
197
  Examples:
@@ -334,6 +335,7 @@ def _collect_kwargs(args: argparse.Namespace, method: Any) -> dict[str, Any]:
334
335
 
335
336
 
336
337
  def main(argv: Optional[Sequence[str]] = None) -> int:
338
+ """CLI entry point."""
337
339
  parser = build_parser()
338
340
  effective = list(sys.argv[1:] if argv is None else argv)
339
341
  if not effective:
gitcode_api/version.txt CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.2.2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitcode-api
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Easy to use Python SDK for the GitCode REST API, community-maintained.
5
5
  Author-email: Hugo Huang <hugo@hugohuang.com>
6
6
  License-Expression: MIT
@@ -120,7 +120,7 @@ asyncio.run(main())
120
120
 
121
121
  ### Context managers
122
122
 
123
- `GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`. Leaving the block calls `close()` / `await close()` on the underlying client automatically, including a custom `http_client=` you passed in.
123
+ `GitCode` and `AsyncGitCode` (and the lower-level `SyncAPIClient` / `AsyncAPIClient`) support `with` / `async with`. Leaving the block calls `close()` / `await close()` on the underlying client automatically, including a custom `http_client=` you passed in. `close()` also clears the LRU cache used by each resource group's `method_signature(...)` helper (see the [Available Resources](#available-resources) section).
124
124
 
125
125
  ```python
126
126
  from gitcode_api import GitCode
@@ -151,16 +151,13 @@ from gitcode_api import GitCode
151
151
 
152
152
  client = GitCode(owner="SushiNinja", repo="GitCode-API")
153
153
 
154
- try:
155
- pull = client.pulls.create(
156
- title="Add feature",
157
- head="feature-branch",
158
- base="main",
159
- body="Implements the new flow.",
160
- )
161
- print(pull.number)
162
- finally:
163
- client.close()
154
+ pull = client.pulls.create(
155
+ title="Add feature",
156
+ head="feature-branch",
157
+ base="main",
158
+ body="Implements the new flow.",
159
+ )
160
+ print(pull.number)
164
161
  ```
165
162
 
166
163
  Get the authenticated user:
@@ -170,11 +167,8 @@ from gitcode_api import GitCode
170
167
 
171
168
  client = GitCode()
172
169
 
173
- try:
174
- user = client.users.me()
175
- print(user.login)
176
- finally:
177
- client.close()
170
+ user = client.users.me()
171
+ print(user.login)
178
172
  ```
179
173
 
180
174
  Search repositories:
@@ -184,12 +178,9 @@ from gitcode_api import GitCode
184
178
 
185
179
  client = GitCode()
186
180
 
187
- try:
188
- repos = client.search.repositories(q="sdk language:python", per_page=10)
189
- for repo in repos:
190
- print(repo.full_name)
191
- finally:
192
- client.close()
181
+ repos = client.search.repositories(q="sdk language:python", per_page=10)
182
+ for repo in repos:
183
+ print(repo.full_name)
193
184
  ```
194
185
 
195
186
  ## Available Resources
@@ -1,22 +1,22 @@
1
1
  gitcode_api/__init__.py,sha256=NvLp28D9brVbmv2ROSZ8mxKDuIamE9xeutBKGl9pra8,497
2
- gitcode_api/__main__.py,sha256=MHKZ_ae3fSLGTLUUMOx15fWdeOnJSHhq-zslRP5F5Lc,79
2
+ gitcode_api/__main__.py,sha256=Yd8P4MSNcWFqUTKnUaNibbWX4Vd-MVVNmhPFaohzqcA,137
3
3
  gitcode_api/_base_client.py,sha256=PFsTMZJI4p5INjubRa4H4JcybYLGt-B9VkSAfTgpxfI,13280
4
- gitcode_api/_base_resource.py,sha256=4yZftwUh0cRAdLReAAgDULVu5pBCsixxBR_x6l2dPUw,2237
4
+ gitcode_api/_base_resource.py,sha256=mlKe1b_1AKcqxhptaCpP-AOjKkLNzCbYG-Pkp1HYWrA,2238
5
5
  gitcode_api/_cli_banner.py,sha256=res6C4V_rVSLyHMr1PwCpjV2OLn05lWJkRfxai3SCb8,978
6
- gitcode_api/_client.py,sha256=AOpp1P7vdSlMcn0XP3JMPnAKbQMftMO9WMubBGw2LZc,8129
6
+ gitcode_api/_client.py,sha256=bmZxBHdfshM5Kv_EurHUVu8rsEj0k3Up3ATSIPaFrvc,8258
7
7
  gitcode_api/_exceptions.py,sha256=T5N8gBGmPSktDkLP5P_hxbzOHw3W378TzxN1xja40pA,1140
8
- gitcode_api/_models.py,sha256=2bR6Wxc3Ie7iM3UFNY0ThWeNjxFHzDAC-8QFgcgcT_0,108599
9
- gitcode_api/cli.py,sha256=3fWJokeB9EVJkNYLQEKevoqUcLag_i0Dv97qZoxhktg,14126
10
- gitcode_api/version.txt,sha256=HltRzeUVOWqfp2KQnPjKZYTMxWSzJdLuvup2F1_pXE0,6
8
+ gitcode_api/_models.py,sha256=v-GZzCGAb3_frY6wFiQww9m271U5MigivpEHDHnoDcI,109030
9
+ gitcode_api/cli.py,sha256=GyqHg6cn_AqzJis7WshgdQaQv7w2imNWWoBjxiLVpzA,14194
10
+ gitcode_api/version.txt,sha256=xipcxhrEUlk1dT9ewoTAoFKksdpLOjWA3OK313ohVK4,6
11
11
  gitcode_api/resources/__init__.py,sha256=nsCKW0bFDZ5ombJZxLThmO82sOuF7o4OKUMRkAmwbwk,1725
12
12
  gitcode_api/resources/_shared.py,sha256=7bCym8bIfs818SiYYrBGI7-ZtiYlxECSDG3RduInu10,5387
13
13
  gitcode_api/resources/account.py,sha256=mnc2p7wI-nBnHFNdWPNiHfmZpT6d3RDQC777gewtm4M,38801
14
14
  gitcode_api/resources/collaboration.py,sha256=8lyk78GTjVXddiE9fieutsMGovRjteGfTJcAhwLoR0M,101607
15
15
  gitcode_api/resources/misc.py,sha256=guDwh4cxbTVsSa7EivaYM3bKMJ8_Op4KucGbKEoayKE,22412
16
16
  gitcode_api/resources/repositories.py,sha256=EAK2znZhEsgVUu-NDEQslSEEYJzvb-kHuh4mW57y6sc,78178
17
- gitcode_api-1.2.0.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
18
- gitcode_api-1.2.0.dist-info/METADATA,sha256=-e38q2ElfQ_LanrAqmY7o6k6i1wdAOr82RgGN0wj20o,8189
19
- gitcode_api-1.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
- gitcode_api-1.2.0.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
21
- gitcode_api-1.2.0.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
22
- gitcode_api-1.2.0.dist-info/RECORD,,
17
+ gitcode_api-1.2.2.dist-info/licenses/LICENSE,sha256=gOACXuWhMu6PJKVLr9RQbxX3HULnZIGNXCaMFJIXhoA,1067
18
+ gitcode_api-1.2.2.dist-info/METADATA,sha256=ClJo4MvNHJ-Y1Xig0fwPmcmWCiIOp_elZYKz2AXzJCk,8202
19
+ gitcode_api-1.2.2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
20
+ gitcode_api-1.2.2.dist-info/entry_points.txt,sha256=dIPylJcgohIE2RRIlt3In2WzcwDK8TOdkL_ReKuij4o,53
21
+ gitcode_api-1.2.2.dist-info/top_level.txt,sha256=gIlg0ptyOUHJT64ajOjWIhRPYgIQnMIvnhhnesw9fxU,12
22
+ gitcode_api-1.2.2.dist-info/RECORD,,