Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit233b79e

Browse files
chore: explicitly import gitlab.v4.objects/cli
As we only support the v4 Gitlab API, explicitly importgitlab.v4.objects and gitlab.v4.clie instead of dynamically importingit depending on the API version.This has the added benefit of mypy being able to type check the Gitlab__init__() function as currently it will fail if we enable typechecking of __init__() it will fail.Also, this also helps by not confusing tools like pyinstaller/cx_freeze withdynamic imports so you don't need hooks for standalone executables. Andaccording tohttps://docs.gitlab.com/ee/api/, "GraphQL co-exists with the current v4 REST API. If we have a v5 API, this should be a compatibility layer on top of GraphQL."
1 parent5cc60d5 commit233b79e

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

‎gitlab/cli.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
importargparse
2121
importfunctools
22-
importimportlib
2322
importre
2423
importsys
2524

@@ -158,12 +157,18 @@ def docs():
158157
sys.exit("Docs parser is only intended for build_sphinx")
159158

160159
parser=_get_base_parser(add_help=False)
161-
cli_module=importlib.import_module("gitlab.v4.cli")
160+
# NOTE: We must delay import of gitlab.v4.cli until now or
161+
# otherwise it will cause circular import errors
162+
importgitlab.v4.cli
162163

163-
return_get_parser(cli_module)
164+
return_get_parser(gitlab.v4.cli)
164165

165166

166167
defmain():
168+
# NOTE: We must delay import of gitlab.v4.cli until now or
169+
# otherwise it will cause circular import errors
170+
importgitlab.v4.cli
171+
167172
if"--version"insys.argv:
168173
print(gitlab.__version__)
169174
sys.exit(0)
@@ -181,10 +186,12 @@ def main():
181186
parser.print_help()
182187
sys.exit(0)
183188
sys.exit(e)
184-
cli_module=importlib.import_module("gitlab.v%s.cli"%config.api_version)
189+
# We only support v4 API at this time
190+
ifconfig.api_versionnotin ("4",):
191+
raiseModuleNotFoundError(name="gitlab.v%s.cli"%self._api_version)
185192

186193
# Now we build the entire set of subcommands and do the complete parsing
187-
parser=_get_parser(cli_module)
194+
parser=_get_parser(gitlab.v4.cli)
188195
try:
189196
importargcomplete
190197

@@ -229,6 +236,6 @@ def main():
229236
ifdebug:
230237
gl.enable_debug()
231238

232-
cli_module.run(gl,what,action,args,verbose,output,fields)
239+
gitlab.v4.cli.run(gl,what,action,args,verbose,output,fields)
233240

234241
sys.exit(0)

‎gitlab/client.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
"""Wrapper for the GitLab API."""
1818

19-
importimportlib
2019
importtime
2120

2221
importrequests
@@ -99,7 +98,14 @@ def __init__(
9998
self.pagination=pagination
10099
self.order_by=order_by
101100

102-
objects=importlib.import_module("gitlab.v%s.objects"%self._api_version)
101+
# We only support v4 API at this time
102+
ifself._api_versionnotin ("4",):
103+
raiseModuleNotFoundError(name="gitlab.v%s.objects"%self._api_version)
104+
# NOTE: We must delay import of gitlab.v4.objects until now or
105+
# otherwise it will cause circular import errors
106+
importgitlab.v4.objects
107+
108+
objects=gitlab.v4.objects
103109
self._objects=objects
104110

105111
self.broadcastmessages=objects.BroadcastMessageManager(self)
@@ -147,8 +153,14 @@ def __getstate__(self):
147153

148154
def__setstate__(self,state):
149155
self.__dict__.update(state)
150-
objects=importlib.import_module("gitlab.v%s.objects"%self._api_version)
151-
self._objects=objects
156+
# We only support v4 API at this time
157+
ifself._api_versionnotin ("4",):
158+
raiseModuleNotFoundError(name="gitlab.v%s.objects"%self._api_version)
159+
# NOTE: We must delay import of gitlab.v4.objects until now or
160+
# otherwise it will cause circular import errors
161+
importgitlab.v4.objects
162+
163+
self._objects=gitlab.v4.objects
152164

153165
@property
154166
defurl(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp