8000 chore: convert to using relative imports · python-gitlab/python-gitlab@a9cf620 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9cf620

Browse files
chore: convert to using relative imports
Switch to using relative imports to ensure that we are importing from within our library. Also use the form: from foo import bar as bar When we want to signify that we want the import to be re-exported. https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-no-implicit-reexport
1 parent 2708f91 commit a9cf620

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+231
-248
lines changed

gitlab/__init__.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,18 @@
1919
import warnings
2020
from typing import Any
2121

22-
import gitlab.config # noqa: F401
23-
from gitlab.__version__ import ( # noqa: F401
24-
__author__,
25-
__copyright__,
26-
__email__,
27-
__license__,
28-
__title__,
29-
__version__,
30-
)
31-
from gitlab.client import Gitlab, GitlabList # noqa: F401
32-
from gitlab.exceptions import * # noqa: F401,F403
22+
from . import config as config # noqa: F401
23+
from . import const as const
24+
from . import exceptions as exceptions # noqa: F401
25+
from .__version__ import __author__ as __author__ # noqa: F401
26+
from .__version__ import __copyright__ as __copyright__ # noqa: F401
27+
from .__version__ import __email__ as __email__ # noqa: F401
28+
from .__version__ import __license__ as __license__ # noqa: F401
29+
from .__version__ import __title__ as __title__ # noqa: F401
30+
from .__version__ import __version__ as __version__ # noqa: F401
31+
from .client import Gitlab as Gitlab # noqa: F401
32+
from .client import GitlabList as GitlabList # noqa: F401
33+
from .exceptions import * # noqa: F401,F403
3334

3435
warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab")
3536

@@ -39,12 +40,12 @@
3940
# 'from gitlab.const import *' statement.
4041
def __getattr__(name: str) -> Any:
4142
# Deprecate direct access to constants without namespace
42-
if name in gitlab.const._DEPRECATED:
43+
if name in const._DEPRECATED:
4344
warnings.warn(
4445
f"\nDirect access to 'gitlab.{name}' is deprecated and will be "
4546
f"removed in a future major python-gitlab release. Please "
4647
f"use 'gitlab.const.{name}' instead.",
4748
DeprecationWarning,
4849
)
49-
return getattr(gitlab.const, name)
50+
return getattr(const, name)
5051
raise AttributeError(f"module {__name__} has no attribute {name}")

gitlab/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import gitlab.cli
1+
from . import cli
22

33
if __name__ == "__main__":
4-
gitlab.cli.main()
4+
cli.main()

gitlab/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@
2020
from types import ModuleType
2121
from typing import Any, Dict, Iterable, NamedTuple, Optional, Tuple, Type
2222

23-
import gitlab
24-
from gitlab import types as g_types
25-
from gitlab.exceptions import GitlabParsingError
26-
23+
from .__version__ import __version__
2724
from .client import Gitlab, GitlabList
25+
from .exceptions import GitlabParsingError
26+
from .types import GitlabAttribute
2827

