Skip to content
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

refactor: use init command from craft-application #5129

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mr-cal
Copy link
Collaborator

@mr-cal mr-cal commented Oct 23, 2024

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • Have you successfully run tox run -m lint?
  • Have you successfully run tox run -e test-py310? (supported versions: py39, py310, py311, py312)

Replace Snapcraft's init implementation with craft-application's implementation. Somehow I added more lines of code 🙃

There are no behavioral changes with just snapcraft init. However, the command now accepts additional parameters added in craft-application: name, profile, and project-dir.

Fixes #5098
(CRAFT-3543)

Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>
Comment on lines -153 to -161
@property
def command_groups(self):
"""Replace craft-application's LifecycleCommand group."""
_command_groups = super().command_groups
for index, command_group in enumerate(_command_groups):
if command_group.name == "Lifecycle":
_command_groups[index] = cli.CORE24_LIFECYCLE_COMMAND_GROUP

return _command_groups
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would have had to do more hacks for InitCommand, hence canonical/craft-application#545.

@mr-cal mr-cal force-pushed the work/CRAFT-3543/init-command branch 4 times, most recently from c11a314 to d235c56 Compare October 23, 2024 19:26
Signed-off-by: Callahan Kovacs <callahan.kovacs@canonical.com>

if parsed_args.name:
craft_cli.emit.progress(
"Ignoring '--name' parameter because it is not supported yet.",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure if this should be an error, a warning, or if I should change the default template to use this as the snap name.

Copy link
Contributor

Choose a reason for hiding this comment

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

if you changed the default template to support the name, would you be able to drop this class wholesale?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. The other extra things that snapcraft adds are:

  • checking for a project file under snapcraft.yaml, snap/snapcraft.yaml, build-aux/snap/snapcraft.yaml or .snapcraft.yaml
  • An emit message pointing to documentation.

I think the first is worth keeping. The second could be added as a comment to the snapcraft.yaml file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alright. Then I think it should be an error and we should plan to address it soon

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd vote for starting to support the name from the start, and address the rest in the separate item.

Out of curiosity, shouldn't you override the InitService and use the command from upstream (if you ignore the documentation message)?

@@ -24,9 +24,9 @@ click==8.1.7
codespell==2.3.0
colorama==0.4.6
coverage==7.6.1
craft-application==4.2.6
git+https://github.com/canonical/craft-application@work/CRAFT-3543-use-app-commands#egg=craft-application
Copy link
Contributor

Choose a reason for hiding this comment

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

reminder to update this


if parsed_args.name:
craft_cli.emit.progress(
"Ignoring '--name' parameter because it is not supported yet.",
Copy link
Contributor

Choose a reason for hiding this comment

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

if you changed the default template to support the name, would you be able to drop this class wholesale?

try:
project = get_snap_project()
craft_cli.emit.progress("Checking for an existing 'snapcraft.yaml'.")
project = get_snap_project(project_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

this one sounds like maybe it should go on Snapcraft's (new) InitService
(we can also do this later)


emit.message(f"Created {str(snapcraft_yaml_path)!r}.")
emit.message(
craft_cli.emit.message(
Copy link
Contributor

Choose a reason for hiding this comment

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

it also feels like maybe this message should be on the initservice; or maybe a way for the service to give a template-based string to be presented to the user after init is done (this would be useful in rockcraft, which has per-profile docs)
(we can also do this later)

Copy link
Contributor

@dariuszd21 dariuszd21 left a comment

Choose a reason for hiding this comment

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

Looks good!


if parsed_args.name:
craft_cli.emit.progress(
"Ignoring '--name' parameter because it is not supported yet.",
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd vote for starting to support the name from the start, and address the rest in the separate item.

Out of curiosity, shouldn't you override the InitService and use the command from upstream (if you ignore the documentation message)?

Comment on lines +14 to +15
fi

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fi
fi
snapcraft clean

Comment on lines +4 to +9
PROFILE/default_profile: null
PROFILE/simple_profile: simple
PROFILE: null
PROJECT_DIR/default_dir: null
PROJECT_DIR/project_dir: test-project-dir
PROJECT_DIR: null
Copy link
Contributor

Choose a reason for hiding this comment

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

I recently realized that in that case it will be one test case per variant, so it won't create a combination of simple_profile with project_dir set. Is that ok ?

It will create 4 variant's: default_profile, simple_profile, project_dir, default_dir.
In that case if I can see correctly default_profile and default_dir will be the same test with different name

Copy link
Contributor

Choose a reason for hiding this comment

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

spread variants are so annoying. I also only semi-recently internalized that this:

environment:
    VAR1/bla: var1-bla
    VAR1/ble: var1-ble
    VAR2/bla: var2-bla
    VAR2/ble: var2-ble

can be thought of as:

environment:
  bla:
    VAR1: var1-bla
    VAR2: var2-bla
  ble:
    VAR1: var1-be
    VAR2: var2-ble

@mr-cal mr-cal marked this pull request as draft October 28, 2024 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use upstream init command from craft-application
3 participants