diff --git a/README.md b/README.md index ee8c147..2a0fd1e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,10 @@ # bandcamp-importer -Process Bandcamp downloads and import into Plex + +Auto-generated by poetry-slam. + + +## Usage + +```bash +bandcamp_importer --help +``` diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..edc0b63 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,54 @@ +[tool.poetry] +name = "bandcamp-importer" +version = "1.0" +description = "bandcamp-importer: automatically generated by poetry-slam." +authors = ["evilchili "] +readme = "README.md" +packages = [ + {include = "*", from = "src"}, +] + +[tool.poetry.dependencies] +python = "^3.10" +python-dotenv = "^0.21.0" +rich = "^13.7.0" +typer = "^0.9.0" + +[tool.poetry.group.dev.dependencies] +pytest = "^8.1.1" +pytest-cov = "^5.0.0" + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api" + + +[tool.poetry.scripts] +bandcamp_importer = "bandcamp_importer.cli:app" + + +### SLAM + +[tool.black] +line-length = 120 +target-version = ['py310'] + +[tool.isort] +multi_line_output = 3 +line_length = 120 +include_trailing_comma = true + +[tool.autoflake] +check = false # return error code if changes are needed +in-place = true # make changes to files instead of printing diffs +recursive = true # drill down directories recursively +remove-all-unused-imports = true # remove all unused imports (not just those from the standard library) +ignore-init-module-imports = true # exclude __init__.py when removing unused imports +remove-duplicate-keys = true # remove all duplicate keys in objects +remove-unused-variables = true # remove unused variables + +[tool.pytest.ini_options] +log_cli_level = "DEBUG" +addopts = "--cov=src --cov-report=term-missing" + +### ENDSLAM diff --git a/src/bandcamp_importer/__init__.py b/src/bandcamp_importer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/bandcamp_importer/cli.py b/src/bandcamp_importer/cli.py new file mode 100644 index 0000000..68d2cd4 --- /dev/null +++ b/src/bandcamp_importer/cli.py @@ -0,0 +1,57 @@ +import io +import logging +from pathlib import Path +from typing import Optional + +import typer +from dotenv import load_dotenv +from rich.logging import RichHandler + +CONFIG_DEFAULTS = """ +# bandcamp-importer Defaults + +LOG_LEVEL=INFO +""" + +app = typer.Typer() +app_state = dict( + config_file=Path("~/.config/bandcamp-importer.conf").expanduser(), +) + +logger = logging.getLogger("bandcamp_importer.cli") + + +@app.callback(invoke_without_command=True) +def main( + context: typer.Context, + verbose: bool = typer.Option(False, help="Enable verbose output."), + log_level: str = typer.Option("error", help=" Set the log level."), + config_file: Optional[Path] = typer.Option( + app_state["config_file"], + help="Path to the bandcamp_importer configuration file", + ), +): + """ + Configure the execution environment with global parameters. + """ + app_state["config_file"] = config_file + load_dotenv(stream=io.StringIO(CONFIG_DEFAULTS)) + load_dotenv(app_state["config_file"]) + + logging.basicConfig( + format="%(message)s", + level=getattr(logging, log_level.upper()), + handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[typer])], + ) + app_state["verbose"] = verbose + + if context.invoked_subcommand is None: + logger.debug("No command specified; invoking default handler.") + run(context) + + +def run(context: typer.Context): + """ + The default CLI entrypoint is bandcamp_importer.cli.run(). + """ + raise NotImplementedError("Please define bandcamp_importer.cli.run().") diff --git a/test/test_bandcamp_importer.py b/test/test_bandcamp_importer.py new file mode 100644 index 0000000..e3c0b4e --- /dev/null +++ b/test/test_bandcamp_importer.py @@ -0,0 +1,7 @@ +import pytest + + +@pytest.mark.xfail +def test_tests_are_implemented(): + print("Yyou have not implemented any tests yet.") + assert False diff --git a/test/test_bandcamp_importer_cli.py b/test/test_bandcamp_importer_cli.py new file mode 100644 index 0000000..a5d214e --- /dev/null +++ b/test/test_bandcamp_importer_cli.py @@ -0,0 +1,8 @@ +import pytest + +from bandcamp_importer import cli + + +@pytest.mark.xfail +def test_tests_are_implemented(): + assert cli.main()