From 52a484be33b6f24bd7fa52de804f856a00e7b5c7 Mon Sep 17 00:00:00 2001 From: adisbladis Date: Thu, 1 Oct 2020 19:08:57 +0200 Subject: [PATCH] Reformat with nixpkgs-fmt 1.0.0 --- default.nix | 7 +- editable.nix | 35 ++++---- hooks/default.nix | 12 ++- lib.nix | 3 +- mk-poetry-dep.nix | 27 +++--- nix/sources.nix | 8 +- overrides.nix | 222 ++++++++++++++++++++++++---------------------- pep425.nix | 13 +-- pep508.nix | 164 ++++++++++++++++++---------------- 9 files changed, 264 insertions(+), 227 deletions(-) diff --git a/default.nix b/default.nix index d38f30f40..37420acfb 100644 --- a/default.nix +++ b/default.nix @@ -278,9 +278,10 @@ lib.makeScope pkgs.newScope (self: { ) { inherit app; }; }; - meta = lib.optionalAttrs (lib.hasAttr "description" pyProject.tool.poetry) { - inherit (pyProject.tool.poetry) description; - } // lib.optionalAttrs (lib.hasAttr "homepage" pyProject.tool.poetry) { + meta = lib.optionalAttrs (lib.hasAttr "description" pyProject.tool.poetry) + { + inherit (pyProject.tool.poetry) description; + } // lib.optionalAttrs (lib.hasAttr "homepage" pyProject.tool.poetry) { inherit (pyProject.tool.poetry) homepage; } // { inherit (py.meta) platforms; diff --git a/editable.nix b/editable.nix index 8b0d933e4..12b659d4c 100644 --- a/editable.nix +++ b/editable.nix @@ -29,25 +29,26 @@ let # A python package that contains simple .egg-info and .pth files for an editable installation editablePackage = python.pkgs.toPythonModule (pkgs.runCommandNoCC "${name}-editable" { } '' - mkdir -p "$out/${python.sitePackages}" - cd "$out/${python.sitePackages}" + mkdir -p "$out/${python.sitePackages}" + cd "$out/${python.sitePackages}" - # See https://docs.python.org/3.8/library/site.html for info on such .pth files - # These add another site package path for each line - touch poetry2nix-editable.pth - ${lib.concatMapStringsSep "\n" (src: '' - echo "${toString src}" >> poetry2nix-editable.pth - '') - (lib.attrValues editablePackageSources)} + # See https://docs.python.org/3.8/library/site.html for info on such .pth files + # These add another site package path for each line + touch poetry2nix-editable.pth + ${lib.concatMapStringsSep "\n" + (src: '' + echo "${toString src}" >> poetry2nix-editable.pth + '') + (lib.attrValues editablePackageSources)} - # Create a very simple egg so pkg_resources can find this package - # See https://setuptools.readthedocs.io/en/latest/formats.html for more info on the egg format - mkdir "${name}.egg-info" - cd "${name}.egg-info" - ln -s ${pkgInfoFile} PKG-INFO - ${lib.optionalString (pyProject.tool.poetry ? plugins) '' - ln -s ${entryPointsFile} entry_points.txt - ''} + # Create a very simple egg so pkg_resources can find this package + # See https://setuptools.readthedocs.io/en/latest/formats.html for more info on the egg format + mkdir "${name}.egg-info" + cd "${name}.egg-info" + ln -s ${pkgInfoFile} PKG-INFO + ${lib.optionalString (pyProject.tool.poetry ? plugins) '' + ln -s ${entryPointsFile} entry_points.txt + ''} '' ); in diff --git a/hooks/default.nix b/hooks/default.nix index e248a5e22..6d60df284 100644 --- a/hooks/default.nix +++ b/hooks/default.nix @@ -24,7 +24,8 @@ in pyprojectPatchScript = "${./pyproject-without-path.py}"; }; } ./remove-path-dependencies.sh - ) { }; + ) + { }; pipBuildHook = callPackage ( @@ -37,7 +38,8 @@ in inherit pythonInterpreter pythonSitePackages; }; } ./pip-build-hook.sh - ) { }; + ) + { }; poetry2nixFixupHook = callPackage ( @@ -47,7 +49,8 @@ in name = "fixup-hook.sh"; deps = [ ]; } ./fixup-hook.sh - ) { }; + ) + { }; # When the "wheel" package itself is a wheel the nixpkgs hook (which pulls in "wheel") leads to infinite recursion # It doesn't _really_ depend on wheel though, it just copies the wheel. @@ -58,7 +61,8 @@ in name = "wheel-unpack-hook.sh"; deps = [ ]; } ./wheel-unpack-hook.sh - ) { }; + ) + { }; } diff --git a/lib.nix b/lib.nix index 01342f46d..6a0ee70f8 100644 --- a/lib.nix +++ b/lib.nix @@ -158,7 +158,8 @@ let + "Add such a section as described in https://python-poetry.org/docs/pyproject/#poetry-and-pep-517"; requires = lib.attrByPath [ "build-system" "requires" ] (throw missingBuildBackendError) pyProject; requiredPkgs = builtins.map (n: lib.elemAt (builtins.match "([^!=<>~\[]+).*" n) 0) requires; - in builtins.map (drvAttr: pythonPackages.${drvAttr} or (throw "unsupported build system requirement ${drvAttr}")) requiredPkgs; + in + builtins.map (drvAttr: pythonPackages.${drvAttr} or (throw "unsupported build system requirement ${drvAttr}")) requiredPkgs; # Find gitignore files recursively in parent directory stopping with .git findGitIgnores = path: diff --git a/mk-poetry-dep.nix b/mk-poetry-dep.nix index 8d73fad2e..9619e3649 100644 --- a/mk-poetry-dep.nix +++ b/mk-poetry-dep.nix @@ -53,9 +53,11 @@ pythonPackages.callPackage pyProjectPath = localDepPath + "/pyproject.toml"; pyProject = poetryLib.readTOML pyProjectPath; in - if builtins.pathExists pyProjectPath then poetryLib.getBuildSystemPkgs { - inherit pythonPackages pyProject; - } else [ ]; + if builtins.pathExists pyProjectPath then + poetryLib.getBuildSystemPkgs + { + inherit pythonPackages pyProject; + } else [ ]; fileInfo = let @@ -151,15 +153,18 @@ pythonPackages.callPackage # Interpreters should declare what wheel types they're compatible with (python type + ABI) # Here we can then choose a file based on that info. src = - if isGit then ( - builtins.fetchGit { - inherit (source) url; - rev = source.reference; - ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD"; - } - ) else if isLocal then (poetryLib.cleanPythonSources { src = localDepPath; }) else fetchFromPypi { + if isGit then + ( + builtins.fetchGit { + inherit (source) url; + rev = source.reference; + ref = sourceSpec.branch or sourceSpec.rev or sourceSpec.tag or "HEAD"; + } + ) else if isLocal then (poetryLib.cleanPythonSources { src = localDepPath; }) else + fetchFromPypi { pname = name; inherit (fileInfo) file hash kind; }; } - ) { } + ) +{ } diff --git a/nix/sources.nix b/nix/sources.nix index e999000f3..fda1d21b4 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -24,7 +24,8 @@ let $ niv modify -a type=tarball -a builtin=true '' - builtins_fetchTarball { inherit (spec) url sha256; }; + builtins_fetchTarball + { inherit (spec) url sha256; }; fetch_builtin-url = spec: builtins.trace '' @@ -106,8 +107,9 @@ let ( name: spec: if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" + then + abort + "The values in sources.json should not have an 'outPath' attribute" else spec // { outPath = fetch config.pkgs name spec; } ) diff --git a/overrides.nix b/overrides.nix index 9dcbfa8fb..ca6c0c7cc 100644 --- a/overrides.nix +++ b/overrides.nix @@ -89,7 +89,8 @@ self: super: cffi = # cffi is bundled with pypy - if self.python.implementation == "pypy" then null else ( + if self.python.implementation == "pypy" then null else + ( super.cffi.overridePythonAttrs ( old: { buildInputs = old.buildInputs ++ [ pkgs.libffi ]; @@ -476,21 +477,23 @@ self: super: ); molecule = - if lib.versionOlder super.molecule.version "3.0.0" then (super.molecule.overridePythonAttrs ( - old: { - patches = (old.patches or [ ]) ++ [ - # Fix build with more recent setuptools versions - (pkgs.fetchpatch { - url = "https://github.com/ansible-community/molecule/commit/c9fee498646a702c77b5aecf6497cff324acd056.patch"; - sha256 = "1g1n45izdz0a3c9akgxx14zhdw6c3dkb48j8pq64n82fa6ndl1b7"; - excludes = [ "pyproject.toml" ]; - }) - ]; + if lib.versionOlder super.molecule.version "3.0.0" then + (super.molecule.overridePythonAttrs ( + old: { + patches = (old.patches or [ ]) ++ [ + # Fix build with more recent setuptools versions + (pkgs.fetchpatch { + url = "https://github.com/ansible-community/molecule/commit/c9fee498646a702c77b5aecf6497cff324acd056.patch"; + sha256 = "1g1n45izdz0a3c9akgxx14zhdw6c3dkb48j8pq64n82fa6ndl1b7"; + excludes = [ "pyproject.toml" ]; + }) + ]; + buildInputs = old.buildInputs ++ [ self.setuptools-scm-git-archive ]; + } + )) else + super.molecule.overridePythonAttrs (old: { buildInputs = old.buildInputs ++ [ self.setuptools-scm-git-archive ]; - } - )) else super.molecule.overridePythonAttrs (old: { - buildInputs = old.buildInputs ++ [ self.setuptools-scm-git-archive ]; - }); + }); mongomock = super.mongomock.overridePythonAttrs (oa: { buildInputs = oa.buildInputs ++ [ self.pbr ]; @@ -534,15 +537,16 @@ self: super: name = "site.cfg"; text = ( lib.generators.toINI - { } { - ${blasImplementation} = { - include_dirs = "${blas}/include"; - library_dirs = "${blas}/lib"; - } // lib.optionalAttrs (blasImplementation == "mkl") { - mkl_libs = "mkl_rt"; - lapack_libs = ""; - }; - } + { } + { + ${blasImplementation} = { + include_dirs = "${blas}/include"; + library_dirs = "${blas}/lib"; + } // lib.optionalAttrs (blasImplementation == "mkl") { + mkl_libs = "mkl_rt"; + lapack_libs = ""; + }; + } ); }; in @@ -594,7 +598,7 @@ self: super: } ); - poetry-core = super.poetry-core.overridePythonAttrs(old: { + poetry-core = super.poetry-core.overridePythonAttrs (old: { # "Vendor" dependencies (for build-system support) postPatch = '' echo "import sys" >> poetry/__init__.py @@ -634,61 +638,65 @@ self: super: ); pyarrow = - if lib.versionAtLeast super.pyarrow.version "0.16.0" then super.pyarrow.overridePythonAttrs ( - old: - let - parseMinor = drv: lib.concatStringsSep "." (lib.take 2 (lib.splitVersion drv.version)); - - # Starting with nixpkgs revision f149c7030a7, pyarrow takes "python3" as an argument - # instead of "python". Below we inspect function arguments to maintain compatibilitiy. - _arrow-cpp = pkgs.arrow-cpp.override ( - builtins.intersectAttrs - (lib.functionArgs pkgs.arrow-cpp.override) { python = self.python; python3 = self.python; } - ); - - ARROW_HOME = _arrow-cpp; - arrowCppVersion = parseMinor pkgs.arrow-cpp; - pyArrowVersion = parseMinor super.pyarrow; - errorMessage = "arrow-cpp version (${arrowCppVersion}) mismatches pyarrow version (${pyArrowVersion})"; - in - if arrowCppVersion != pyArrowVersion then throw errorMessage else { + if lib.versionAtLeast super.pyarrow.version "0.16.0" then + super.pyarrow.overridePythonAttrs + ( + old: + let + parseMinor = drv: lib.concatStringsSep "." (lib.take 2 (lib.splitVersion drv.version)); + + # Starting with nixpkgs revision f149c7030a7, pyarrow takes "python3" as an argument + # instead of "python". Below we inspect function arguments to maintain compatibilitiy. + _arrow-cpp = pkgs.arrow-cpp.override ( + builtins.intersectAttrs + (lib.functionArgs pkgs.arrow-cpp.override) + { python = self.python; python3 = self.python; } + ); + + ARROW_HOME = _arrow-cpp; + arrowCppVersion = parseMinor pkgs.arrow-cpp; + pyArrowVersion = parseMinor super.pyarrow; + errorMessage = "arrow-cpp version (${arrowCppVersion}) mismatches pyarrow version (${pyArrowVersion})"; + in + if arrowCppVersion != pyArrowVersion then throw errorMessage else { - nativeBuildInputs = old.nativeBuildInputs ++ [ - self.cython - pkgs.pkgconfig - pkgs.cmake - ]; + nativeBuildInputs = old.nativeBuildInputs ++ [ + self.cython + pkgs.pkgconfig + pkgs.cmake + ]; - preBuild = '' - export PYARROW_PARALLEL=$NIX_BUILD_CORES - ''; + preBuild = '' + export PYARROW_PARALLEL=$NIX_BUILD_CORES + ''; - PARQUET_HOME = _arrow-cpp; - inherit ARROW_HOME; + PARQUET_HOME = _arrow-cpp; + inherit ARROW_HOME; - buildInputs = old.buildInputs ++ [ - pkgs.arrow-cpp - ]; + buildInputs = old.buildInputs ++ [ + pkgs.arrow-cpp + ]; - PYARROW_BUILD_TYPE = "release"; - PYARROW_WITH_PARQUET = true; - PYARROW_CMAKE_OPTIONS = [ - "-DCMAKE_INSTALL_RPATH=${ARROW_HOME}/lib" + PYARROW_BUILD_TYPE = "release"; + PYARROW_WITH_PARQUET = true; + PYARROW_CMAKE_OPTIONS = [ + "-DCMAKE_INSTALL_RPATH=${ARROW_HOME}/lib" - # This doesn't use setup hook to call cmake so we need to workaround #54606 - # ourselves - "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW" - ]; + # This doesn't use setup hook to call cmake so we need to workaround #54606 + # ourselves + "-DCMAKE_POLICY_DEFAULT_CMP0025=NEW" + ]; - dontUseCmakeConfigure = true; - } - ) else super.pyarrow.overridePythonAttrs ( - old: { - nativeBuildInputs = old.nativeBuildInputs ++ [ - self.cython - ]; - } - ); + dontUseCmakeConfigure = true; + } + ) else + super.pyarrow.overridePythonAttrs ( + old: { + nativeBuildInputs = old.nativeBuildInputs ++ [ + self.cython + ]; + } + ); pycairo = ( drv: ( @@ -748,20 +756,22 @@ self: super: # Tests fail because of no audio device and display. doCheck = false; preConfigure = '' - sed \ - -e "s/origincdirs = .*/origincdirs = []/" \ - -e "s/origlibdirs = .*/origlibdirs = []/" \ - -e "/'\/lib\/i386-linux-gnu', '\/lib\/x86_64-linux-gnu']/d" \ - -e "/\/include\/smpeg/d" \ - -i buildconfig/config_unix.py - ${lib.concatMapStrings (dep: '' - sed \ - -e "/origincdirs =/a\ origincdirs += ['${lib.getDev dep}/include']" \ - -e "/origlibdirs =/a\ origlibdirs += ['${lib.getLib dep}/lib']" \ - -i buildconfig/config_unix.py - '') buildInputs - } - LOCALBASE=/ ${self.python.interpreter} buildconfig/config.py + sed \ + -e "s/origincdirs = .*/origincdirs = []/" \ + -e "s/origlibdirs = .*/origlibdirs = []/" \ + -e "/'\/lib\/i386-linux-gnu', '\/lib\/x86_64-linux-gnu']/d" \ + -e "/\/include\/smpeg/d" \ + -i buildconfig/config_unix.py + ${lib.concatMapStrings + (dep: '' + sed \ + -e "/origincdirs =/a\ origincdirs += ['${lib.getDev dep}/include']" \ + -e "/origlibdirs =/a\ origlibdirs += ['${lib.getLib dep}/lib']" \ + -i buildconfig/config_unix.py + '') + buildInputs + } + LOCALBASE=/ ${self.python.interpreter} buildconfig/config.py ''; } ); @@ -1034,13 +1044,14 @@ self: super: ); shellingham = - if lib.versionAtLeast super.shellingham.version "1.3.2" then ( - super.shellingham.overridePythonAttrs ( - old: { - format = "pyproject"; - } - ) - ) else super.shellingham; + if lib.versionAtLeast super.shellingham.version "1.3.2" then + ( + super.shellingham.overridePythonAttrs ( + old: { + format = "pyproject"; + } + ) + ) else super.shellingham; tables = super.tables.overridePythonAttrs ( old: { @@ -1162,17 +1173,18 @@ self: super: zipp = if super.zipp == null then null else ( - if lib.versionAtLeast super.zipp.version "2.0.0" then ( - super.zipp.overridePythonAttrs ( - old: { - prePatch = '' - substituteInPlace setup.py --replace \ - 'setuptools.setup()' \ - 'setuptools.setup(version="${super.zipp.version}")' - ''; - } - ) - ) else super.zipp + if lib.versionAtLeast super.zipp.version "2.0.0" then + ( + super.zipp.overridePythonAttrs ( + old: { + prePatch = '' + substituteInPlace setup.py --replace \ + 'setuptools.setup()' \ + 'setuptools.setup(version="${super.zipp.version}")' + ''; + } + ) + ) else super.zipp ).overridePythonAttrs ( old: { propagatedBuildInputs = old.propagatedBuildInputs ++ [ diff --git a/pep425.nix b/pep425.nix index ffa78c5dc..d32e3aacc 100644 --- a/pep425.nix +++ b/pep425.nix @@ -71,12 +71,13 @@ let withPython = ver: abi: x: (isPyVersionCompatible ver x.pyVer) && (isPyAbiCompatible abi x.abi); withPlatform = if isLinux - then ( - x: x.platform == "manylinux1_${stdenv.platform.kernelArch}" - || x.platform == "manylinux2010_${stdenv.platform.kernelArch}" - || x.platform == "manylinux2014_${stdenv.platform.kernelArch}" - || x.platform == "any" - ) + then + ( + x: x.platform == "manylinux1_${stdenv.platform.kernelArch}" + || x.platform == "manylinux2010_${stdenv.platform.kernelArch}" + || x.platform == "manylinux2014_${stdenv.platform.kernelArch}" + || x.platform == "any" + ) else (x: hasInfix "macosx" x.platform || x.platform == "any"); filterWheel = x: let diff --git a/pep508.nix b/pep508.nix index e0c0b7a1d..ba8145398 100644 --- a/pep508.nix +++ b/pep508.nix @@ -8,30 +8,32 @@ let # Strip leading/trailing whitespace from string stripStr = s: lib.elemAt (builtins.split "^ *" (lib.elemAt (builtins.split " *$" s) 0)) 2; findSubExpressionsFun = acc: c: ( - if c == "(" then ( - let - posNew = acc.pos + 1; - isOpen = acc.openP == 0; - startPos = if isOpen then posNew else acc.startPos; - in - acc // { - inherit startPos; - exprs = acc.exprs ++ [ (substr acc.exprPos (acc.pos - 1) acc.expr) ]; - pos = posNew; - openP = acc.openP + 1; - } - ) else if c == ")" then ( - let - openP = acc.openP - 1; - exprs = findSubExpressions (substr acc.startPos acc.pos acc.expr); - in - acc // { - inherit openP; - pos = acc.pos + 1; - exprs = if openP == 0 then acc.exprs ++ [ exprs ] else acc.exprs; - exprPos = if openP == 0 then acc.pos + 1 else acc.exprPos; - } - ) else acc // { pos = acc.pos + 1; } + if c == "(" then + ( + let + posNew = acc.pos + 1; + isOpen = acc.openP == 0; + startPos = if isOpen then posNew else acc.startPos; + in + acc // { + inherit startPos; + exprs = acc.exprs ++ [ (substr acc.exprPos (acc.pos - 1) acc.expr) ]; + pos = posNew; + openP = acc.openP + 1; + } + ) else if c == ")" then + ( + let + openP = acc.openP - 1; + exprs = findSubExpressions (substr acc.startPos acc.pos acc.expr); + in + acc // { + inherit openP; + pos = acc.pos + 1; + exprs = if openP == 0 then acc.exprs ++ [ exprs ] else acc.exprs; + exprPos = if openP == 0 then acc.pos + 1 else acc.exprPos; + } + ) else acc // { pos = acc.pos + 1; } ); # Make a tree out of expression groups (parens) @@ -122,26 +124,28 @@ let substituteVar ]; in - if builtins.typeOf exprs == "set" then ( - if exprs.type == "expr" then ( - let - mVal = ''[a-zA-Z0-9\'"_\. ]+''; - mOp = "in|[!=<>]+"; - e = stripStr exprs.value; - m = builtins.map stripStr (builtins.match ''^(${mVal}) *(${mOp}) *(${mVal})$'' e); - m0 = processVar (builtins.elemAt m 0); - m2 = processVar (builtins.elemAt m 2); - in - { - type = "expr"; - value = { - # HACK: We don't know extra at eval time, so we assume the expression is always true - op = if m0 == "extra" then "true" else builtins.elemAt m 1; - values = [ m0 m2 ]; - }; - } - ) else exprs - ) else builtins.map transformExpressions exprs; + if builtins.typeOf exprs == "set" then + ( + if exprs.type == "expr" then + ( + let + mVal = ''[a-zA-Z0-9\'"_\. ]+''; + mOp = "in|[!=<>]+"; + e = stripStr exprs.value; + m = builtins.map stripStr (builtins.match ''^(${mVal}) *(${mOp}) *(${mVal})$'' e); + m0 = processVar (builtins.elemAt m 0); + m2 = processVar (builtins.elemAt m 2); + in + { + type = "expr"; + value = { + # HACK: We don't know extra at eval time, so we assume the expression is always true + op = if m0 == "extra" then "true" else builtins.elemAt m 1; + values = [ m0 m2 ]; + }; + } + ) else exprs + ) else builtins.map transformExpressions exprs; # Recursively eval all expressions evalExpressions = exprs: @@ -179,18 +183,20 @@ let builtins.elem (unmarshal x) values; }; in - if builtins.typeOf exprs == "set" then ( - if exprs.type == "expr" then ( - let - expr = exprs; - result = (op."${expr.value.op}") (builtins.elemAt expr.value.values 0) (builtins.elemAt expr.value.values 1); - in - { - type = "value"; - value = result; - } - ) else exprs - ) else builtins.map evalExpressions exprs; + if builtins.typeOf exprs == "set" then + ( + if exprs.type == "expr" then + ( + let + expr = exprs; + result = (op."${expr.value.op}") (builtins.elemAt expr.value.values 0) (builtins.elemAt expr.value.values 1); + in + { + type = "value"; + value = result; + } + ) else exprs + ) else builtins.map evalExpressions exprs; # Now that we have performed an eval all that's left to do is to concat the graph into a single bool reduceExpressions = exprs: @@ -200,30 +206,34 @@ let "or" = x: y: x || y; }; reduceExpressionsFun = acc: v: ( - if builtins.typeOf v == "set" then ( - if v.type == "value" then ( - acc // { - value = cond."${acc.cond}" acc.value v.value; - } - ) else if v.type == "bool" then ( + if builtins.typeOf v == "set" then + ( + if v.type == "value" then + ( + acc // { + value = cond."${acc.cond}" acc.value v.value; + } + ) else if v.type == "bool" then + ( + acc // { + cond = v.value; + } + ) else throw "Unsupported type" + ) else if builtins.typeOf v == "list" then + ( + let + ret = builtins.foldl' + reduceExpressionsFun + { + value = true; + cond = "and"; + } + v; + in acc // { - cond = v.value; + value = cond."${acc.cond}" acc.value ret.value; } ) else throw "Unsupported type" - ) else if builtins.typeOf v == "list" then ( - let - ret = builtins.foldl' - reduceExpressionsFun - { - value = true; - cond = "and"; - } - v; - in - acc // { - value = cond."${acc.cond}" acc.value ret.value; - } - ) else throw "Unsupported type" ); in (