Issue1838658

classification
Title: 'platform' module is not available
Type: Severity: normal
Components: Library Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, mehendran, zyasoft
Priority: normal Keywords: patch

Created on 2007-11-26.12:13:45 by mehendran, last changed 2008-09-14.06:47:09 by zyasoft.

Files
File name Uploaded Description Edit Remove
module_platform.diff mehendran, 2007-11-26.12:13:45 platform module
patch_platform.diff mehendran, 2007-12-20.08:45:44 platform module latest version
Messages
msg2950 (view) Author: Mehendran (mehendran) Date: 2007-11-26.12:13:45
I have attached the patch. The architecture function 
returns a tuple with empty values in place of giving
correct values. I couldn't find the right way to do it though I know some solutions specific to OSs. I have posted this question to community. Apart from that, 
the testcase file test_platform.py runs properly.

Waiting for your valuable comments...

Thanks,
Mehendran
msg2951 (view) Author: Charlie Groves (cgroves) Date: 2007-11-30.21:07:30
It appears that platform.py in CPythonLib already has significant work done in it to make it work with java, ie it already imports java.lang.System in some places.  Rather than the approach in this version, which appears to take that and just replace some pieces with Java specific functionality, it'd be better to see something that could run in both CPython and Jython as it's already tending.  That way it can eventually be shared between the two codebases and we don't have to update our platform module whenever CPython's changes.  Also, if  you are going to copy from the CPython version, don't rip out the attribution and copyrights from the previous authors.
msg2952 (view) Author: Mehendran (mehendran) Date: 2007-12-07.15:30:36
As you said, Yes,  I have already seen that platform,py is in CPythonLib and
significant work has been done in it.
I imported and tested platform module.
The output:
   test_architecture (__main__.PlatformTest) ... ERROR
   test_dist (__main__.PlatformTest) ... ok
   test_java_ver (__main__.PlatformTest) ... ('1.5.0', 'IBM Corporation', ('IBM J9 VM', '2.3', 'IBM Corporation'), (None, None, None)) ok
   test_libc_ver (__main__.PlatformTest) ... ERROR
   test_mac_ver (__main__.PlatformTest) ... ok
   test_machine (__main__.PlatformTest) ... ok
   test_node (__main__.PlatformTest) ... myhostname ok
   test_platform (__main__.PlatformTest) ... ERROR
   test_processor (__main__.PlatformTest) ...ok
   test_python_build (__main__.PlatformTest) ... ERROR
   test_python_compiler (__main__.PlatformTest) ... ERROR
   test_release (__main__.PlatformTest) ... 1.5.0 ok
   test_system (__main__.PlatformTest) ... Java ok
   test_system_alias (__main__.PlatformTest) ... ('Java', '1.5.0', 'IBM J9 VM, 2.3, IBM Corporation') ok
   test_uname (__main__.PlatformTest) ... ('Java', 'brajesh', '1.5.0', 'IBM J9 VM, 2.3, IBM Corporation', '', '') ok
   test_version (__main__.PlatformTest) ... IBM J9 VM, 2.3, IBM Corporation ok
   test_win32_ver (__main__.PlatformTest) ... ok


and it is not recognizing the actual underlying OS. its recognizing Java
as OS and retrives the details. From the above example it could be clear 
for you.

In CPython implementation, there are 5 functions which are not
required for Jython . they are python specific functions. 
   1. libc_ver()
   2. python_build()
   3. python_compiler()
   4. python_version()
   5. python_version_tuple()

In the platform patch, those functions had been replaced with   
   a. jython_compiler()
   b. jython_version()
   c. jython_version_tuple()

The output of cpython platform module.

$>  python Lib/test/test_platform.py
   test_architecture (__main__.PlatformTest) ... ('32bit', 'ELF') ok
   test_dist (__main__.PlatformTest) ... ok
   test_java_ver (__main__.PlatformTest) ... ('', '', ('', '', ''), ('', '', '')) ok
   test_libc_ver (__main__.PlatformTest) ... ('glibc', '2.3') ok
   test_mac_ver (__main__.PlatformTest) ... ok
   test_machine (__main__.PlatformTest) ... i686 ok
   test_node (__main__.PlatformTest) ... myhostname  ok
   test_platform (__main__.PlatformTest) ... Linux-2.6.16.46-0.14-bigsmp-i686-with-SuSE-10-i586 ok
   test_processor (__main__.PlatformTest) ... i686 ok
   test_python_build (__main__.PlatformTest) ... (3, 'Nov 29 2007 12:11:09') ok
   test_python_compiler (__main__.PlatformTest) ... ok
   test_release (__main__.PlatformTest) ... 2.6.16.46-0.14-bigsmp ok
   test_system (__main__.PlatformTest) ... Linux ok
   test_system_alias (__main__.PlatformTest) ... ('Linux', '2.6.16.46-0.14-bigsmp', '#1 SMP Thu May 17 14:00:09 UTC 2007') ok
   test_uname (__main__.PlatformTest) ... ('Linux', 'brajesh', '2.6.16.46-0.14-bigsmp', '#1 SMP Thu May 17 14:00:09 UTC 2007', 'i686', 'i686')ok
   test_version (__main__.PlatformTest) ... #1 SMP Thu May 17 14:00:09 UTC 2007 ok
   test_win32_ver (__main__.PlatformTest) ... ok

The output of platform module after my patch :-

   test_architecture (__main__.PlatformTest) ... ('', '') ok /* This is not yet implemented currently  
                                                            it just returns the empty tuple */
   test_dist (__main__.PlatformTest) ... ('SuSE', '10', 'i586') ok
   test_java_ver (__main__.PlatformTest) ... ('1.5.0', 'IBM Corporation', ('IBM J9 VM', '2.3', 'IBM Corporation'), (None, None, None)) ok
   test_jython_compiler (__main__.PlatformTest) ... java1.5.0 ok
   test_jython_version (__main__.PlatformTest) ... 2.3a0 ok
   test_jython_version_tuple (__main__.PlatformTest) ... ('2', '3', '0') ok
   test_mac_ver (__main__.PlatformTest) ... ('', ('', '', ''), '') ok
   test_machine (__main__.PlatformTest) ... i686 ok
   test_node (__main__.PlatformTest) ... myhostname ok
   test_platform (__main__.PlatformTest) ... Linux-2.6.16.46-0.14-bigsmp-i686-i686-with-SuSE-10-i586  ok
   test_processor (__main__.PlatformTest) ... i686 ok
   test_release (__main__.PlatformTest) ... 2.6.16.46-0.14-bigsmp ok
   test_system (__main__.PlatformTest) ... Linux ok
   test_system_alias (__main__.PlatformTest) ... ('Linux', '2.6.16.46-0.14-bigsmp', '#1 SMP Thu May 17 14:00:09 UTC 2007') ok
   test_uname (__main__.PlatformTest) ... ('Linux', 'brajesh', '2.6.16.46-0.14-bigsmp', '#1 SMP Thu May 17 14:00:09 UTC 2007', 'i686', 'i686') ok
   test_version (__main__.PlatformTest) ... #1 SMP Thu May 17 14:00:09 UTC 2007 ok
   test_win32_ver (__main__.PlatformTest) ... ('', '', '', '') ok

which actually matches the output of all the cpython platform module.

The actual problem is, its not recognising the actual OS( Linux,Mac,Win
etc) instead it recognizes java vm as platform and retrieves the values
of it.

we have reused most of the code from the cpython platform module and it
had been modified properly.

To make the module sync up with the CpythonLib 
1. we import platform from the CPythonLib to a new class and then
   tailoring the new class (but the module name will get changed)
2. we can generate the platform module by copying the important
   working CpythonLib platform module and with our functions.
3. we will rewrite everything in .java files

currently I am able to think of these solutions only..
I am sorry for ripping out the attribution and copyrights 
from the previous authors.

please send if there is any better way of doing this.

msg2953 (view) Author: Charlie Groves (cgroves) Date: 2007-12-08.22:32:26
I'm trying to say that your approach is in the right direction, but it's possible for it to work on Jython and CPython at the same time and that's always the best route.  If we have code that can be used by CPython too, eventually we can push modifications back in their direction and not have to maintain a separate copy.  That's always better because it allows us to pick up modifications that they make without manual merging on our part on every version update.  Because you ripped out part of the CPython implementation, it no longer works for CPython and our version becomes a fork instead of a patch to be applied to CPython at a later date. 
msg2954 (view) Author: Mehendran (mehendran) Date: 2007-12-20.08:45:44
The platform module which is in CPythonLib is untouched 
and I have made changes to other java files. Now it will
work fine.

The banner will be changed by this patch and it will be 
consistent to the python console's banner.
  
The testcases which are failing in the test_platform.py 
had been commented out.

Reasons:
1. test_architecture() its searching for the python
   excecutable 
2. libc_ver() is not required for Jython
3. test_platform()  is using the libc_ver() and,
4. tests related to python version

In the previous version of the patch, there were jython
specific functions. If I am integrating them into the 
patch, then we need to apply the patch on every update 
of the platform module in cpython.

Please suggest if there is any other way.

File Added: patch_platform.diff
msg2955 (view) Author: Charlie Groves (cgroves) Date: 2007-12-20.18:39:18
You can't just say sys.platform is the underlying os.  Jython runs on a separate platform, java, that has different assumptions and qualities than any other base platform.  Changing platform.py is fine, you'll notice that I said you were heading in the right direction in my comments, it's just that those modifications should be such that CPython and Jython can use the same module.  If that isn't possible, explain why and we can start to use a forked version.

With this patch in place, regrtest fails internally before it even runs a single test.  The first thing I do when evaluating a patch, before even looking at the code, is to run regrtest with it.  If it causes unexplained test failures, I'm not going to apply it.
msg3594 (view) Author: Jim Baker (zyasoft) Date: 2008-09-14.06:47:09
Fixed in 2.5 with r4758
Tested with test_platform
History
Date User Action Args
2008-09-14 06:47:09zyasoftsetstatus: open -> closed
title: Patch for [ 1835119 ] 'platform' module is not available -> 'platform' module is not available
nosy: + zyasoft
messages: + msg3594
components: + Library, - None
resolution: fixed
2007-11-26 12:13:45mehendrancreate