# Pip: Modify or replace the entry\_point sripts

**URL:** <https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007>\
**Category:** Packaging\
**Created:** [December 17, 2022, 7:41pm UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007 "2022-12-17T19:41:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![buhtz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/buhtz/32/9970_2.png) [@buhtz](https://discuss.python.org/u/buhtz)\
**Post date:** [December 17, 2022, 7:41pm UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/1 "2022-12-17T19:41:55Z")

</div>

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](https://github.com/pypa/setuptools/discussions/3729).

I’m using pyproject.toml to define [enry points](https://setuptools.pypa.io/en/latest/userguide/entry_point.html). 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?

---

<div class="post-metadata">

**Author:** ![ericvsmith](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@ericvsmith](https://discuss.python.org/u/ericvsmith)\
**Post date:** [December 17, 2022, 9:01pm UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/2 "2022-12-17T21:01:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ericvsmith](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@ericvsmith](https://discuss.python.org/u/ericvsmith)\
**Post date:** [December 18, 2022, 2:08am UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/3 "2022-12-18T02:08:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![FFY00](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ffy00/32/4007_2.png) [@FFY00](https://discuss.python.org/u/FFY00)\
**Post date:** [December 18, 2022, 7:04am UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/4 "2022-12-18T07:04:14Z")

</div>

> [@buhtz](#):
>
> Is there an offical standardizied and elegant/pythonic way to achiev this?

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.

---

<div class="post-metadata">

**Author:** ![buhtz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/buhtz/32/9970_2.png) [@buhtz](https://discuss.python.org/u/buhtz)\
**Post date:** [December 18, 2022, 8:48am UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/5 "2022-12-18T08:48:36Z")

</div>

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. 😄

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

---

<div class="post-metadata">

**Author:** ![FFY00](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/ffy00/32/4007_2.png) [@FFY00](https://discuss.python.org/u/FFY00)\
**Post date:** [December 18, 2022, 9:29am UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/6 "2022-12-18T09:29:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![buhtz](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/buhtz/32/9970_2.png) [@buhtz](https://discuss.python.org/u/buhtz)\
**Post date:** [December 18, 2022, 9:47am UTC](https://discuss.python.org/t/pip-modify-or-replace-the-entry-point-sripts/22007/7 "2022-12-18T09:47:41Z")

</div>

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

> **[bit\_demo](https://codeberg.org/buhtz/bit_demo)**
>
> bit\_demo
