Issue2475

classification
Title: Backported python 3 pathlib and pathlib2 do not work b/c of meta class issues
Type: behaviour Severity: normal
Components: Library Versions: Jython 2.7
Milestone: Jython 2.7.1
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: seletz, stefan.richthofer, zyasoft
Priority: normal Keywords:

Created on 2016-02-24.12:42:26 by seletz, last changed 2017-06-09.04:57:18 by zyasoft.

Files
File name Uploaded Description Edit Remove
smime.p7s seletz, 2017-02-09.07:32:07
Messages
msg10776 (view) Author: Stefan Eletzhofer (seletz) Date: 2016-02-24.12:42:26
The back-ported pathlib and pathlib2 modules throw a traceback on import.

Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_60
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Cellar/jython/2.7.0/libexec/Lib/site-packages/pathlib.py", line 1275, in <module>
    class PosixPath(Path, PurePosixPath):
TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict
msg11058 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-02.02:06:15
Some weeks ago I did some work on a metaclass-related issue: http://bugs.jython.org/issue2515

Maybe because of those changes, maybe because of something else, this issue looks different nowadays:

Jython 2.7.1b3 (default:77f1bcd04321+, Feb 1 2017, 19:21:14) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.8.0_121
Type "help", "copyright", "credits" or "license" for more information.
>>> import pathlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/workspace/linux/Jython/packages/pathlib-1.0.1/pathlib.py", line 341, in <module>
    class _NormalAccessor(_Accessor):
  File "/data/workspace/linux/Jython/packages/pathlib-1.0.1/pathlib.py", line 359, in _NormalAccessor
    open = _wrap_strfunc(os.open)
  File "/data/workspace/linux/Jython/packages/pathlib-1.0.1/pathlib.py", line 344, in _wrap_strfunc
    @functools.wraps(strfunc)
  File "/data/workspace/linux/Jython/ssh/jython/dist/Lib/functools.py", line 33, in update_wrapper
    setattr(wrapper, attr, getattr(wrapped, attr))
AttributeError: 'reflectedfunction' object has no attribute '__module__'
>>> 

pathlib still doesn't import but now it seems to be the same issue as in #2476
msg11081 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-07.17:05:11
With recent work on #2476 (https://github.com/jythontools/jython/commit/1452e07de33fd894dc4e9ddc815389f990758e83) functools.wraps is now workable. However pathlib still doesn't work; it now shows the for me the same behavior you originally describe.

TypeError: Error when calling the metaclass bases
    multiple bases have instance lay-out conflict

This is due to __slots__. You can probably fix this by guarding __slots__ in Jython case like we did (so far) in #1777, but this is tedious in pathlib case, because they use __slots__ frequently while in sympy it were only three or four occurrences.

I'll think about a better solution for the __slots__ issue.
msg11087 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-08.16:30:24
I pinned the __slots__/lay-out conflict issue in #2551. Stefan: Feel free to enter nosy list of that one. With #2551 fixed, pathlib will have good chance to work.
msg11092 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-08.22:36:24
With #2551 fixed I claim this one is fixed too.
Stefan: Please try if pathlib works now. For me both pathlib and pathlib2 (after adding scandir and six to path) import fine now.
msg11096 (view) Author: Stefan Eletzhofer (seletz) Date: 2017-02-09.07:32:07
Hi,

thanks for your work on this!  Is there a branch where I can test?

-----Urspr√ľngliche Nachricht-----
Von: Stefan Richthofer [mailto:report@bugs.jython.org] 
Gesendet: 08 February 2017 23:36
An: Stefan Eletzhofer <stefan.eletzhofer@nexiles.com>
Betreff: [issue2475] Backported python 3 pathlib and pathlib2 do not work b/c of meta class issues

Stefan Richthofer added the comment:

With #2551 fixed I claim this one is fixed too.
Stefan: Please try if pathlib works now. For me both pathlib and pathlib2 (after adding scandir and six to path) import fine now.

----------
assignee:  -> stefan.richthofer
milestone: Jython 2.7.2 -> Jython 2.7.1
priority:  -> normal
resolution:  -> fixed
status: open -> pending
title: Backported python 3 pythlib and pathlib2 do not work b/c of meta class issues -> Backported python 3 pathlib and pathlib2 do not work b/c of meta class issues
type:  -> behaviour

_______________________________________
Jython tracker <report@bugs.jython.org>
<http://bugs.jython.org/issue2475>
_______________________________________
msg11097 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-09.15:50:08
Sure. I guess the easiest way is to clone our github mirror, https://github.com/jythontools/jython

One caveat: Building is only supported with Java 7 due to old version of antlr. You can however unofficially build with Java 8 by running ant twice.
msg11106 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-02-22.03:16:46
I just noted that installing scandir in Jython via pip fails:

bin/pip install scandir
Collecting scandir
  Using cached scandir-1.5.tar.gz
Installing collected packages: scandir
  Running setup.py install for scandir ... error
    Complete output from command /data/workspace/linux/Jython/installer_test/linux_2.7.1/bin/jython -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-88durY/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-wqw0MV-record/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.java1.8.0_121-2.7
    copying scandir.py -> build/lib.java1.8.0_121-2.7
    running build_ext
    building '_scandir' extension
    error: Compiling extensions is not supported on Jython
    
    ----------------------------------------
Command "/data/workspace/linux/Jython/installer_test/linux_2.7.1/bin/jython -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-88durY/scandir/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-wqw0MV-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-88durY/scandir/

It tries to build a C-extension, which isn't supported in Jython. However, scandir actually works with Jython if you install it by hand, i.e. without running its setup.py, but just copy scandir.py into a suitable location; it's only the setup that fails.
(scandir has all sorts of fallbacks letting it work without the C-extension; I only tried this on Linux so far however)

I am about to file a separate issue for this, just posting the info here right now, because that also breaks pathlib2 setup via pip. You can however make it work by handcrafted setup for now.
msg11424 (view) Author: Jim Baker (zyasoft) Date: 2017-06-09.04:57:18
Note that scandir installs properly and works as expected (due to other recent changes presumably, which I will not attempt to enumerate).
History
Date User Action Args
2017-06-09 04:57:18zyasoftsetstatus: pending -> closed
nosy: + zyasoft
messages: + msg11424
2017-02-22 03:16:47stefan.richthofersetmessages: + msg11106
2017-02-09 15:50:09stefan.richthofersetmessages: + msg11097
2017-02-09 07:32:07seletzsetfiles: + smime.p7s
messages: + msg11096
2017-02-08 22:36:24stefan.richthofersetstatus: open -> pending
priority: normal
type: behaviour
assignee: stefan.richthofer
title: Backported python 3 pythlib and pathlib2 do not work b/c of meta class issues -> Backported python 3 pathlib and pathlib2 do not work b/c of meta class issues
messages: + msg11092
milestone: Jython 2.7.2 -> Jython 2.7.1
resolution: fixed
2017-02-08 16:30:24stefan.richthofersetmessages: + msg11087
2017-02-07 17:05:11stefan.richthofersetmessages: + msg11081
2017-02-02 02:06:17stefan.richthofersetnosy: + stefan.richthofer
messages: + msg11058
2016-02-26 19:25:20zyasoftsetmilestone: Jython 2.7.2
2016-02-24 12:42:26seletzcreate