https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Web browser: --- Bug ID: 61231 Summary: Undefined global WindowsError in version.py Product: Pywikibot Version: core (2.0) Hardware: All OS: All Status: NEW Severity: major Priority: Unprioritized Component: General Assignee: Pywikipedia-bugs@lists.wikimedia.org Reporter: russblau@hotmail.com Classification: Unclassified Mobile Platform: ---
On Tools Lab, my tool http://tools.wmflabs.org/russbot/csd.py is throwing the following exception (edited for brevity):
/data/project/russbot/cgi-bin/csd.py in () => 37 import pywikibot /shared/pywikipedia/rewrite/pywikibot/__init__.py in () => 418 from .page import Page, ImagePage, Category, Link, User, ItemPage, PropertyPage, Claim /shared/pywikipedia/rewrite/pywikibot/page.py in () => 17 import pywikibot.site /shared/pywikipedia/rewrite/pywikibot/site.py in () => 32 from pywikibot import pagegenerators /shared/pywikipedia/rewrite/pywikibot/pagegenerators.py in () => 31 from pywikibot.comms import http /shared/pywikipedia/rewrite/pywikibot/comms/http.py in () => 62 version=pywikibot.version.getversiondict()) /shared/pywikipedia/rewrite/pywikibot/version.py in getversiondict() 51 else: => 52 (tag, rev, date, hsh) = getversion_git(_program_dir) /shared/pywikipedia/rewrite/pywikibot/version.py in getversion_git(path='/shared/pywikipedia/rewrite') 132 try: 133 subprocess.Popen([cmd], stdout=subprocess.PIPE).communicate() => 134 except WindowsError: 135 # some windows git versions provide git.cmd instead of git.exe 136 cmd = 'git.cmd' WindowsError undefined <type 'exceptions.NameError'>: global name 'WindowsError' is not defined args = ("global name 'WindowsError' is not defined",) message = "global name 'WindowsError' is not defined"
Curiously, I can import pywikibot when starting Python from the command prompt; the exception is only thrown when Python is started from the webserver.
local-russbot@tools-login:~$ version.py Pywikibot: [https] r-p-pywikibot-core.git (ef8fcb5, g2752, 2014/02/11, 06:31:56, ok) Release version: 2.0b1 Python: 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] unicode test: ok
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #1 from Russell Blau russblau@hotmail.com --- A little further testing shows that, when starting Python from the command prompt, WindowsError is still undefined (not too surprising, since this is a Linux machine), but evidently importing pywikibot in this configuration does not hit the try/except block on line 134 of version.py
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #2 from Merlijn van Deen valhallasw@arctus.nl --- We can either replace it by OSError, or add
try: WindowsError except NameError: class WindowError(OSError): pass
somewhere on top (or in pywikibot.exceptions?)
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #3 from Russell Blau russblau@hotmail.com --- I'd vote for OSError as more general. If you wanted to go the latter route, it would have to be in version.py; putting it in any other module would not work because of namespace issues.
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Mpaa mpaa.wiki@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |nullzero.free@gmail.com
--- Comment #4 from Mpaa mpaa.wiki@gmail.com --- *** Bug 61816 has been marked as a duplicate of this bug. ***
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #5 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 114988 had a related patch set uploaded by Merlijn van Deen: (bug 61231) use OSError as WindowsError does not exist on unix hosts
https://gerrit.wikimedia.org/r/114988
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Gerrit Notification Bot gerritadmin@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |PATCH_TO_REVIEW
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #6 from Gerrit Notification Bot gerritadmin@wikimedia.org --- Change 114988 merged by jenkins-bot: (bug 61231) use OSError as WindowsError does not exist on unix hosts
https://gerrit.wikimedia.org/r/114988
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
xqt info@gno.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|PATCH_TO_REVIEW |RESOLVED Resolution|--- |FIXED
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Russell Blau russblau@hotmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |REOPENED Resolution|FIXED |---
--- Comment #7 from Russell Blau russblau@hotmail.com --- This just leads to a new error:
/usr/lib/python2.7/subprocess.py in _execute_child(self=<subprocess.Popen object>, args=['git.cmd', '--no-pager', 'log', '-1', '--pretty=format:"%ad|%an|%h|%H|%d"--abbrev-commit', '--date=iso'], executable='git.cmd', preexec_fn=None, close_fds=False, cwd='/shared/pywikipedia/rewrite', env=None, universal_newlines=False, startupinfo=None, creationflags=0, shell=False, p2cread=None, p2cwrite=None, c2pread=8, c2pwrite=9, errread=None, errwrite=None) 1247 if fd is not None: 1248 os.close(fd) => 1249 raise child_exception 1250 1251 child_exception = OSError(2, 'No such file or directory')
<type 'exceptions.OSError'>: [Errno 2] No such file or directory args = (2, 'No such file or directory') child_traceback = 'Traceback (most recent call last):\n File "/usr/...st)\nOSError: [Errno 2] No such file or directory\n' errno = 2 filename = None message = '' strerror = 'No such file or directory'
Basically, getversiondict() needs to be able to fail gracefully and return some kind of placeholder value if it isn't able to locate either a GIT or SVN version number, rather than throw an exception and stop the entire framework from executing.
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #8 from Sorawee Porncharoenwase nullzero.free@gmail.com --- @Russell Blau: This is irrelevant to this bug. It's about tools lab. Normally this problem would not occur because /usr/bin is in $PATH, so calling "git" has no problem. However, in tools web server, /usr/bin is not in $PATH. merely calling git therefore is not enough; we have to call /usr/bin/git.
Do you think tools lab needs to reconfigure? I asked someone in IRC, and he said like don't solve the problem with $PATH.
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Andre Klapper aklapper@wikimedia.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|REOPENED |RESOLVED Resolution|--- |FIXED
--- Comment #9 from Andre Klapper aklapper@wikimedia.org --- Closing again as per comment 8, as the original bug reported in *this* report is fixed.
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
Merlijn van Deen valhallasw@arctus.nl changed:
What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugzilla.wikimedia. | |org/show_bug.cgi?id=61846
https://bugzilla.wikimedia.org/show_bug.cgi?id=61231
--- Comment #10 from Sorawee Porncharoenwase nullzero.free@gmail.com --- Well, I mean my comment is unrelated to the bug, not his comment. Anyway, since Merjin van Deen has filed another bug separately already, let's follow the other bug instead.
pywikipedia-bugs@lists.wikimedia.org