Skip to content

Commit 8c58b07

Browse files
authored
Merge pull request #1310 from JohnVillalovos/jlvillal/v4_only
chore: explicitly import gitlab.v4.objects/cli
2 parents 3aef19c + 233b79e commit 8c58b07

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
import argparse
2121
import functools
22-
import importlib
2322
import re
2423
import 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

166167
def 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)

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-
import importlib
2019
import time
2120

2221
import requests
@@ -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+
if self._api_version not in ("4",):
103+
raise ModuleNotFoundError(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+
import gitlab.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+
if self._api_version not in ("4",):
158+
raise ModuleNotFoundError(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+
import gitlab.v4.objects
162+
163+
self._objects = gitlab.v4.objects
152164

153165
@property
154166
def url(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy