Setuptools errors with python plugin in core22

I have a part which uses the python plugin. I am migrating from core18 base to core22. There are 4 python scripts in a subdirectory.

When I build for core22 I get errors from setuptools about a flat layout. What is the recommended way to handle this in the snapcraft file?

Errors from the build below:

Preparing metadata (setup.py): started
2024-07-03 11:19:04.936 ::   Preparing metadata (setup.py): finished with status 'error'
2024-07-03 11:19:04.944 ::   error: subprocess-exited-with-error
2024-07-03 11:19:04.944 ::
2024-07-03 11:19:04.944 ::   × python setup.py egg_info did not run successfully.
2024-07-03 11:19:04.945 ::   │ exit code: 1
2024-07-03 11:19:04.945 ::   ╰─> [14 lines of output]
2024-07-03 11:19:04.945 ::       error: Multiple top-level modules discovered in a flat-layout: ['gpio', 'eink', 'testgpio'].
2024-07-03 11:19:04.945 ::
2024-07-03 11:19:04.946 ::       To avoid accidental inclusion of unwanted files or directories,
2024-07-03 11:19:04.946 ::       setuptools will not proceed with this build.
2024-07-03 11:19:04.946 ::
2024-07-03 11:19:04.946 ::       If you are trying to create a single distribution with multiple modules
2024-07-03 11:19:04.946 ::       on purpose, you should not rely on automatic discovery.
2024-07-03 11:19:04.947 ::       Instead, consider the following options:
2024-07-03 11:19:04.947 ::
2024-07-03 11:19:04.947 ::       1. set up custom discovery (`find` directive with `include` or `exclude`)
2024-07-03 11:19:04.947 ::       2. use a `src-layout`
2024-07-03 11:19:04.947 ::       3. explicitly set `py_modules` or `packages` with a list of names
2024-07-03 11:19:04.948 ::
2024-07-03 11:19:04.948 ::       To find more information, look for "package discovery" on setuptools docs.
2024-07-03 11:19:04.948 ::       [end of output]
2024-07-03 11:19:04.948 ::
2024-07-03 11:19:04.949 ::   note: This error originates from a subprocess, and is likely not a problem with pip.
2024-07-03 11:19:04.949 :: error: metadata-generation-failed

Is the only solution to split this part into 4 separate parts, one for each python script, with each script in its own subdir. Or is there a way to pass the packages[] information to setuptools via the snapcraft part?

I found out that I can specify the py_modules via the setup.py file in the same directory as my scripts. In this way when setuptools runs it will read the information there in the same way as in a non snapcraft build environment.

1 Like