Skip to content
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

acousticbrainz: refactor plugin #2251

Merged
merged 9 commits into from
Nov 20, 2016
Merged

acousticbrainz: refactor plugin #2251

merged 9 commits into from
Nov 20, 2016

Conversation

nathdwek
Copy link
Member

Personally I like this rewrite very much. However, the rewrite is sizeable, there is no test coverage and I do not even use this plugin, so we should think twice about it before merging.

Summary of changes:

  • drop reduce and operator although they were not outrageously misused
  • separate information scheme from logic
  • simplify some functions

@ghost
Copy link

ghost commented Oct 31, 2016

can you split it into more commits then? make it much easier to review.

@nathdwek
Copy link
Member Author

I probably should :). I just liked this solution very much and because there was no tests to look over my shoulder I wanted to get feedback as I go on (Also it was 3AM).

@nathdwek
Copy link
Member Author

I split it up in two commits, that's really the best I could do.
If everything goes well, the linter should not complain anymore.
I improved some things, and managed to test it on my setup: it seems to work.
Docstrings for the interesting bits are coming.

data = self._get_data(item.mb_trackid)
if data:
# Get each field and assign it on the item.
item.danceable = get_value(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I tried my best to convince git this whole patch did not change as much as git thinks it did, but to no avail.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This looks good to me so far—I very much like this declarative approach better than the old imperative one. I haven't actually tried running it, but I say we merge it if it seems to work after a little bit of experimentation. (And then, of course, we should try to add some end-to-end tests using captured AB service responses.)

def _fetch_info(self, items, write):
"""Get data from AcousticBrainz for the items.
"""
for item in (item for item in items if item.mb_trackid):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, this strikes me as slightly less idiomatic than:

for item in items:
    if not item.mb_trackid:
        continue

but I definitely don't have a strong argument against it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not like it either when I wrote it, I think I will go back on it.

if write:
item.try_write()

def _map_dict_to_scheme(self, dictionary, scheme):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It goes without saying, but these helpers (this one and the one below) could use some nice docstrings to explain how they fit together.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I plan for all of these to have docstrings, but this one especially is hard to get right!

@nathdwek
Copy link
Member Author

nathdwek commented Nov 1, 2016

The bulk of the doc is in! Let me know what you think.

I'm continuing to do some rudimentary tests on my machine, but if anyone here uses this plugin extensively or knows its potential quirks, it would be nice to have some cross checks or results.

@nathdwek
Copy link
Member Author

nathdwek commented Nov 5, 2016

I'm writing unit tests and there are remaining obvious blunders in my code. Hopefully I'll fix those and then get out an integration test as well.

@nathdwek
Copy link
Member Author

nathdwek commented Nov 5, 2016

I added a test with realistic data for the business logic, and the validation data was generated using the plugin on master. So far so good. I think I just need to get an integration test out now.

@nathdwek nathdwek changed the title [Needs testing] acousticbrainz: refactor plugin acousticbrainz: refactor plugin Nov 8, 2016
@nathdwek
Copy link
Member Author

Two questions:

  • How would you go about implementing an integration test? Are there dummy albums on acousticbrainz for this purpose (IIRC there are on musicbrainz, and we use them)? Is is absolutely necessary?
  • I just realized DefaultList doesn't support slicing. I'd say YAGNI on this one. I will definitely add this to the doc, but maybe also we should throw an adequate NotImplementedError?

@nathdwek
Copy link
Member Author

nathdwek commented Nov 17, 2016

I took a step towards simplifying the approach a bit by dropping DefaultList. I think I am going to merge this very soon.

nath@home added 8 commits November 20, 2016 22:03
* Less lazy names
* Separate root function from childs more naturally
* Actually use defaultdict
* I don't see DefaultList be really helpful in many other cases, so having
  a beets.util.collections module (which could also conflict with the collections
  module from standard library) with only that in it is a little silly.
* It was elegant and concise, but there are implementation issues: it is not
  recommended to subclass builtin types, but the alternatives differ between python
  2 and 3 (subclass sequence or container or collections.abc?), moreover,
  interpreters can differ in the way they map syntaxic sugar to magic functions.
* Also, slicing and negative indexing could do weird things, so the class wouldn't
  be really intuitive and simple at the same time
* Readability and consistency
* Better logging: warn by default for attributes that were not found,
  but don't drown user with info when everything is going well.
@nathdwek
Copy link
Member Author

Here it comes.

@nathdwek nathdwek merged commit 871a815 into master Nov 20, 2016
nathdwek pushed a commit that referenced this pull request Aug 15, 2018
@arcresu arcresu deleted the drop-reduce branch April 24, 2019 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants