scientific-python / repo-review

Framework that can run checks on repos
https://repo-review.readthedocs.io
BSD 3-Clause "New" or "Revised" License
62 stars 3 forks source link

Plugin mechanism with a poetry managed package #195

Closed jack-mcivor closed 5 months ago

jack-mcivor commented 5 months ago

Is it possible to write custom checks whilst using a poetry style pyproject.toml setup?

My attempt is:

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "ex-repo-review"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = "^3.10"
repo-review = {extras = ["cli"], version = "^0.10.4"}

[project.entry-points."repo_review.checks"]
examples = "ex_repo_review.checks:repo_review_checks"

But this does not seem to register the plugin

 ╭─ Error ─────────────────────────────────────────────────────╮
 │ No checks registered. Please install a repo-review plugin.  │
 ╰─────────────────────────────────────────────────────────────╯

I guess the poetry way of describing entry points might be required, but I cannot get this to work also

[tool.poetry.scripts."repo_review.checks"]
examples = "ex_repo_review.checks:repo_review_checks"

Causes an error on poetry install

# The Poetry configuration is invalid:
#   - data.scripts.repo_review.checks must be valid exactly by one definition (0 matches found)

My project structure is

├── README.md
├── poetry.lock
├── pyproject.toml
└── src
    └── ex_repo_review
        ├── __init__.py
        └── checks.py

And this seems to work fine without poetry & a standard [project] table.

I suspect maybe I'm doing something incorrect with the quoting but can't wrap my head around it

henryiii commented 5 months ago

Sure! Poetry doesn't support [project] tables (yet, they claim it they will support it, in fact switch to it, in 2.0 eventually. I think it might come sooner, there's a PR). So you have to use Poetry's custom tool table for everything (or switch to PDM, which is just like Poetry but follows standards ;) ). They call entry-points "plugins":

[tool.poetry.plugins."repo_review.checks"]
examples = "ex_repo_review.checks:repo_review_checks"

https://python-poetry.org/docs/pyproject/#plugins

henryiii commented 5 months ago

(PS: you can't ever mix and match project tables with another form of config; if you have a project table, all metadata must come from it unless listed in project.dynamic. Static analysis tools like GitHub dependency graph are allowed to assume the table is complete expect for that list. Poetry's the only major build backend left with a non-PEP 621 style config, so it's really mostly relevant for Poetry)

jack-mcivor commented 5 months ago

Thanks, works a treat!