Skip to content

Commit

Permalink
feat: lower required python version to 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
maxhoesel committed Oct 1, 2021
1 parent ee780ae commit e19f198
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions src/musicbird/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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})")
Expand Down
2 changes: 1 addition & 1 deletion src/musicbird/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/musicbird/prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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/
Expand All @@ -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")),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
2 changes: 1 addition & 1 deletion tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit e19f198

Please sign in to comment.