[issue10395] new os.path function to extract common prefix based on path components
Changes by Serhiy Storchaka storch...@gmail.com: -- resolution: - fixed stage: patch review - resolved status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Paul Moore added the comment: The patch looks good to me. rhettinger: I'm not sure I see a problem with the doc changes in the latest patch - noting that commonprefix may return an invalid path is fine, and what the current docs say. Directing people to commonpath if they don't want invalid paths also seems fine. Paddy McCarthy: I don't think that the backward compatibility cost of moving os.path.commonprefix is worth it. -- nosy: +paul.moore ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Roundup Robot added the comment: New changeset ec6c812fbc1f by Serhiy Storchaka in branch 'default': Issue #10395: Added os.path.commonpath(). Implemented in posixpath and ntpath. https://hg.python.org/cpython/rev/ec6c812fbc1f -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Serhiy Storchaka added the comment: The patch only adds a reference to commonpath() in commonprefix() documentation. The note about invalid paths already was here. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Paddy McCarthy added the comment: Can we now: 1. Move os.path.commonprefix to str.commonprefix or string.commonprefix 2. Deprecate the use of os.path.commonprefix 3. Add os.path.commonpath 4. Update the documentation. This seems to have lingered for too long and yet people have been willing to do the work it seems (from 1999). -- nosy: +Paddy McCarthy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Serhiy Storchaka added the comment: Here is revised patch. The behavior is changed in correspondence with results of Python-ideas discussion, extended tests, fixed several bugs. -- keywords: +patch stage: commit review - patch review Added file: http://bugs.python.org/file35942/ospath_commonpath.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Raymond Hettinger added the comment: This patch looks reasonable except for the doc change to os.path.commonprefix(). Remember, that function IS working as documented and that our policy is to document in an affirmative manner (here is what the function does and how to use it versus being preachy about broken-by-design etc.) -- nosy: +rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Éric Araujo mer...@netwok.org: -- stage: patch review - commit review versions: +Python 3.5 -Python 3.4 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Serhiy Storchaka storch...@gmail.com: -- assignee: - serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Serhiy Storchaka added the comment: Some conclusions of discussion at Python-ideas (http://comments.gmane.org/gmane.comp.python.ideas/17719): 1. commonpath() should eat double slashes in input (['/usr/bin', '/usr//bin'] - '/usr/bin'). In any case the current implementation eats slashes on output (['/usr//bin', '/usr//bin'] - '/usr/bin', not '/usr//bin'). 2. commonpath() should raise an exception instead of returning None on incompatible input. 3. May be commonpath() should eat also '.' components and return '.' instead of '' when relative paths have no common prefix. I am not sure. In general the current patch looks good enough. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Rafik Draoui ra...@rafik.ca: Added file: http://bugs.python.org/file27974/patch10395-3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Rafik Draoui added the comment: Here is a new patch addressing some of storchaka review comments, and implementing a version in ntpath. For the Windows version, I did as proposed in msg174819, but as I am not familiar with the semantics and subtleties of paths in Windows maybe this version of ntpath.commonpath is too simplistic and would return wrong results in some cases. I would like someone more knowledgeable in Windows to take care of it, or maybe just provide a test suite with lots of different corner cases that I could use to provide a better implementation. -- Added file: http://bugs.python.org/file27899/patch10395-2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Rafik Draoui added the comment: Here is a patch with an implementation of os.path.commonpath, along with tests and documentation. At the moment, this is only implemented for POSIX, as I don't feel like I know enough about Windows to tackle drive letters and UNC in paths without spending some more time on it. This probably needs more tests for corner cases. -- nosy: +rafik Added file: http://bugs.python.org/file27883/patch10395 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Serhiy Storchaka storch...@gmail.com: -- stage: needs patch - patch review ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Serhiy Storchaka added the comment: At the moment, this is only implemented for POSIX, as I don't feel like I know enough about Windows to tackle drive letters and UNC in paths without spending some more time on it. Just use splitdrive() and first ensure that all drivespecs are same, then find common prefix for pathspecs. -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Éric Araujo added the comment: Rafik is working on os.path.commonpath for the bug day. -- versions: +Python 3.4 -Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Santoso Wijaya santoso.wij...@gmail.com: -- nosy: +santa4nt versions: +Python 3.3 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Eric Snow ericsnowcurren...@gmail.com added the comment: You can already get the better prefix using os.path, albeit less efficiently. Here's an example: def commondirname(paths): subpath = os.path.commonprefix(paths) for path in paths: if path == subpath: return subpath else: return os.path.join(os.path.split(subpath)[0], ) However, would it be better to implicitly normalize paths first rather than doing a character-by-character comparison? Here is an unoptimized demonstration of what I mean: def commondirname(paths): result = for path in paths: path = os.path.normcase(os.path.abspath(path)) if not result: result = path else: while not path.startswith(result + os.path.sep): result, _ = os.path.split(result) if os.path.splitdrive(result)[1] == os.path.sep: return result return result -- nosy: +ericsnow ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Roman Evstifeev someuniquen...@gmail.com: -- nosy: +Roman.Evstifeev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
Changes by Éric Araujo mer...@netwok.org: -- nosy: +eric.araujo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10395] new os.path function to extract common prefix based on path components
R. David Murray rdmur...@bitdance.com added the comment: Indeed, as I remember it there are people using commonprefix as a string function in situations having nothing to do with os paths. I'm changing the title to reflect the fact that this is really a feature request for a new function. IMO it is a reasonable feature request. Finding a name for it ought to be an interesting exercise. I think that this should only be accepted if there is also a windows implementation. -- nosy: +r.david.murray stage: - needs patch title: os.path.commonprefix broken by design - new os.path function to extract common prefix based on path components type: - feature request ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue10395 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com