2928
__all__ = [
3029
"RequiredOptional",
@@ -35,7 +34,7 @@
3534

3635

3736
_URL_ATTRIBUTE_ERROR = (
38-
f"https://python-gitlab.readthedocs.io/en/{gitlab.__version__}/"
37+
f"https://python-gitlab.readthedocs.io/en/{__version__}/"
3938
f"faq.html#attribute-error-list"
4039
)
4140

@@ -317,7 +316,7 @@ class RESTManager(object):
317316
_path: Optional[str] = None
318317
_obj_cls: Optional[Type[RESTObject]] = None
319318
_from_parent_attrs: Dict[str, Any] = {}
320-
_types: Dict[str, Type[g_types.GitlabAttribute]] = {}
319+
_types: Dict[str, Type[GitlabAttribute]] = {}
321320

322321
_computed_path: Optional[str]
323322
_parent: Optional[RESTObject]

gitlab/client.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@
2323
import requests.utils
2424
from 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

3129
REDIRECT_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)
@@ -234,7 +232,7 @@ def from_config(
234232
Raises:
235233
gitlab.config.GitlabDataError: If the configuration is not correct.
236234
"""
237-
config = gitlab.config.GitlabConfigParser(
235+
config = gl_config.GitlabConfigParser(
238236
gitlab_id=gitlab_id, config_files=config_files
239237
)
240238
return cls(
@@ -287,7 +285,7 @@ def version(self) -> Tuple[str, str]:
287285

288286
return cast(str, self._server_version), cast(str, self._server_revision)
289287

290-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabVerifyError)
288+
@exceptions.on_http_error(exceptions.GitlabVerifyError)
291289
def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
292290
"""Validate a gitlab CI configuration.
293291
@@ -308,7 +306,7 @@ def lint(self, content: str, **kwargs: Any) -> Tuple[bool, List[str]]:
308306
assert not isinstance(data, requests.Response)
309307
return (data["status"] == "valid", data["errors"])
310308

311-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabMarkdownError)
309+
@exceptions.on_http_error(exceptions.GitlabMarkdownError)
312310
def markdown(
313311
self, text: str, gfm: bool = False, project: Optional[str] = None, **kwargs: Any
314312
) -> str:
@@ -335,7 +333,7 @@ def markdown(
335333
assert not isinstance(data, requests.Response)
336334
return data["html"]
337335

338-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
336+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
339337
def get_license(self, **kwargs: Any) -> Dict[str, Any]:
340338
"""Retrieve information about the current license.
341339
@@ -354,7 +352,7 @@ def get_license(self, **kwargs: Any) -> Dict[str, Any]:
354352
return result
355353
return {}
356354

357-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabLicenseError)
355+
@exceptions.on_http_error(exceptions.GitlabLicenseError)
358356
def set_license(self, license: str, **kwargs: Any) -> Dict[str, Any]:
359357
"""Add a new license.
360358
@@ -445,7 +443,7 @@ def _get_base_url(self, url: Optional[str] = None) -> str:
445443
The base URL
446444
"""
447445
if not url:
448-
return gitlab.const.DEFAULT_URL
446+
return const.DEFAULT_URL
449447

450448
return url.rstrip("/")
451449

@@ -479,7 +477,7 @@ def _check_redirects(self, result: requests.Response) -> None:
479477
if item.request.method == "GET":
480478
continue
481479
target = item.headers.get("location")
482-
raise gitlab.exceptions.RedirectError(
480+
raise exceptions.RedirectError(
483481
REDIRECT_MSG.format(
484482
status_code=item.status_code,
485483
reason=item.reason,
@@ -639,13 +637,13 @@ def http_request(
639637
pass
640638

641639
if result.status_code == 401:
642-
raise gitlab.exceptions.GitlabAuthenticationError(
640+
raise exceptions.GitlabAuthenticationError(
643641
response_code=result.status_code,
644642
error_message=error_message,
645643
response_body=result.content,
646644
)
647645

648-
raise gitlab.exceptions.GitlabHttpError(
646+
raise exceptions.GitlabHttpError(
649647
response_code=result.status_code,
650648
error_message=error_message,
651649
response_body=result.content,
@@ -691,7 +689,7 @@ def http_get(
691689
try:
692690
return result.json()
693691
except Exception as e:
694-
raise gitlab.exceptions.GitlabParsingError(
692+
raise exceptions.GitlabParsingError(
695693
error_message="Failed to parse the server message"
696694
) from e
697695
else:
@@ -788,7 +786,7 @@ def http_post(
788786
if result.headers.get("Content-Type", None) == "application/json":
789787
return result.json()
790788
except Exception as e:
791-
raise gitlab.exceptions.GitlabParsingError(
789+
raise exceptions.GitlabParsingError(
792790
error_message="Failed to parse the server message"
793791
) from e
794792
return result
@@ -836,7 +834,7 @@ def http_put(
836834
try:
837835
return result.json()
838836
except Exception as e:
839-
raise gitlab.exceptions.GitlabParsingError(
837+
raise exceptions.GitlabParsingError(
840838
error_message="Failed to parse the server message"
841839
) from e
842840

@@ -856,7 +854,7 @@ def http_delete(self, path: str, **kwargs: Any) -> requests.Response:
856854
"""
857855
return self.http_request("delete", path, **kwargs)
858856

859-
@gitlab.exceptions.on_http_error(gitlab.exceptions.GitlabSearchError)
857+
@exceptions.on_http_error(exceptions.GitlabSearchError)
860858
def search(
861859
self, scope: str, search: str, **kwargs: Any
862860
) -> Union["GitlabList", List[Dict[str, Any]]]:
@@ -932,7 +930,7 @@ def _query(
932930
try:
933931
self._data: List[Dict[str, Any]] = result.json()
934932
except Exception as e:
935-
raise gitlab.exceptions.GitlabParsingError(
933+
raise exceptions.GitlabParsingError(
936934
error_message="Failed to parse the server message"
937935
) from e
938936

gitlab/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18-
from gitlab.__version__ import __title__, __version__
18+
from .__version__ import __title__, __version__
1919

2020
# NOTE(jlvillal): '_DEPRECATED' only affects users accessing constants via the
2121
# top-level gitlab.* namespace. See 'gitlab/__init__.py:__getattr__()' for the

gitlab/v4/objects/access_requests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from gitlab.base import RESTManager, RESTObject
2-
from gitlab.mixins import (
1+
from ...base import RESTManager, RESTObject
2+
from ...mixins import (
33
AccessRequestMixin,
44
CreateMixin,
55
DeleteMixin,

gitlab/v4/objects/appearance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, cast, Dict, Optional, Union
22

3-
from gitlab import exceptions as exc
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
5-
from gitlab.mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
3+
from ... import exceptions as exc
4+
from ...base import RequiredOptional, RESTManager, RESTObject
5+
from ...mixins import GetWithoutIdMixin, SaveMixin, UpdateMixin
66

77
__all__ = [
88
"ApplicationAppearance",

gitlab/v4/objects/applications.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
2-
from gitlab.mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin
1+
from ...base import RequiredOptional, RESTManager, RESTObject
2+
from ...mixins import CreateMixin, DeleteMixin, ListMixin, ObjectDeleteMixin
33

44
__all__ = [
55
"Application",

gitlab/v4/objects/audit_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"""
55
from typing import Any, cast, Union
66

7-
from gitlab.base import RESTManager, RESTObject
8-
from gitlab.mixins import RetrieveMixin
7+
from ...base import RESTManager, RESTObject
8+
from ...mixins import RetrieveMixin
99

1010
__all__ = [
1111
"AuditEvent",

gitlab/v4/objects/award_emojis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4-
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
3+
from ...base import RequiredOptional, RESTManager, RESTObject
4+
from ...mixins import NoUpdateMixin, ObjectDeleteMixin
55

66
__all__ = [
77
"GroupEpicAwardEmoji",

gitlab/v4/objects/badges.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4-
from gitlab.mixins import BadgeRenderMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
3+
from ...base import RequiredOptional, RESTManager, RESTObject
4+
from ...mixins import BadgeRenderMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
55

66
__all__ = [
77
"GroupBadge",

gitlab/v4/objects/boards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4-
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
3+
from ...base import RequiredOptional, RESTManager, RESTObject
4+
from ...mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
55

66
__all__ = [
77
"GroupBoardList",

gitlab/v4/objects/branches.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4-
from gitlab.mixins import NoUpdateMixin, ObjectDeleteMixin
3+
from ...base import RequiredOptional, RESTManager, RESTObject
4+
from ...mixins import NoUpdateMixin, ObjectDeleteMixin
55

66
__all__ = [
77
"ProjectBranch",

gitlab/v4/objects/broadcast_messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
4-
from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
3+
from ...base import RequiredOptional, RESTManager, RESTObject
4+
from ...mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
55

66
__all__ = [
77
"BroadcastMessage",

gitlab/v4/objects/clusters.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from typing import Any, cast, Dict, Optional, Union
22

3-
from gitlab import exceptions as exc
4-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
5-
from gitlab.mixins import CreateMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
3+
from ... import exceptions as exc
4+
from ...base import RequiredOptional, RESTManager, RESTObject
5+
from ...mixins import CreateMixin, CRUDMixin, ObjectDeleteMixin, SaveMixin
66

77
__all__ = [
88
"GroupCluster",

gitlab/v4/objects/commits.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
import requests
44

5-
from gitlab import cli
6-
from gitlab import exceptions as exc
7-
from gitlab.base import RequiredOptional, RESTManager, RESTObject
8-
from gitlab.mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin
9-
5+
from ... import cli
6+
from ... import exceptions as exc
7+
from ...base import RequiredOptional, RESTManager, RESTObject
8+
from ...mixins import CreateMixin, ListMixin, RefreshMixin, RetrieveMixin
109
from .discussions import ProjectCommitDiscussionManager # noqa: F401
1110

1211
__all__ = [

gitlab/v4/objects/container_registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from typing import Any, cast, TYPE_CHECKING, Union
22

3-
from gitlab import cli
4-
from gitlab import exceptions as exc
5-
from gitlab.base import RESTManager, RESTObject
6-
from gitlab.mixins import DeleteMixin, ListMixin, ObjectDeleteMixin, RetrieveMixin
3+
from ... import cli
4+
from ... import exceptions as exc
5+
from ...base import RESTManager, RESTObject
6+
from ...mixins import DeleteMixin, ListMixin, ObjectDeleteMixin, RetrieveMixin
77

88
__all__ = [
99
"ProjectRegistryRepository",

gitlab/v4/objects/custom_attributes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Any, cast, Union
22

3-
from gitlab.base import RESTManager, RESTObject
4-
from gitlab.mixins import DeleteMixin, ObjectDeleteMixin, RetrieveMixin, SetMixin
3+
from ...base import RESTManager, RESTObject
4+
from ...mixins import DeleteMixin, ObjectDeleteMixin, RetrieveMixin, SetMixin
55

66
__all__ = [
77
"GroupCustomAttribute",

0 commit comments

Comments
 (0)
0