pywin32 icon indicating copy to clipboard operation
pywin32 copied to clipboard

Limited support of the PyPy

Open olecsys opened this issue 7 years ago • 32 comments

Hello,

I want to suggest limited support of the pywin32 in the PyPy implementation of the Python. Unfortunately PyPy does not provide some functions that pywin32 uses:

  • Py_SetProgramName
  • Py_Initialize
  • PySys_SetArgv

Many Python packages use pywin32 as dependency. I use twisted and it depends on your project. But it does not use win32service, COM objects, etc. So my suggestion is to build all projects that does not require these functions via setup.py. I think platform.python_implementation() is good point to separate CPython and PyPy. I'll be able to make Pull Request, if you'll agree with the approach. And probably I'll need your help in some cases.

olecsys avatar Dec 11 '18 05:12 olecsys

I'm not sure what you are proposing exactly, either in terms of distribution artifacts nor what a patch might look like, so if you could elaborate I could give a thoughtful response.

mhammond avatar Dec 11 '18 10:12 mhammond

Hello @mhammond, I'll try to explain what I mean. I could execute my twisted application in PyPy 2.7 under Windows OS. I've made some changes to pywin32 setup.py and compiled pywin32 with Python 2.7 VS Build Tools, but it looks like a trick and hack. I just comment out modules, that did not compile. I suggest to add PyPy support in setup.py with more elegant method. I'am sending you my current setup.py. So I could try to make more elegant code and send you it later. setup.py.zip

olecsys avatar Dec 12 '18 11:12 olecsys

Why don't the modules compile?

mhammond avatar Dec 13 '18 03:12 mhammond

Main problem is that PyPy CPython compatibility C header Python.h(and PyPy library) does not provide these functions:

  • Py_SetProgramName
  • Py_Initialize
  • PySys_SetArgv

It seems that PyPy maintainers do not plan to implement them for now.

olecsys avatar Dec 13 '18 04:12 olecsys

