Calling packaged custom recipes

Hi,

We were looking at packaging our custom recipes (nothing fancy!), and have that package pip install-ed in our various projects.

But here's the thing : unless I'm missing something, I do not see a way to call prodigy my-recipe -F my_package, because it seems -F only wants to resolve to a file path.

I could find the file actual file path, but that implies a little too much hard coding for my taste, e.g.

$VIRTUAL_ENV/lib/python{explicit_version}/
  {pip_package_name_with_explicit_version}/
  {actual_package}/{file with all recipes}.py

seems really error prone (with or without the virtual env).

Am I missing something ?
Any suggestions ?

(I guess I can "fool" the file resolution by creating a local .py file that will import all my custom recipes but I'd rather get advice before trying to find work arounds)

Hi! If you're using a Python package, Prodigy actually has a built-in mechanism that lets you expose your recipes via entry points: https://prodi.gy/docs/install#entry-points This means that if your package is installed in the same environment as Prodigy and exposes entry points of the group prodigy_recipes, Prodigy will automatically find them and load them – without you having to import your package at all.

If you haven't worked with entry points before, this blog post is a great intro: https://amir.rachum.com/blog/2017/07/28/python-entry-points/

And here's an example of our sense2vec package exposing custom recipes via entry points in its setup.cfg: https://github.com/explosion/sense2vec/blob/c22078c4e6c13038ab1c7718849ff97aa54fb9d8/setup.cfg#L40-L45 The syntax is package:module.function, so sense2vec:prodigy_recipes.teach will expose the function teach in prodigy_recipes.py in the sense2vec module.

1 Like

Oh I forgot about that!

Of course it works like a charm. No messing around with file names or imports.

Thanks.