Python: add files to source before build


I am trying to package a Python service which I would like to bundle with certain static files that are generated in another part. These files are moved to the staging area and I try to pull them in with the prepare section of my python part:

    plugin: python
    python-version: python2
    source: .
      - gunicorn
      - psycopg2
    requirements: requirements.txt
      - libbz2-1.0
      - libncursesw5
      - libtinfo5
      - zlib1g
      - libdb5.3
      - libstdc++6
      - libgcc1
    after: [frontend-deps]
    prepare: |
      install $SNAPCRAFT_STAGE/somejs.js ./mypythonapp/static/somejs.js

I can see that the static files are copied to the correct place under the build directory of my part, but it seems the plugin uses the src directory to build the package and these static files won’t end up in the final built python package.

Looking at the plugin’s source it looks like it would favor the build directory over the source directory when looking for the file. However, the location of setup_file is ignored when basename is called on it despite the whole path is constructed earlier: line 323 setup_py_path = os.path.join(setup_py_dir, '')

Am I doing something wrong? What would be the ideal way to inject static files into the source directory before building the Python package?


What version of snapcraft are you using? Would you temporarily mind using snapcraft from edge to verify it is already fixed there?

Before and after updating from edge:

snapcraft  2.39.2                1177  canonical       classic
snapcraft  2.39.2+git31.47d601f  1264  canonical       classic

With the update from edge my static file ends up in the package. Thanks for the tip. :slight_smile: :+1:

1 Like