23
23
import requests .utils
24
24
from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
25
25
26
- import gitlab .config
27
- import gitlab .const
28
- import gitlab .exceptions
29
- from gitlab import utils
26
+ from . import config as gl_config
27
+ from . import const , exceptions , utils
30
28
31
29
REDIRECT_MSG = (
32
30
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -72,7 +70,7 @@ def __init__(
72
70
per_page : Optional [int ] = None ,
73
71
pagination : Optional [str ] = None ,
74
72
order_by : Optional [str ] = None ,
75
- user_agent : str = gitlab . const .USER_AGENT ,
73
+ user_agent : str = const .USER_AGENT ,
76
74
retry_transient_errors : bool = False ,
77
75
) -> None :
78
76
@@ -109,9 +107,9 @@ def __init__(
109
107
raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
110
108
# NOTE: We must delay import of gitlab.v4.objects until now or
111
109
# otherwise it will cause circular import errors
112
- import gitlab .v4 . objects
110
+ from .v4 import objects as v4_objects
113
111
114
- objects = gitlab . v4 . objects
112
+ objects = v4_objects
115
113
self ._objects = objects
116
114
117
115
self .broadcastmessages = objects .BroadcastMessageManager (self )
@@ -199,9 +197,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
199
197
raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
200
198
# NOTE: We must delay import of gitlab.v4.objects until now or
201
199
# otherwise it will cause circular import errors
202
- import gitlab .v4 . objects
200
+ from .v4 import objects as v4_objects
203
201
204
- self ._objects = gitlab . v4 . objects
202
+ self ._objects = v4_objects
205
203
206
204
@property
207
205
def url (self ) -> str :
@@ -234,7 +232,7 @@ def from_config(
234
232
Raises:
235
233
gitlab.config.GitlabDataError: If the configuration is not correct.
236
234
"""
237
- config = gitlab . config .GitlabConfigParser (
235
+ config = gl_config .GitlabConfigParser (
238
236
gitlab_id = gitlab_id , config_files = config_files
239
237
)
240
238
return cls (
@@ -287,7 +285,7 @@ def version(self) -> Tuple[str, str]:
287
285
288
286
return cast (str , self ._server_version ), cast (str , self ._server_revision )
289
287
290
- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
288
+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
291
289
def lint (self , content : str , ** kwargs : Any ) -> Tuple [bool , List [str ]]:
292
290
"""Validate a gitlab CI configuration.
293
291
@@ -308,7 +306,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
308
306
assert not isinstance (data , requests .Response )
309
307
return (data ["status" ] == "valid" , data ["errors" ])
310
308
311
- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
309
+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
312
310
def markdown (
313
311
self , text : str , gfm : bool = False , project : Optional [str ] = None , ** kwargs : Any
314
312
) -> str :
@@ -335,7 +333,7 @@ def markdown(
335
333
assert not isinstance (data , requests .Response )
336
334
return data ["html" ]
337
335
338
- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
336
+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
339
337
def get_license (self , ** kwargs : Any ) -> Dict [str , Any ]:
340
338
"""Retrieve information about the current license.
341
339
@@ -354,7 +352,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
354
352
return result
355
353
return {}
356
354
357
- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
355
+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
358
356
def set_license (self , license : str , ** kwargs : Any ) -> Dict [str , Any ]:
359
357
"""Add a new license.
360
358
@@ -445,7 +443,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
445
443
The base URL
446
444
"""
447
445
if not url :
448
- return gitlab . const .DEFAULT_URL
446
+ return const .DEFAULT_URL
449
447
450
448
return url .rstrip ("/" )
451
449
@@ -479,7 +477,7 @@ def _check_redirects(self, result: requests.Response) -> None:
479
477
if item .request .method == "GET" :
480
478
continue
481
479
target = item .headers .get ("location" )
482
- raise gitlab . exceptions .RedirectError (
480
+ raise exceptions .RedirectError (
483
481
REDIRECT_MSG .format (
484
482
status_code = item .status_code ,
485
483
reason = item .reason ,
@@ -639,13 +637,13 @@ def http_request(
639
637
pass
640
638
641
639
if result .status_code == 401 :
642
- raise gitlab . exceptions .GitlabAuthenticationError (
640
+ raise exceptions .GitlabAuthenticationError (
643
641
response_code = result .status_code ,
644
642
error_message = error_message ,
645
643
response_body = result .content ,
646
644
)
647
645
648
- raise gitlab . exceptions .GitlabHttpError (
646
+ raise exceptions .GitlabHttpError (
649
647
response_code = result .status_code ,
650
648
error_message = error_message ,
651
649
response_body = result .content ,
@@ -691,7 +689,7 @@ def http_get(
691
689
try :
692
690
return result .json ()
693
691
except Exception as e :
694
- raise gitlab . exceptions .GitlabParsingError (
692
+ raise exceptions .GitlabParsingError (
695
693
error_message = "Failed to parse the server message"
696
694
) from e
697
695
else :
@@ -788,7 +786,7 @@ def http_post(
788
786
if result .headers .get ("Content-Type" , None ) == "application/json" :
789
787
return result .json ()
790
788
except Exception as e :
791
- raise gitlab . exceptions .GitlabParsingError (
789
+ raise exceptions .GitlabParsingError (
792
790
error_message = "Failed to parse the server message"
793
791
) from e
794
792
return result
@@ -836,7 +834,7 @@ def http_put(
836
834
try :
837
835
return result .json ()
838
836
except Exception as e :
839
- raise gitlab . exceptions .GitlabParsingError (
837
+ raise exceptions .GitlabParsingError (
840
838
error_message = "Failed to parse the server message"
841
839
) from e
842
840
@@ -856,7 +854,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
856
854
"""
857
855
return self .http_request ("delete" , path , ** kwargs )
858
856
859
- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
857
+ @exceptions .on_http_error (exceptions .GitlabSearchError )
860
858
def search (
861
859
self , scope : str , search : str , ** kwargs : Any
862
860
) -> Union ["GitlabList" , List [Dict [str , Any ]]]:
@@ -932,7 +930,7 @@ def _query(
932
930
try :
933
931
self ._data : List [Dict [str , Any ]] = result .json ()
934
932
except Exception as e :
935
- raise gitlab . exceptions .GitlabParsingError (
933
+ raise exceptions .GitlabParsingError (
936
934
error_message = "Failed to parse the server message"
937
935
) from e
938
936
0 commit comments