-
Notifications
You must be signed in to change notification settings - Fork 100
Add pathlib support #123
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
base: master
Are you sure you want to change the base?
Add pathlib support #123
Conversation
|
Perhaps you could use a try-except import to check if pathlib is available, and instead provide an option to disable this behavior. This would make |
|
Sure. I've changed the decorator to try-except the pathlib import, fallling back to the usual behavior. One drawback of it, like you've mentioned, is that it will break for any project that doesn't have a pinned version and has pathlib available. The solution is simple though (wrapping value in I like that solution, because again, like you've mentioned, we get Path objects out of the box when it is available. |
|
I do think the pathlib support should be an opt-in. Otherwise, this becomes a major backward incompatible change since basically everyone with Python 3 has to update all their uses and there's no way to have gradual adoption. |
|
Back to this. @pradyunsg Would incrementing the major version be a valid compromise? |
|
I like @keturn 's suggestion of having a separate entry point for As a first pass, I would subclass the AppDirs object like this in a separate module: class AppPaths(AppDirs):
def user_data_dir(self):
s = super(AppPaths, self).user_data_dir()
return Path(s)
...However, to keep with the zero-dependency, vendorisable structure of this library, the whole thing would need to be done in an appdirs wouldn't benefit from Paths being great, but everyone who's making the correct decision of A) using modern python and B) using Paths, would have their choices validated and have the added convenience. |
|
I like that suggestion. I don't mind implementing it, if everyone agrees. |
Hello there.
As you must know, Python has since 3.4 included
pathlibin the standard library, as discussed in PEP 428. Long story short, it's a very nice API to the filesystem that now comes default with Python.I understand that this software aims to have 0 dependencies and at the same time supports
python >=2.7.*. This might be a bit of a blocker, but I tried to keep it as portable as possible, with minimal modifications:AppDirsclass is modified. This means, all other functions/methods preserve their types and have no relationship topathlib.AppDirsis added a new attributeuse_pathlib, to determine whetever to usepathlib. It'sFalseby default, to preserve backwards compability.propertydecorator is replaced by a custom decoratorpath_property.path_propertyis still a property, but with an added check for theuse_pathlibattribute. Only if it's true, does it importpathliband coverts the path string to a Path object. If this branch is taken on a older Python installation, this will break, unlesspathlibis explictily installed withpip.Let me know your opinion on this.