classification
Title: global name 'r' is not defined in upload.py
Type: behavior Stage: resolved
Components: Distutils Versions: Python 3.4, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jason.coombs Nosy List: Anthony.Kong, Esa.Peuha, Sven.Deichmann, berker.peksag, dirn, eric.araujo, jason.coombs, labrat, python-dev, reowen, tarek
Priority: normal Keywords:

Created on 2011-08-29 17:08 by reowen, last changed 2013-11-16 01:10 by jason.coombs. This issue is now closed.

Messages (8)
msg143162 - (view) Author: Russell Owen (reowen) Date: 2011-08-29 17:08
When using distutils to upload code to PyPI I get the following message (but the upload is successful):
{{{
Traceback (most recent call last):
  File "setup.py", line 60, in <module>
    zip_safe = False, # icons (e.g. as used by RO.Wdg.GrayImageDispWdg) are not retrieved in a zip-safe way
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/upload.py", line 60, in run
    self.upload_file(command, pyversion, filename)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/upload.py", line 180, in upload_file
    msg = '\n'.join(('-' * 75, r.read(), '-' * 75))
NameError: global name 'r' is not defined
}}}
A look at the current source code shows that there is indeed no variable "r". I'm not sure what was intended but it seems likely that it would be possible to replace r.read() by reason, status, or a combination of the two.
msg143222 - (view) Author: √Čric Araujo (eric.araujo) * (Python committer) Date: 2011-08-30 15:43
Does it work if you replace r with result?
msg143875 - (view) Author: Andy Dirnberger (dirn) Date: 2011-09-11 20:02
Replacing r with result works only when urlopen doesn't raise HTTPError
msg177033 - (view) Author: Sven Deichmann (Sven.Deichmann) Date: 2012-12-06 10:05
result seems indeed to be what is expected here.

One additional note: This only occurs if you use the --show-response option for the upload command. if you omit that, you get no error message
msg199494 - (view) Author: W. Trevor King (labrat) Date: 2013-10-11 17:38
I just posted a patch fixing this in the current master branch [1].  Ned Deily pointed out that my Issue19226 duplicated an earlier Issue17354, which also has a patch fixing this problem.  Merging either one of these patches should close this issue.  I like my patch's generic charset handling better, but for PyPI uploads either one would work fine.

I've looked through the Mercurial logs, but it looks like this r *has* been around since 34794 (Implement the Distutils 'upload' subcommand (upload package to PyPI), 2005-03-21), so I don't know where the "global name 'r' is not defined" message came from.
msg199544 - (view) Author: Esa Peuha (Esa.Peuha) Date: 2013-10-12 10:26
> so I don't know where the "global name 'r' is not defined" message came from.

It came from Python 2.7. There are two separate bugs here, one in 3.x and the other in 2.7: the 3.x bug has to do with bytes/string separation, while the 2.7 bug is that result was changed to r in baf1a482b57d.
msg202927 - (view) Author: Berker Peksag (berker.peksag) * Date: 2013-11-15 09:47
This is fixed in 3.3 and 3.4 by changeset http://hg.python.org/cpython/rev/5e98c4e9c909#l1.89.

I can still reproduce the NameError in 2.7:

http://hg.python.org/cpython/file/2.7/Lib/distutils/command/upload.py#l180
msg203000 - (view) Author: Roundup Robot (python-dev) Date: 2013-11-16 01:09
New changeset aa3a7d5e0478 by Jason R. Coombs in branch '2.7':
Issue #12853: Correct NameError in distutils upload command.
http://hg.python.org/cpython/rev/aa3a7d5e0478
History
Date User Action Args
2013-11-16 01:10:13jason.coombssetstatus: open -> closed
stage: needs patch -> resolved
resolution: fixed
versions: + Python 3.3, Python 3.4
2013-11-16 01:09:18python-devsetnosy: + python-dev
messages: + msg203000
2013-11-16 01:04:26jason.coombssetassignee: tarek -> jason.coombs
2013-11-15 09:47:58berker.peksagunlinkissue17354 superseder
2013-11-15 09:47:09berker.peksagsetnosy: + berker.peksag, jason.coombs

messages: + msg202927
versions: - Python 3.3, Python 3.4
2013-10-12 10:26:25Esa.Peuhasetnosy: + Esa.Peuha
messages: + msg199544
2013-10-11 17:38:55labratsetnosy: + labrat
messages: + msg199494
2013-10-11 17:24:42ned.deilysetversions: + Python 3.3, Python 3.4
2013-10-11 17:21:15ned.deilylinkissue19226 superseder
2013-06-14 08:43:37berker.peksaglinkissue18204 superseder
2013-06-14 08:40:42berker.peksaglinkissue17354 superseder
2012-12-06 10:05:13Sven.Deichmannsetnosy: + Sven.Deichmann
messages: + msg177033
2011-09-11 20:02:52dirnsetnosy: + dirn
messages: + msg143875
2011-08-30 15:43:23eric.araujosetmessages: + msg143222
versions: - Python 3.2, Python 3.3
2011-08-30 05:29:52Anthony.Kongsetnosy: + Anthony.Kong
2011-08-29 17:29:27pitrousetversions: + Python 3.2, Python 3.3, - Python 3.4
nosy: + tarek, eric.araujo

assignee: tarek
components: + Distutils
stage: needs patch
2011-08-29 17:08:19reowencreate