Commit Graph

6048 Commits

Author SHA1 Message Date
Philipp Wolfer
601df7b158 Simpified initializing Metadata() in formats tests 2019-03-26 07:32:59 +00:00
Laurent Monin
22a1a104fd Merge pull request #1146 from zas/pylint_cleanup
Pylint errors/warnings cleanup
2019-03-25 21:43:22 +01:00
Laurent Monin
f2823f165d Merge pull request #1147 from zas/fix_country_list
Fix country list
2019-03-25 17:57:09 +01:00
Laurent Monin
c80ae1344b Name countries-related tests, classes and variables consistently 2019-03-25 14:40:52 +01:00
Laurent Monin
a458bbe2ff country_list_from_node() -> countries_from_node() 2019-03-25 14:38:51 +01:00
Laurent Monin
a930e688e3 country_list_from_node(): country -> countries
That's a list of countries.
2019-03-25 14:36:56 +01:00
Laurent Monin
f9e1373d9a country_list_from_node(): returns [] instead of implicit None if no release-event in node
Since this code was introduced in f8559fdd7, it was returning None implicitly if no "release-events" were found in node.
This behavior differs from other methods of the same kind like release_dates_and_countries_from_node()

This change shouldn't have any negative impact, since callers always test for emptyness
2019-03-25 14:36:56 +01:00
Laurent Monin
5ae92454f4 Add a test for release without events vs countries 2019-03-25 14:36:56 +01:00
Laurent Monin
8fe3ee23d8 Address PyLint W0105: convert to valid docstrings, they have to be at top 2019-03-25 13:11:38 +01:00
Laurent Monin
95eb1c8904 Fix PyLint W0221: use a property instead of passing a parameter, no use outside this file
picard/webservice/__init__.py:218:4: W0221: Parameters differ from overridden '_init_headers' method (arguments-differ)
picard/webservice/__init__.py:229:4: W0221: Parameters differ from overridden '_init_headers' method (arguments-differ)
picard/webservice/__init__.py:238:4: W0221: Parameters differ from overridden '_init_headers' method (arguments-differ)
picard/webservice/__init__.py:247:4: W0221: Parameters differ from overridden '_init_headers' method (arguments-differ)
2019-03-25 13:11:38 +01:00
Laurent Monin
3d38e39a1f Fix PyLint R1704: rename local a & b to av & bv
picard/similarity.py:55:8: R1704: Redefining argument with the local name 'a' (redefined-argument-from-local)
picard/similarity.py:58:22: R1704: Redefining argument with the local name 'b' (redefined-argument-from-local)
2019-03-25 13:11:38 +01:00
Laurent Monin
6b1b97e41b Fix PyLint W0221: Mapping.get() is using key not name
picard/metadata.py:307:4: W0221: Parameters differ from overridden 'get' method (arguments-differ)

