Skip to content

Commit

Permalink
refactor: use new-style formatting for named placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
nejch authored and JohnVillalovos committed Nov 8, 2021
1 parent 472b300 commit c0d8810
Show file tree
Hide file tree
Showing 51 changed files with 148 additions and 164 deletions.
2 changes: 1 addition & 1 deletion gitlab/base.py
Expand Up @@ -320,7 +320,7 @@ def _compute_path(self, path: Optional[str] = None) -> Optional[str]:
for self_attr, parent_attr in self._from_parent_attrs.items()
}
self._parent_attrs = data
return path % data
return path.format(**data)

@property
def path(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/cli.py
Expand Up @@ -53,7 +53,7 @@ def __init__(
# the class _path attribute, and replace the value with the result.
if TYPE_CHECKING:
assert self.mgr_cls._path is not None
self.mgr_cls._path = self.mgr_cls._path % self.args
self.mgr_cls._path = self.mgr_cls._path.format(**self.args)
self.mgr = self.mgr_cls(gl)

if self.mgr_cls._types:
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/access_requests.py
Expand Up @@ -20,7 +20,7 @@ class GroupAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject):


class GroupAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/groups/%(group_id)s/access_requests"
_path = "/groups/{group_id}/access_requests"
_obj_cls = GroupAccessRequest
_from_parent_attrs = {"group_id": "id"}

Expand All @@ -30,6 +30,6 @@ class ProjectAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject):


class ProjectAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/projects/%(project_id)s/access_requests"
_path = "/projects/{project_id}/access_requests"
_obj_cls = ProjectAccessRequest
_from_parent_attrs = {"project_id": "id"}
4 changes: 2 additions & 2 deletions gitlab/v4/objects/audit_events.py
Expand Up @@ -32,7 +32,7 @@ class GroupAuditEvent(RESTObject):


class GroupAuditEventManager(RetrieveMixin, RESTManager):
_path = "/groups/%(group_id)s/audit_events"
_path = "/groups/{group_id}/audit_events"
_obj_cls = GroupAuditEvent
_from_parent_attrs = {"group_id": "id"}
_list_filters = ("created_after", "created_before")
Expand All @@ -43,7 +43,7 @@ class ProjectAuditEvent(RESTObject):


class ProjectAuditEventManager(RetrieveMixin, RESTManager):
_path = "/projects/%(project_id)s/audit_events"
_path = "/projects/{project_id}/audit_events"
_obj_cls = ProjectAuditEvent
_from_parent_attrs = {"project_id": "id"}
_list_filters = ("created_after", "created_before")
Expand Down
20 changes: 6 additions & 14 deletions gitlab/v4/objects/award_emojis.py
Expand Up @@ -22,7 +22,7 @@ class ProjectIssueAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/issues/%(issue_iid)s/award_emoji"
_path = "/projects/{project_id}/issues/{issue_iid}/award_emoji"
_obj_cls = ProjectIssueAwardEmoji
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
_create_attrs = RequiredOptional(required=("name",))
Expand All @@ -33,9 +33,7 @@ class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = (
"/projects/%(project_id)s/issues/%(issue_iid)s" "/notes/%(note_id)s/award_emoji"
)
_path = "/projects/{project_id}/issues/{issue_iid}/notes/{note_id}/award_emoji"
_obj_cls = ProjectIssueNoteAwardEmoji
_from_parent_attrs = {
"project_id": "project_id",
Expand All @@ -50,7 +48,7 @@ class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/merge_requests/%(mr_iid)s/award_emoji"
_path = "/projects/{project_id}/merge_requests/{mr_iid}/award_emoji"
_obj_cls = ProjectMergeRequestAwardEmoji
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
_create_attrs = RequiredOptional(required=("name",))
Expand All @@ -61,10 +59,7 @@ class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = (
"/projects/%(project_id)s/merge_requests/%(mr_iid)s"
"/notes/%(note_id)s/award_emoji"
)
_path = "/projects/{project_id}/merge_requests/{mr_iid}/notes/{note_id}/award_emoji"
_obj_cls = ProjectMergeRequestNoteAwardEmoji
_from_parent_attrs = {
"project_id": "project_id",
Expand All @@ -79,7 +74,7 @@ class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/snippets/%(snippet_id)s/award_emoji"
_path = "/projects/{project_id}/snippets/{snippet_id}/award_emoji"
_obj_cls = ProjectSnippetAwardEmoji
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
_create_attrs = RequiredOptional(required=("name",))
Expand All @@ -90,10 +85,7 @@ class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):


class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
_path = (
"/projects/%(project_id)s/snippets/%(snippet_id)s"
"/notes/%(note_id)s/award_emoji"
)
_path = "/projects/{project_id}/snippets/{snippet_id}/notes/{note_id}/award_emoji"
_obj_cls = ProjectSnippetNoteAwardEmoji
_from_parent_attrs = {
"project_id": "project_id",
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/badges.py
Expand Up @@ -16,7 +16,7 @@ class GroupBadge(SaveMixin, ObjectDeleteMixin, RESTObject):


class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
_path = "/groups/%(group_id)s/badges"
_path = "/groups/{group_id}/badges"
_obj_cls = GroupBadge
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
Expand All @@ -28,7 +28,7 @@ class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject):


class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
_path = "/projects/%(project_id)s/badges"
_path = "/projects/{project_id}/badges"
_obj_cls = ProjectBadge
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("link_url", "image_url"))
Expand Down
8 changes: 4 additions & 4 deletions gitlab/v4/objects/boards.py
Expand Up @@ -20,7 +20,7 @@ class GroupBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):


