2424import requests .utils
2525from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
2626
27- import gitlab .config
28- import gitlab .const
29- import gitlab .exceptions
30- from gitlab import utils
27+ from .import config as gl_config
28+ from .import const ,exceptions ,utils
3129
3230REDIRECT_MSG = (
3331"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -73,7 +71,7 @@ def __init__(
7371per_page :Optional [int ]= None ,
7472pagination :Optional [str ]= None ,
7573order_by :Optional [str ]= None ,
76- user_agent :str = gitlab . const .USER_AGENT ,
74+ user_agent :str = const .USER_AGENT ,
7775retry_transient_errors :bool = False ,
7876 )-> None :
7977
@@ -110,9 +108,9 @@ def __init__(
110108raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
111109# NOTE: We must delay import of gitlab.v4.objects until now or
112110# otherwise it will cause circular import errors
113- import gitlab .v4 . objects
111+ from .v4 import objects as v4_objects
114112
115- objects = gitlab . v4 . objects
113+ objects = v4_objects
116114self ._objects = objects
117115
118116self .broadcastmessages = objects .BroadcastMessageManager (self )
@@ -202,9 +200,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
202200raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
203201# NOTE: We must delay import of gitlab.v4.objects until now or
204202# otherwise it will cause circular import errors
205- import gitlab .v4 . objects
203+ from .v4 import objects as v4_objects
206204
207- self ._objects = gitlab . v4 . objects
205+ self ._objects = v4_objects
208206
209207@property
210208def url (self )-> str :
@@ -237,7 +235,7 @@ def from_config(
237235 Raises:
238236 gitlab.config.GitlabDataError: If the configuration is not correct.
239237 """
240- config = gitlab . config .GitlabConfigParser (
238+ config = gl_config .GitlabConfigParser (
241239gitlab_id = gitlab_id ,config_files = config_files
242240 )
243241return cls (
@@ -287,14 +285,14 @@ def merge_config(
287285 Raises:
288286 gitlab.config.GitlabDataError: If the configuration is not correct.
289287 """
290- config = gitlab . config .GitlabConfigParser (
288+ config = gl_config .GitlabConfigParser (
291289gitlab_id = gitlab_id ,config_files = config_files
292290 )
293291url = (
294292options .get ("server_url" )
295293or config .url
296294or os .getenv ("CI_SERVER_URL" )
297- or gitlab . const .DEFAULT_URL
295+ or const .DEFAULT_URL
298296 )
299297private_token ,oauth_token ,job_token = cls ._merge_auth (options ,config )
300298
@@ -313,7 +311,7 @@ def merge_config(
313311 )
314312
315313@staticmethod
316- def _merge_auth (options :dict ,config :gitlab . config .GitlabConfigParser )-> Tuple :
314+ def _merge_auth (options :dict ,config :gl_config .GitlabConfigParser )-> Tuple :
317315"""
318316 Return a tuple where at most one of 3 token types ever has a value.
319317 Since multiple types of tokens may be present in the environment,
@@ -371,7 +369,7 @@ def version(self) -> Tuple[str, str]:
371369
372370return cast (str ,self ._server_version ),cast (str ,self ._server_revision )
373371
374- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
372+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
375373def lint (self ,content :str ,** kwargs :Any )-> Tuple [bool ,List [str ]]:
376374"""Validate a gitlab CI configuration.
377375
@@ -392,7 +390,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
392390assert not isinstance (data ,requests .Response )
393391return (data ["status" ]== "valid" ,data ["errors" ])
394392
395- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
393+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
396394def markdown (
397395self ,text :str ,gfm :bool = False ,project :Optional [str ]= None ,** kwargs :Any
398396 )-> str :
@@ -419,7 +417,7 @@ def markdown(
419417assert not isinstance (data ,requests .Response )
420418return data ["html" ]
421419
422- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
420+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
423421def get_license (self ,** kwargs :Any )-> Dict [str ,Any ]:
424422"""Retrieve information about the current license.
425423
@@ -438,7 +436,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
438436return result
439437return {}
440438
441- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
439+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
442440def set_license (self ,license :str ,** kwargs :Any )-> Dict [str ,Any ]:
443441"""Add a new license.
444442
@@ -529,7 +527,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
529527 The base URL
530528 """
531529if not url :
532- return gitlab . const .DEFAULT_URL
530+ return const .DEFAULT_URL
533531
534532return url .rstrip ("/" )
535533
@@ -563,7 +561,7 @@ def _check_redirects(self, result: requests.Response) -> None:
563561if item .request .method == "GET" :
564562continue
565563target = item .headers .get ("location" )
566- raise gitlab . exceptions .RedirectError (
564+ raise exceptions .RedirectError (
567565REDIRECT_MSG .format (
568566status_code = item .status_code ,
569567reason = item .reason ,
@@ -718,13 +716,13 @@ def http_request(
718716pass
719717
720718if result .status_code == 401 :
721- raise gitlab . exceptions .GitlabAuthenticationError (
719+ raise exceptions .GitlabAuthenticationError (
722720response_code = result .status_code ,
723721error_message = error_message ,
724722response_body = result .content ,
725723 )
726724
727- raise gitlab . exceptions .GitlabHttpError (
725+ raise exceptions .GitlabHttpError (
728726response_code = result .status_code ,
729727error_message = error_message ,
730728response_body = result .content ,
@@ -770,7 +768,7 @@ def http_get(
770768try :
771769return result .json ()
772770except Exception as e :
773- raise gitlab . exceptions .GitlabParsingError (
771+ raise exceptions .GitlabParsingError (
774772error_message = "Failed to parse the server message"
775773 )from e
776774else :
@@ -867,7 +865,7 @@ def http_post(
867865if result .headers .get ("Content-Type" ,None )== "application/json" :
868866return result .json ()
869867except Exception as e :
870- raise gitlab . exceptions .GitlabParsingError (
868+ raise exceptions .GitlabParsingError (
871869error_message = "Failed to parse the server message"
872870 )from e
873871return result
@@ -915,7 +913,7 @@ def http_put(
915913try :
916914return result .json ()
917915except Exception as e :
918- raise gitlab . exceptions .GitlabParsingError (
916+ raise exceptions .GitlabParsingError (
919917error_message = "Failed to parse the server message"
920918 )from e
921919
@@ -935,7 +933,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
935933 """
936934return self .http_request ("delete" ,path ,** kwargs )
937935
938- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
936+ @exceptions .on_http_error (exceptions .GitlabSearchError )
939937def search (
940938self ,scope :str ,search :str ,** kwargs :Any
941939 )-> Union ["GitlabList" ,List [Dict [str ,Any ]]]:
@@ -1009,7 +1007,7 @@ def _query(
10091007try :
10101008self ._data :List [Dict [str ,Any ]]= result .json ()
10111009except Exception as e :
1012- raise gitlab . exceptions .GitlabParsingError (
1010+ raise exceptions .GitlabParsingError (
10131011error_message = "Failed to parse the server message"
10141012 )from e
10151013