Is there a guide on developing new integrations in...
# plugins-integrations
e
Is there a guide on developing new integrations in the
kedro run
level? What I'm looking for is to develop an integration with memray but since memray is executed by
memray run my_script.py
I really have no clue on how to go about activating it when using
kedro run
d
Hi @Elior Cohen this is a good question! I don’t actually know the right answer to the CLI question (I’ve asked for help on this one) but perhaps you could use the python context manager to do this, possibly in a
after_context_created
hook https://bloomberg.github.io/memray/api.html
e
But how will I control this dynamically? I'm aiming for developing an extension where if you installed memray you would be able to execute
kedro run -memray ....
d
So I’m waiting on one of the engineers to right CLI way to do this - but my suggestion write the memray outputs to the
*.bin
file during the lifecycle of a run and then you could view the file like they do on the 3rd example here https://bloomberg.github.io/memray/examples/README.html
i
@Elior Cohen according to memray’s docs, you could do either way:
Copy code
memray run [options] file.py [args]
memray run [options] -m module [args]
As each Kedro project is also a Python package with an entrypoint for the runs, you could effectively do:
Copy code
memray run -m <your_kedro_project_package>
If you are doing that in a plugin, I would recommend that you create a new CLI command (e.g.
kedro memray
) which will pass on all arguments to the underlying Kedro run. You could read more about running Kedro project as a package here: https://kedro.readthedocs.io/en/stable/tutorial/package_a_project.html
e
mmm
i use named pipelines how would i during development use specific pipelines and custom arguments in this way? Im not talking about a packaged complete project, but rather during development
i
Check `memray`’s function that is called on their entrypoint and uses it directly, and not as executable: https://github.com/bloomberg/memray/blob/main/setup.py#L324-L328
e
ill look at that
i
You can import it in your plugin, Kedro will automatically add the Kedro project
src/
folder to the Python path and make your project importable, so you can simply call their
main
function with the
-m
option from your own code and provide the module name of the project. To get the module name of the user’s project, you can import it from
from kedro.framework.project import PACKAGE_NAME
(or something like that, not sure about the full path).
d
I've done this before with a similar profiler. You should probably look at using the programmatic API (https://bloomberg.github.io/memray/api.html), not invoking as a script, and then you can set up in
before_pipeline_run
or something, and do any reporting in
after_pipeline_run
hook or something.
e
@Deepyaman Datta the hooks seems the correct way to go about it, I'll check that out
d
@Elior Cohen if you do get something working I’d love to share it with the community via docs or a plugin - so let us know how you get on and shout if you need to discuss anything further 🙂
e
Will do
@Ivan Danov I'm trying to work on this now, and I'm trying to go for your suggestion of using the memray API inside the
before|after_pipeline_run
. I was wondering, is there a way inside the
before|after_pipeline_run
implementation to access a command line argument? What I want to achieve is something like
kedro run --memray
and if
--memray
is specified to add hooks to the
before|after_pipeline_run
and otherwise not. I looked at the spec and I don't see anything that gives me access to the arguments
d
so you can actually provide your own run command which can registerd with a plugin https://kedro.readthedocs.io/en/stable/development/commands_reference.html#customise-or-override-project-specific-kedro-commands so if you wanted to create a
kedro-memray
plugin with it’s own run command and
before|after
hooks that would work neatly?
e
thx, I'll check it out
d
This is a plugin a wrote a while back if you want to see me do some of the same things
e
cool I'll check it out
d
I think (in kinda an ugly way) I add a
--simple
option to the run command here https://github.com/datajoely/kedro-rich/blob/d92651a7579c048e265d8b07fc4e45ab4ed66b87/kedro_rich/rich_cli.py#L64