class GroupBoardListManager(CRUDMixin, RESTManager):
_path = "/groups/%(group_id)s/boards/%(board_id)s/lists"
_path = "/groups/{group_id}/boards/{board_id}/lists"
_obj_cls = GroupBoardList
_from_parent_attrs = {"group_id": "group_id", "board_id": "id"}
_create_attrs = RequiredOptional(required=("label_id",))
Expand All @@ -37,7 +37,7 @@ class GroupBoard(SaveMixin, ObjectDeleteMixin, RESTObject):


class GroupBoardManager(CRUDMixin, RESTManager):
_path = "/groups/%(group_id)s/boards"
_path = "/groups/{group_id}/boards"
_obj_cls = GroupBoard
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(required=("name",))
Expand All @@ -51,7 +51,7 @@ class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):


class ProjectBoardListManager(CRUDMixin, RESTManager):
_path = "/projects/%(project_id)s/boards/%(board_id)s/lists"
_path = "/projects/{project_id}/boards/{board_id}/lists"
_obj_cls = ProjectBoardList
_from_parent_attrs = {"project_id": "project_id", "board_id": "id"}
_create_attrs = RequiredOptional(required=("label_id",))
Expand All @@ -68,7 +68,7 @@ class ProjectBoard(SaveMixin, ObjectDeleteMixin, RESTObject):


class ProjectBoardManager(CRUDMixin, RESTManager):
_path = "/projects/%(project_id)s/boards"
_path = "/projects/{project_id}/boards"
_obj_cls = ProjectBoard
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("name",))
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/branches.py
Expand Up @@ -14,7 +14,7 @@ class ProjectBranch(ObjectDeleteMixin, RESTObject):


class ProjectBranchManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/branches"
_path = "/projects/{project_id}/repository/branches"
_obj_cls = ProjectBranch
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("branch", "ref"))
Expand All @@ -25,7 +25,7 @@ class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):


class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/protected_branches"
_path = "/projects/{project_id}/protected_branches"
_obj_cls = ProjectProtectedBranch
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/clusters.py
Expand Up @@ -17,7 +17,7 @@ class GroupCluster(SaveMixin, ObjectDeleteMixin, RESTObject):


