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

feat(ux): display project.name_with_namespace on project repr#1996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nejch merged 1 commit intopython-gitlab:mainfromPsycojoker:project-name-in-repr
May 7, 2022

Conversation

Psycojoker
Copy link
Contributor

This change the repr from:

$ gitlab.projects.get(id=some_id)<Project id:some_id>

To:

$ gitlab.projects.get(id=some_id)<Project id:some_id name_with_namespace:"group_name / project_name">

This is especially useful when working on random projects or listing of
projects since users generally don't remember projects ids.


On a side note I've encountered this error when trying to do a commit:

An unexpected error has occurred: CalledProcessError: command: ('/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node', '/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save')return code: 1expected return code: 0stdout: (none)stderr:    /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node)    Check the log at /home/psycojoker/.cache/pre-commit/pre-commit.log

I have to admit that, while I totally understand the importance of linters and good commit messages, having a hard dependency on a specific version of nodejs and glibc just do to a commit on a full python feels a bit ... intense? 😅

Anyway, thanks a lot for this project ❤️

nejch reacted with heart emoji
This change the repr from:$ gitlab.projects.get(id=some_id)<Project id:some_id>To:$ gitlab.projects.get(id=some_id)<Project id:some_id name_with_namespace:"group_name / project_name">This is especially useful when working on random projects or listing ofprojects since users generally don't remember projects ids.
@JohnVillalovos
Copy link
Member

Cool. Just as an FYI we also have apprint andpformat functions if of any use. Not a replacement for your PR though.

project = gl.projects.get(id=some_id)project.pprint()
Psycojoker reacted with thumbs up emoji

@codecov-commenter
Copy link

Codecov Report

Merging#1996 (e598762) intomain (882fe7a) willincrease coverage by9.03%.
The diff coverage is20.00%.

@@            Coverage Diff             @@##             main    #1996      +/-   ##==========================================+ Coverage   83.47%   92.51%   +9.03%==========================================  Files          78       78                Lines        4938     4943       +5     ==========================================+ Hits         4122     4573     +451+ Misses        816      370     -446
FlagCoverage Δ
cli_func_v481.42% <20.00%> (?)
py_func_v480.43% <20.00%> (?)
unit83.41% <20.00%> (-0.07%)⬇️

Flags with carried forward coverage won't be shown.Click here to find out more.

Impacted FilesCoverage Δ
gitlab/v4/objects/projects.py87.71% <20.00%> (+7.50%)⬆️
gitlab/base.py92.59% <0.00%> (+0.52%)⬆️
gitlab/exceptions.py100.00% <0.00%> (+0.69%)⬆️
gitlab/config.py94.44% <0.00%> (+1.66%)⬆️
gitlab/v4/objects/members.py94.73% <0.00%> (+1.75%)⬆️
gitlab/v4/objects/export_import.py94.59% <0.00%> (+2.70%)⬆️
gitlab/types.py96.66% <0.00%> (+3.33%)⬆️
gitlab/v4/objects/wikis.py96.42% <0.00%> (+3.57%)⬆️
gitlab/v4/objects/notes.py94.23% <0.00%> (+3.84%)⬆️
gitlab/v4/objects/groups.py88.65% <0.00%> (+4.25%)⬆️
... and33 more

Copy link
Member

@JohnVillalovosJohnVillalovos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Overall looks good to me. Left a minor suggestion.

Unsure if we want a unit/functional test or not for this?@nejch what do you think?


if hasattr(self, "name_with_namespace"):
return (
f'{project_repr[:-1]} name_with_namespace:"{self.name_with_namespace}">'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can use the!r to quote the value.

Suggested change
f'{project_repr[:-1]} name_with_namespace:"{self.name_with_namespace}">'
f"{project_repr[:-1]} name_with_namespace:{self.name_with_namespace!r}>"

@JohnVillalovos
Copy link
Member

On a side note I've encountered this error when trying to do a commit:

An unexpected error has occurred: CalledProcessError: command: ('/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node', '/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save')return code: 1expected return code: 0stdout: (none)stderr:    /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node)    Check the log at /home/psycojoker/.cache/pre-commit/pre-commit.log

