Fully customizable run/debug configuration

Hi, I find it surprising that there is apparently no possibility in PyCharm to create a fully customizable run configuration.

What I'd like to do is to hook the “run” triangle icon (displayed in the file editor next to functions/methods) to an arbitrary command which would use as arguments the Python module's qualified name and the function name. For instance, if I have a module containing test functions, I'd like to define a run configuration which runs `my_test_tool $ModuleQualifiedName$::$FunctionName$`, so that if I click on the “run” icon displayed beside function `test_something()` in module `foo.bar`, PyCharm will run `my_test_tool foo.bar::test_something`

In practice, the command I want to run looks like `poetry run pytest --pyargs some.module::some_function --some-other-arguments`. I know that PyCharm has some Poetry/Pytest integration, and I guess it's possible to get it to work for my project somehow, but I'm looking for a more generic answer if possible: instead of letting me figure out how the JetBrains team implemented each integration, why not let me configure the exact command used to run it? That would be much easier for me.

There's a “Shell Script” configuration template which seems close enough to what I would like, but it doesn't provide any Python-specific placeholders such as information about the module.

I know this is the PyCharm community and not the support team, and y'all are not in the heads of JetBrains developers (do they read this forum?) but did I miss anything? Instead of this sophisticated run configuration wizard, isn't it possible to use something both simpler and more powerful?

0

Hi Tanguy Penet!

Are External tools + Built-in IDE macros what you are looking for?

0

Thanks, that brings me closer to my goal, and I would have never thought of following those steps. To be honest, it feels like a bit of a hack to use “External Tools” for this, and hopefully something similarly customizable can be added to the “Run/Debug Configurations” at some point :)

But for now I'm happy to try this method (though I know in my specific case with Poetry, the real fix would be to get the built-in integrations to work, but I've given up on that for now).

Problem is, I couldn't find the macros I need: the fully qualified name of the current module, and the name of the current function, where “current” refers to the place in the editor where I've clicked on the “Run” icon.

Did I miss anything, or is that information just not available?

0

the fully qualified name of the current module

it must be $ModuleName$

the name of the current function

Unfortunately, this macro is indeed not implemented. Please feel free to submit your suggestions as a feature request to our issue tracker at https://youtrack.jetbrains.com/issues/py?q=type:%20Feature%20.

Would $SelectedText$ macro work in this scenario (if you select the function name in the editor first and then press Run)?

Another option is to use $Prompt$ to ask for function name. Would it work for you?

0

Thanks for your suggestions. For me $ModuleName$ returns only the top-level module, e.g. if I'm in file my_project/foo/bar/baz.py it outputs my_project instead of my_project.foo.bar.baz

As for the function name, $Prompt$ is much too tedious for me, but $SelectedText$ sounds like a good alternative for now. I've created a feature request so that we can hopefully have a dedicated macro at some point.

0

请先登录再写评论。