This sounds fine in theory, but it will depend on what the final patch looks like. It sounds like you really only want the "win32" modules, so maybe you could experiment with conditionally setting ext_modules to only win32_extensions (and we could consider splitting win32_extensions into 2 categories, so things like service support are easier to exclude.

mhammond avatar Dec 14 '18 01:12 mhammond

Yes, I'll try to experiment with ext_modules. Thank you for advice. I'll let you know about results.

olecsys avatar Dec 17 '18 08:12 olecsys

Did this experiment get any further? xref https://foss.heptapod.net/pypy/pypy/-/issues/3286, where @SleepyRoy asked for support for the missing c-api functions from PyPy.

mattip avatar Aug 23 '20 08:08 mattip

Hello @mattip, actually I did not try to make the experiment then, i.e. I was very busy. But now I could try to make it with pypy3 and we'll see results.

olecsys avatar Aug 24 '20 01:08 olecsys

Indeed, just a subset of pywin32 would help a lot. pywin32 is a fantastic tool.

Many thanks.

rchateauneu avatar Oct 06 '20 12:10 rchateauneu

trying to buid a PyPy distro, I'm blocked on the Jupyter eco-system part per the missing pywin32... is there any hope ?

stonebig avatar May 09 '21 08:05 stonebig

I'm blocked on the Jupyter eco-system part

You shouldn't be blocked on the latest versions of the various jupyter libraries. Please file an issue on the repo of the library that is failing to build and ping me.

mattip avatar May 09 '21 10:05 mattip

apparently, jupyter-core still wants pywin32 : https://github.com/jupyter/jupyter_core/search?q=pywin32&type=code

image

stonebig avatar May 09 '21 10:05 stonebig

This is really off-topic for pywin32. Let's discuss it at jupyter/jupyter_core#226

mattip avatar May 09 '21 10:05 mattip

I got CI to pass on the conda-forge feedstock by removing these modules (some small fixes were required to PyPy, they will be part of the upcoming release). Are any of these widely used? How could pywin32 make it clear that these have been removed for PyPy?

  • pythoncom, and its dependents adsi, axcontrol, axscript, axdebug, internet, mapi, exchange, shell, propsys, taskscheduler, bits, ifilter, directsound, authorization
  • win32ui, and its dependents win32uiole, dde
  • servicemanager, pythonservice, and PyISAPI_loader

mattip avatar Aug 24 '21 16:08 mattip

Are any of these widely used?

Yes, very widely used.

How could pywin32 make it clear that these have been removed for PyPy?

I don't understand what you mean - I will never remove them from PyPy. Shipping anything with pywin32 in the name but without these modules would be useless to many many pywin32 users, and I'd ask that you do not do that, because I'll be the one handling the bugs about why fundamental things do not work.

mhammond avatar Aug 24 '21 21:08 mhammond

OK makes sense. I will not pursue this path.

mattip avatar Aug 25 '21 04:08 mattip

Why do you want to ship any of this in the first place? If there's only 1 or 2 things from win32api or similar, then maybe we can work out how to do that, and do it in a way that it would be compatible with the user doing a full install of pywin32?

IOW, I don't object at all to you shipping bits of pywin32, just not a kind of "frankenstein" version :)

mhammond avatar Aug 25 '21 11:08 mhammond

Problem is pywin32 is claimed per jupyter-core , unless they accept cgohlke patch, but apparently they did incorporate it 17hours ago

stonebig avatar Aug 25 '21 11:08 stonebig

If there's only 1 or 2 things from win32api or similar, then maybe we can work out how to do that, and do it in a way that it would be compatible with the user doing a full install of pywin32?

@mhammond, do you have any ideas on how to do this? If so, I can try and send a PR.

isuruf avatar Apr 27 '22 23:04 isuruf

@mhammond, do you have any ideas on how to do this? If so, I can try and send a PR.

No - I've no idea what parts people want to ship and I've no idea how jupyter's build process works. There's no PR possible for pywin32 that would address this.

mhammond avatar Apr 27 '22 23:04 mhammond

@mhammond, I'd like to ship all the parts that can be built using PyPy and only disable modules that use features that PyPy doesn't support. jupyter now doesn't need pywin32, but there are other packages that do need pywin32.

isuruf avatar Apr 27 '22 23:04 isuruf

FYI, I only need win32api, win32con, win32event, win32process, win32com.shell for a project.

isuruf avatar Apr 27 '22 23:04 isuruf

fair enough - but sorry, I've no idea how pypy works nor how you would do that. The initial comment here talks about pypy missing some really fundamental APIs and I'd be reluctant to take a complicated PR that works around these limitations - so a better approach might be to fix pypy?

mhammond avatar Apr 27 '22 23:04 mhammond

PyPy is an alternative python implementation. When building a python extension, the extension has suffix pypy39-pp73-win_amd64.pyd instead of cp39-win_amd64.pyd for CPython (reference implementation). So there's no possibility of a pywin32 built for PyPy clashing with a pywin32 built for CPython.

A PR would simply disable building the modules that require features that PyPy doesn't support. For eg: https://raw.githubusercontent.com/mattip/pywin32-feedstock/182ec7282aa78027bfcae08e0667c64ff4ad7587/recipe/patches/0001-remove-modules-needing-pythonservice.cpp-for-pypy.patch

I asked @mattip who is a core contributor of PyPy recently what the status of PyPy implementing these missing features at https://foss.heptapod.net/pypy/pypy/-/issues/3286#note_162769. I'll try to go that route and maybe we'll see support for these features in a new PyPy release.

isuruf avatar Apr 27 '22 23:04 isuruf

I'd be fine with a relatively simple PR touching only setup.py

mhammond avatar Apr 27 '22 23:04 mhammond

Thanks.

@mattip, since it's your patch, would you like to send the PR?

isuruf avatar Apr 28 '22 00:04 isuruf

I have started working on this in a branch. The changes to avoid the com_extensions and the pythonwin_extensions is straightforward. I also added PyPy to the CI matrix, and some tests will require skipping. It seems PyPy is still missing some basic functionality, like PyUnicode_EncodeCodePage, and maybe more.

mattip avatar Apr 28 '22 05:04 mattip

like PyUnicode_EncodeCodePage,

If only some of those obscure strings functions are causing problems, many of them can probably be killed now that python 2 support has been dropped. They might not all be trivial to kill, but it is possible. I'll try and clean some of these up soon, but it's likely to take me a few weeks to get to this.

mhammond avatar Apr 28 '22 05:04 mhammond

Any progress here? I have same issue with pypy that copying bmp raw data to windows clipboard, using win32clipboard which is a part of pywin32

x151973 avatar Dec 16 '23 02:12 x151973

@x151973 https://github.com/mhammond/pywin32/pull/1860 removed PyUnicode_EncodeCodePage. For everything else, go follow those issues:

  • https://github.com/pypy/pypy/issues/1720
  • https://github.com/pypy/pypy/issues/3286
  • https://github.com/pypy/pypy/issues/3836

Avasam avatar Mar 12 '24 02:03 Avasam