Skip to content
This repository

ImportError in _get_system_username on cyqwin without win32api installed #123

Closed
bitprophet opened this Issue August 18, 2011 · 12 comments

1 participant

Jeff Forcier
Jeff Forcier
Owner

Description

function _get_system_username() fails when using cygwin without win32api installed.

`
/usr/lib/python2.5/site-packages/fabric/state.py in _get_system_username()
72 return pwd.getpwuid(os.getuid())[0]
73 else:
---> 74 import win32api
75 import win32security
76 import win32profile

ImportError: No module named win32api
`

Possibly use this instead:
`import os

return os.getlogin()`


See also #146 for another report on the same general issue (and a patch from Ali Saifee which looks like the same suggestion as Nate's -- that os.getlogin works under at least some Windows Python platforms. Guessing Ali was also on Cygwin.


Originally submitted by Nathan Sutton (nate) on 2009-12-17 at 03:03pm EST

Relations

  • Duplicated by #146: windows port needs pywin32

Closed as Done on 2010-06-18 at 01:49pm EDT

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


here is the trace

/usr/lib/python2.5/site-packages/fabric/state.py in _get_system_username()
72         return pwd.getpwuid(os.getuid())[0]
73     else:
---> 74         import win32api
75         import win32security
76         import win32profile
ImportError: No module named win32api

on 2009-12-17 at 03:06pm EST

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


this should work instead

import os
return os.getlogin()

on 2009-12-17 at 03:08pm EST

Jeff Forcier
Owner

Jeff Forcier (bitprophet) posted:


Have you actually tried using os.getlogin on Windows? According to the Python docs, it's a Unix-only operation, which (I imagine) is why all username/homedir patches I've received have made use of win32api.

Let me know -- I don't test or develop on Windows myself so I'm basically at the mercy of active Fab users who use Windows :) and need to get you guys to come to a consensus ;)


on 2009-12-17 at 08:33pm EST

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


well I use cygwin on windows and do not have win32 stuff installed and can't run fabric without it. Either is should be on the dependency list or break out cygwin as a different state.

If I remove 'cygwin' from the list (win32 = os.platform in ['win32']) the import works. I haven't tested if anything in the api works yet though.


on 2009-12-17 at 10:46pm EST

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


Well it seems to work under cygwin on vista and xp for me. Also the current "not win32" works as well.

cygwin screenshot

I will do some work on it and submit a patch.


on 2009-12-17 at 09:46pm EST

Jeff Forcier
Owner

Jeff Forcier (bitprophet) posted:


I see, it's been a while so I forgot that we check for cygwin as well. So you're saying that recent Pythons that come with Cygwin have a working os.getlogin() method, then?

Could you test out the other few spots in the code where we make use of the win32 flag to see whether their "unix" branches work under Cygwin? (I.e. I don't want to end up removing the cygwin check only to find that those other spots do need win32api after all, even under Cygwin.)

IIRC the other major spot was checking user home directories; might be one or two others. Grepping for win32 should find them right quick.


on 2009-12-18 at 02:51pm EST

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


both work on my systems (vista and XP with cygwin)

`pwd.getpwuid(os.getuid())[0]`
`os.path.expanduser('~/')`

cygwin screenshot


on 2009-12-18 at 03:22pm EST

Jeff Forcier
Owner

Nathan Sutton (nate) posted:


I am currently setting up a project which will be utilizing fabric. I have removed the 'cygwin' item from win32 = sys.platform in ['win32', 'cygwin']. Once I get the project set up and running I will report back with updates on how things are working.


on 2009-12-18 at 03:25pm EST

Jeff Forcier
Owner

Jeff Forcier (bitprophet) posted:


Great, and thanks for taking the time to troubleshoot all this.


on 2009-12-18 at 05:12pm EST

Jeff Forcier
Owner

Carl Meyer (carljm) posted:


I just had to get someone up and running with Fabric on Cygwin, and I had to remove 'cygwin' from that win32 check as well. As far as I can tell the win32api package isn't even available for Cygwin Python, so the status quo is guaranteed to always be broken on Cygwin. Haven't been running long enough to say for sure that everything works with cygwin removed from that check, but it can't be worse than the alternative.


on 2010-05-20 at 03:09pm EDT

Jeff Forcier
Owner

Jeff Forcier (bitprophet) posted:


Adding note re #146.

In testing out some stuff for #7 I am also trying to tackle this issue (though I'll be landing these changes in 0.9.x and only then porting up to master and the #7 feature branch).

I have Cygwin and its Python installed on a WinXP vm and am going to also drop ActiveState on there and hope they don't clobber each other too much.

What I'm expecting to find is that ActiveState and other non-Cygwin Python builds do still require the win32 module, and will hopefully all report win32 in sys.platform, and Cygwin will be enough like Linux/BSD that we can simply drop the cygwin test entirely, as has been recommended by commenters.

If that holds up then I can update the install docs to make this clear. If not then I'll try to see what other patterns exist.


on 2010-06-18 at 11:47am EDT

Jeff Forcier
Owner

Jeff Forcier (bitprophet) posted:


Yup, ActiveState reports win32, and I can confirm that Cygwin falls down quite hard with the way things currently stand. Also confirming that simply nuking the cygwin test makes things work just fine (certainly, the two places we use the flag both report good values in Cygwin now).

I worry slightly about why we put the Cygwin test in but it's clearly outdated at this point and is causing more harm than good.

Going to close this ticket once I make the commit; please reopen if there is any fallout or if there are other areas I missed. (Paramiko itself does a similar test somewhere but I have no control over it and it's not causing any problems in Cygwin for me.)


on 2010-06-18 at 01:45pm EDT

Jeff Forcier bitprophet closed this August 18, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.