Skip to content

Commit e853a30

Browse files
author
Gauvain Pocentek
committed
Reorganise the code to handle v3 and v4 objects
Having objects managing both versions will only make the code more complicated, with lots of tests everywhere. This solution might generate some code duplication, but it should be maintainable.
1 parent f373885 commit e853a30

File tree

7 files changed

+98
-576
lines changed

7 files changed

+98
-576
lines changed

gitlab/__init__.py

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from __future__ import print_function
2020
from __future__ import division
2121
from __future__ import absolute_import
22+
import importlib
2223
import inspect
2324
import itertools
2425
import json
@@ -31,7 +32,7 @@
3132
import gitlab.config
3233
from gitlab.const import * # noqa
3334
from gitlab.exceptions import * # noqa
34-
from gitlab.objects import * # noqa
35+
from gitlab.v3.objects import * # noqa
3536

3637
__title__ = 'python-gitlab'
3738
__version__ = '0.20'
@@ -91,40 +92,43 @@ def __init__(self, url, private_token=None, email=None, password=None,
9192
#: Create a session object for requests
9293
self.session = requests.Session()
9394

94-
self.broadcastmessages = BroadcastMessageManager(self)
95-
self.keys = KeyManager(self)
96-
self.deploykeys = DeployKeyManager(self)
97-
self.gitlabciymls = GitlabciymlManager(self)
98-
self.gitignores = GitignoreManager(self)
99-
self.groups = GroupManager(self)
100-
self.hooks = HookManager(self)
101-
self.issues = IssueManager(self)
102-
self.licenses = LicenseManager(self)
103-
self.namespaces = NamespaceManager(self)
104-
self.notificationsettings = NotificationSettingsManager(self)
105-
self.projects = ProjectManager(self)
106-
self.runners = RunnerManager(self)
107-
self.settings = ApplicationSettingsManager(self)
108-
self.sidekiq = SidekiqManager(self)
109-
self.snippets = SnippetManager(self)
110-
self.users = UserManager(self)
111-
self.teams = TeamManager(self)
112-
self.todos = TodoManager(self)
95+
objects = importlib.import_module('gitlab.v%s.objects' %
96+
self._api_version)
97+
98+
self.broadcastmessages = objects.BroadcastMessageManager(self)
99+
self.keys = objects.KeyManager(self)
100+
self.deploykeys = objects.DeployKeyManager(self)
101+
self.gitlabciymls = objects.GitlabciymlManager(self)
102+
self.gitignores = objects.GitignoreManager(self)
103+
self.groups = objects.GroupManager(self)
104+
self.hooks = objects.HookManager(self)
105+
self.issues = objects.IssueManager(self)
106+
self.licenses = objects.LicenseManager(self)
107+
self.namespaces = objects.NamespaceManager(self)
108+
self.notificationsettings = objects.NotificationSettingsManager(self)
109+
self.projects = objects.ProjectManager(self)
110+
self.runners = objects.RunnerManager(self)
111+
self.settings = objects.ApplicationSettingsManager(self)
112+
self.sidekiq = objects.SidekiqManager(self)
113+
self.snippets = objects.SnippetManager(self)
114+
self.users = objects.UserManager(self)
115+
self.teams = objects.TeamManager(self)
116+
self.todos = objects.TodoManager(self)
113117

114118
# build the "submanagers"
115-
for parent_cls in six.itervalues(globals()):
119+
for parent_cls in six.itervalues(vars(objects)):
116120
if (not inspect.isclass(parent_cls)
117-
or not issubclass(parent_cls, GitlabObject)
118-
or parent_cls == CurrentUser):
121+
or not issubclass(parent_cls, objects.GitlabObject)
122+
or parent_cls == objects.CurrentUser):
119123
continue
120124

121125
if not parent_cls.managers:
122126
continue
123127

124-
for var, cls, attrs in parent_cls.managers:
128+
for var, cls_name, attrs in parent_cls.managers:
125129
var_name = '%s_%s' % (self._cls_to_manager_prefix(parent_cls),
126130
var)
127-
manager = cls(self)
131+
manager = getattr(objects, cls_name)(self)
128132
setattr(self, var_name, manager)
129133

130134
@property

gitlab/tests/test_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from httmock import urlmatch # noqa
2626

2727
from gitlab import * # noqa
28-
from gitlab.objects import BaseManager # noqa
28+
from gitlab.v3.objects import BaseManager # noqa
2929

3030

3131
class FakeChildObject(GitlabObject):

gitlab/v3/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)