diff --git a/docs/source/install.rst b/docs/source/install.rst index b3d5494..1cb3458 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -13,7 +13,7 @@ Requirements To run MusicBird you need: * A machine running a recent distribution of Linux with enough CPU power to convert music files -* Python 3.8 or later +* Python 3.6 or later * :code:`pip` * :code:`ffmpeg` installed and ready to go diff --git a/src/musicbird/db.py b/src/musicbird/db.py index 318626c..dbebb33 100644 --- a/src/musicbird/db.py +++ b/src/musicbird/db.py @@ -117,7 +117,7 @@ def __init__(self, path: Path, delete: bool = False, pretend: bool = False) -> N self._init_db_con(pretend=True) elif delete and not pretend: try: - path.unlink(missing_ok=True) + path.unlink() logger.info(f"Removed previous database at {self.path}") except FileNotFoundError: pass @@ -202,7 +202,8 @@ def _init_db_con(self, pretend: bool = False): self._con = sqlite3.connect(":memory:", check_same_thread=False) else: self.path.parent.mkdir(parents=True, exist_ok=True) - self._con = sqlite3.connect(self.path, check_same_thread=False) + # Python <= 3.7 needs a string instead of a Path object + self._con = sqlite3.connect(str(self.path), check_same_thread=False) self._con.row_factory = sqlite3.Row with self._con: self._con.execute(f"CREATE TABLE IF NOT EXISTS {SQLiteLibrary._FILES_TABLE} ({columns})") diff --git a/src/musicbird/encoder.py b/src/musicbird/encoder.py index 0f73749..909a735 100644 --- a/src/musicbird/encoder.py +++ b/src/musicbird/encoder.py @@ -53,7 +53,7 @@ def __init__(self, config: Dict) -> None: # Check if we can access ffmpeg try: - subprocess.run(["ffmpeg", "-version"], capture_output=True, check=True) + subprocess.run(["ffmpeg", "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True) except FileNotFoundError as e: logger.fatal("Could not access ffmpeg. Pease make sure that it is installed") raise e diff --git a/src/musicbird/prune.py b/src/musicbird/prune.py index 1cd4b24..48682fa 100644 --- a/src/musicbird/prune.py +++ b/src/musicbird/prune.py @@ -53,13 +53,18 @@ def prune(config: Dict, db: LibraryDB, pretend=False) -> bool: dest = file.get_dest_path(config) if not pretend: try: - dest.unlink(missing_ok=True) + dest.unlink() + except FileNotFoundError: db.remove_file(file) successes.append(file) logger.info(f"Removed file: {dest}") except OSError as e: logger.error(f"Could not remove file {dest}: {repr(e)}") failures.append(file) + else: + db.remove_file(file) + successes.append(file) + logger.info(f"Removed file: {dest}") else: successes.append(file) db.remove_file(file) diff --git a/tests/conftest.py b/tests/conftest.py index 752b08f..5ac935e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,5 +1,6 @@ # pylint: disable=redefined-outer-name +from distutils.dir_util import copy_tree from pathlib import Path from typing import Dict, List, Tuple import shutil @@ -20,7 +21,7 @@ def library_and_db(library) -> Tuple[Path, Dict[Path, Dict], LibraryDB]: @pytest.fixture def library(tmp_path) -> Tuple[Path, List[File]]: - """Creates a temporary library that contains tes files to use. + """Creates a temporary library that contains test files to use. The returned path has the following directory structure: tmp_path/ @@ -34,7 +35,8 @@ def library(tmp_path) -> Tuple[Path, List[File]]: """ files_path = "tests/files" - shutil.copytree(files_path, Path(tmp_path), dirs_exist_ok=True) + # shutils.copytree takes Path objects, but the exist_ok flag was only added in Python 3.8 + copy_tree(files_path, str(Path(tmp_path))) config = { "source": str(Path(tmp_path).joinpath("library")), "destination": str(Path(tmp_path).joinpath("dest")), diff --git a/tests/unit/test_cli.py b/tests/unit/test_cli.py index 23c6e67..40bfe27 100644 --- a/tests/unit/test_cli.py +++ b/tests/unit/test_cli.py @@ -5,11 +5,11 @@ def test_command_entrypoint(): args = ["musicbird", "--version"] - result = subprocess.run(args, check=True, capture_output=True) + result = subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert __version__ == result.stdout.decode(encoding="utf-8").rstrip('\n') def test_module_call(): args = ["python3", "-m", "musicbird", "--version"] - result = subprocess.run(args, check=True, capture_output=True) + result = subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert __version__ == result.stdout.decode(encoding="utf-8").rstrip('\n') diff --git a/tests/unit/test_config.py b/tests/unit/test_config.py index 6b67c15..2500c9a 100644 --- a/tests/unit/test_config.py +++ b/tests/unit/test_config.py @@ -34,7 +34,7 @@ def test_config_print_command(library: Tuple[Path, List[File]]): with workdir.joinpath("config.yml").open() as f: config: Dict = yaml.safe_load(f) args = ["musicbird", "-c", str(workdir.joinpath("config.yml")), "config", "print", "--format", "json"] - result = subprocess.run(args, check=True, capture_output=True) + result = subprocess.run(args, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert config.items() <= json.loads(result.stdout).items() diff --git a/tox.ini b/tox.ini index 4a8069e..216a6a0 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,13 @@ [tox] envlist = - py3{8,9}, + py3{6,7,8,9}, lint docs [gh-actions] python = + 3.6: py36 + 3.7: py37 3.8: py38 3.9: py39