Mailing List Archive

[issue5117] os.path.relpath problem with root drive directory on windows
New submission from eliben <eliben@gmail.com>:

This is correct:

relpath(r'd:\abc\jho', r'd:\abc')
=> 'jho'

But this isn't:
relpath(r'd:\jho', r'd:\\')
=> '..\jho'

Neither is this:
relpath(r'd:\jho', r'd:')
=> '..\..\..\jho'

----------
components: Library (Lib)
messages: 80860
nosy: eliben
severity: normal
status: open
title: os.path.relpath problem with root drive directory on windows
type: behavior
versions: Python 2.6

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

About this,

>But this isn't:
>relpath(r'd:\jho', r'd:\\')
>=> '..\jho'

Same happens on posixpath.

from posixpath import relpath
print relpath(r'/abc', r'/') #=> ../abc

I'll look at the code.

----------
nosy: +ocean-city

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
eliben <eliben@gmail.com> added the comment:

The problem is with these lines:

start_list = abspath(start).split(sep)
path_list = abspath(path).split(sep)

In case of 'd:\', the split returns two elements, the second empty.

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

I hope attached patch will fix this bug.

----------
keywords: +patch
Added file: http://bugs.python.org/file12904/fix_relpath.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

If it is better _abspath_split("/") to return [""] instead of [] for
consistency, "fix_relpath_v2.patch" might be better. (There is no
difference for relpath behavior though)

Added file: http://bugs.python.org/file12905/fix_relpath_v2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


Removed file: http://bugs.python.org/file12905/fix_relpath_v2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


Added file: http://bugs.python.org/file12906/fix_relpath_v2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

It seems that there is still problem.

>>> ntpath.relpath("//whiterab-c2znlh/foo/", "//whiterab-c2znlh/bar/")
'..\\foo'

This should raise ValueError because "//whiterab-c2znlh/foo" is UNC root
prefix (like "e:" for normal path) not "//whiterab-c2znlh" AFAIK.

I'll look into more deeper...

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp> added the comment:

I hope this works.

Added file: http://bugs.python.org/file12907/fix_relpath_v3.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


Removed file: http://bugs.python.org/file12904/fix_relpath.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


Removed file: http://bugs.python.org/file12906/fix_relpath_v2.patch

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com
[issue5117] os.path.relpath problem with root drive directory on windows [ In reply to ]
Changes by Hirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>:


----------
versions: +Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue5117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/list-python-bugs%40lists.gossamer-threads.com