-
-
Notifications
You must be signed in to change notification settings - Fork 146
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
Namespacing for file operations #58
Comments
On one hand, I like namespaces (let's do more of those). On the other hand, this new model is more verbose. I want to explore some concerns with that approach. For the majority of use cases, user's will be invoking the 'file' apis, so when they port their code, they will be replacing 'p.op()' with 'p.file.op()' everywhere. I suspect as they're doing that find/replace in their codebase, they will begin to wonder, "is the .file attribute really necessary?" A secondary concern is that 'file' almost runs contradictory to some operations, such as listdir. I don't see listdir mentioned above. Would directory operations be in their own namespace, then? What about operations that cross purposes (such as mtime or exists)? I believe you're on to something here, but surely the devil is in the details. Do please feel free to put together the experimental branch for further evaluation and discussion. Do consider as well: As currently deployed, path.py is released as a single module. This simplicity of layout allows other projects to "vendor" path.py by adding that module to their project (e.g. Paver). You should try to retain that constraint. It's also too early to drop support for Python 2.7. While I agree that Python 3 is the new target platform for innovation, any project that's going to remain popular will need to support Python 2 for the next year or two. If Python 2.7 support is omitted from the experimental branch, it will certainly be back-ported to 2.7 shortly after its initial release by somebody. Probably better just to maintain Python 2.7 support in the branch if it's not too onerous. If dropping 2.7 support is essential to this effort, then let's ticket the deprecation separately and have this ticket depend on that deprecation. |
Ok, I just pushed 2 branches : experimental, which will be the 'master', but for all the experimental features, and "filenamespacing", which is one feature branch dedicated to namespacing specifically. I worked a bit on namespacing today, and moved most file operations to the Unit tests pass with py.test under Python 2.7 and Python 3.3. For now the result is that come from :
TO
I didn't make crazy changes for now : no removed alias, no renamed methods, etc. I prefer that we agree on each little increment and merge them one at a time. Let me know if I can merge that to "experiment". |
Ok, you seem busy so I took a bet and merged it. I will add more to it later. |
It's true. I've been busy. I don't know when I'll have time to review the proposal in order to answer my questions. |
It's ok, i contribute once a century so I won't complain :) Le mer. 19 mars 2014 10:33:27 CET, Jason R. Coombs a écrit :
|
Just my 2 cents, I don't like the added namespace, it is way too verbose. I would prefer a backward incompatible new version of path.py. Another way to implement file-only methods or properties is to create a subclass to path dedicated to files. This was if the user wants to use a file-only method, he has to explicitly cast the path first. |
I like Nodd's suggestion, but it does fall prey to the problem with OO inheritance. How do you create a File(Path), which is a Path, but which doesn't implement the full interface of a path (directory-only methods)? Perhaps instead you can have the Path class derive from two classes, File and Directory. I'm not even sure that's possible if File and Directory are themselves subclasses of I think an alternate PR would be in order. |
Although these ideas have their merits, we seem to have stalled on a suitable interface. I'm closing for now, but feel free to revive as interest allows. |
I gave some thoughts to the discussion we had here : #26
The
status
proposal gave me an idea. We could actually generalize since thepath
class is becomming big, and maybe it would be beneficial to start separating responsabilities in the lib.Some actions are clearly not related to a path, but to a file such as :
etc
Also, the fact the class
path
is supposed to deal with only a path make it difficult to add handy features that are file related without making it a strange melting pot.This is why I'm suggesting we make a namespace dedicated to file operations. We could simply name it
file
, and it would be used this way :This would remove from the main namespace a lot of methods, making shell exploration easier. It would also be the occasion to remove duplicates, matching the Zen of Python "there should be only one way to do it". Currently we keep several names to match the
os.path
API and aliases for compat reasons. While this is supposed to help, with the current size of the lib, it's becoming less and less convenient to instinctly find the proper method without several trials or looking at the source code.Enventually, it allows us to make the API more modern and adopt a fluid syntaxe :
file
could also be a callable that opens the file and returns a file like object :The
file()
callable would accept all the parameterscodec.open
accept, a bit like whatpath.open
does, but withencoding
as well (set to 'utf8' as default like in Python 3).However, it would not returns a stdlib file like object, but rather a proxy (or a monkeypatched deepcopy for perfs) with all the same attributes except an additional
.path
returning the originalpath
object used to open the file :Last time you shared with me your concern about being backward incompatible, so i'm suggesting this to be added in an experimental branch in which we can play with what can be the future of path.py. Including all rejected features that would have made it backward incompatible, just to see where it leads us.
This branch can be used for future features such as asynchronous file system manipulations, name wrangling, advanced permission checks or anything that is not acceptable to put in the good old path.py.
path.py is now very stable and feature complete, and I don't think it's going to move much. We can safely support this version ad vitam and consider freezing it in the comming years while trying new things on the experimental branch.
Another benefit of the experimental branch is we can drop 2.7 support and focus on Python 3, making the codebase a bit smaller. path.py as is will always be supported for 2.7 and 3 and always be available. We don't really need to touch it.
The text was updated successfully, but these errors were encountered: