instruction
stringclasses
100 values
code
stringlengths
78
193k
response
stringlengths
259
170k
file
stringlengths
59
203
Annotate my code with docstrings
from __future__ import annotations import datetime import re from functools import cache, total_ordering from typing import TYPE_CHECKING, Any from jellyfish import levenshtein_distance from unidecode import unidecode from beets import config, metadata_plugins from beets.util import as_string, cached_classproperty, ...
--- +++ @@ -45,6 +45,11 @@ def _string_dist_basic(str1: str, str2: str) -> float: + """Basic edit distance between two strings, ignoring + non-alphanumeric characters and case. Comparisons are based on a + transliteration/lowering to ASCII characters. Normalized by string + length. + """ assert ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/autotag/distance.py
Generate documentation strings for clarity
# This file is part of beets. # Copyright 2016, Pedro Silva. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, mod...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""List duplicate tracks or albums.""" import os import shlex @@ -31,6 +32,7 @@ class DuplicatesPlugin(BeetsPlugin): + """List duplicate tracks or a...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/duplicates.py
Add docstrings to make code maintainable
# This file is part of beets. # Copyright 2016, Malte Ried. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modi...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Filter imported files using a regular expression.""" import re @@ -64,6 +65,9 @@ return [task] def file_filter(self, full_path): + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/filefilter.py
Replace inline comments with docstrings
# This file is part of beets. # Copyright 2020, Callum Brown. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, mo...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""An AURA server using Flask.""" from __future__ import annotations @@ -128,6 +129,7 @@ @dataclass class AURADocument: + """Base class for building...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/aura.py
Write docstrings for utility functions
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Support for beets plugins.""" from __future__ import annotations @@ -101,15 +102,28 @@ class PluginConflictError(Exception): + """Indicates that...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/plugins.py
Add structured docstrings to improve clarity
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Some simple performance benchmarks for beets.""" import cProfile import timeit @@ -94,6 +95,7 @@ class BenchmarkPlugin(BeetsPlugin): + """A plugi...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/bench.py
Create structured documentation for my script
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,13 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""A drop-in replacement for the standard-library `logging` module. + +Provides everything the "logging" module does. In addition, beets' logger +(as obtained...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/logging.py
Generate docstrings with parameter types
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Representation of type information for DBCore model fields.""" from __future__ import annotations @@ -33,6 +34,10 @@ class ModelType(typing.Protoco...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/dbcore/types.py
Write reusable docstrings
from __future__ import annotations import os from typing import TYPE_CHECKING from beets import logging, ui from beets.util import MoveOperation, displayable_path, normpath, syspath from beets.util.diff import colordiff from .utils import do_query if TYPE_CHECKING: from beets.util import PathLike # Global log...
--- +++ @@ -1,3 +1,4 @@+"""The 'move' command: Move/copy files to the library or a new base directory.""" from __future__ import annotations @@ -18,6 +19,20 @@ def show_path_changes(path_changes): + """Given a list of tuples (source, destination) that indicate the + path changes, log the changes as INFO-...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/move.py
Add docstrings for internal functions
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,10 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""This module contains all of the core logic for beets' command-line +interface. To invoke the CLI, just call beets.ui.main(). The actual +CLI commands are i...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/__init__.py
Include argument descriptions in docstrings
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Allows beets to embed album art into file metadata.""" import os.path import tempfile @@ -28,6 +29,12 @@ def _confirm(objs, album): + """Show the...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/embedart.py
Generate docstrings for this script
# This file is part of beets. # Copyright 2019, Rahul Ahuja. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, mod...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Update library's tags using Beatport.""" from beets import autotag, library, ui, util from beets.plugins import BeetsPlugin, apply_item_changes @@ -62,6...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/bpsync.py
Create docstrings for reusable components
from beets import ui def list_items(lib, query, album, fmt=""): if album: for album in lib.albums(query): ui.print_(format(album, fmt)) else: for item in lib.items(query): ui.print_(format(item, fmt)) def list_func(lib, opts, args): list_items(lib, args, opts.alb...
--- +++ @@ -1,8 +1,12 @@+"""The 'list' command: query and show library contents.""" from beets import ui def list_items(lib, query, album, fmt=""): + """Print out items in lib matching query. If album, then search for + albums instead of single items. + """ if album: for album in lib.albu...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/list.py
Provide clean and structured docstrings
from __future__ import annotations import abc import re from contextlib import contextmanager from functools import cache, cached_property, wraps from typing import ( TYPE_CHECKING, Generic, Literal, NamedTuple, TypedDict, TypeVar, ) import unidecode from confuse import NotFoundError from be...
--- +++ @@ -1,3 +1,9 @@+"""Metadata source plugin interface. + +This allows beets to lookup metadata from various sources. We define +a common interface for all metadata sources which need to be +implemented as plugins. +""" from __future__ import annotations @@ -37,6 +43,7 @@ @cache def find_metadata_source_pl...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/metadata_plugins.py
Document this module using docstrings
from __future__ import annotations import shlex import beets from beets import dbcore, logging, plugins log = logging.getLogger("beets") # Special path format key. PF_KEY_DEFAULT = "default" # Query construction helpers. def parse_query_parts(parts, model_cls): # Get query types and their prefix characters....
--- +++ @@ -15,6 +15,12 @@ def parse_query_parts(parts, model_cls): + """Given a beets query string as a list of components, return the + `Query` and `Sort` they represent. + + Like `dbcore.parse_sorted_query`, with beets query prefixes and + ensuring that implicit path queries are made explicit with 'p...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/library/queries.py
Turn comments into proper docstrings
from __future__ import annotations import warnings from importlib import import_module from typing import TYPE_CHECKING, Any from packaging.version import Version import beets if TYPE_CHECKING: from logging import Logger def _format_message(old: str, new: str | None = None) -> str: next_major = f"{Version...
--- +++ @@ -30,6 +30,12 @@ def deprecate_for_maintainers( old: str, new: str | None = None, stacklevel: int = 1 ) -> None: + """Issue a deprecation warning visible to maintainers during development. + + Emits a DeprecationWarning that alerts developers about deprecated code + patterns. Unlike user-facing...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/deprecation.py
Add docstrings for production code
# This file is part of beets. # Copyright 2021, Edgars Supe. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, mod...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds an album template field for formatted album types.""" from __future__ import annotations @@ -26,8 +27,10 @@ class AlbumTypesPlugin(BeetsPlugin...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/albumtypes.py
Add docstrings to improve code quality
from collections import Counter from itertools import chain from beets import autotag, config, importer, logging, plugins, ui from beets.autotag import Recommendation from beets.util import PromptChoice, displayable_path from beets.util.color import colorize, dist_colorize from beets.util.units import human_bytes, hum...
--- +++ @@ -19,8 +19,13 @@ class TerminalImportSession(importer.ImportSession): + """An import session that runs in a terminal.""" def choose_match(self, task): + """Given an initial autotagging of items, go through an interactive + dance with the user to ask for a choice of metadata. Return...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/import_/session.py
Add inline docstrings for readability
from __future__ import annotations from difflib import SequenceMatcher from typing import TYPE_CHECKING from .color import colorize if TYPE_CHECKING: from collections.abc import Iterable from beets.dbcore.db import FormattedMapping from beets.library.models import LibModel def colordiff(a: str, b: str...
--- +++ @@ -13,6 +13,7 @@ def colordiff(a: str, b: str) -> tuple[str, str]: + """Intelligently highlight the differences between two strings.""" before = "" after = "" @@ -48,6 +49,10 @@ def _field_diff( field: str, old: FormattedMapping, new: FormattedMapping ) -> str | None: + """Given two...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/diff.py
Replace inline comments with docstrings
from __future__ import annotations from typing import Any from typing_extensions import NotRequired, TypedDict JSONDict = dict[str, Any] class LRCLibAPI: class Item(TypedDict): id: int name: str trackName: str artistName: str albumName: str duration: float | Non...
--- +++ @@ -9,6 +9,7 @@ class LRCLibAPI: class Item(TypedDict): + """Lyrics data item returned by the LRCLib API.""" id: int name: str @@ -22,6 +23,12 @@ class GeniusAPI: + """Genius API data types. + + This documents *only* the fields that are used in the plugin. + :attr:...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/_typing.py
Add docstrings that explain inputs and outputs
from __future__ import annotations import re from contextlib import suppress from dataclasses import dataclass, field from functools import cached_property from typing import TYPE_CHECKING, Any from urllib.parse import urlparse from beets.util import unique_list if TYPE_CHECKING: from beets.library import Item ...
--- +++ @@ -18,6 +18,12 @@ @dataclass class Lyrics: + """Represent lyrics text together with structured source metadata. + + This value object keeps the canonical lyrics body, optional provenance, and + optional translation metadata synchronized across fetching, translation, and + persistence. + """ ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/lyrics.py
Insert docstrings into my code
# This file is part of beets. # Copyright 2016, Jan-Erik Dahlin # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""If the title is empty, try to extract it from the filename +(possibly also extract track and artist) +""" import os import re @@ -40,14 +43,24 @@ de...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/fromfilename.py
Add documentation for all methods
# This file is part of beets. # Copyright 2022, J0J0 Todos. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modi...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Provides utilities to read, write and manipulate m3u playlist files.""" import traceback @@ -19,18 +20,28 @@ class EmptyPlaylistError(Exception): +...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/m3u.py
Add detailed documentation for each class
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds Chromaprint/Acoustid acoustic fingerprinting support to the +autotagger. Requires the pyacoustid library. +""" from __future__ import annotations ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/chroma.py
Document this module using docstrings
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Parsing of strings into DBCore queries.""" from __future__ import annotations @@ -48,6 +49,49 @@ prefixes: Prefixes = {}, default_class: type[...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/dbcore/queryparse.py
Write beginner-friendly docstrings
# This file is part of beets. # Copyright 2016, François-Xavier Thomas. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Use command-line tools to check for audio file corruption.""" import errno import os @@ -29,6 +30,14 @@ class CheckerCommandError(Exception): + "...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/badfiles.py
Write beginner-friendly docstrings
from __future__ import annotations from typing import TYPE_CHECKING, NamedTuple import beets from .color import ( ESC_TEXT_REGEX, RESET_COLOR, color_len, color_split, uncolorize, ) if TYPE_CHECKING: from collections.abc import Callable, Iterator class Side(NamedTuple): prefix: str ...
--- +++ @@ -17,6 +17,12 @@ class Side(NamedTuple): + """A labeled segment of a two-column layout row with optional fixed width. + + Holds prefix, content, and suffix strings that together form one side of + a formatted row. Width measurements account for ANSI color codes, which + do not contribute to vi...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/layout.py
Add docstrings including usage examples
# This file is part of beets. # Copyright 2019, Rahul Ahuja. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, mod...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds Deezer release and track search support to the autotagger""" from __future__ import annotations @@ -51,6 +52,7 @@ super().__init__() ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/deezer.py
Document this script properly
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Helpers around the extraction of album/track ID's from metadata sources.""" from __future__ import annotations @@ -47,6 +48,12 @@ def extract_relea...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/id_extractors.py
Add docstrings to improve readability
import os from beets import logging, ui from beets.util import syspath from beets.util.units import human_bytes, human_seconds # Global logger. log = logging.getLogger("beets") def show_stats(lib, query, exact): items = lib.items(query) total_size = 0 total_time = 0.0 total_items = 0 artists =...
--- +++ @@ -1,3 +1,4 @@+"""The 'stats' command: show library statistics.""" import os @@ -10,6 +11,7 @@ def show_stats(lib, query, exact): + """Shows some statistics about the matched items.""" items = lib.items(query) total_size = 0 @@ -57,4 +59,4 @@ stats_cmd.parser.add_option( "-e", "--e...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/stats.py
Add docstrings with type hints explained
import os from beets import config, ui from beets.util import displayable_path, editor_command, interactive_open def config_func(lib, opts, args): # Make sure lazy configuration is loaded config.resolve() # Print paths. if opts.paths: filenames = [] for source in config.sources: ...
--- +++ @@ -1,3 +1,4 @@+"""The 'config' command: show and edit user configuration.""" import os @@ -44,6 +45,9 @@ def config_edit(cli_options): + """Open a program to edit the user configuration. + An empty config file is created if no existing config file exists. + """ path = cli_options.config ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/config.py
Add docstrings following best practices
# This file is part of beets. # Copyright 2023, Max Rumpf. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modif...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Plugin to rewrite fields based on a given query.""" import re import shlex @@ -27,6 +28,13 @@ def rewriter(field, simple_rules, advanced_rules): + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/advancedrewrite.py
Add docstrings to meet PEP guidelines
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -40,11 +40,15 @@ class ImportAbortError(Exception): + """Raised when the user aborts the tagging operation.""" pass class ImportSession: + """Controls an import action. Subclasses should implement methods to + communicate with the user or otherwise make decisions. + """ log...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/importer/session.py
Create docstrings for all classes and functions
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -70,11 +70,13 @@ class ImportAbortError(Exception): + """Raised when the user aborts the tagging operation.""" pass class Action(Enum): + """Enumeration of possible actions for an import task.""" SKIP = "SKIP" ASIS = "ASIS" @@ -88,6 +90,10 @@ class BaseImportTask: + "...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/importer/tasks.py
Add docstrings for production code
from beets import ui def do_query(lib, query, album, also_items=True): if album: albums = list(lib.albums(query)) items = [] if also_items: for al in albums: items += al.items() else: albums = [] items = list(lib.items(query)) if album...
--- +++ @@ -1,8 +1,15 @@+"""Utility functions for beets UI commands.""" from beets import ui def do_query(lib, query, album, also_items=True): + """For commands that operate on matched items, performs a query + and returns a list of matching items and a list of matching + albums. (The latter is only no...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/utils.py
Generate docstrings with examples
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""High-level utilities for manipulating image files associated with +music and items' embedded album art. +""" import os from tempfile import NamedTempora...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/_utils/art.py
Add return value explanations in docstrings
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -44,6 +44,10 @@ def read_tasks(session: ImportSession): + """A generator yielding all the albums (as ImportTask objects) found + in the user-specified list of paths. In the case of a singleton + import, yields single-item tasks instead. + """ skipped = 0 for toppath in session.pat...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/importer/stages.py
Write docstrings describing each step
from beets import library, ui from beets.util import functemplate from .utils import do_query def modify_items(lib, mods, dels, query, write, move, album, confirm, inherit): # Parse key=value specifications into a dictionary. model_cls = library.Album if album else library.Item # Get the items to modif...
--- +++ @@ -1,3 +1,4 @@+"""The `modify` command: change metadata fields.""" from beets import library, ui from beets.util import functemplate @@ -6,6 +7,12 @@ def modify_items(lib, mods, dels, query, write, move, album, confirm, inherit): + """Modifies matching items according to user-specified assignments a...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/modify.py
Add docstrings to clarify complex logic
from __future__ import annotations import os from dataclasses import dataclass from functools import cached_property from typing import TYPE_CHECKING from beets import config, ui from beets.autotag import hooks from beets.util import displayable_path from beets.util.color import colorize, dist_colorize from beets.uti...
--- +++ @@ -28,6 +28,11 @@ @dataclass class ChangeRepresentation: + """Keeps track of all information needed to generate a (colored) text + representation of the changes that will be made if an album or singleton's + tags are changed according to `match`, which must be an AlbumMatch or + TrackMatch objec...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/import_/display.py
Create docstrings for API functions
import re def raw_seconds_short(string: str) -> float: match = re.match(r"^(\d+):([0-5]\d)$", string) if not match: raise ValueError("String not in M:SS format") minutes, seconds = map(int, match.groups()) return float(minutes * 60 + seconds) def human_seconds_short(interval): interval =...
--- +++ @@ -2,6 +2,11 @@ def raw_seconds_short(string: str) -> float: + """Formats a human-readable M:SS string as a float (number of seconds). + + Raises ValueError if the conversion cannot take place due to `string` not + being in the right format. + """ match = re.match(r"^(\d+):([0-5]\d)$", str...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/units.py
Include argument descriptions in docstrings
from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: from collections.abc import Collection, Sequence def sanitize_choices( choices: Sequence[str], choices_all: Collection[str] ) -> list[str]: seen: set[str] = set() others = [x for x in choices_all if x not in choice...
--- +++ @@ -9,6 +9,10 @@ def sanitize_choices( choices: Sequence[str], choices_all: Collection[str] ) -> list[str]: + """Clean up a stringlist configuration attribute: keep only choices + elements present in choices_all, remove duplicate elements, expand '*' + wildcard while keeping original stringlist o...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/config.py
Add minimal docstrings for each function
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,10 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""A clone of the Music Player Daemon (MPD) that plays music from a +Beets library. Attempts to implement a compatible protocol to allow +use of the wide rang...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/bpd/__init__.py
Expand my code with proper documentation strings
from __future__ import annotations import atexit import threading from contextlib import contextmanager from functools import cached_property from http import HTTPStatus from typing import TYPE_CHECKING, Any, ClassVar, Generic, Protocol, TypeVar import requests from requests.adapters import HTTPAdapter from urllib3.u...
--- +++ @@ -33,6 +33,7 @@ class Closeable(Protocol): + """Protocol for objects that have a close method.""" def close(self) -> None: ... @@ -41,6 +42,12 @@ class SingletonMeta(type, Generic[C]): + """Metaclass ensuring a single shared instance per class. + + Creates one instance per class type...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/_utils/requests.py
Document this script properly
import collections import errno import select import socket import sys import time import traceback import types # Basic events used for thread scheduling. class Event: pass class WaitableEvent(Event): def waitables(self): return (), (), () def fire(self): pass class ValueEvent(Ev...
--- +++ @@ -1,3 +1,10 @@+"""Extremely simple pure-Python implementation of coroutine-style +asynchronous socket I/O. Inspired by, but inferior to, Eventlet. +Bluelet can also be thought of as a less-terrible replacement for +asyncore. + +Bluelet: easy concurrency without all the messy parallelism. +""" import collec...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/bluelet.py
Provide clean and structured docstrings
# This file is part of beets. # Copyright 2016, Blemjhoo Tezoulbr <baobab@heresiarch.info>. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitati...
--- +++ @@ -13,6 +13,7 @@ # included in all copies or substantial portions of the Software. +"""Warns you about things you hate (or even blocks import).""" from beets.importer import Action from beets.library import Album, Item, parse_query_string @@ -23,6 +24,9 @@ def summary(task): + """Given an Import...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/ihate.py
Document this code for team use
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -33,6 +33,29 @@ @dataclass class ImportState: + """Representing the progress of an import task. + + Opens the state file on creation of the class. If you want + to ensure the state is written to disk, you should use the + context manager protocol. + + Tagprogress allows long tagging tasks t...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/importer/state.py
Generate documentation strings for clarity
from __future__ import annotations import operator import re from dataclasses import dataclass, field from functools import cached_property, singledispatchmethod, wraps from itertools import groupby, starmap from typing import TYPE_CHECKING, Any, Literal, ParamSpec, TypedDict, TypeVar from requests_ratelimiter impor...
--- +++ @@ -1,3 +1,12 @@+"""Helpers for communicating with the MusicBrainz webservice. + +Provides rate-limited HTTP session and convenience methods to fetch and +normalize API responses. + +This module centralizes request handling and response shaping so callers can +work with consistently structured data without embe...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/_utils/musicbrainz.py
Write proper docstrings for these functions
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,24 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Simple but robust implementation of generator/coroutine-based +pipelines in Python. The pipelines may be run either sequentially +(single-threaded) or in p...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/pipeline.py
Generate consistent docstrings
import os from beets import config, logging, plugins, ui from beets.util import displayable_path, normpath, syspath from .session import TerminalImportSession # Global logger. log = logging.getLogger("beets") def paths_from_logfile(path): with open(path, encoding="utf-8") as fp: for i, line in enumera...
--- +++ @@ -1,3 +1,4 @@+"""The `import` command: import new music into the library.""" import os @@ -11,6 +12,9 @@ def paths_from_logfile(path): + """Parse the logfile and yield skipped paths to pass to the `import` + command. + """ with open(path, encoding="utf-8") as fp: for i, line in...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/import_/__init__.py
Generate documentation strings for clarity
import hashlib from urllib.parse import parse_qs, urlencode, urljoin, urlsplit, urlunsplit import requests from beets.plugins import BeetsPlugin def api_url(host, port, endpoint): # check if http or https is defined as host and create hostname hostname_list = [host] if host.startswith("http://") or hos...
--- +++ @@ -1,3 +1,12 @@+"""Updates the Emby Library whenever the beets library is changed. + +emby: + host: localhost + port: 8096 + username: user + apikey: apikey + password: password +""" import hashlib from urllib.parse import parse_qs, urlencode, urljoin, urlsplit, urlunsplit @@ -8,6 +17,19 @@ ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/embyupdate.py
Create simple docstrings for beginners
# This file is part of beets. # Copyright 2016, Fabrice Laporte # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Abstraction layer to resize images using PIL, ImageMagick, or a +public resizing proxy if neither is available. +""" from __future__ import annotations ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/artresizer.py
Please document this code using docstrings
from __future__ import annotations import os import string import sys import time import unicodedata from functools import cached_property from pathlib import Path from typing import TYPE_CHECKING, ClassVar from mediafile import MediaFile, UnreadableFileError import beets from beets import dbcore, logging, plugins, ...
--- +++ @@ -35,6 +35,7 @@ class LibModel(dbcore.Model["Library"]): + """Shared concrete functionality for Items and Albums.""" # Config key that specifies how an instance should be formatted. _format_config_key: str @@ -43,6 +44,7 @@ @cached_classproperty def _types(cls) -> dict[str, types...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/library/models.py
Can you add docstrings to this Python file?
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds Beatport release and track search support to the autotagger""" from __future__ import annotations @@ -56,6 +57,17 @@ _api_base = "https://oaut...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/beatport.py
Create docstrings for each class method
from __future__ import annotations import os import re from functools import cache from typing import TYPE_CHECKING, Literal import confuse from beets import config if TYPE_CHECKING: from beets.autotag.distance import Distance # ANSI terminal colorization code heavily inspired by pygments: # https://bitbucket....
--- +++ @@ -118,6 +118,12 @@ @cache def get_color_config() -> dict[ColorName, str]: + """Parse and validate color configuration, converting names to ANSI codes. + + Processes the UI color configuration, handling both new list format and + legacy single-color format. Validates all color names against known c...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/color.py
Document this module using docstrings
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,19 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""This module implements a string formatter based on the standard PEP +292 string.Template class extended with function calls. Variables, as +with string.Tem...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/functemplate.py
Generate docstrings for this script
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""A simple utility for constructing filesystem-like trees from beets +libraries. +""" from __future__ import annotations @@ -32,6 +35,7 @@ def _inser...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/_utils/vfs.py
Add documentation for all methods
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Facilities for automatically determining files' correct metadata.""" from __future__ import annotations @@ -114,6 +115,7 @@ db_obj: Album | Item, ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/autotag/__init__.py
Create documentation for each function signature
# This file is part of beets. # Copyright 2016, Philippe Mongeau. # Copyright 2021, Graham R. Cobb. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and ascociated documentation files (the # "Software"), to deal in the Software without restriction, including # without ...
--- +++ @@ -16,6 +16,7 @@ # This module is adapted from Fuzzy in accordance to the licence of # that module +"""Provides a bare-ASCII matching query.""" from unidecode import unidecode @@ -26,9 +27,15 @@ class BareascQuery(StringFieldQuery[str]): + """Compare items using bare ASCII, without accents etc."...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/bareasc.py
Add docstrings including usage examples
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""The Query type hierarchy for DBCore.""" from __future__ import annotations @@ -47,9 +48,16 @@ class ParsingError(ValueError): + """Abstract clas...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/dbcore/query.py
Generate docstrings with parameter types
import os from beets import library, logging, ui from beets.util import syspath from .utils import do_query # Global logger. log = logging.getLogger("beets") def write_items(lib, query, pretend, force): items, _ = do_query(lib, query, False, False) for item in items: # Item deleted? if no...
--- +++ @@ -1,3 +1,4 @@+"""The `write` command: write tag information to files.""" import os @@ -11,6 +12,9 @@ def write_items(lib, query, pretend, force): + """Write tag information from the database to the respective files + in the filesystem. + """ items, _ = do_query(lib, query, False, False)...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/write.py
Document my Python code with docstrings
from beets import util class FileOperationError(Exception): def __init__(self, path, reason): super().__init__(path, reason) self.path = path self.reason = reason def __str__(self): return f"{util.displayable_path(self.path)}: {self.reason}" class ReadError(FileOperationErr...
--- +++ @@ -2,23 +2,37 @@ class FileOperationError(Exception): + """Indicate an error when interacting with a file on disk. + + Possibilities include an unsupported media type, a permissions + error, and an unhandled Mutagen exception. + """ def __init__(self, path, reason): + """Create an...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/library/exceptions.py
Generate helpful docstrings for debugging
# This file is part of beets. # Copyright 2015-2016, Ohm Patel. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Fetch various AcousticBrainz metadata using MBID.""" from collections import defaultdict from typing import ClassVar @@ -127,6 +128,7 @@ return ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/acousticbrainz.py
Add well-formatted docstrings
import os import re from beets import library, logging, plugins, ui from beets.util import syspath # Global logger. log = logging.getLogger("beets") def print_completion(*args): from beets.ui.commands import default_commands for line in completion_script(default_commands + plugins.commands()): ui....
--- +++ @@ -1,3 +1,4 @@+"""The 'completion' command: print shell script for command line completion.""" import os import re @@ -41,6 +42,11 @@ def completion_script(commands): + """Yield the full completion shell script as strings. + + ``commands`` is alist of ``ui.Subcommand`` instances to generate + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/completion.py
Provide clean and structured docstrings
# This file is part of beets. # Copyright 2016, Verrus, <github.com/Verrus/beets-plugin-featInTitle> # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Moves "featured" artists to the title from the artist field.""" from __future__ import annotations @@ -55,6 +56,11 @@ for_artist: bool = True, ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/ftintitle.py
Create docstrings for reusable components
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Fetches album art.""" from __future__ import annotations @@ -54,6 +55,7 @@ class ImageAction(Enum): + """Indicates whether an image is useable o...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/fetchart.py
Add docstrings for production code
# This file is part of beets. # Copyright 2016, Jakob Schnitzer. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy,...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Converts tracks or albums to external directory""" import logging import os @@ -45,11 +46,16 @@ def replace_ext(path, ext): + """Return the path ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/convert.py
Write docstrings for algorithm functions
# This file is part of beets. # Copyright 2016, aroquen # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Determine BPM by pressing a key to the rhythm.""" import time @@ -20,6 +21,9 @@ def bpm(max_strokes): + """Returns average BPM (possibly of a pl...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/bpm.py
Generate consistent documentation across files
# This file is part of beets. # Copyright 2016, Pieter Mulder. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, m...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Calculate acoustic information and submit to AcousticBrainz.""" import errno import hashlib @@ -30,9 +31,14 @@ class ABSubmitError(Exception): + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/absubmit.py
Add clean documentation to messy code
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds Discogs album search support to the autotagger. Requires the +python3-discogs-client library. +""" from __future__ import annotations @@ -116,6 +1...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/discogs/__init__.py
Add docstrings that explain logic
from __future__ import annotations from typing import TYPE_CHECKING import platformdirs import beets from beets import dbcore from beets.util import normpath from . import migrations from .models import Album, Item from .queries import PF_KEY_DEFAULT, parse_query_parts, parse_query_string if TYPE_CHECKING: fro...
--- +++ @@ -17,6 +17,7 @@ class Library(dbcore.Database): + """A database of music containing songs and albums.""" _models = (Item, Album) _migrations = ( @@ -45,11 +46,22 @@ # Adding objects to the database. def add(self, obj): + """Add the :class:`Item` or :class:`Album` object to...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/library/library.py
Add verbose docstrings with examples
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Miscellaneous utility functions.""" from __future__ import annotations @@ -71,6 +72,18 @@ class HumanReadableError(Exception): + """An Exception...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/util/__init__.py
Document this module using docstrings
import textwrap from beets import library, ui def _print_keys(query): for row in query: ui.print_(f" {row['key']}") def fields_func(lib, opts, args): def _print_rows(names): names.sort() ui.print_(textwrap.indent("\n".join(names), " ")) ui.print_("Item fields:") _print_r...
--- +++ @@ -1,3 +1,4 @@+"""The `fields` command: show available fields for queries and format strings.""" import textwrap @@ -5,6 +6,9 @@ def _print_keys(query): + """Given a SQLite query result, print the `key` field of each + returned row, with indentation of 2 spaces. + """ for row in query: ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/fields.py
Generate consistent documentation across files
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""The central Model and Database constructs for DBCore.""" from __future__ import annotations @@ -71,9 +72,16 @@ class DBAccessError(Exception): + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/dbcore/db.py
Provide clean and structured docstrings
# This file is part of beets. # Copyright 2015, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Allows custom commands to be run when an event is emitted by beets""" from __future__ import annotations @@ -25,8 +26,13 @@ class BytesToStrFormatt...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/hook.py
Write docstrings for data processing functions
from __future__ import annotations from contextlib import suppress from functools import cached_property from typing import TYPE_CHECKING, NamedTuple, TypeVar from confuse.exceptions import ConfigError import beets from beets import ui from beets.dbcore.db import Migration from beets.dbcore.types import MULTI_VALUE_...
--- +++ @@ -28,14 +28,17 @@ def chunks(lst: list[T], n: int) -> Iterator[list[T]]: + """Yield successive n-sized chunks from lst.""" for i in range(0, len(lst), n): yield lst[i : i + n] class MultiGenreFieldMigration(Migration): + """Backfill multi-value genres from legacy single-string gen...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/library/migrations.py
Add well-formatted docstrings
import os from beets import library, logging, ui from beets.util import ancestry, syspath from beets.util.color import colorize from .utils import do_query # Global logger. log = logging.getLogger("beets") def update_items(lib, query, album, move, pretend, fields, exclude_fields=None): with lib.transaction():...
--- +++ @@ -1,3 +1,4 @@+"""The `update` command: Update library contents according to on-disk tags.""" import os @@ -12,6 +13,13 @@ def update_items(lib, query, album, move, pretend, fields, exclude_fields=None): + """For all the items matched by the query, update the library to + reflect the item's embe...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/update.py
Document this script properly
from beets import ui from .utils import do_query def remove_items(lib, query, album, delete, force): # Get the matching items. items, albums = do_query(lib, query, album) objs = albums if album else items # Confirm file removal if not forcing removal. if not force: # Prepare confirmatio...
--- +++ @@ -1,3 +1,4 @@+"""The `remove` command: remove items from the library (and optionally delete files).""" from beets import ui @@ -5,6 +6,9 @@ def remove_items(lib, query, album, delete, force): + """Remove items matching query from lib. If album, then match and + remove whole albums. If delete, a...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beets/ui/commands/remove.py
Turn comments into proper docstrings
import os from beets import importer, util from beets.plugins import BeetsPlugin class ImportAddedPlugin(BeetsPlugin): def __init__(self): super().__init__() self.config.add( { "preserve_mtimes": False, "preserve_write_mtimes": False, } ...
--- +++ @@ -1,3 +1,8 @@+"""Populate an item's `added` and `mtime` fields by using the file +modification time (mtime) of the item's source file before import. + +Reimported albums and items are skipped. +""" import os @@ -72,15 +77,20 @@ self.replaced_album_paths = set(task.replaced_albums.keys()) d...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/importadded.py
Add detailed documentation for each class
import os import stat from beets import config from beets.plugins import BeetsPlugin from beets.util import ancestry, displayable_path, syspath def convert_perm(perm): if isinstance(perm, int): perm = str(perm) return int(perm, 8) def check_permissions(path, permission): return oct(stat.S_IMOD...
--- +++ @@ -1,3 +1,10 @@+"""Fixes file permissions after the file gets written on import. Put something +like the following in your config.yaml to configure: + + permissions: + file: 644 + dir: 755 +""" import os import stat @@ -8,16 +15,27 @@ def convert_perm(perm): + """Convert a s...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/permissions.py
Write docstrings including parameters and return values
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Searches for albums in the MusicBrainz database.""" from __future__ import annotations @@ -73,6 +74,9 @@ def _preferred_alias( aliases: list[JSOND...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/musicbrainz.py
Write docstrings for utility functions
# This file is part of beets. # Copyright 2017, Dorian Soergel. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Gets parent work, its disambiguation and id, composer, composer sort name +and work composition date +""" from __future__ import annotations @@ -69,6 +...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/parentwork.py
Add docstrings that explain inputs and outputs
# This file is part of beets. # Copyright 2016, Pedro Silva. # Copyright 2017, Quentin Young. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limita...
--- +++ @@ -13,6 +13,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""List missing tracks.""" from __future__ import annotations @@ -57,10 +58,18 @@ def _missing_count(album): + """Return number of missing items in...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/missing.py
Write docstrings for this repository
# This file is part of beets. # Copyright 2016, Fabrice Laporte. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy,...
--- +++ @@ -13,6 +13,10 @@ # included in all copies or substantial portions of the Software. +"""Write paths of imported files in various formats to ease later import in a +music player. Also allow printing the new file locations to stdout in case +one wants to manually add music to a player by its path. +""" im...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/importfeeds.py
Generate helpful docstrings for debugging
# This file is part of beets. # Copyright 2016, Peter Schnebel and Johann Klähn. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the righ...
--- +++ @@ -35,6 +35,7 @@ def is_url(path): + """Try to determine if the path is an URL.""" if isinstance(path, bytes): # if it's bytes, then it's a path return False return path.split("://", 1)[0] in ["http", "https"] @@ -57,6 +58,7 @@ self.client = mpd.MPDClient() def connect...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/mpdstats.py
Write docstrings that follow conventions
# This file is part of beets. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribu...
--- +++ @@ -32,6 +32,7 @@ class PlaylistQuery(InQuery[bytes]): + """Matches files listed by a playlist file.""" @property def subvals(self) -> Sequence[BLOB_TYPE]: @@ -142,6 +143,7 @@ self._log.error("Failed to update playlist: {}", playlist) def find_playlists(self): + ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/playlist.py
Write docstrings for algorithm functions
# This file is part of beets. # Copyright 2016, Fabrice Laporte, Yevgeny Bezman, and Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without...
--- +++ @@ -50,15 +50,24 @@ class ReplayGainError(Exception): + """Raised when a local (to a track or an album) error occurs in one + of the backends. + """ class FatalReplayGainError(Exception): + """Raised when a fatal error occurs in one of the backends.""" class FatalGstreamerPluginReplayG...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/replaygain.py
Add docstrings that explain inputs and outputs
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Cleans extraneous metadata from files' tags via a command or +automatically whenever tags are written. +""" import mediafile import mutagen @@ -39,6 +42...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/scrub.py
Include argument descriptions in docstrings
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Allows inline path template customization code in the config file.""" import itertools import traceback @@ -23,6 +24,7 @@ class InlineError(Exceptio...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/inline.py
Help me write clear docstrings
# This file is part of beets. # Copyright 2019, Rahul Ahuja. # Copyright 2022, Alok Saboo. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitatio...
--- +++ @@ -13,6 +13,10 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds Spotify release and track search support to the autotagger. + +Also includes Spotify playlist construction. +""" from __future__ import annotations...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/spotify.py
Document this script properly
# This file is part of beets. # Copyright 2016, Dang Mai <contact@dangmai.net>. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the right...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Generates smart playlists based on beets queries.""" from __future__ import annotations @@ -193,6 +194,20 @@ return queries_and_sorts, None ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/smartplaylist.py
Add docstrings that explain inputs and outputs
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Uses user-specified rewriting rules to canonicalize names for path +formats. +""" import re from collections import defaultdict @@ -21,6 +24,10 @@ d...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/rewrite.py
Add docstrings that explain inputs and outputs
from __future__ import annotations import shutil from pathlib import Path from typing import TYPE_CHECKING import mediafile from beets import ui, util from beets.plugins import BeetsPlugin if TYPE_CHECKING: from beets.library import Item, Library class ReplacePlugin(BeetsPlugin): def commands(self): ...
--- +++ @@ -48,6 +48,7 @@ self.replace_file(new_file_path, song) def file_check(self, filepath: Path) -> None: + """Check if the file exists and is supported""" if not filepath.is_file(): raise ui.UserError( f"'{util.displayable_path(filepath)}' is not a vali...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/replace.py
Write docstrings for algorithm functions
# This file is part of beets. # Copyright 2017, Pauli Kettunen. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -12,6 +12,16 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Updates a Kodi library whenever the beets library is changed. +This is based on the Plex Update plugin. + +Put something like the following in your config....
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/kodiupdate.py
Help me add docstrings to my project
from urllib.parse import urlencode, urljoin from xml.etree import ElementTree import requests from beets import config from beets.plugins import BeetsPlugin def get_music_section( host, port, token, library_name, secure, ignore_cert_errors ): api_endpoint = append_token("library/sections", token) url =...
--- +++ @@ -1,3 +1,12 @@+"""Updates an Plex library whenever the beets library is changed. + +Plex Home users enter the Plex Token to enable updating. +Put something like the following in your config.yaml to configure: + plex: + host: localhost + port: 32400 + token: token +""" from urllib.pa...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/plexupdate.py
Write clean docstrings for readability
# This file is part of beets. # Copyright 2018, Tobias Sauerwein. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy...
--- +++ @@ -12,6 +12,9 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Updates a Sonos library whenever the beets library is changed. +This is based on the Kodi Update plugin. +""" import soco @@ -24,9 +27,13 @@ se...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/sonosupdate.py
Add docstrings following best practices
# This file is part of beets. # Copyright 2016, Rafael Bodill https://github.com/rafi # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the...
--- +++ @@ -54,6 +54,11 @@ class CustomUser(pylast.User): + """Custom user class derived from pylast.User, and overriding the + _get_things method to return MBID and album. Also introduces new + get_top_tracks_by_page method to allow access to more than one page of top + tracks. + """ def __in...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/lastimport.py
Generate consistent documentation across files
# This file is part of beets. # Copyright 2016, David Hamp-Gonsalves # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, c...
--- +++ @@ -12,6 +12,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Send the results of a query to the configured music player as a playlist.""" import random import shlex @@ -43,6 +44,9 @@ item_type="track", ke...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/play.py
Add concise docstrings to each method
# This file is part of beets. # Copyright 2016, Adrian Sampson. # Copyright 2026, J0J0 Todos. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limita...
--- +++ @@ -14,6 +14,7 @@ # included in all copies or substantial portions of the Software. +"""Last.fm API client for genre lookups.""" from __future__ import annotations @@ -45,8 +46,13 @@ class LastFmClient: + """Client for fetching genres from Last.fm.""" def __init__(self, log: BeetsLogger, ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/lastgenre/client.py
Add docstrings for better understanding
# This file is part of beets. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribu...
--- +++ @@ -11,6 +11,7 @@ # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. +"""Adds support for ipfs. Requires go-ipfs and a running ipfs daemon""" import os import shutil @@ -279,6 +280,7 @@ return library.Library(path) ...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/ipfs.py
Help me add docstrings to my project
# This file is part of beets. # Copyright 2016, Adrian Sampson. # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, ...
--- +++ @@ -13,6 +13,14 @@ # included in all copies or substantial portions of the Software. +"""Gets genres for imported music based on Last.fm tags. + +Uses a provided whitelist file to determine which tags are valid genres. +The included (default) genre list was originally produced by scraping Wikipedia +and has...
https://raw.githubusercontent.com/beetbox/beets/HEAD/beetsplug/lastgenre/__init__.py