Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"from plumbum.cmd import" does not work on python 3.3 #56

Closed
blin opened this issue Mar 16, 2013 · 3 comments
Closed

"from plumbum.cmd import" does not work on python 3.3 #56

blin opened this issue Mar 16, 2013 · 3 comments
Labels

Comments

@blin
Copy link

blin commented Mar 16, 2013

When trying to import any command in python 3.3 following exception occurs

>>> from plumbum.cmd import wc
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1597, in _handle_fromlist
  File "/usr/lib/python3.3/site-packages/plumbum/local_machine.py", line 537, in __getitem__
    return LocalCommand(self.which(cmd))
  File "/usr/lib/python3.3/site-packages/plumbum/local_machine.py", line 508, in which
    raise CommandNotFound(progname, list(cls.env.path))
plumbum.commands.CommandNotFound: ('__path__', [<LocalPath /usr/local/bin>, <LocalPath /usr/bin>, <LocalPath /bin>, <LocalPath /usr/local/sbin>, <LocalPath /usr/sbin>, <LocalPath /sbin>, <LocalPath ~/bin>, <LocalPath /usr/bin/vendor_perl>, <LocalPath /usr/bin/core_perl>, <LocalPath /usr/lib/qt4/bin>, <LocalPath /home/blin/bin>, <LocalPath /home/blin/bin>])

This seems to be due to http://docs.python.org/3/whatsnew/3.3.html#importlib

What happens is that

__import__('plumbum.cmd', fromlist=('wc')

eventually calls

hasattr(plumbum.cmd, '__path__')

which calls

plumbum.local_machine.local.__getitem__('__path__').

which fails.

Proposed solution is to replace

__getattr__ = local.__getitem__

in cmd with

def __getattr__(self, name):
    if name != '__path__':
        return local.__getitem__(name)
    else:
        pass
@tomerfiliba
Copy link
Owner

did you test it on the master branch or on the 1.1 release? i have a faint memory of fixing this already, but of course i might be wrong. anyhow, thanks for reporting!

@tomerfiliba
Copy link
Owner

@blin
Copy link
Author

blin commented Mar 16, 2013

I've tested it on 1.1 relesase.

This indeed solves the issue. It is a small change, but maybe you can release it as 1.1.1?

I guess i'll contact arch linux package maintainer for plumbum and ask him to include a patch until official release.

Thank you for a grate project!

@blin blin closed this as completed Mar 16, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants