Python apps

The official Python example in " Getting started" doesn’t build on a fresh ubuntu 22.04 machine, leading to the error:

Staging yt-dlp 
+ snapcraftctl stage
Priming yt-dlp 
+ snapcraftctl prime
Determining the version from the project repo (version: git).
fatal: not a git repository (or any of the parent directories): .git
Run the same command again with --debug to shell into the environment if you wish to introspect this failure.

The error led me to an old post by popey Git error while building snap which says

version: git really only works if your snapcraft.yaml is in the source tree you’re building…

so why does the official python example use this syntax? The repository GitHub - yt-dlp/yt-dlp: A feature-rich command-line audio/video downloader doesn’t contain a snapcraft.yaml. The workaround suggested by popey did work which means arguably the official example should be changed to be:

name: yt-dlp
summary: A fork of youtube-dl with additional features and patches
description: |
      Download and play videos on your local system. Runs from the command
      line and with all the features and patches of youtube-dlc in addition
      to the latest youtube-dl.

#version: git
adopt-info: yt-dlp

grade: stable
confinement: devmode
base: core20
architectures:
  - build-on: [arm64, armhf, amd64]

apps:
  yt-dlp:
    command: bin/yt-dlp
    plugs: [home, network, network-bind, removable-media]

parts:
  yt-dlp:
    plugin: python
    source: https://github.com/yt-dlp/yt-dlp.git
    # https://forum.snapcraft.io/t/git-error-while-building-snap/10130 advice
    override-build: |
      snapcraftctl build
      snapcraftctl set-version $(git describe --tags)

where I replaced version: git with adopt-info: yt-dlp and added the override-build lines.