Skip to content

Commit

Permalink
fix typo in release history + fix m3u load logic on empty file
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-martino committed Jul 23, 2024
1 parent a8f2eaf commit 68df56c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
15 changes: 12 additions & 3 deletions docs/info/release-history.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
`.. Add log for your proposed changes here.
.. Add log for your proposed changes here.
The versions shall be listed in descending order with the latest release first.
Expand Down Expand Up @@ -32,13 +32,23 @@ The format is based on `Keep a Changelog <https://keepachangelog.com/en>`_,
and this project adheres to `Semantic Versioning <https://semver.org/spec/v2.0.0.html>`_


1.1.3
=====

Fixed
-----
* When given an empty :py:class:`.M3U` playlist file, produces expected result i.e. an empty playlist.
Previously always added all given tracks to playlist when calling :py:meth:`.M3U.load`


1.1.2
=====

Changed
-------
* :py:meth:`.File.get_filepaths` now ignores hidden files.
* Replace os.makedirs with Pathlib implementation of ``mkdir``q everywhere.
* Replace os.makedirs with Pathlib implementation of ``mkdir`` everywhere.


1.1.1
=====
Expand Down Expand Up @@ -498,4 +508,3 @@ Fixed
=====

Initial release! 🎉
`
5 changes: 5 additions & 0 deletions musify/libraries/local/playlist/m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ async def load(self, tracks: Collection[LocalTrack] = ()) -> Self:
paths_raw = self.path_mapper.map_many([line.strip() for line in file], check_existence=True)
path_list = list(map(Path, paths_raw))

if not path_list: # empty playlist file
self.clear()
self._original = []
return self

self.matcher = FilterDefinedList(values=path_list)
self.matcher.transform = lambda x: Path(self.path_mapper.map(x, check_existence=False))

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ test = [
]
docs = [
"musify[build]",
"sphinx~=7.3",
"sphinx~=7.4",
"renku_sphinx_theme",
"graphviz~=0.20",
"sphinx-autodoc-typehints~=2.2",
Expand Down
11 changes: 11 additions & 0 deletions tests/libraries/local/playlist/test_m3u.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def test_init_fails(self):
with pytest.raises(InvalidFileType):
M3U(path=path_txt)

async def test_load_from_empty_file_with_tracks(self, tracks: list[LocalTrack], tmp_path: Path):
path = tmp_path.joinpath("test").with_suffix(".m3u")
path.touch(exist_ok=True)

pl = M3U(path=path)
await pl.load(tracks=tracks)

assert not pl
assert not pl.tracks
assert not pl._original

async def test_load_fake_file_with_no_tracks(self, tracks: list[LocalTrack], tmp_path: Path):
path_fake = tmp_path.joinpath("does_not_exist").with_suffix(".m3u")

Expand Down

0 comments on commit 68df56c

Please sign in to comment.