class GroupClusterManager(CRUDMixin, RESTManager):
_path = "/groups/%(group_id)s/clusters"
_path = "/groups/{group_id}/clusters"
_obj_cls = GroupCluster
_from_parent_attrs = {"group_id": "id"}
_create_attrs = RequiredOptional(
Expand Down Expand Up @@ -63,7 +63,7 @@ class ProjectCluster(SaveMixin, ObjectDeleteMixin, RESTObject):


class ProjectClusterManager(CRUDMixin, RESTManager):
_path = "/projects/%(project_id)s/clusters"
_path = "/projects/{project_id}/clusters"
_obj_cls = ProjectCluster
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(
Expand Down
10 changes: 5 additions & 5 deletions gitlab/v4/objects/commits.py
Expand Up @@ -143,7 +143,7 @@ def signature(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:


class ProjectCommitManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits"
_path = "/projects/{project_id}/repository/commits"
_obj_cls = ProjectCommit
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(
Expand All @@ -158,7 +158,7 @@ class ProjectCommitComment(RESTObject):


class ProjectCommitCommentManager(ListMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits/%(commit_id)s" "/comments"
_path = "/projects/{project_id}/repository/commits/{commit_id}/comments"
_obj_cls = ProjectCommitComment
_from_parent_attrs = {"project_id": "project_id", "commit_id": "id"}
_create_attrs = RequiredOptional(
Expand All @@ -171,7 +171,7 @@ class ProjectCommitStatus(RefreshMixin, RESTObject):


class ProjectCommitStatusManager(ListMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits/%(commit_id)s" "/statuses"
_path = "/projects/{project_id}/repository/commits/{commit_id}/statuses"
_obj_cls = ProjectCommitStatus
_from_parent_attrs = {"project_id": "project_id", "commit_id": "id"}
_create_attrs = RequiredOptional(
Expand Down Expand Up @@ -202,10 +202,10 @@ def create(
# project_id and commit_id are in the data dict when using the CLI, but
# they are missing when using only the API
# See #511
base_path = "/projects/%(project_id)s/statuses/%(commit_id)s"
base_path = "/projects/{project_id}/statuses/{commit_id}"
path: Optional[str]
if data is not None and "project_id" in data and "commit_id" in data:
path = base_path % data
path = base_path.format(**data)
else:
path = self._compute_path(base_path)
if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/container_registry.py
Expand Up @@ -18,7 +18,7 @@ class ProjectRegistryRepository(ObjectDeleteMixin, RESTObject):


class ProjectRegistryRepositoryManager(DeleteMixin, ListMixin, RESTManager):
_path = "/projects/%(project_id)s/registry/repositories"
_path = "/projects/{project_id}/registry/repositories"
_obj_cls = ProjectRegistryRepository
_from_parent_attrs = {"project_id": "id"}

Expand All @@ -30,7 +30,7 @@ class ProjectRegistryTag(ObjectDeleteMixin, RESTObject):
class ProjectRegistryTagManager(DeleteMixin, RetrieveMixin, RESTManager):
_obj_cls = ProjectRegistryTag
_from_parent_attrs = {"project_id": "project_id", "repository_id": "id"}
_path = "/projects/%(project_id)s/registry/repositories/%(repository_id)s/tags"
_path = "/projects/{project_id}/registry/repositories/{repository_id}/tags"

@cli.register_custom_action(
"ProjectRegistryTagManager",
Expand Down
6 changes: 3 additions & 3 deletions gitlab/v4/objects/custom_attributes.py
Expand Up @@ -16,7 +16,7 @@ class GroupCustomAttribute(ObjectDeleteMixin, RESTObject):


class GroupCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTManager):
_path = "/groups/%(group_id)s/custom_attributes"
_path = "/groups/{group_id}/custom_attributes"
_obj_cls = GroupCustomAttribute
_from_parent_attrs = {"group_id": "id"}

Expand All @@ -26,7 +26,7 @@ class ProjectCustomAttribute(ObjectDeleteMixin, RESTObject):


class ProjectCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTManager):
_path = "/projects/%(project_id)s/custom_attributes"
_path = "/projects/{project_id}/custom_attributes"
_obj_cls = ProjectCustomAttribute
_from_parent_attrs = {"project_id": "id"}

Expand All @@ -36,6 +36,6 @@ class UserCustomAttribute(ObjectDeleteMixin, RESTObject):


class UserCustomAttributeManager(RetrieveMixin, SetMixin, DeleteMixin, RESTManager):
_path = "/users/%(user_id)s/custom_attributes"
_path = "/users/{user_id}/custom_attributes"
_obj_cls = UserCustomAttribute
_from_parent_attrs = {"user_id": "id"}
2 changes: 1 addition & 1 deletion gitlab/v4/objects/deploy_keys.py
Expand Up @@ -29,7 +29,7 @@ class ProjectKey(SaveMixin, ObjectDeleteMixin, RESTObject):


class ProjectKeyManager(CRUDMixin, RESTManager):
_path = "/projects/%(project_id)s/deploy_keys"
_path = "/projects/{project_id}/deploy_keys"
_obj_cls = ProjectKey
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("title", "key"), optional=("can_push",))
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/deploy_tokens.py
Expand Up @@ -26,7 +26,7 @@ class GroupDeployToken(ObjectDeleteMixin, RESTObject):


class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/groups/%(group_id)s/deploy_tokens"
_path = "/groups/{group_id}/deploy_tokens"
_from_parent_attrs = {"group_id": "id"}
_obj_cls = GroupDeployToken
_create_attrs = RequiredOptional(
Expand All @@ -47,7 +47,7 @@ class ProjectDeployToken(ObjectDeleteMixin, RESTObject):


class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
_path = "/projects/%(project_id)s/deploy_tokens"
_path = "/projects/{project_id}/deploy_tokens"
_from_parent_attrs = {"project_id": "id"}
_obj_cls = ProjectDeployToken
_create_attrs = RequiredOptional(
Expand Down
2 changes: 1 addition & 1 deletion gitlab/v4/objects/deployments.py
Expand Up @@ -14,7 +14,7 @@ class ProjectDeployment(SaveMixin, RESTObject):


class ProjectDeploymentManager(RetrieveMixin, CreateMixin, UpdateMixin, RESTManager):
_path = "/projects/%(project_id)s/deployments"
_path = "/projects/{project_id}/deployments"
_obj_cls = ProjectDeployment
_from_parent_attrs = {"project_id": "id"}
_list_filters = (
Expand Down
8 changes: 4 additions & 4 deletions gitlab/v4/objects/discussions.py
Expand Up @@ -25,7 +25,7 @@ class ProjectCommitDiscussion(RESTObject):


class ProjectCommitDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/repository/commits/%(commit_id)s/" "discussions"
_path = "/projects/{project_id}/repository/commits/{commit_id}/discussions"
_obj_cls = ProjectCommitDiscussion
_from_parent_attrs = {"project_id": "project_id", "commit_id": "id"}
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
Expand All @@ -36,7 +36,7 @@ class ProjectIssueDiscussion(RESTObject):


class ProjectIssueDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/issues/%(issue_iid)s/discussions"
_path = "/projects/{project_id}/issues/{issue_iid}/discussions"
_obj_cls = ProjectIssueDiscussion
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
Expand All @@ -49,7 +49,7 @@ class ProjectMergeRequestDiscussion(SaveMixin, RESTObject):
class ProjectMergeRequestDiscussionManager(
RetrieveMixin, CreateMixin, UpdateMixin, RESTManager
):
_path = "/projects/%(project_id)s/merge_requests/%(mr_iid)s/discussions"
_path = "/projects/{project_id}/merge_requests/{mr_iid}/discussions"
_obj_cls = ProjectMergeRequestDiscussion
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
_create_attrs = RequiredOptional(
Expand All @@ -63,7 +63,7 @@ class ProjectSnippetDiscussion(RESTObject):


class ProjectSnippetDiscussionManager(RetrieveMixin, CreateMixin, RESTManager):
_path = "/projects/%(project_id)s/snippets/%(snippet_id)s/discussions"
_path = "/projects/{project_id}/snippets/{snippet_id}/discussions"
_obj_cls = ProjectSnippetDiscussion
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
_create_attrs = RequiredOptional(required=("body",), optional=("created_at",))
2 changes: 1 addition & 1 deletion gitlab/v4/objects/environments.py
Expand Up @@ -43,7 +43,7 @@ def stop(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
class ProjectEnvironmentManager(
RetrieveMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
):
_path = "/projects/%(project_id)s/environments"
_path = "/projects/{project_id}/environments"
_obj_cls = ProjectEnvironment
_from_parent_attrs = {"project_id": "id"}
_create_attrs = RequiredOptional(required=("name",), optional=("external_url",))
Expand Down
4 changes: 2 additions & 2 deletions gitlab/v4/objects/epics.py
Expand Up @@ -29,7 +29,7 @@ class GroupEpic(ObjectDeleteMixin, SaveMixin, RESTObject):


class GroupEpicManager(CRUDMixin, RESTManager):
_path = "/groups/%(group_id)s/epics"
_path = "/groups/{group_id}/epics"
_obj_cls = GroupEpic
_from_parent_attrs = {"group_id": "id"}
_list_filters = ("author_id", "labels", "order_by", "sort", "search")
Expand Down Expand Up @@ -71,7 +71,7 @@ def save(self, **kwargs):
class GroupEpicIssueManager(
ListMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTManager
):
_path = "/groups/%(group_id)s/epics/%(epic_iid)s/issues"
_path = "/groups/{group_id}/epics/{epic_iid}/issues"
_obj_cls = GroupEpicIssue
_from_parent_attrs = {"group_id": "group_id", "epic_iid": "iid"}
_create_attrs = RequiredOptional(required=("issue_id",))
Expand Down

0 comments on commit c0d8810

Please sign in to comment.