2323import requests .utils
2424from requests_toolbelt .multipart .encoder import MultipartEncoder # type: ignore
2525
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
3028
3129REDIRECT_MSG = (
3230 "python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -72,7 +70,7 @@ def __init__(
7270 per_page : Optional [int ] = None ,
7371 pagination : Optional [str ] = None ,
7472 order_by : Optional [str ] = None ,
75- user_agent : str = gitlab . const .USER_AGENT ,
73+ user_agent : str = const .USER_AGENT ,
7674 retry_transient_errors : bool = False ,
7775 ) -> None :
7876
@@ -109,9 +107,9 @@ def __init__(
109107 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
110108 # NOTE: We must delay import of gitlab.v4.objects until now or
111109 # otherwise it will cause circular import errors
112- import gitlab .v4 . objects
110+ from .v4 import objects as v4_objects
113111
114- objects = gitlab . v4 . objects
112+ objects = v4_objects
115113 self ._objects = objects
116114
117115 self .broadcastmessages = objects .BroadcastMessageManager (self )
@@ -201,9 +199,9 @@ def __setstate__(self, state: Dict[str, Any]) -> None:
201199 raise ModuleNotFoundError (name = f"gitlab.v{ self ._api_version } .objects" )
202200 # NOTE: We must delay import of gitlab.v4.objects until now or
203201 # otherwise it will cause circular import errors
204- import gitlab .v4 . objects
202+ from .v4 import objects as v4_objects
205203
206- self ._objects = gitlab . v4 . objects
204+ self ._objects = v4_objects
207205
208206 @property
209207 def url (self ) -> str :
@@ -236,7 +234,7 @@ def from_config(
236234 Raises:
237235 gitlab.config.GitlabDataError: If the configuration is not correct.
238236 """
239- config = gitlab . config .GitlabConfigParser (
237+ config = gl_config .GitlabConfigParser (
240238 gitlab_id = gitlab_id , config_files = config_files
241239 )
242240 return cls (
@@ -289,7 +287,7 @@ def version(self) -> Tuple[str, str]:
289287
290288 return cast (str , self ._server_version ), cast (str , self ._server_revision )
291289
292- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabVerifyError )
290+ @exceptions .on_http_error (exceptions .GitlabVerifyError )
293291 def lint (self , content : str , ** kwargs : Any ) -> Tuple [bool , List [str ]]:
294292 """Validate a gitlab CI configuration.
295293
@@ -310,7 +308,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
310308 assert not isinstance (data , requests .Response )
311309 return (data ["status" ] == "valid" , data ["errors" ])
312310
313- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabMarkdownError )
311+ @exceptions .on_http_error (exceptions .GitlabMarkdownError )
314312 def markdown (
315313 self , text : str , gfm : bool = False , project : Optional [str ] = None , ** kwargs : Any
316314 ) -> str :
@@ -337,7 +335,7 @@ def markdown(
337335 assert not isinstance (data , requests .Response )
338336 return data ["html" ]
339337
340- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
338+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
341339 def get_license (self , ** kwargs : Any ) -> Dict [str , Any ]:
342340 """Retrieve information about the current license.
343341
@@ -356,7 +354,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
356354 return result
357355 return {}
358356
359- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabLicenseError )
357+ @exceptions .on_http_error (exceptions .GitlabLicenseError )
360358 def set_license (self , license : str , ** kwargs : Any ) -> Dict [str , Any ]:
361359 """Add a new license.
362360
@@ -447,7 +445,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
447445 The base URL
448446 """
449447 if not url :
450- return gitlab . const .DEFAULT_URL
448+ return const .DEFAULT_URL
451449
452450 return url .rstrip ("/" )
453451
@@ -481,7 +479,7 @@ def _check_redirects(self, result: requests.Response) -> None:
481479 if item .request .method == "GET" :
482480 continue
483481 target = item .headers .get ("location" )
484- raise gitlab . exceptions .RedirectError (
482+ raise exceptions .RedirectError (
485483 REDIRECT_MSG .format (
486484 status_code = item .status_code ,
487485 reason = item .reason ,
@@ -636,13 +634,13 @@ def http_request(
636634 pass
637635
638636 if result .status_code == 401 :
639- raise gitlab . exceptions .GitlabAuthenticationError (
637+ raise exceptions .GitlabAuthenticationError (
640638 response_code = result .status_code ,
641639 error_message = error_message ,
642640 response_body = result .content ,
643641 )
644642
645- raise gitlab . exceptions .GitlabHttpError (
643+ raise exceptions .GitlabHttpError (
646644 response_code = result .status_code ,
647645 error_message = error_message ,
648646 response_body = result .content ,
@@ -688,7 +686,7 @@ def http_get(
688686 try :
689687 return result .json ()
690688 except Exception as e :
691- raise gitlab . exceptions .GitlabParsingError (
689+ raise exceptions .GitlabParsingError (
692690 error_message = "Failed to parse the server message"
693691 ) from e
694692 else :
@@ -785,7 +783,7 @@ def http_post(
785783 if result .headers .get ("Content-Type" , None ) == "application/json" :
786784 return result .json ()
787785 except Exception as e :
788- raise gitlab . exceptions .GitlabParsingError (
786+ raise exceptions .GitlabParsingError (
789787 error_message = "Failed to parse the server message"
790788 ) from e
791789 return result
@@ -833,7 +831,7 @@ def http_put(
833831 try :
834832 return result .json ()
835833 except Exception as e :
836- raise gitlab . exceptions .GitlabParsingError (
834+ raise exceptions .GitlabParsingError (
837835 error_message = "Failed to parse the server message"
838836 ) from e
839837
@@ -853,7 +851,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
853851 """
854852 return self .http_request ("delete" , path , ** kwargs )
855853
856- @gitlab . exceptions .on_http_error (gitlab . exceptions .GitlabSearchError )
854+ @exceptions .on_http_error (exceptions .GitlabSearchError )
857855 def search (
858856 self , scope : str , search : str , ** kwargs : Any
859857 ) -> Union ["GitlabList" , List [Dict [str , Any ]]]:
@@ -929,7 +927,7 @@ def _query(
929927 try :
930928 self ._data : List [Dict [str , Any ]] = result .json ()
931929 except Exception as e :
932- raise gitlab . exceptions .GitlabParsingError (
930+ raise exceptions .GitlabParsingError (
933931 error_message = "Failed to parse the server message"
934932 ) from e
935933
0 commit comments