I have to admit that, while I totally understand the importance of linters and good commit messages, having a hard dependency on a specific version of nodejs and glibc just do to a commit on a full python feels a bit ... intense? 😅

So don't tell@nejch 😜 But I still don't usepre-commit myself. I run my tests manually for the most part and then push the PR. I let the Github CI tell me if I screwed up the commit message.

Copy link
Member

@nejchnejch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks@Psycojoker for this, I really like the idea to make repr more human-readable.

What do you think about generalizing it a bit to have a more declarative approach on individual resources (project, group,..) and handling the__repr__ based on that in theRESTObject method, like we do withid using_id_attr now? Otherwise, we'll have to add a bunch more overrides if people want similar for other objects (or even GroupProject, UserProject.. etc).

For this, I'd introduce a_repr_attr on individual resources, and handle that centrally here:

def__repr__(self)->str:
ifself._id_attr:
returnf"<{self.__class__.__name__}{self._id_attr}:{self.get_id()}>"
else:
returnf"<{self.__class__.__name__}>"

Just to illustrate this, here's a full list (I think) of objects, a lot of them would benefit from this feature. I don't want you to do this for all of them, but if you could try to add it for every type of*Project we have a good start to check it works. If it's too repetitive, we could introduce mixins for this at some point, or some other more reusable way if you have any ideas :) WDYT@Psycojoker@JohnVillalovos

ApplicationApplicationAppearanceApplicationSettingsAuditEventBroadcastMessageCurrentUserCurrentUserEmailCurrentUserGPGKeyCurrentUserKeyCurrentUserStatusDeployKeyDeployTokenDockerfileEventFeatureGenericPackageGeoNodeGitignoreGitlabciymlGroupGroupAccessRequestGroupAccessTokenGroupAuditEventGroupBadgeGroupBillableMemberGroupBillableMemberMembershipGroupBoardGroupBoardListGroupClusterGroupCustomAttributeGroupDeployTokenGroupDescendantGroupGroupEpicGroupEpicAwardEmojiGroupEpicDiscussionNoteGroupEpicIssueGroupEpicNoteGroupEpicNoteAwardEmojiGroupEpicResourceLabelEventGroupExportGroupHookGroupImportGroupIssueGroupIssuesStatisticsGroupLabelGroupMemberGroupMemberAllGroupMergeRequestGroupMilestoneGroupNotificationSettingsGroupPackageGroupProjectGroupRunnerGroupSubgroupGroupVariableGroupWikiHookIssueIssuesStatisticsKeyLDAPGroupLicenseListMergeRequestNamespaceNotificationSettingsOptionalPagesDomainPersonalAccessTokenProjectProjectAccessRequestProjectAccessTokenProjectAdditionalStatisticsProjectApprovalProjectApprovalRuleProjectArtifactProjectAuditProjectAuditEventProjectBadgeProjectBoardProjectBoardListProjectBranchProjectClusterProjectCommitProjectCommitCommentProjectCommitDiscussionProjectCommitDiscussionNoteProjectCommitStatusProjectCustomAttributeProjectDeployTokenProjectDeploymentProjectDeploymentMergeRequestProjectEnvironmentProjectEventProjectExportProjectFileProjectForkProjectHookProjectImportProjectIssueProjectIssueAwardEmojiProjectIssueDiscussionProjectIssueDiscussionNoteProjectIssueLinkProjectIssueNoteProjectIssueNoteAwardEmojiProjectIssueResourceLabelEventProjectIssueResourceMilestoneEventProjectIssueResourceStateEventProjectIssuesStatisticsProjectJobProjectKeyProjectLabelProjectMemberProjectMemberAllProjectMergeRequestProjectMergeRequestApprovalProjectMergeRequestApprovalRuleProjectMergeRequestApprovalStateProjectMergeRequestAwardEmojiProjectMergeRequestDiffProjectMergeRequestDiscussionProjectMergeRequestDiscussionNoteProjectMergeRequestNoteProjectMergeRequestNoteAwardEmojiProjectMergeRequestPipelineProjectMergeRequestResourceLabelEventProjectMergeRequestResourceMilestoneEventProjectMergeRequestResourceStateEventProjectMergeTrainProjectMilestoneProjectNoteProjectNotificationSettingsProjectPackageProjectPackageFileProjectPagesDomainProjectPipelineProjectPipelineBridgeProjectPipelineJobProjectPipelineScheduleProjectPipelineScheduleVariableProjectPipelineTestReportProjectPipelineTestReportSummaryProjectPipelineVariableProjectProtectedBranchProjectProtectedTagProjectPushRulesProjectRegistryRepositoryProjectRegistryTagProjectReleaseProjectReleaseLinkProjectRemoteMirrorProjectRunnerProjectServiceProjectSnippetProjectSnippetAwardEmojiProjectSnippetDiscussionProjectSnippetDiscussionNoteProjectSnippetNoteProjectSnippetNoteAwardEmojiProjectTagProjectTriggerProjectUserProjectVariableProjectWikiRepositoryMixinRunnerRunnerJobSnippetStarredProjectTodoTopicUserUserActivitiesUserCustomAttributeUserEmailUserEventUserGPGKeyUserImpersonationTokenUserKeyUserMembershipUserPersonalAccessTokenUserProjectUserStatusVariable

