This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Unsupported provider

classification
Title: 'import site' fails when called from an unlinked directory
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, georg.brandl, labrat, vstinner
Priority: normal Keywords: patch

Created on 2009-07-31 09:53 by labrat, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue6612.patch labrat, 2010-07-29 21:46 patch against current python-trunk fixing issue6612
deleted_cwd.patch vstinner, 2010-10-07 23:51
Messages (8)
msg91129 - (view) Author: W. Trevor King (labrat) * Date: 2009-07-31 09:53
I don't imagine this comes up very often, but:

$ mkdir /tmp/a; cd /tmp/a; rmdir /tmp/a; python -c 'import site';
rmdir: removing directory, /tmp/a
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/wking/lib/python/site.py", line 73, in <module>
    __boot()
  File "/home/wking/lib/python/site.py", line 33, in __boot
    imp.load_module('site',stream,path,descr)
  File "/usr/lib/python2.5/site.py", line 408, in <module>
    main()
  File "/usr/lib/python2.5/site.py", line 392, in main
    paths_in_sys = removeduppaths()
  File "/usr/lib/python2.5/site.py", line 96, in removeduppaths
    dir, dircase = makepath(dir)
  File "/usr/lib/python2.5/site.py", line 72, in makepath
    dir = os.path.abspath(os.path.join(*paths))
  File "/usr/lib/python2.5/posixpath.py", line 403, in abspath
    path = join(os.getcwd(), path)
OSError: [Errno 2] No such file or directory
msg111971 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-29 17:07
I'm quite sure nobody will want to do anything about it...
msg112014 - (view) Author: W. Trevor King (labrat) * Date: 2010-07-29 21:46
I just fixed it myself ;).  As I said before, not really a big deal, but it was an easy fix.  I've attached a patch, or you can merge my hg branch f python-trunk at

  http://www.physics.drexel.edu/~wking/code/hg/hgwebdir.cgi/python/
msg112043 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-07-30 06:56
Thanks! Reopening.
msg117863 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-10-02 08:36
A unit test is needed. Not to check the code, but to ensure that we don't break it in the future.
msg118152 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-10-07 23:40
There was a bug in copy_absolute(): if _Py_wgetcwd() failed, the result was undefined (depending of the content of "path" buffer). Especially, absolutize() calls copy_absolute() with a buffer allocated on the stack: the content of this buffer depends on the undefined content of the stack.

Fixed in Python 3.2 (r85309+r85311), 2.7 (r85312) and 3.1 (r85313).

copy_absolute() is used (by calculate_path()) to fill sys.path.
msg118153 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-10-07 23:51
deleted_cwd.patch, patch based on labrat's patch updated to py3k:
http://www.physics.drexel.edu/~wking/code/hg/hgwebdir.cgi/python/rev/77f3ad10ba45

Procedure to test the patch:
 - go into Python source tree
 - make a directory "z"
 - enter z directory
 - delete the z directory (in another terminal)
 - run ../python
msg118479 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-10-12 22:57
Fixed in 3.2 (r85386+r85387+r85389), 2.7 (r85390), 3.1 (r85391).

Thanks labrat for your patch. I added you to Misc/ACKS.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50861
2010-10-12 22:57:27vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg118479
2010-10-07 23:52:00vstinnersetfiles: + deleted_cwd.patch

messages: + msg118153
2010-10-07 23:40:06vstinnersetnosy: + vstinner
messages: + msg118152
2010-10-02 08:36:18amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg117863
2010-07-30 06:56:08georg.brandlsetstatus: languishing -> open
versions: + Python 3.1, Python 3.2, - Python 2.6, Python 2.5
messages: + msg112043

components: + Library (Lib)
type: behavior
stage: patch review
2010-07-29 21:46:40labratsetfiles: + issue6612.patch
keywords: + patch
messages: + msg112014

versions: + Python 2.6, Python 2.7
2010-07-29 17:07:27georg.brandlsetstatus: open -> languishing
nosy: + georg.brandl
messages: + msg111971

2009-07-31 09:53:25labratcreate