Some of the values required by the snapcraft.yaml file might be already provided by other metadata sources available in the upstream project.
Instead of duplicating this information, you can declare that a snapcraft part must parse the metadata file from the source, and adopt that parsed information. For example, the following
snapcraft.yaml will parse the file called
metadata-file and try to extract from it the
description for the snap.
name: my-snap-name adopt-info: part-with-metadata parts: part-with-metadata: plugin: dump parse-info: <metadata-file>
Appstream is a standard for metadata of software components. It can provide the
icon for the snap, and the
desktop files for the apps.
Let’s say we have an upstream project with the following appstream file in
<?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>
Then you can adopt this info into your
snapcraft.yaml like this:
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 and it will use the referred icon and desktop files.
Note that appstream doesn’t use a path to declare the desktop file. It uses a
Desktop File ID.
To know which appstream
desktop-id corresponds to your app, you must declare the
common-id of the app in the
snapcraft.yaml. snapcraft will search for a parsed appstream file with the same component
id and extract the
Then it will search for the desktop file in the directories
usr/share relative to the part source, following the
Desktop File ID rules.
If your setup.py uses
description can be extracted from
setup.py to be used as the
description of the resulting snap.
Let’s say we have the following
setup.py in the root of a hypothetical git tree http://github.com/example/sampleapp.git that looks like:
import setuptools setuptools.setup( name='hello-world', version='1.0', author='snapcrafter', email@example.com', description='A simple hello world in python', scripts=['hello'] )
Then you can adopt this info into your snapcraft.yaml like this:
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"