Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkgs/development/python-modules/beets-audible/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
hatchling,

# native
beets,
beets-minimal,

# dependencies
markdownify,
Expand Down Expand Up @@ -35,7 +35,7 @@ buildPythonPackage rec {
];

nativeBuildInputs = [
beets
beets-minimal
];

pythonRelaxDeps = true;
Expand Down
118 changes: 80 additions & 38 deletions pkgs/development/python-modules/beets/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
** };
** };
** }
**
** For an example adding a builtin plugin, see
** passthru.tests.with-new-builtin-plugin below
*/
{
lib,
stdenv,
buildPythonPackage,
fetchFromGitHub,
beets,

# build-system
poetry-core,
Expand Down Expand Up @@ -104,24 +106,16 @@

# passthru.tests
runCommand,
beets,
}:

let
# Avoid using `rec`, so that using e.g `passthru` or any other attributes
# defined inside, will have to be done via the beets argument, which can be
# overriden. Until `finalAttrs` support reaches `buildPythonPackage`, there
# is no way to avoid this. See:
#
# https://github.com/NixOS/nixpkgs/issues/258246
version = "2.5.1";
in
buildPythonPackage {
buildPythonPackage (finalAttrs: {
pname = "beets";
version = "2.5.1";
src = fetchFromGitHub {
owner = "beetbox";
repo = "beets";
tag = "v${version}";
tag = "v${finalAttrs.version}";
hash = "sha256-H3jcEHyK13+RHVlV4zp+8M3LZ0Jc2FdmAbLpekGozLA=";
};
pyproject = true;
Expand Down Expand Up @@ -154,7 +148,9 @@ buildPythonPackage {
typing-extensions
lap
]
++ (lib.concatMap (p: p.propagatedBuildInputs) (lib.attrValues beets.passthru.plugins.enabled));
++ (lib.concatMap (p: p.propagatedBuildInputs) (
lib.attrValues finalAttrs.finalPackage.passthru.plugins.enabled
));

nativeBuildInputs = [
gobject-introspection
Expand Down Expand Up @@ -195,7 +191,7 @@ buildPythonPackage {
makeWrapperArgs = [
"--set GI_TYPELIB_PATH \"$GI_TYPELIB_PATH\""
"--set GST_PLUGIN_SYSTEM_PATH_1_0 \"$GST_PLUGIN_SYSTEM_PATH_1_0\""
"--prefix PATH : ${lib.makeBinPath beets.passthru.plugins.wrapperBins}"
"--prefix PATH : ${lib.makeBinPath finalAttrs.finalPackage.passthru.plugins.wrapperBins}"
];

nativeCheckInputs = [
Expand All @@ -208,12 +204,12 @@ buildPythonPackage {
pillow
writableTmpDirAsHomeHook
]
++ beets.passthru.plugins.wrapperBins;
++ finalAttrs.finalPackage.passthru.plugins.wrapperBins;

__darwinAllowLocalNetworking = true;

disabledTestPaths =
beets.passthru.plugins.disabledTestPaths
finalAttrs.finalPackage.passthru.plugins.disabledTestPaths
++ [
# touches network
"test/plugins/test_aura.py"
Expand Down Expand Up @@ -255,14 +251,14 @@ buildPythonPackage {
\( -name '*.py' -o -path 'beetsplug/*/__init__.py' \) -print \
| sed -n -re 's|^beetsplug/([^/.]+).*|\1|p' \
| sort -u > plugins_available
${diffPlugins (lib.attrNames beets.passthru.plugins.builtins) "plugins_available"}
${diffPlugins (lib.attrNames finalAttrs.finalPackage.passthru.plugins.builtins) "plugins_available"}

export BEETS_TEST_SHELL="${lib.getExe bashInteractive} --norc"

env EDITOR="${writeScript "beetconfig.sh" ''
#!${runtimeShell}
cat > "$1" <<CFG
plugins: ${lib.concatStringsSep " " (lib.attrNames beets.passthru.plugins.enabled)}
plugins: ${lib.concatStringsSep " " (lib.attrNames finalAttrs.finalPackage.passthru.plugins.enabled)}
CFG
''}" "$out/bin/beet" config -e
env EDITOR=true "$out/bin/beet" config -e
Expand Down Expand Up @@ -442,30 +438,39 @@ buildPythonPackage {
testPaths = [ ];
};
};
base = lib.mapAttrs (_: a: { builtin = true; } // a) beets.passthru.plugins.builtins;
base = lib.mapAttrs (
_: a: { builtin = true; } // a
) finalAttrs.finalPackage.passthru.plugins.builtins;
overrides = lib.mapAttrs (
plugName:
lib.throwIf (beets.passthru.plugins.builtins.${plugName}.deprecated or false)
lib.throwIf (finalAttrs.finalPackage.passthru.plugins.builtins.${plugName}.deprecated or false)
"beets evaluation error: Plugin ${plugName} was enabled in pluginOverrides, but it has been removed. Remove the override to fix evaluation."
) pluginOverrides;
all = lib.mapAttrs (
n: a:
{
name = n;
enable = !disableAllPlugins;
builtin = false;
propagatedBuildInputs = [ ];
testPaths = [ "test/plugins/test_${n}.py" ];
wrapperBins = [ ];
}
// a
) (lib.recursiveUpdate beets.passthru.plugins.base beets.passthru.plugins.overrides);
enabled = lib.filterAttrs (_: p: p.enable) beets.passthru.plugins.all;
disabled = lib.filterAttrs (_: p: !p.enable) beets.passthru.plugins.all;
all =
lib.mapAttrs
(
n: a:
{
name = n;
enable = !disableAllPlugins;
builtin = false;
propagatedBuildInputs = [ ];
testPaths = [ "test/plugins/test_${n}.py" ];
wrapperBins = [ ];
}
// a
)
(
lib.recursiveUpdate finalAttrs.finalPackage.passthru.plugins.base finalAttrs.finalPackage.passthru.plugins.overrides
);
enabled = lib.filterAttrs (_: p: p.enable) finalAttrs.finalPackage.passthru.plugins.all;
disabled = lib.filterAttrs (_: p: !p.enable) finalAttrs.finalPackage.passthru.plugins.all;
disabledTestPaths = lib.flatten (
lib.attrValues (lib.mapAttrs (_: v: v.testPaths) beets.passthru.plugins.disabled)
lib.attrValues (lib.mapAttrs (_: v: v.testPaths) finalAttrs.finalPackage.passthru.plugins.disabled)
);
wrapperBins = lib.concatMap (p: p.wrapperBins) (
lib.attrValues finalAttrs.finalPackage.passthru.plugins.enabled
);
wrapperBins = lib.concatMap (p: p.wrapperBins) (lib.attrValues beets.passthru.plugins.enabled);
};
tests = {
gstreamer =
Expand All @@ -483,8 +488,45 @@ buildPythonPackage {
backend: gstreamer
EOF

${beets}/bin/beet -c $out/config.yaml > /dev/null
${finalAttrs.finalPackage}/bin/beet -c $out/config.yaml > /dev/null
'';
with-new-builtin-plugin = finalAttrs.finalPackage.overrideAttrs (
newAttrs: oldAttrs: {
postPatch = (oldAttrs.postPatch or "") + ''
mkdir -p beetsplug/my_special_plugin
touch beetsplug/my_special_plugin/__init__.py
'';
passthru = lib.recursiveUpdate oldAttrs.passthru {
plugins.builtins.my_special_plugin = { };
};
}
);
# Test that disabling
with-mpd-plugins-disabled = beets.override {
pluginOverrides = {
# These two plugins require mpd2 Python dependency. If they are
# disabled, this dependency shouldn't be pulled, and the `runCommand`
# test below should fail with a `ModuleNotFoundError`
mpdstats.enable = false;
mpdupdate.enable = false;
};
};
mpd-plugins-really-disabled = runCommand "beets-mpd-plugins-disabled-test" { } ''
set -euo pipefail
export HOME=$(mktemp -d)
mkdir $out

cat << EOF > $out/config.yaml
plugins:
- mpdstats
EOF
${finalAttrs.finalPackage.passthru.tests.with-mpd-plugins-disabled}/bin/beet \
-c $out/config.yaml \
--help 2> $out/help-stderr || true
${finalAttrs.finalPackage.passthru.tests.with-mpd-plugins-disabled}/bin/beet \
-c $out/config.yaml \
mpdstats --help 2> $out/mpdstats-help-stderr || true
'';
};
};

Expand All @@ -501,4 +543,4 @@ buildPythonPackage {
platforms = lib.platforms.linux ++ lib.platforms.darwin;
mainProgram = "beet";
};
}
})
Loading