path.py: isdir() not working with python27

156 views
Skip to first unread message

Jesse Capper

unread,
Jan 9, 2014, 4:47:25 PM1/9/14
to python_in...@googlegroups.com
Loading the same path.py module into a 2.6.4 and 2.7.3 session produces different results when calling Path(path/to/file).isdir()

2.6.4 works as expected - outputs True or False
2.7.3 raises a TypeError: TypeError: _isdir() takes exactly 1 argument (0 given)

Anyone know why the behavior changed?

This is an easy manual fix except that we also use pymel which ships with its own path.py module that pymel calls return. Replacing that on each user's machine is more involved and I was hoping for an easier solution.

Kurian O.S

unread,
Jan 9, 2014, 5:01:17 PM1/9/14
to python_in...@googlegroups.com
path = 'path/to/file'

if os.path.isdir(path):
     print "Yes it is ! "

This didnt work for you ?


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7fe466f0-9628-4b31-8ed8-0e872a94974d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
--:: Kurian ::--

Jesse Capper

unread,
Jan 9, 2014, 5:26:04 PM1/9/14
to python_in...@googlegroups.com
That works fine. My issue is when using the path module, which pymel also uses. We have code that utilizes the path module inside and outside of pymel. It's easy to patch fix the issue outside of pymel but since pymel includes its own path.py, and that lives locally on every user's machine, replacing that is a bit more cumbersome.

A simplified version of the issue:

import os.path
 
path = 'c:\\temp'
class foo(unicode):        
    isdir = os.path.isdir
   
foo(path).isdir()
# 2.6.4 # True
# 2.7.3 # TypeError: _isdir() takes exactly 1 argument (0 given) #
 
print os.path.isdir(path)
# 2.6.4 # True
# 2.7.3 # True

On Thursday, January 9, 2014 2:01:17 PM UTC-8, Kurian wrote:
path = 'path/to/file'

if os.path.isdir(path):
     print "Yes it is ! "

This didnt work for you ?
On Thu, Jan 9, 2014 at 1:47 PM, Jesse Capper <jesse....@gmail.com> wrote:
Loading the same path.py module into a 2.6.4 and 2.7.3 session produces different results when calling Path(path/to/file).isdir()

2.6.4 works as expected - outputs True or False
2.7.3 raises a TypeError: TypeError: _isdir() takes exactly 1 argument (0 given)

Anyone know why the behavior changed?

This is an easy manual fix except that we also use pymel which ships with its own path.py module that pymel calls return. Replacing that on each user's machine is more involved and I was hoping for an easier solution.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
--:: Kurian ::--

Jesse Kretschmer

unread,
Jan 9, 2014, 5:37:21 PM1/9/14
to python_in...@googlegroups.com
I did a quick web search and apparently many folks have had trouble transitioning from 2.7.2 to 2.7.3 do to some backported features from Python 3. I don't think the idea of path objects was well tested. Rather than changing the path.py file on all the client machines, you could try monkey patching the isdir function.

dgovil

unread,
Jan 9, 2014, 5:42:43 PM1/9/14
to python_in...@googlegroups.com
In Linux, it's working in Python 2.7.3 and 2.6.4 for me, but I can't say I'm a fan of that style of implied argument passing.
The only issue I can think of is that I had weird bugs sometimes with using backslashes on Windows. Python supports forwards slashes on windows, so maybe try that?

Otherwise I would just make an isdir wrapper instead of passing it through like that. That should work.

Jesse Capper

unread,
Jan 9, 2014, 5:52:47 PM1/9/14
to python_in...@googlegroups.com
Yeah I'm not a fan of it either.

My hope was to not have to patch the file on every artist's machine, but I guess I will have to.

I just saw that there is an updated path.py module, but that pymel doesn't ship with it -- they're still using an older version (dated 2004 in the file)

Jesse Kretschmer

unread,
Jan 9, 2014, 5:54:41 PM1/9/14
to python_in...@googlegroups.com
I've tested this in windows with Maya 2014 (2.7.3), and I am getting the error regardless of slashes.

I just did a basic monkey patch, and it seems to work. If you create a userSetup.py in your PYTHONPATH, you should be able to overwrite the isdir function.

