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

project_loader: add basic template support #2189

Merged
merged 12 commits into from Aug 14, 2018

Conversation

kyrofa
Copy link
Contributor

@kyrofa kyrofa commented Aug 2, 2018

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on bug reports?
  • If this is a new feature. Have you discussed the design on the forum?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh unit?

This PR resolves LP: #1785109 by adding support for templates. Templates have the ability to add YAML snippets to apps, YAML snippets to parts, and indeed add entire parts to a project. Don't introduce any actual templates, just the groundwork for them.

In a desire to reduce duplication between snaps, introduce support for
templates. Templates have the ability to add YAML snippets to apps, YAML
snippets to parts, and indeed add entire parts to a project. Don't
introduce any actual templates, just the groundwork for them.

LP: #1785109

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
@codecov-io
Copy link

codecov-io commented Aug 3, 2018

Codecov Report

Merging #2189 into master will decrease coverage by <.01%.
The diff coverage is 91.25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2189      +/-   ##
==========================================
- Coverage   91.21%   91.21%   -0.01%     
==========================================
  Files         208      210       +2     
  Lines       13160    13318     +158     
  Branches     1957     1982      +25     
==========================================
+ Hits        12004    12148     +144     
- Misses        788      795       +7     
- Partials      368      375       +7
Impacted Files Coverage Δ
snapcraft/internal/project_loader/_env.py 96.22% <ø> (ø) ⬆️
snapcraft/internal/project_loader/errors.py 96.15% <100%> (+0.59%) ⬆️
snapcraft/internal/project_loader/_schema.py 100% <100%> (ø) ⬆️
snapcraft/internal/project_loader/_config.py 99.52% <100%> (ø) ⬆️
snapcraft/cli/_runner.py 95.45% <100%> (+0.1%) ⬆️
snapcraft/internal/common.py 97.22% <100%> (+0.12%) ⬆️
snapcraft/internal/project_loader/__init__.py 92.3% <100%> (+0.3%) ⬆️
snapcraft/internal/dirs.py 53.33% <50%> (-0.52%) ⬇️
snapcraft/cli/templates.py 87.09% <87.09%> (ø)
snapcraft/internal/project_loader/_templates.py 91.17% <91.17%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b772997...648a67b. Read the comment docs.

@@ -148,6 +149,10 @@
"share/snapcraft/libraries",
["libraries/" + x for x in os.listdir("libraries")],
),
(
"share/snapcraft/template-data",
["templates/" + x for x in os.listdir("templates")],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wanted to get rid of this mechanism and do something a bit more pkg_resource driven as this fails when creating a source package to push over to pypi (unless you edit that other file https://github.com/snapcore/snapcraft/blob/master/MANIFEST.in). If possible, we should get away from that early.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's probably beyond the scope of this PR to change this, so I'll edit the manifest here, but yeah, let's change that.


template_names = os.listdir(common.get_templatesdir())
if not template_names:
click.echo("No templates supported")
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe even tie it to the base? So then different people running it don't get confused with, hey I get some, what about you? Or is this going to list everything regardless of base?

# Wrap the output depending on terminal size
width = common.get_terminal_width()
for line in common.format_output_in_columns(
sorted(template_names), max_width=width
Copy link
Collaborator

Choose a reason for hiding this comment

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

alternatively we should list what bases it supports here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, let me try some different formatting, here.

# Don't modify the dict passed in
yaml_data = copy.deepcopy(yaml_data)

# Get the base being used for this project (defaults to "core")
Copy link
Collaborator

Choose a reason for hiding this comment

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

core is not a base :-)
I would default to nothing and if needed, introduce this later

Copy link
Collaborator

Choose a reason for hiding this comment

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

IOW, let's tie this to the use of bases.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remember that today, you can run snapcraft on arch and if no stage packages or build-packages are introduced, chances are, it might just work. This would introduce another vector of confusion.

Copy link
Contributor Author

@kyrofa kyrofa Aug 10, 2018

Choose a reason for hiding this comment

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

It would be easy to raise an exception here, but that's an artificial constraint. I disagree on this point, for a few reasons:

  1. Remote parts are a problem today, with a ton of assumed knowledge and documentation issues. They are hard to use, and templates will be better. They are also very widely used (desktop helpers in particular).
  2. Templates are the only option for folks using remote parts that move to bases (as remote parts are not supported). By not allowing folks to transition to templates before they transition to using bases, we make the move to using bases quite a lot more work than is actually necessary.
  3. Running snapcraft today on things other than Ubuntu is not something we support without bases. Making decisions based on how snapcraft runs on other distros today sounds a bit like support 😉 .

Unless supporting templates before bases actually makes our lives harder, I think it's a good idea. We can chat about this more in-person, though.

Copy link
Contributor Author

@kyrofa kyrofa Aug 10, 2018

Choose a reason for hiding this comment

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

We chatted about this in person, and the big concern is simply that the core16 base, once it exists, cannot guarantee that it will continue building on trusty as well, which supporting templates without bases would entail (i.e. defaulting to core16 templates). As a result, I've started raising an exception if no base is specified. Basically, supporting templates before bases will make our lives harder.

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>

```yaml
# Keys in the root of the yaml specify the supported bases
core16:
Copy link
Collaborator

Choose a reason for hiding this comment

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

change this to core18, it is the new and flashy (and currently existing) base.

sergiusens
sergiusens previously approved these changes Aug 10, 2018
@sergiusens sergiusens dismissed their stale review August 10, 2018 17:47

sorry, I missed a chunk

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
@@ -121,6 +116,10 @@ def load_template(template_name: str) -> Dict[str, Any]:


def _find_template(base: str, template_name: str) -> Dict[str, Any]:
# A bade is required in order to use templates, so raise an error if not specified.
Copy link
Collaborator

Choose a reason for hiding this comment

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

bade?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well duh. What would YOU call it? 😉

Fixed.

# Yaml snippet you want to add to parts in the `snapcraft.yaml` (e.g.
# `after`)

# You can also put whatever parts here you want, and they will be put
Copy link
Collaborator

Choose a reason for hiding this comment

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

whatever parts you want here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yikes, awkward wording indeed. Fixed.

# containing this README.
my-template-part:
plugin: dump
source: $SNAPCRAFT_TEMPLATES_DIR/my-template-name/src
Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, this might be the reason. Maybe this should be more encapsulated to the actual template instead?

Copy link
Contributor Author

@kyrofa kyrofa Aug 14, 2018

Choose a reason for hiding this comment

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

Well, remember that templates can only alter the snapcraft.yaml. They're not particularly special beasts; we can't really do any magic there or we kill the ability for someone to copy/paste them into their local snapcraft.yaml to tweak.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, I mean SNAPCRAFT_TEMPLATE_DIR specific to the template and not the entire namespace

Copy link
Collaborator

@sergiusens sergiusens left a comment

Choose a reason for hiding this comment

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

the only thing that worried me a bit is the use of an overreaching environment variable. Given that everything will remain under tight control, the fact that this environment is public is not a worry.

@kyrofa
Copy link
Contributor Author

kyrofa commented Aug 14, 2018

ftp.gnu.org is down right now, which caused the autotools spread tests to fail, but I just tested them locally, so I'm merging.

@kyrofa kyrofa merged commit efcf047 into canonical:master Aug 14, 2018
@kyrofa kyrofa deleted the feature/1785109/templates branch August 14, 2018 19:33
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.

None yet

3 participants