https://hg.python.org/cpython/file/3.5/Lib/_collections_abc.py#l594
2019-03-25 13:11:38 +01:00
Laurent Monin
42b0cdcd17 Fix PyLint W0611: import is unused because code is using picard.api_versions not api_versions
picard/plugin.py:35:0: W0611: Unused api_versions imported from picard (unused-import)
2019-03-25 13:11:38 +01:00
Laurent Monin
7c1f5efcad Fix PyLint R0201 and R0203
picard/formats/mutagenext/tak.py:45:4: R0201: Method could be a function (no-self-use)
picard/formats/mutagenext/tak.py:55:4: R0203: Consider using a decorator instead of calling staticmethod (no-staticmethod-decorator
2019-03-25 13:11:38 +01:00
Laurent Monin
f0adc86f89 Disable PyLint C0123, this is intentional as explained in the comment 2019-03-24 17:48:59 +01:00
Laurent Monin
d7b77141eb Remove unused imports
picard/ui/util.py:20:0: W0611: Unused QtGui imported from PyQt5 (unused-import)
picard/ui/util.py:31:0: W0611: Unused icontheme imported from picard.util (unused-import)
2019-03-24 17:47:07 +01:00
Laurent Monin
2c457b8dcd Fix PyLint E0202
picard/config.py:260:4: E0202: An attribute defined in picard.config line 244 hides this method (method-hidden)
picard/config.py:287:4: E0202: An attribute defined in picard.config line 244 hides this method (method-hidden)
2019-03-24 17:44:18 +01:00
Laurent Monin
30449d56f7 Fix E1003: Bad first argument 'CoverArtProviderCaa' given to super() (bad-super-call) 2019-03-24 14:49:48 +01:00
Laurent Monin
4983631f70 Merge pull request #1142 from zas/coverimage_metadata_cleanup
CoverArtImage/ImageList/Metadata cleanup
2019-03-24 14:33:50 +01:00
Laurent Monin
7fe2fda12e Merge pull request #1144 from zas/cluster_match_cleanup
Clean up various matching iterations, unify a bit
2019-03-24 14:33:26 +01:00
Laurent Monin
195f3ab9bb Drop debug parameter and associate output, make code easier to read 2019-03-24 12:10:12 +01:00
Laurent Monin
6ab7755f74 Use same parameter name as the overridden method, fixing a pylint warning
https://github.com/metabrainz/picard/pull/1142#discussion_r268423763

Replace `image` by `value` according to https://hg.python.org/cpython/file/3.5/Lib/_collections_abc.py#l895
2019-03-24 12:06:20 +01:00
Laurent Monin
1159df51da Remove extra parenthesis 2019-03-24 11:36:10 +01:00
Laurent Monin
3cbcc1cf0e Reduce code redundancy, using a locally-defined method to output messages 2019-03-23 18:45:24 +01:00
Laurent Monin
7e8235ebf8 rg_id -> release_group_id 2019-03-23 17:19:06 +01:00
Laurent Monin
b9bcf47805 Album._match_files(): add a debug parameter
- it will ease testing, using debug=False will not call log.debug()
2019-03-23 17:13:15 +01:00
Laurent Monin
ecf3cbb3bc Move part of File._lookup_finished() to new File._match_to_track()
- separate UI-related code from processing code
- it will ease testing
2019-03-23 17:11:14 +01:00
Laurent Monin
5e4b698c25 Move part of code from Cluster._lookup_finished() to new _match_to_album()
It will ease testing, separating UI-related code from processing code
2019-03-23 16:46:09 +01:00
Laurent Monin
b33e59428f Clean up various matching iterations, unify a bit
- use generators for candidates
- introduce picard.util.find_best_match() and sort_by_similarity() with tests
- partially revert change that removed sorted(), it was actually faster and cleaner
- use namedtuples to get rid of numeric indexes
- when no match, output max similarity, threshold and number of candidates to debug log
- make code easier to understand, using long names and namedtuple attributes, and simpler workflow
- use repr(best_match) for debug, as it provides all the needed info
- set values explicitly using namedtuple kw parameters
- use same prefix for namedtuples names, it eases searching through code

Typical debug output looks like:
```
D: 13:16:41,806 cluster._lookup_finished:223: BestMatch(similarity=0.79, result=SimMatchRelease(similarity=0.79, release={'id': '36b8f767-c4c0-4ba1-becd-f40a452303d5', 'score': 79, 'count': 1, 'title': 'Purple', 'status': 'Official', 'packaging': 'Jewel Case', 'text-representation': {'language': 'eng', 'script': 'Latn'}, 'artist-credit': [{'artist': {'id': '8c32bb01-58a3-453b-8050-8c0620edb0e5', 'name': 'Stone Temple Pilots', 'sort-name': 'Stone Temple Pilots'}}], 'release-group': {'id': '01d45519-54a6-3427-b0dc-222203fa5d57', 'type-id': 'f529b476-6e62-324f-b0aa-1f3e33d313fc', 'title': 'Purple', 'primary-type': 'Album'}, 'date': '1995-08-25', 'country': 'US', 'release-events': [{'date': '1995-08-25', 'area': {'id': '489ce91b-6658-3307-9877-795b68554c98', 'name': 'United States', 'sort-name': 'United States', 'iso-3166-1-codes': ['US']}}], 'track-count': 11, 'media': [{'format': 'CD', 'disc-count': 10, 'track-count': 11}]}), num_results=25) < threshold=0.800000
```
2019-03-23 16:29:44 +01:00
Laurent Monin
4730e42e45 Merge pull request #1143 from zas/fix_missing_clear_existing_tags
Cleanup missing clear existing tags setting fix
2019-03-23 10:51:09 +01:00
Laurent Monin
7e3c9673c8 Add test for Metadata.apply_func() with preserved tags 2019-03-22 11:04:44 +01:00
Laurent Monin
b81947e22d Add test for Metadata.strip_whitespace() 2019-03-22 10:54:31 +01:00
Laurent Monin
b3d1ef2f41 Metadata.strip_whitespace(): no need of lambda, directly pass str.strip 2019-03-22 10:54:09 +01:00
Laurent Monin
99896bff8b Add tests for ImageList copy()/clear()/del
Note: clear() is apparently inherited, i read docs saying otherwise, so i add a test for it to be sure
2019-03-22 10:32:32 +01:00
Laurent Monin
3a44ec41e2 Disable pylint warning about ImageList.insert() 2019-03-22 10:32:32 +01:00
Laurent Monin
9340c6c2ec Drop Metadata.set_front_image(), replace with ImageList.strip_front_images()
- only used in ui/coverartbox.py and not directly linked to metadata
- add tests
-
2019-03-22 10:32:31 +01:00
Laurent Monin
76b85a4e1f Introduce ImageList.copy()
- imagelist[:] returns a list, not an ImageList
- it returns an instance of ImageList
2019-03-22 10:32:31 +01:00
Laurent Monin
caa03f3f0a ImageList: inherit from MutableSequence instead of list
Note: i got rid of old __getitem__() which makes no sense imho
It returned an instance of itself for each element, not sure what was the goal
2019-03-22 10:32:31 +01:00
Laurent Monin
78c9890e21 Drop Metadata.append_image(), use Metadata.images.append() instead 2019-03-22 10:32:31 +01:00
Laurent Monin
6bf103bf34 Drop useless Metadata.remove_image() 2019-03-22 10:32:31 +01:00
Laurent Monin
0b837ebe8d Move Metadata.images_to_be_saved_to_tags() to ImageList.to_be_saved_to_tags()
- make it a generator
- drop @property, it's a function, no point in hiding it
- add tests
2019-03-22 10:32:31 +01:00
Laurent Monin
eb73ea6bc4 Replace Metadata.get_single_front_image() with ImageList.get_front_image()
- it makes much more sense, Metadata.images is an ImageList
- minimal changes required
- add tests for it
2019-03-22 10:32:31 +01:00
Laurent Monin
d60afe35d7 ImageList(): fix untestable class, since it requires gettext...
- image.types_as_string() was called from get_image_type() without translate=False
- dependency wasn't satisfied, so impossible to test as is
- make tests depending on languages isn't a good idea anyway
- use new CoverArtImage.normalized_types() instead
- simplify code
- add tests for ImageList.append() and ImageList.__eq__()
2019-03-22 10:32:31 +01:00
Laurent Monin
45e70a676f CoverArtImage: add a function normalizing types
This is needed because types can be in any order (and even contains duplicate)
So output of types_as_string() was differing, depending on how types were set
2019-03-22 10:32:31 +01:00
Laurent Monin
9d7b8dc995 CoverArtImage.__init__(): add parameters to override supported types
It's convenient for testing
2019-03-22 10:32:31 +01:00
Laurent Monin
bc11a330ab Introduce SettingsOverride class to fix this more elegantly
- basically it returns config.setting[key] when key isn't in the internal dict
- it protects config.setting from any write, since __setitem__ only write to self._dict
- del settings['xxx'] will remove 'xxx' from internal dict, but still allow access to config.setting
- it can be used for tests
- minimal implementation based on MutableMapping
- add tests for it
2019-03-22 10:29:57 +01:00
Laurent Monin
25ceef01e4 Remove unused (and obsolete) use_va_format from settings 2019-03-22 10:29:57 +01:00
Laurent Monin
26b5f56f04 Sort settings 2019-03-22 10:29:57 +01:00
Laurent Monin
4990cef589 Fix crash introduced when opening Options: KeyError: 'clear_existing_tags'
It was introduced in 04dcd4691b, settings for examples were missing this setting
2019-03-22 10:28:56 +01:00
Laurent Monin
ca069ae767 Merge pull request #1141 from zas/metadata_use_cleanup
Metadata cleanup, second pass
2019-03-21 21:52:14 +01:00