1919
2020import argparse
2121import functools
22- import importlib
2322import re
2423import sys
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+ import gitlab .v4 .cli
162163
163- return _get_parser (cli_module )
164+ return _get_parser (gitlab . v4 . cli )
164165
165166
166167def main ():
168+ # NOTE: We must delay import of gitlab.v4.cli until now or
169+ # otherwise it will cause circular import errors
170+ import gitlab .v4 .cli
171+
167172 if "--version" in sys .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+ if config .api_version not in ("4" ,):
191+ raise ModuleNotFoundError (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 import argcomplete
190197
@@ -229,6 +236,6 @@ def main():
229236 if debug :
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 )
0 commit comments