-
Notifications
You must be signed in to change notification settings - Fork 42
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new content subgroup to repository commands #194
Conversation
@@ -112,7 +114,7 @@ def sync( | |||
) | |||
|
|||
|
|||
@repository.command() | |||
@repository.command(deprecated=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments.
I still need to convince myself, that the magic around the dynamic natural key content lookup is a good thing (or at least the best we can get...).
pulpcore/cli/file/repository.py
Outdated
@@ -82,6 +83,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non | |||
repository.add_command(task_command(decorators=nested_lookup_options)) | |||
repository.add_command(version_command(decorators=nested_lookup_options)) | |||
repository.add_command(label_command(decorators=nested_lookup_options)) | |||
repository.add_command(repository_content_command(contexts={"file": PulpFileContentContext})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be "file:file"
.
In the end nothing prevents us from adding content managed by another plugin to a repository.
e.g., I always wanted to test, whether we can replace pulp_deb's GenericContent by FileContent (they are basically identical).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there nothing in the code to prevent this? I know the plugin's repository models has a CONTENT_TYPES
list field, but I'm not sure if that's check when adding content. Going with that naming scheme could be a lot of extra typing for plugin's with more than one content type and I'm not sure if there's benefit for allowing cross-plugin content sharing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably add that later...if needed
Of course we would add the "file:" by default for the user.
Have you seen this https://github.com/pulp/pulp-cli/pull/195/files#diff-2330f1d2bec4c88428af0e90f4ad6feff6a1663af7be7b9fedb645ed98846f68R218, I think I could do a similar thing with a group option variant. With a group option the options would be defined before hand and they could use a generic callback that has access to all options for the lookup to get the content context. I will take a look into this and see if I can simplify the crazy magic code. |
Hmm, Something like that may actually work. Better yet, this mutex option will show up in the Help screen nonetheless. And only bug out in the parsing step. Worth a try. |
f2250b0
to
ef69910
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, a lot to digest here...
But looking at the amount of code to add to the file section, i must say that it is pretty much very descriptive and not much boiler plate. 👍
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv) | ||
|
||
@click.command("remove") | ||
@click.option("--all", is_flag=True, help=_("Remove all content from repository version")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wow, that is new. ;)
7b6eae9
to
ed43993
Compare
ed43993
to
6f87a06
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, the size of the PR is probably the reason i find something new every time i look at it.
value = opts.get(self.name) | ||
if self.callback is not None: | ||
value = self.callback(ctx, self, {o: opts[o] for o in all_options}) # type: ignore | ||
if self.expose_value: | ||
ctx.params[self.name] = value | ||
return value, args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't look into the upstream implementation, but is this something, we could do with a super().handle_parse_result()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. super().handle_parse_result()
does some casting and ensures the value passed in is a string that can be converted to the option's type. There is no easy way to ensure that the conversion won't mess up the combined value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah i see, this is combining the value. Is this parsing step not called for each command in the group? how is this not clashing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parsing step is called for each option in the group, but only the option that has the callback will get the final value from processing each value in the group. This does mean that you can't supply defaults to these grouped options as the defaults are only filled in from super().handle_parse_result()
. However, you can have a callback for each option in the group and all those callbacks will receive the values for each option in the group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
pulpcore/cli/common/generic.py
Outdated
bv = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None | ||
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bv = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None | |
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=bv) | |
base_version_href = f"{repo_ctx.pulp_href}versions/{base_version}/" if base_version is not None else None | |
repo_ctx.modify(repo_ctx.pulp_href, add_content=[content_ctx.pulp_href], base_version=base_version_href) |
If we moved the first line to callback that returns a RepositoryVersionContext
, we would get another GET call, but also a better error message if the base_version did not exist. WDYT?
1b1133e
to
699d775
Compare
699d775
to
89ee971
Compare
fixes: #171
@mdellweg I marked the current repository content commands as deprecated to give time for users to update their usage to the new commands, but I can remove them if you want me to.
I set up the factory to allow for plugins that have multiple content types (ansible) and for plugins that have content that requires multiple fields for uniqueness (ansible, file). This requires some complex dynamic option generation in the factory, but I think the tradeoff is worth for the ease of adding this content subgroup to new plugins.