Here's what I tested (http://pastebin.com/RU7eTk14). I don't know how robust the isdir function has to be:
import sys
import os
import stat
import os.path

def my_isdir(path=None):
    if path and hasattr('root',path):
        path = path.root
    return stat.S_ISDIR(os.stat(path).st_mode)
        
os.path.isdir = my_isdir

class foo(str):
    isdir = os.path.isdir
    
print foo('C:/temp').isdir()
print sys.version

result:
True
2.7.3 (default, Aug  1 2012, 16:33:56) [MSC v.1600 64 bit (AMD64)]



To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/485a5536-5a89-47fb-8d6e-729300f258ae%40googlegroups.com.

Chad Dombrova

unread,
Jan 9, 2014, 6:00:52 PM1/9/14
to python_in...@googlegroups.com, python_in...@googlegroups.com
Are you getting the same error using the pymel that ships with 2014?

Sent from Mailbox for iPhone


Jesse Capper

unread,
Jan 9, 2014, 6:10:55 PM1/9/14
to python_in...@googlegroups.com
Yes I am. I am using Pymel 1.0.5 with Maya Version: Extension for Maya 2014.

There is a newer version of path.py (5.0), that has a fix for this issue: https://github.com/jaraco/path.py
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
--:: Kurian ::--

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Jesse Kretschmer

unread,
Jan 9, 2014, 6:10:59 PM1/9/14
to python_in...@googlegroups.com
On Thu, Jan 9, 2014 at 3:00 PM, Chad Dombrova <cha...@gmail.com> wrote:
Are you getting the same error using the pymel that ships with 2014?

Yup, the error seems to be related to the core os.path module in Python 2.7.3 which ships with maya.

Here's a paste from a vanilla maya 2014 install:

import pymel.core.system
import maya.cmds

print cmds.about(apiVersion=True)
print pymel.core.system.Path('C:/temp').isdir()

201400
# Error: _isdir() takes exactly 1 argument (0 given)
# Traceback (most recent call last):
#   File "<maya console>", line 5, in <module>

Jesse Capper

unread,
Jan 9, 2014, 6:24:00 PM1/9/14
to python_in...@googlegroups.com, je...@krets.com
That's not a bad idea. We wouldn't have to roll out changes to each machine in that case.

Thanks.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscribe@googlegroups.com.



--
--:: Kurian ::--

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

Jesse Kretschmer

unread,
Jan 9, 2014, 7:01:40 PM1/9/14
to Jesse Capper, python_in...@googlegroups.com
To be clear, this is a bad idea. I can't endorse ham-fistedly replacing anything in the core library. 

...but I might be just fine for a small deployment. You will have to keep your eye out for strange errors that could arise from modification. As an aside, I decided to these this with a useSetup.py, and it worked. You will need to make sure that your monkey patch is executed before you load pymel.

I did some more investigation into the problem. The spyderlib project worked around the issue by updating the path.py is in included in their package:

That spyderlib link also points to the cpython changeset that caused the bug (http://hg.python.org/cpython/rev/f1509fc75435/).

Perhaps Chad can get an updated path.py pushed into PyMel for a future release of Maya.

Jesse Capper

unread,
Jan 9, 2014, 7:25:33 PM1/9/14
to python_in...@googlegroups.com, Jesse Capper, je...@krets.com
Thanks for the info on the change!

Also, I'm not actually writing my own isdir method. Since the issue is arising from using the new _isdir method from the nt module, I just switch back to using the old genericpath.isdir method instead, which is what would get used anyway if the _isdir import failed..
So I only added this to userSetup.py:

if sys.version_info >= (2, 7, 3):
    os.path.isdir = genericpath.isdir

Chad Dombrova

unread,
Jan 9, 2014, 7:44:22 PM1/9/14
to Maya Python Group
Upgraded pymel's path.py to version 5.0: https://github.com/LumaPictures/pymel/commits/master

Thanks for pointing out that repo on github.  path.py disappeared for awhile. Glad to see that it's back.

-chad





Reply all
Reply to author
Forward
0 new messages