Works around the issue that os.path.isabs detects a path like \\server\share not as absolute.
This can break file naming on Windows shares and result in recursive sub folders.
See also https://bugs.python.org/issue22302
- catch exceptions in extract_year_from_date() and log them to debug
- return None if year cannot be extracted
- check for None in metadata.compare_to_release_parts() before trying to compare years
This isn't perfect, the function is called a lot of time and it spams debug log (if enabled)
Note: I removed a very old comment in imports that doesn't make any sense (it was introduced 6 years ago in 323d12892c) and it was making isort unhappy.
In identify(), comparaison was done against `str` instead of `bytecode`, due to the lack of `b` prefix
ImageInfoTest: add missing test PDF file identification
With this change backslashes can be used in filenames on systems other than Windows. Only if Windows compatibility is activated backslashes will be replaced as before.
- 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
```
Add a config for isort (https://github.com/timothycrosley/isort)
Run isort -rc . and make import style consistent across files
Add a note about `isort` in CONTRIBUTING.md
The unit tests only consider the string and whether any path component starts with a ".". On Windows the dotfiles are not used for hidden files so the tests fail. To have proper tests on Windows would require to have an actual folder structure with hidden files and folders.
This will allow explicit loading of hidden files, but still will ignore hidden files and folders on deeper levels if the "show_hidden_files" option is disabled.
This fixes PICARD-589 and improves PICARD-528.