Skip to content

'import site' fails when called from an unlinked directory #50861

Closed

Description

@wking
mannequin
BPO 6612
Nosy @birkenfeld, @amauryfa, @vstinner, @wking
Files
  • issue6612.patch: patch against current python-trunk fixing issue6612
  • deleted_cwd.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2010-10-12.22:57:27.982>
    created_at = <Date 2009-07-31.09:53:25.040>
    labels = ['type-bug', 'library']
    title = "'import site' fails when called from an unlinked directory"
    updated_at = <Date 2010-10-12.22:57:27.980>
    user = 'https://github.com/wking'

    bugs.python.org fields:

    activity = <Date 2010-10-12.22:57:27.980>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2010-10-12.22:57:27.982>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2009-07-31.09:53:25.040>
    creator = 'labrat'
    dependencies = []
    files = ['18264', '19154']
    hgrepos = []
    issue_num = 6612
    keywords = ['patch']
    message_count = 8.0
    messages = ['91129', '111971', '112014', '112043', '117863', '118152', '118153', '118479']
    nosy_count = 4.0
    nosy_names = ['georg.brandl', 'amaury.forgeotdarc', 'vstinner', 'labrat']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue6612'
    versions = ['Python 3.1', 'Python 2.7', 'Python 3.2']

    Activity

    1. wking commented on Jul 31, 2009

      wkingmannequin
      MannequinAuthor

      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
    2. birkenfeld commented on Jul 29, 2010

      @birkenfeld
      Member

      I'm quite sure nobody will want to do anything about it...

    3. added
      stale
      on Jul 29, 2010
    4. wking commented on Jul 29, 2010

      wkingmannequin
      MannequinAuthor

      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/

    5. birkenfeld commented on Jul 30, 2010

      @birkenfeld
      Member

      Thanks! Reopening.

    6. added
      stdlib
      type-bug
      and removed
      stale
      on Jul 30, 2010
    7. amauryfa commented on Oct 2, 2010

      @amauryfa
      Contributor

      A unit test is needed. Not to check the code, but to ensure that we don't break it in the future.

    8. vstinner commented on Oct 7, 2010

      @vstinner
      Member

      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.

    9. vstinner commented on Oct 7, 2010

      @vstinner
      Member

      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
    10. vstinner commented on Oct 12, 2010

      @vstinner
      Member

      Fixed in 3.2 (r85386+r85387+r85389), 2.7 (r85390), 3.1 (r85391).

      Thanks labrat for your patch. I added you to Misc/ACKS.

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      stdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions