To help avoid unnecessary duplication, and for convenience, Snapcraft can process and incorporate external metadata from within snapcraft.yaml by using
parse-info within a part and a corresponding
For example, the following
snapcraft.yaml will parse a file called
metadata-file. Snapcraft will attempt to extract
description metadata for the snap, all of which are mandatory:
name: my-snap-name adopt-info: part-with-metadata parts: part-with-metadata: plugin: dump source: . parse-info: [metadata-file]
See The snapcraft format for further details on Snapcraft metadata and how it’s used.
An external metadata source can be one of the following:
- Appstream: a standard for software components
- setup.py: commonly used by Python projects to help with package installation
Scriptlets: a snapcraftctl-driven command to generate
See below for details on incorporating each of the above into your snapcraft.yaml.
Appstream is a metadata standard used to describe a common set software components. It can be parsed by snapcraft to provide the
icon for a snap, along with the location of an app’s desktop file.
The following is a typical example from an upstream project. It’s an appstream file called
<?xml version="1.0" encoding="UTF-8"?> <component type="desktop-application"> <id>com.example.sampleapp</id> <summary>Single-line elevator pitch for your amazing application</summary> <description> This is applications's description. A paragraph or two to tell the most important story about it. </description> <icon type="local">assets/icon.png</icon> <launchable type="desktop-id"> com.example.sampleapp.desktop </launchable> </component>
We adopt the above metadata into
snapcraft.yaml with the following:
name: sampleapp-name adopt-info: sampleapp apps: sampleapp: command: sampleapp common-id: com.example.sampleapp parts: sampleapp: plugin: dump source: http://github.com/example/sampleapp.git parse-info: [sampleapp.metainfo.xml]
The resulting snap will take the summary and description from the appstream file as well as using the referred icon and desktop files for the app.
Appstream uses a
Desktop File ID instead of a path to declare a desktop file.
To link a
desktop-id within the appstream file to your app, you must define a
common-id in snapcraft.yaml.
Snapcraft will search for a parsed appstream file with the same component identifier, com.example.sampleapp in the above example, and extract the
desktop-id from there. It will then search the
usr/share directories relative to the part source, and by following the Desktop File ID rules.
A setup.py file is used by many Python projects to help with package installation. If your setup.py uses setuptools and defines
description, these can be extracted from
setup.py and used as the
description metadata in the resulting snap.
The following is an example
setup.py in the root of a hypothetical git tree:
import setuptools setuptools.setup( name='hello-world', version='1.0', author='snapcrafter', firstname.lastname@example.org', description='A simple hello world in python', scripts=['hello'] )
You can adopt the relevant metadata in the above with the following snapcraft.yaml
name: sampleapp-name summary: sampleapp summary adopt-info: sampleapp apps: sampleapp: command: sampleapp parts: sampleapp: plugin: python source: http://github.com/example/sampleapp.git parse-info: [setup.py]
Individual parts in your
snapcraft.yaml can set the
grade by using
snapcraftctl. All you need to do is select which part to adopt using
# ... adopt-info: my-part # ... parts: my-part: # ... override-pull: | snapcraftctl pull snapcraftctl set-version "my-version" snapcraftctl set-grade "devel"
See Scriptlets for more details on using scripting elements within snapcraft.yaml.
Snapcraft versions and compatibility