query
On this page

makePythonWriter

pkgs.writers.makePythonWriter

Functor
Docs pulled from | This Revision | 18 days ago


Nixpkgs manual

makePythonWriter takes python and compatible pythonPackages and produces python script writer, which validates the script with flake8 at build time. If any libraries are specified, python.withPackages is used as interpreter, otherwise the "bare" python is used.

Inputs

python

1. Function argument

pythonPackages

2. Function argument

buildPythonPackages

3. Function argument

name

4. Function argument

attrs

5. Function argument

Noogle detected

This is a Functor

Learn about functors

Implementation

The following is the current implementation of this function.

makePythonWriter =
    python: pythonPackages: buildPythonPackages: name:
    {
      libraries ? [ ],
      flakeIgnore ? [ ],
      doCheck ? true,
      ...
    }@args:
    let
      ignoreAttribute =
        optionalString (flakeIgnore != [ ])
          "--ignore ${concatMapStringsSep "," escapeShellArg flakeIgnore}";
    in
    makeScriptWriter (
      (removeAttrs args [
        "libraries"
        "flakeIgnore"
        "doCheck"
      ])
      // {
        interpreter =
          if libraries == [ ] then
            python.interpreter
          else if (lib.isFunction libraries) then
            (python.withPackages libraries).interpreter
          else
            (python.withPackages (ps: libraries)).interpreter;
        check = optionalString (python.isPy3k && doCheck) (
          writeDash "pythoncheck.sh" ''
            exec ${buildPythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
          ''
        );
      }
    ) name;