summaryrefslogtreecommitdiff
path: root/gitlab/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'gitlab/client.py')
-rw-r--r--gitlab/client.py50
1 files changed, 24 insertions, 26 deletions
diff --git a/gitlab/client.py b/gitlab/client.py
index b791c8f..6eccb50 100644
--- a/gitlab/client.py
+++ b/gitlab/client.py
@@ -24,10 +24,8 @@ import requests
import requests.utils
from requests_toolbelt.multipart.encoder import MultipartEncoder # type: ignore
-import gitlab.config
-import gitlab.const
-import gitlab.exceptions
-from gitlab import utils
+from . import config as gl_config
+from . import const, exceptions, utils
REDIRECT_MSG = (
"python-gitlab detected a {status_code} ({reason!r}) redirection. You must update "
@@ -73,7 +71,7 @@ class Gitlab(object):
per_page: Optional[int] = None,
pagination: Optional[str] = None,
order_by: Optional[str] = None,
- user_agent: str = gitlab.const.USER_AGENT,
+ user_agent: str = const.USER_AGENT,
retry_transient_errors: bool = False,
) -> None:
@@ -110,9 +108,9 @@ class Gitlab(object):
raise ModuleNotFoundError(name=f"gitlab.v{self._api_version}.objects")
# NOTE: We must delay import of gitlab.v4.objects until now or
# otherwise it will cause circular import errors
- import gitlab.v4.objects
+ from .v4 import objects as v4_objects
- objects = gitlab.v4.objects
+ objects = v4_objects
self._objects = objects
self.broadcastmessages = objects.BroadcastMessageManager(self)
@@ -202,9 +200,9 @@ class Gitlab(object):
raise ModuleNotFoundError(name=f"gitlab.v{self._api_version}.objects")
# NOTE: We must delay import of gitlab.v4.objects until now or
# otherwise it will cause circular import errors
- import gitlab.v4.objects
+ from .v4 import objects as v4_objects
- self._objects = gitlab.v4.objects
+ self._objects = v4_objects
@property
def url(self) -> str:
@@ -237,7 +235,7 @@ class Gitlab(object):
Raises:
gitlab.config.GitlabDataError: If the configuration is not correct.
"""
- config = gitlab.config.GitlabConfigParser(
+ config = gl_config.GitlabConfigParser(
gitlab_id=gitlab_id, config_files=config_files
)
return cls(
@@ -287,14 +285,14 @@ class Gitlab(object):
Raises:
gitlab.config.GitlabDataError: If the configuration is not correct.
"""
- config = gitlab.config.GitlabConfigParser(
+ config = gl_config.GitlabConfigParser(
gitlab_id=gitlab_id, config_files=config_files
)
url = (
options.get("server_url")
or config.url
or os.getenv("CI_SERVER_URL")
- or gitlab.const.DEFAULT_URL
+ or const.DEFAULT_URL
)
private_token, oauth_token, job_token = cls._merge_auth(options, config)
@@ -313,7 +311,7 @@ class Gitlab(object):
)
@staticmethod
- def _merge_auth(options: dict, config: gitlab.config.GitlabConfigParser) -> Tuple:
+ def _merge_auth(options: dict, config: gl_config.GitlabConfigParser) -> Tuple:
"""
Return a tuple where at most one of 3 token types ever has a value.
Since multiple types of tokens may be present in the environment,
@@ -371,7 +369,7 @@ class Gitlab(object):
return cast(str, self._server_version), cast(str, self._server_revision)
- @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabVerifyError)
+ @exceptions.on_http_error(exceptions.GitlabVerifyError)
def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
"""Validate a gitlab CI configuration.
@@ -392,7 +390,7 @@ class Gitlab(object):
assert not isinstance(data, requests.Response)
return (data["status"] == "valid", data["errors"])
- @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
+ @exceptions.on_http_error(exceptions.GitlabMarkdownError)
def markdown(
self, text: str, gfm: bool = False, project: Optional[str] = None, **kwargs: Any
) -> str:
@@ -419,7 +417,7 @@ class Gitlab(object):
assert not isinstance(data, requests.Response)
return data["html"]
- @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
+ @exceptions.on_http_error(exceptions.GitlabLicenseError)
def get_license(self, **kwargs: Any) -> Dict[str, Any]:
"""Retrieve information about the current license.
@@ -438,7 +436,7 @@ class Gitlab(object):
return result
return {}
- @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
+ @exceptions.on_http_error(exceptions.GitlabLicenseError)
def set_license(self, license: str, **kwargs: Any) -> Dict[str, Any]:
"""Add a new license.
@@ -529,7 +527,7 @@ class Gitlab(object):
The base URL
"""
if not url:
- return gitlab.const.DEFAULT_URL
+ return const.DEFAULT_URL
return url.rstrip("/")
@@ -563,7 +561,7 @@ class Gitlab(object):
if item.request.method == "GET":
continue
target = item.headers.get("location")
- raise gitlab.exceptions.RedirectError(
+ raise exceptions.RedirectError(
REDIRECT_MSG.format(
status_code=item.status_code,
reason=item.reason,
@@ -718,13 +716,13 @@ class Gitlab(object):
pass
if result.status_code == 401:
- raise gitlab.exceptions.GitlabAuthenticationError(
+ raise exceptions.GitlabAuthenticationError(
response_code=result.status_code,
error_message=error_message,
response_body=result.content,
)
- raise gitlab.exceptions.GitlabHttpError(
+ raise exceptions.GitlabHttpError(
response_code=result.status_code,
error_message=error_message,
response_body=result.content,
@@ -770,7 +768,7 @@ class Gitlab(object):
try:
return result.json()
except Exception as e:
- raise gitlab.exceptions.GitlabParsingError(
+ raise exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e
else:
@@ -867,7 +865,7 @@ class Gitlab(object):
if result.headers.get("Content-Type", None) == "application/json":
return result.json()
except Exception as e:
- raise gitlab.exceptions.GitlabParsingError(
+ raise exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e
return result
@@ -915,7 +913,7 @@ class Gitlab(object):
try:
return result.json()
except Exception as e:
- raise gitlab.exceptions.GitlabParsingError(
+ raise exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e
@@ -935,7 +933,7 @@ class Gitlab(object):
"""
return self.http_request("delete", path, **kwargs)
- @gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
+ @exceptions.on_http_error(exceptions.GitlabSearchError)
def search(
self, scope: str, search: str, **kwargs: Any
) -> Union["GitlabList", List[Dict[str, Any]]]:
@@ -1009,7 +1007,7 @@ class GitlabList(object):
try:
self._data: List[Dict[str, Any]] = result.json()
except Exception as e:
- raise gitlab.exceptions.GitlabParsingError(
+ raise exceptions.GitlabParsingError(
error_message="Failed to parse the server message"
) from e