Title: ongoing pain with platform detection via and sys.platform
Type: behaviour Severity: normal
Components: Any Versions: Jython 2.7
Milestone: Jython 2.7.1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: darjus, jeff.allen, stefan.richthofer, zyasoft
Priority: normal Keywords:

Created on 2017-02-24.11:52:36 by stefan.richthofer, last changed 2017-06-11.21:51:51 by stefan.richthofer.

msg11123 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-24.11:52:35
I am currently implementing a way that will give us fine-grained control of how Jython displays and sys.platform to certain modules.
Actually to certain classes and even certain methods as well.
Opening this issue to keep track of that development and to collect ideas for tagets.

It is based on an idea from JyNI, which we also discussed in #2521.

However it seems that implementing the PyShadowString idea as mentioned in #2521 would break to much code (I did some experiments).
So I added more control by allowing to add 'targets' to PyShadowString. PyShadowString will then only apply its fake-__eq__ implementation if a target is in the traceback. A target can be any regex-String and can be registered with scope on class or scope on method.

This will get clearer once I can come up with an actual implementation. Stay tuned...
msg11128 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-24.15:15:31
I added my draft for this as of
Given that there are no targets registered by default (yet), it cannot (?) break anything. Let me give a demonstration:

Jython 2.7.1b3 (default:24ef3218632f+, Feb 24 2017, 15:35:03) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
'java ( ==posix for targets )'
>>> str(
>>> == 'posix'
>>> == 'posix'
>>> == 'posixx'
>>>[:3] == 'pos'
>>>[:3] == 'jav'
'jav ( ==pos for targets )'
>>> import sys
>>> sys.platform
'java1.8.0_121 ( ==linux2 for targets )'
>>> sys.platform.startswith('linux')
>>> sys.platform.addtarget('org\.python.*')
>>> sys.platform.startswith('linux')
>>> sys.platform == 'linux2'
>>> 'linux2' == sys.platform
msg11168 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-03.16:21:52
Setting this to pending/fixed, because a workable solution has been added to trunk. Should however not be closed before it has been tested in field a bit.
msg11427 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-06-10.02:13:57
JyNI is now using this technique as of

For now it targets (hard-coded) ctypes and PyOpenGL (but additional targets can easily be added on Python-code level as shown above).

I will test if - together with support for oversized functions - now original PyOpenGL is runnable rather than the slightly modified variant JyOpenGL (
msg11428 (view) Author: Jim Baker (zyasoft) Date: 2017-06-10.05:24:29
Are we ready to close this bug yet?

I suppose we can consider this API still unstable/WIP, but regardless it will be part of the forthcoming release.
msg11430 (view) Author: Jeff Allen (jeff.allen) Date: 2017-06-10.06:58:05
No actual objection here to closing. I haven't come across us using it in the standard library yet. Should we do that before we consider it a success?

It's very much last resort, IMO. (And the need will go away in 3.)
msg11436 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-06-11.21:51:50
I'm fine with closing.

I think it shouldn't be used in standard library unless some real usecase pops up - never change a running system.

Its main intend is to be a tool for easier support of extensions (pure python or not) that fail because of platform detection. Also to be able to give better debug instructions. If a user asks: "Why does xy-framework not work in Jython?" I want to be able to give advise if I suspect it's because of platform detection:

Before this, there was no easy way to do something like that; it would have involved to patch xy in some way.

That said, I'd like to write a NEWS-entry about it, so it's documented at least there.
Date User Action Args
2017-06-11 21:51:51stefan.richthofersetstatus: pending -> closed
messages: + msg11436
2017-06-10 06:58:05jeff.allensetmessages: + msg11430
2017-06-10 05:24:29zyasoftsetmessages: + msg11428
2017-06-10 02:13:57stefan.richthofersetmessages: + msg11427
2017-03-03 16:49:44stefan.richthofersetstatus: open -> pending
2017-03-03 16:21:52stefan.richthofersetresolution: fixed
messages: + msg11168
2017-02-24 15:15:31stefan.richthofersetmessages: + msg11128
2017-02-24 15:14:57stefan.richthofersetmessages: - msg11127
2017-02-24 15:14:29stefan.richthofersetmessages: + msg11127
2017-02-24 11:52:36stefan.richthofercreate