@nejch
Copy link
Member

On a side note I've encountered this error when trying to do a commit:

An unexpected error has occurred: CalledProcessError: command: ('/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node', '/home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/npm', 'install', '--dev', '--prod', '--ignore-prepublish', '--no-progress', '--no-save')return code: 1expected return code: 0stdout: (none)stderr:    /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by /home/psycojoker/.cache/pre-commit/repox1_osb0o/node_env-default/bin/node)    Check the log at /home/psycojoker/.cache/pre-commit/pre-commit.log

I have to admit that, while I totally understand the importance of linters and good commit messages, having a hard dependency on a specific version of nodejs and glibc just do to a commit on a full python feels a bit ... intense? sweat_smile

So don't tell@nejch stuck_out_tongue_winking_eye But I still don't usepre-commit myself. I run my tests manually for the most part and then push the PR. I let the Github CI tell me if I screwed up the commit message.

About pre-commit - sorry to hear that. Generally the idea ofpre-commit is to handle all of its environments for any kind of tool regardless of language and avoid exactly the type of issue you have here. But looks like that comes with hiccups (pre-commit/pre-commit#2351). I'll change tocommitizen based on your feedback which is python native, though it'll still be managed by pre-commit's env so we might get similar issues still.

We kind of do need pre-commit or something like that if we keep adding more linters and nitpicky rules though. Otherwise people will push a lot of failing code and it creates more noise for followers and extra effort, especially with new contributors where every push needs approval for CI to run.

The other option is that we calm down with the linting a bit and make things looser. But the commit messages at least are nice, as it makes our release process really smooth and we can bring out new versions much quicker if needed :)

@nejch
Copy link
Member

I've started#1998 to address the pre-commit issue. We can also just merge this as is and work on refactoring after, just let us know@Psycojoker if you'd like to try yourself already. :)

@nejch
Copy link
Member

Ok, so let's get this in to have the feature and I'll rework it based on my comment in a follow-up.

@nejchnejch merged commit82c9a07 intopython-gitlab:mainMay 7, 2022
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@JohnVillalovosJohnVillalovosJohnVillalovos left review comments

@nejchnejchnejch requested changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@Psycojoker@JohnVillalovos@codecov-commenter@nejch

[8]ページ先頭

©2009-2025 Movatter.jp