Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite853a30

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 morecomplicated, with lots of tests everywhere. This solution might generatesome code duplication, but it should be maintainable.
1 parentf373885 commite853a30

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__importprint_function
2020
from __future__importdivision
2121
from __future__importabsolute_import
22+
importimportlib
2223
importinspect
2324
importitertools
2425
importjson
@@ -31,7 +32,7 @@
3132
importgitlab.config
3233
fromgitlab.constimport*# noqa
3334
fromgitlab.exceptionsimport*# noqa
34-
fromgitlab.objectsimport*# noqa
35+
fromgitlab.v3.objectsimport*# 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-
forparent_clsinsix.itervalues(globals()):
119+
forparent_clsinsix.itervalues(vars(objects)):
116120
if (notinspect.isclass(parent_cls)
117-
ornotissubclass(parent_cls,GitlabObject)
118-
orparent_cls==CurrentUser):
121+
ornotissubclass(parent_cls,objects.GitlabObject)
122+
orparent_cls==objects.CurrentUser):
119123
continue
120124

121125
ifnotparent_cls.managers:
122126
continue
123127

124-
forvar,cls,attrsinparent_cls.managers:
128+
forvar,cls_name,attrsinparent_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
fromhttmockimporturlmatch# noqa
2626

2727
fromgitlabimport*# noqa
28-
fromgitlab.objectsimportBaseManager# noqa
28+
fromgitlab.v3.objectsimportBaseManager# noqa
2929

3030

3131
classFakeChildObject(GitlabObject):

‎gitlab/v3/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp