-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new function: os.path.relpath #42530
Comments
Hello, This patch adds a 'relpath' function to module os.path Here's a description of this function: This patch includes Windows and *nix versions. Note: there is no 'classic mac' version as I don't know Changed files are: I'll send a second patch for the documentation shortly. As this is my first submission please be gentle with me |
Logged In: YES Thanks for the patch, it's not in bad shape. Please attach A couple of things about the patch. Some of these should be
Another note that isn't a big deal. It's good that you made You can attach new versions to this tracker item, but try to |
Logged In: YES Hi, Thanks for all your comments; I'll amend my code & re-submit " By adding this check on the input I wanted to avoid this >>> os.path.relpath('')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/cvsrep/python/dist/src/Lib/posixpath.py", line
473, in relpath
return os.path.join(*rel_list)
TypeError: join() takes at least 1 argument (0 given) Which to me is obscure and forces you to dive into the " When writing this I tried to maintain a consistent style Regards, Richard |
Logged In: YES To the OP: have you completed the patch? To the others: is this okay to get into 2.5? |
Logged In: YES Most of the patch is completed as per Neal's suggestions for |
Logged In: YES Sorry Richard. It's still in my inbox. I'll try to get to |
Logged In: YES Hi all, |
Logged In: YES Here is a second version of the 'relpath' function.
This function (if accepted) will also require the following relpath(path, start=os.curdir)
Return a relative filepath to 'path' either from the current
directory or from an optional 'start' point. |
I've attaching a tweaked/updated version of this patch. Is anyone bothered that there's no OS/2 or classic Mac implementation for this? If not, I can go ahead and commit it. File Added: relpath.patch |
Since there is an "Availability" remark, I wouldn't be concerned. |
Checked in as r54419. Thanks for the patch, Richard! |
The test fails on Windows. In particular, this test: self.assertEqual(posixpath.relpath(os.path.abspath("a")), "a") fails. os.path.abspath("a") gives something like r"c:\python26\a". posixpath.relpath is then not able to cope with it. As a result, it returns r"c:\python26\a" as the relative path. Using posixpath.abspath doesn't help, either, since that will give r"c:\python26/a" which relpath then still cannot process correctly. One solution would be to use pass a POSIX path and start path to relpath; the other would be to use os.path in both cases. |
Since the trouble is os.getcwd() returns a non-posix path on Windows, I've taken the approach of mocking os.getcwd() so that it returns something posix-y. Martin, could you verify that the attached patch works on Windows? |
The patch works fine, please apply. |
Checked in as r54556. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: