-
Notifications
You must be signed in to change notification settings - Fork 22
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
Use pathlib in tests and add symlink test #84
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a disclaimer, the handling of filesystem encoding and locale belongs to the "dark magic" parts of beets that I don't really understand in depth.
In principle, it would be great to just have pathlib everywhere, but the benefits of starting to add it here are unclear to me. Could you comment a bit on your motivation to refactor this now? If I remember correctly, there was a project to move beets to pathlib, but that never went anywhere.
My impression is that this might introduce extra friction at the interface between beets and the plugin, given that beets still (tries to) consistently represents everything as bytes internally. I've marked a few places where I'm not sure that the expected types are being used.
I didn't review this PR in full; and I don't think I have the time to do so: That would require going back to the beets code quite a lot and checking my expectations about it.
If I were to make this change myself, I think I'd try to add typings to as much of beets and alternatives as possible to have the support of the type checker in getting it right.
test/cli_test.py
Outdated
@@ -506,7 +493,7 @@ def test_convert_and_embed(self): | |||
self.config["convert"]["embed"] = True | |||
|
|||
album = self.add_album(myexternal="true", format="m4a") | |||
album.artpath = self.IMAGE_FIXTURE1 | |||
album.artpath = str(self.IMAGE_FIXTURE1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure beets expects bytes
here.
@@ -518,14 +505,14 @@ def test_convert_write_tags(self): | |||
|
|||
# We "convert" by copying the file. Setting the title simulates | |||
# a badly behaved converter | |||
mediafile_converted = MediaFile(syspath(item.path)) | |||
mediafile_converted = MediaFile(item.path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
item.path
should be the beets-internal representation (i.e. bytes
), right? Then, from my understanding, the syspath
is required as that represenation is not the correct one to pass to OS APIs on Windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t know enough about MediaFile
to understand what’s going on. But this is test code and it works on both platforms on CI some I’m ok with just using it as is.
mediafile_converted.title = "WRONG" | ||
mediafile_converted.save() | ||
|
||
self.runcli("alt", "update", "myexternal") | ||
item.load() | ||
|
||
alt_mediafile = MediaFile(syspath(self.get_path(item))) | ||
alt_mediafile = MediaFile(self.get_path(item)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In contrast to the above, this passes a pathlib.Path
to Mediafile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I said above, this is test code and works on both platforms so it’s fine
Of course. I’ve been bugged by finding the cause for #74 and my suspicion is that it comes from beets’s path handling. In addition to that, I feel that beets’s path handling is hard to understand, difficult to use and a lot less readable than
I understand your concern. But in my experience the main friction comes from how beets handles paths and how hard that is to understand and predict. For example, you said that beets “tries to“ use bytes for paths but that is not actually the case on Windows where This is also why improved type hints don’t solve the underlying problem. (The would help improve understanding in a lot of other areas, though.)
That’s ok, thanks for your effort anyway. Since this only touches test code (for now) I think it’s ok to play a bit loose with things like the type passed to |
a69b59c
to
9ca498d
Compare
9e226ef
to
aa05a13
Compare
It definitely is, and I don't think there's any documentation on how it's supposed to work. However, I'm not sure whether
It should be the case on Windows as well: From my understanding, the intended usage is
Thus, overall, except for input and at API boundaries, any path handled by beets should always be represented as bytes. I'm pretty sure that there are still some bugs lurking in beets, definitely in some of the vendored plugins and possibly even in the core.
One idea that I mentioned at some point is using newtypes for
I'm still not fully convinced, since this means that the testing code might end up using different types/code paths than the real usage in beets. That said and given that I'm not going to review this in more depth, please ignore my comments and go with your judgement if you're convinced that this should be done! |
Thanks for the reply. I appreciate your input on this. I’ve reflected on the change again but I think the main argument is still very strong: There’s a standard, pythonic way to deal with paths robustly and not care about the OS. That way is different from beets’s but I trust the former more and I believe it is the way forward. I’m willing to deal with the friction that comes from using both. With that in mind, I’ll go ahead and merge this change. I’ll have another PR ready soon that also switches to |
No description provided.