jni / skan

Python module to analyse skeleton (thin object) images
https://skeleton-analysis.org
BSD 3-Clause "New" or "Revised" License
118 stars 39 forks source link

Pyproject.toml #216

Closed ns-rse closed 11 months ago

ns-rse commented 11 months ago

Closes #213

Switches from setup.{cfg,py} to pyproject.toml.

Installs locally ok and all tests pass.

This may not be quite ready though as I noticed however on starting napari I see the following about the declared entrypoint and skan not being imported.

❱ napari
libGL error: glx: failed to create dri3 screen
libGL error: failed to load driver: nouveau
11:12:36 ERROR napari.manifest -> 'skan' could not be imported: Cannot find module 'skan' declared in entrypoint: 'skan:napari.yaml'

I can however go to Plugins > Install/Uninstall Plugins and select napari and it loads ok. On restarting napari the error message isn't there. I suspect however this might be because this is downloading the plugin anew rather than using the entry point of the locally installed package.

I read through the Your First Plugin — napari documentation which refers to both setup.cfg and pyproject.toml being required and shows the entry point being defined in setup.cfg.

I have also looked at an new plugin brainglobe/brainrender-napari: A napari plugin to render BrainGlobe atlases and associated data as layers. and that only uses pyproject.toml and defines the entry point within and I've copied that approach, although the package isn't nested within src/ which I think may be where I've gone wrong.

Documentation on how to add such a nested entry point seems sparse, or perhaps more accurately my searching was futile. With...

[project.entry-points."napari.manifest"]
skan-napari = "skan:napari.yaml"

I tried modifying the target to both src:skan:napari.yaml and src/skan:napari.yaml but installation failed in both instances due to an invalid python-entry-point-reference.

      configuration error: `project.entry-points.napari.manifest.skan-napari` must be python-entrypoint-reference
      DESCRIPTION:
          Reference to a Python object. It is either in the form
          ``importable.module``, or ``importable.module:object.attr``.

      GIVEN VALUE:
          "src/skan:napari.yaml"

      OFFENDING RULE: 'format'

      DEFINITION:
          {
              "type": "string",
              "format": "python-entrypoint-reference",
              "$comment": "https://packaging.python.org/specifications/entry-points/"
          }
      Traceback (most recent call last):
        File "/home/neil/miniconda3/envs/napari-env/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/home/neil/miniconda3/envs/napari-env/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
        File "/home/neil/miniconda3/envs/napari-env/lib/python3.10/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 132, in get_requires_for_build_editable
          return hook(config_settings)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 468, in get_requires_for_build_editable
          return self.get_requires_for_build_wheel(config_settings)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
          self.run_setup()
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 1, in <module>
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/__init__.py", line 103, in setup
          return distutils.core.setup(**attrs)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/_distutils/core.py", line 159, in setup
          dist.parse_config_files()
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/dist.py", line 653, in parse_config_files
          pyprojecttoml.apply_configuration(self, filename, ignore_option_errors)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 66, in apply_configuration
          config = read_configuration(filepath, True, ignore_option_errors, dist)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 127, in read_configuration
          validate(subset, filepath)
        File "/tmp/pip-build-env-8b01mlta/overlay/lib/python3.10/site-packages/setuptools/config/pyprojecttoml.py", line 55, in validate
          raise ValueError(f"{error}\n{summary}") from None
      ValueError: invalid pyproject.toml config: `project.entry-points.napari.manifest.skan-napari`.
      configuration error: `project.entry-points.napari.manifest.skan-napari` must be python-entrypoint-reference
      [end of output]

Any pointers to documentation, thoughts/suggestions/advice welcome as I wouldn't want to break anything.

jni commented 11 months ago

Thanks @ns-rse! This came off a slightly out of date main so I rebased it, but then I couldn't push back here, so I used your commits in #217. It's now merged! 🎉 Thank you! It's a nice PR to have as a model for my other projects.

Though tbh I dislike the syntax in pyproject.toml relative to setup.cfg. But we don't get a say in that. 😂

ns-rse commented 11 months ago

Excellent, glad to hear it might be of use. :slightly_smiling_face: