Skip to content

Conversation

@AraHaan
Copy link
Contributor

@AraHaan AraHaan commented Jul 11, 2024

When I was working on my own copy of Py_Initialize() for my own embedded interpreter that:

  • manually sets sys.path (set to the base name of the exe since I store the python stlib in a zip file in it's win32 resource section)
  • Disables the default explicit import site (set to 0)
  • prevents the user site-packages folder from being added (set to 0),

The way I did this was with a direct copy and paste of the code in Py_InitializeEx and changed a only what I needed to implement my own Py_Initialize that suited my own needs. I hated how I needed to define Py_BUILD_CORE_MODULE and include #include <internal/pycore_runtime.h> And then checked and saw that everything but the if check in Py_InitializeEx is inside of Py_InitializeFromConfig and that the if check could be replaced easily with Py_IsInitialized. Because of that I submitted this change to remove the needless code duplication here since Py_InitializeFromConfig is used anyways. It also might increase performance very slightly as a result as well for free.

Because this is a trivial change to an implementation detail and does not affect functionality at all, I feel like this might not need an issue first. Very glad I took the time to look at this code and seen that it could be simplified somewhat.

@AraHaan AraHaan force-pushed the patch-1 branch 2 times, most recently from 47a50c5 to c4883ab Compare July 12, 2024 13:44
@ericsnowcurrently
Copy link
Member

Thanks for working on this, @AraHaan! I'll take a look as soon as I can.

FYI, once you've created the PR (and it isn't "draft"), it's usually best if you do not rebase. Rebasing makes it harder for reviewers. For example, it's harder to know what has changed since the last time I looked at the PR. Do note that we always squash the PR commits into a single merge commit, so you don't need to worry about cluttering up the commit log with your own intermediate commits.

@AraHaan
Copy link
Contributor Author

AraHaan commented Jul 12, 2024

Thanks for working on this, @AraHaan! I'll take a look as soon as I can.

FYI, once you've created the PR (and it isn't "draft"), it's usually best if you do not rebase. Rebasing makes it harder for reviewers. For example, it's harder to know what has changed since the last time I looked at the PR. Do note that we always squash the PR commits into a single merge commit, so you don't need to worry about cluttering up the commit log with your own intermediate commits.

I was rebasing onto current main using the website. Sorry about that.

When I was working on my own copy of ``Py_Initialize()`` for my own embedded interpreter that:
- manually sets ``sys.path`` (set to the base name of the exe since I story the python stlib in a zip file in it's win32 resource section)
- Disables the default explicit ``import site`` (set to 0)
- prevents the user site-packages folder from being added (set to 0),

The way I did this was with a direct copy and paste of the code in ``Py_InitializeEx`` and changed a only what I needed to implement my own ``Py_Initialize`` that suited my own needs. I hated how I needed to define ``Py_BUILD_CORE_MODULE`` and include ``#include <internal/pycore_runtime.h>`` And then checked and saw that everything but the if check in ``Py_InitializeEx`` is inside of ``Py_InitializeFromConfig`` and that the if check could be replaced easily with ``Py_IsInitialized``. Because of that I submitted this change to remove the needless code duplication here since ``Py_InitializeFromConfig`` is used anyways. It also might increase performance very slightly as a result as well for free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants