napari / cookiecutter-napari-plugin

Cookiecutter for napari plugins
BSD 3-Clause "New" or "Revised" License
69 stars 41 forks source link

napari.manifest -> 'dkfz_random_forest_noise_removal:napari.yaml' could not be imported: Could not find file 'napari.yaml' in module 'dkfz_random_forest_noise_removal' #100

Closed Karol-G closed 2 years ago

Karol-G commented 2 years ago

Hi,

I created a widget plugin with cookiecutter. However, after generating a wheel with python -m build and trying to install it with pip install dist\DKFZ_random_forest_noise_removal-0.0.1-py3-none-any.whl, I get the following error:

napari.manifest -> 'dkfz_random_forest_noise_removal:napari.yaml' could not be imported: Could not find file 'napari.yaml' in module 'dkfz_random_forest_noise_removal'.

I used the cookiecutter version 1.7.3.

This is the setup.cfg:

[metadata]
name = DKFZ-random-forest-noise-removal
version = 0.0.1
author = Karol Gotkowski
author_email = karol.gotkowski@dkfz-heidelberg.de

license = BSD-3-Clause
description = Removes the "noise" sometimes resulting from applying Random Forest, which consits of many tiny classes. These classes should be removed.
long_description = file: README.md
long_description_content_type = text/markdown
classifiers =
    Development Status :: 2 - Pre-Alpha
    Intended Audience :: Developers
    Framework :: napari
    Topic :: Software Development :: Testing
    Programming Language :: Python
    Programming Language :: Python :: 3
    Programming Language :: Python :: 3.7
    Programming Language :: Python :: 3.8
    Programming Language :: Python :: 3.9
    Programming Language :: Python :: 3.10
    Operating System :: OS Independent
    License :: OSI Approved :: BSD License

[options]
packages = find:
include_package_data = True
python_requires = >=3.7
package_dir =
    =src

# add your package requirements here
install_requires =
    numpy

[options.packages.find]
where = src

[options.package_data]
DKFZ-random-forest-noise-removal = 
    napari.yaml

[options.entry_points] 
napari.manifest = 
    DKFZ-random-forest-noise-removal = dkfz_random_forest_noise_removal:napari.yaml

This is the napari.yaml located in src/dkfz_random_forest_noise_removal/napari.yaml:

name: DKFZ-random-forest-noise-removal
display_name: Random Forest Noise Removal
contributions:
  commands: 
    - id: DKFZ-random-forest-noise-removal.make_qwidget
      python_name: dkfz_random_forest_noise_removal._widget:RandomForestNoiseRemoval
      title: Random Forest Noise Removal
  widgets:
    - command: DKFZ-random-forest-noise-removal.make_qwidget
      display_name: Random Forest Noise Removal

Any idea why napari.yaml cannot be found?

Best, Karol

brisvag commented 2 years ago

When I had this issue it was because include_package_data was in the wrong place, but as far as I can tell everything looks fine :/ @tlambert03 @nclack hopefully can spot the issue :)

tlambert03 commented 2 years ago

very sorry about this @Karol-G ... this is an issue caused by the src layout used in the cookiecutter. I'll submit a fix.

The solution for you is to change the [options.package_data] entry. You can either just delete it entirely (since include_package_data = True in the [options] section is sufficient in this basic case), or to explicitly include all yaml files regardless of where they are, change it to:

[options.package_data]
* = *.yaml
Karol-G commented 2 years ago

This worked for me, thanks!

[options.package_data]
* = *.yaml
tlambert03 commented 2 years ago

actually... strangely enough, I don't actually get this problem when I build the cookiecutter:

[options]
packages = find:
include_package_data = True
python_requires = >=3.8
package_dir =
    =src

# add your package requirements here
install_requires =
    numpy

[options.packages.find]
where = src

[options.package_data]
napari-foobar = 
    napari.yaml

[options.entry_points] 
napari.manifest = 
    napari-foobar = napari_foobar:napari.yaml

so, I guess I'm a still a little stumped as to why your first setup.cfg didn't work. but I'll update it to the more general package data just in case