Pip: Modify or replace the entry_point sripts

I was redirected to this forum from the pypa/pip project. My question is about “pip”. Am I correct at this place?

I was pointed to “pip” from this original question at the setuptools forum.

I’m using pyproject.toml to define enry points. This somehow generates shell scripts starting my python code. I was told that this scripts are generated by pip and not by setuptools. That is why I’m asking here.

I want to replace or modify that scripts. Because I will offer my users to start the application not only as usual user but also as root. I use policy-kit for that and starting python via pkexec. Or in other cases I would like to modify environment variables.

Is there an offical standardizied and elegant/pythonic way to achiev this?

Why don’t you just do this work inside your function that’s invoked by the entry point?

Re-reading my response, it sounds a little harsh. But it’s a genuine question. Let me rephrase it as : What is it that you don’t think you can accomplish by doing it in the entry point function? If we understand that, we can better respond to your question.

1 Like

To modify the scripts? No. But as Eric mentioned, this can be done in the Python code.

In your polkit use-case, you would provide a new entrypoint that simply runs os.execv('pkexec', ['your-original-entrypoint']). In the environment variables use-case, you just change os.environ as desired and call the original entrypoint function.

1 Like

Thanks for your reply’s.
As it often is it is much easier with Python then someone can think. Of course your solutions are easy but they didn’t come to my mind. :smile:

That you can replace a process (via os.execv()) was new to me.

Running a subprocess would also work, but since replacing the process is possible, we might as well use it :blush:

Please find an example of that solution in my demonstrator repo.