Issue2557

classification
Title: ongoing pain with platform detection via os.name and sys.platform
Type: behaviour Severity: normal
Components: Any Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: pending 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-03-03.16:49:44 by stefan.richthofer.

Messages
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 os.name 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 https://hg.python.org/jython/rev/a01c366576b8.
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
>>> os.name
'java ( ==posix for targets )'
>>> str(os.name)
'java'
>>> os.name == 'posix'
False
>>> os.name.startswith('pos')
False
>>> os.name.gettargets()
[]
>>> os.name.addtarget('org\.python.*')
>>> os.name == 'posix'
True
>>> os.name == 'posixx'
False
>>> os.name.startswith('pos')
True
>>> os.name.startswith('jav')
True
>>> os.name[:3] == 'pos'
True
>>> os.name[:3] == 'jav'
True
>>> os.name[:3]
'jav ( ==pos for targets )'
>>> import sys
>>> sys.platform
'java1.8.0_121 ( ==linux2 for targets )'
>>> sys.platform.startswith('linux')
False
>>> sys.platform.addtarget('org\.python.*')
>>> sys.platform.startswith('linux')
True
>>> sys.platform == 'linux2'
True
>>> 'linux2' == sys.platform
True
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.
History
Date User Action Args
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