query
On this page

makePythonWriter

pkgs.writers.makePythonWriter

Functor
Docs pulled from | This Revision | 10 minutes ago


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 (
      (builtins.removeAttrs args [
        "libraries"
        "flakeIgnore"
        "doCheck"
      ])
      // {
        interpreter =
          if pythonPackages != pkgs.pypy2Packages || pythonPackages != pkgs.pypy3Packages then
            if libraries == [ ] then python.interpreter else (python.withPackages (ps: libraries)).interpreter
          else
            python.interpreter;
        check = optionalString (python.isPy3k && doCheck) (
          writeDash "pythoncheck.sh" ''
            exec ${buildPythonPackages.flake8}/bin/flake8 --show-source ${ignoreAttribute} "$1"
          ''
        );
      }
    ) name;