diff options
Diffstat (limited to 'nixpkgs/pkgs/development/interpreters/python')
27 files changed, 172 insertions, 31 deletions
diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix index 77b37c5f5c3..696be2136ec 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/2.7/default.nix @@ -263,7 +263,7 @@ in with passthru; stdenv.mkDerivation ({ doCheck = false; # expensive, and fails meta = { - homepage = http://python.org; + homepage = "http://python.org"; description = "A high-level dynamically-typed programming language"; longDescription = '' Python is a remarkably powerful dynamic programming language that diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix index b778b62f908..43d635f3a33 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/default.nix @@ -28,6 +28,8 @@ , stripTkinter ? false , rebuildBytecode ? true , stripBytecode ? false +, includeSiteCustomize ? true +, static ? false }: assert x11Support -> tcl != null @@ -130,7 +132,7 @@ in with passthru; stdenv.mkDerivation { CPPFLAGS = concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs); LDFLAGS = concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs); LIBS = "${optionalString (!stdenv.isDarwin) "-lcrypt"} ${optionalString (ncurses != null) "-lncurses"}"; - NIX_LDFLAGS = optionalString stdenv.isLinux "-lgcc_s"; + NIX_LDFLAGS = optionalString (stdenv.isLinux && !stdenv.hostPlatform.isMusl) "-lgcc_s" + optionalString stdenv.hostPlatform.isMusl "-lgcc_eh"; # Determinism: We fix the hashes of str, bytes and datetime objects. PYTHONHASHSEED=0; @@ -169,7 +171,7 @@ in with passthru; stdenv.mkDerivation { # Never even try to use lchmod on linux, # don't rely on detecting glibc-isms. "ac_cv_func_lchmod=no" - ]; + ] ++ optional static "LDFLAGS=-static"; preConfigure = '' for i in /usr /sw /opt /pkg; do # improve purity @@ -237,7 +239,7 @@ in with passthru; stdenv.mkDerivation { '' + optionalString stripTests '' # Strip tests rm -R $out/lib/python*/test $out/lib/python*/**/test{,s} - '' + '' + '' + optionalString includeSiteCustomize '' # Include a sitecustomize.py file cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py '' + optionalString rebuildBytecode '' @@ -262,7 +264,7 @@ in with passthru; stdenv.mkDerivation { # Enforce that we don't have references to the OpenSSL -dev package, which we # explicitly specify in our configure flags above. disallowedReferences = - stdenv.lib.optionals (openssl != null) [ openssl.dev ] + stdenv.lib.optionals (openssl != null && !static) [ openssl.dev ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ # Ensure we don't have references to build-time packages. # These typically end up in shebangs. @@ -274,7 +276,7 @@ in with passthru; stdenv.mkDerivation { enableParallelBuilding = true; meta = { - homepage = http://python.org; + homepage = "http://python.org"; description = "A high-level dynamically-typed programming language"; longDescription = '' Python is a remarkably powerful dynamic programming language that diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix index e27959c05e8..e033858acc0 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-html.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python27-docs-html-2.7.16"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-html.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-html.tar.bz2"; sha256 = "1razs1grzhai65ihaiyph8kz6ncjkgp1gsn3c8v7kanf13lqim02"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix index 0226f7cd880..c9a770a6fcf 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-a4.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python27-docs-pdf-a4-2.7.16"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-pdf-a4.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-pdf-a4.tar.bz2"; sha256 = "14ml1ynrlbhg43737bdsb8k5y39wsffqj4iwhylhb8n8l5dplfdq"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix index 88d1a693166..e03d031bae4 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-pdf-letter.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python27-docs-pdf-letter-2.7.16"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-pdf-letter.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-pdf-letter.tar.bz2"; sha256 = "019i8n48m71mn31v8d85kkwyqfgcgqnqh506y4a7fcgf656bajs0"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix index ea35e9fb6a3..d19d7be1935 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/2.7-text.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python27-docs-text-2.7.16"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-text.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/2.7.16/python-2.7.16-docs-text.tar.bz2"; sha256 = "1da7swlykvc013684nywycinfz3v8dqkcmv0zj8p7l5lyi5mq03r"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-html.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-html.nix index 45783eb8263..a83363b5c47 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-html.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-html.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python37-docs-html-3.7.2"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-html.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-html.tar.bz2"; sha256 = "19wbrawpdam09fmyipfy92sxwn1rl93v8jkfqsfx028qhvzf0422"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-a4.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-a4.nix index 998af644c71..e60032f71bf 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-a4.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-a4.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python37-docs-pdf-a4-3.7.2"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-pdf-a4.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-pdf-a4.tar.bz2"; sha256 = "0vdx762m30hjaabn6w88awcj2qpbz0b6z59zn9wmamd35k59lfba"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-letter.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-letter.nix index 1c6aea5ee3c..b737a1e3299 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-letter.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-pdf-letter.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python37-docs-pdf-letter-3.7.2"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-pdf-letter.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-pdf-letter.tar.bz2"; sha256 = "17g57vlyvqx0k916q84q2pcx7y8myw0fda9fvg9kh0ph930c837x"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-text.nix b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-text.nix index 32388780f6f..2897042ec04 100644 --- a/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-text.nix +++ b/nixpkgs/pkgs/development/interpreters/python/cpython/docs/3.7-text.nix @@ -5,7 +5,7 @@ stdenv.mkDerivation { name = "python37-docs-text-3.7.2"; src = fetchurl { - url = http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-text.tar.bz2; + url = "http://docs.python.org/ftp/python/doc/3.7.2/python-3.7.2-docs-text.tar.bz2"; sha256 = "0h50rlr8jclwfxa106b42q2vn2ynp219c4zsy5qz65n5m3b7y1g2"; }; installPhase = '' diff --git a/nixpkgs/pkgs/development/interpreters/python/default.nix b/nixpkgs/pkgs/development/interpreters/python/default.nix index 94f04b73f49..099632b1e85 100644 --- a/nixpkgs/pkgs/development/interpreters/python/default.nix +++ b/nixpkgs/pkgs/development/interpreters/python/default.nix @@ -96,10 +96,10 @@ in { sourceVersion = { major = "3"; minor = "7"; - patch = "6"; + patch = "7"; suffix = ""; }; - sha256 = "0gskry19ylw91p38pdq36qcgk6h3x5i4ia0ik977kw2943kwr8jm"; + sha256 = "0di1y2cna823qgk6sd2lvpjdm3g2qikdd50i2bjd330dpzqsk806"; inherit (darwin) configd; inherit passthruFun; }; @@ -147,6 +147,7 @@ in { stripTkinter = true; rebuildBytecode = false; stripBytecode = true; + includeSiteCustomize = false; }).overrideAttrs(old: { pname = "python3-minimal"; meta = old.meta // { diff --git a/nixpkgs/pkgs/development/interpreters/python/hooks/default.nix b/nixpkgs/pkgs/development/interpreters/python/hooks/default.nix index 47690320e81..4d736426f3b 100644 --- a/nixpkgs/pkgs/development/interpreters/python/hooks/default.nix +++ b/nixpkgs/pkgs/development/interpreters/python/hooks/default.nix @@ -89,6 +89,14 @@ in rec { }; } ./python-imports-check-hook.sh) {}; + pythonNamespacesHook = callPackage ({}: + makeSetupHook { + name = "python-namespaces-hook.sh"; + substitutions = { + inherit pythonSitePackages; + }; + } ./python-namespaces-hook.sh) {}; + pythonRemoveBinBytecodeHook = callPackage ({ }: makeSetupHook { name = "python-remove-bin-bytecode-hook"; diff --git a/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh b/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh new file mode 100644 index 00000000000..50f21819d17 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/hooks/python-namespaces-hook.sh @@ -0,0 +1,40 @@ +# Clean up __init__.py's found in namespace directories +echo "Sourcing python-namespaces-hook" + +pythonNamespacesHook() { + echo "Executing pythonNamespacesHook" + + for namespace in ${pythonNamespaces[@]}; do + echo "Enforcing PEP420 namespace: ${namespace}" + + # split namespace into segments. "azure.mgmt" -> "azure mgmt" + IFS='.' read -ra pathSegments <<< $namespace + constructedPath=$out/@pythonSitePackages@ + + # Need to remove the __init__.py at each namespace level + # E.g `azure/__init__.py` and `azure/mgmt/__init__.py` + # The __pycache__ entry also needs to be removed + for pathSegment in ${pathSegments[@]}; do + constructedPath=${constructedPath}/${pathSegment} + pathToRemove=${constructedPath}/__init__.py + pycachePath=${constructedPath}/__pycache__/__init__* + + if [ -f "$pathToRemove" ]; then + echo "Removing $pathToRemove" + rm "$pathToRemove" + fi + + if [ -f "$pycachePath" ]; then + echo "Removing $pycachePath" + rm "$pycachePath" + fi + done + done + + echo "Finished executing pythonNamespacesHook" +} + +if [ -z "${dontUsePythonNamespacesHook-}" -a -n "${pythonNamespaces-}" ]; then + postFixupHooks+=(pythonNamespacesHook) +fi + diff --git a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix index 180bc63857c..22938a45585 100644 --- a/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/nixpkgs/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -16,6 +16,7 @@ , pipInstallHook , pythonCatchConflictsHook , pythonImportsCheckHook +, pythonNamespacesHook , pythonRemoveBinBytecodeHook , pythonRemoveTestsDirHook , setuptoolsBuildHook @@ -131,6 +132,9 @@ let ] ++ lib.optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ # This is a test, however, it should be ran independent of the checkPhase and checkInputs pythonImportsCheckHook + ] ++ lib.optionals (python.pythonAtLeast "3.3") [ + # Optionally enforce PEP420 for python3 + pythonNamespacesHook ] ++ nativeBuildInputs; buildInputs = buildInputs ++ pythonPath; diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix index 54400ae3e0a..e782eb2fdee 100644 --- a/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix +++ b/nixpkgs/pkgs/development/interpreters/python/pypy/default.nix @@ -151,7 +151,7 @@ in with passthru; stdenv.mkDerivation rec { enableParallelBuilding = true; # almost no parallelization without STM meta = with stdenv.lib; { - homepage = http://pypy.org/; + homepage = "http://pypy.org/"; description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})"; license = licenses.mit; platforms = [ "i686-linux" "x86_64-linux" "x86_64-darwin" ]; diff --git a/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix index 7ac8037293f..0ebd3364834 100644 --- a/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix +++ b/nixpkgs/pkgs/development/interpreters/python/pypy/prebuilt.nix @@ -117,7 +117,7 @@ in with passthru; stdenv.mkDerivation { inherit passthru; meta = with stdenv.lib; { - homepage = http://pypy.org/; + homepage = "http://pypy.org/"; description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})"; license = licenses.mit; platforms = [ "x86_64-linux" ]; diff --git a/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py b/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py index e03b244dbc0..72ce951328f 100644 --- a/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py +++ b/nixpkgs/pkgs/development/interpreters/python/sitecustomize.py @@ -21,6 +21,19 @@ paths = os.environ.pop('NIX_PYTHONPATH', None) if paths: functools.reduce(lambda k, p: site.addsitedir(p, k), paths.split(':'), site._init_pathinfo()) -executable = os.environ.pop('NIX_PYTHONEXECUTABLE', None) -if 'PYTHONEXECUTABLE' not in os.environ and executable: - sys.executable = executable +# Check whether we are in a venv. +# Note Python 2 does not support base_prefix so we assume we are not in a venv. +in_venv = sys.version_info.major == 3 and sys.prefix != sys.base_prefix + +if not in_venv: + executable = os.environ.pop('NIX_PYTHONEXECUTABLE', None) + prefix = os.environ.pop('NIX_PYTHONPREFIX', None) + + if 'PYTHONEXECUTABLE' not in os.environ and executable is not None: + sys.executable = executable + if prefix is not None: + # Because we cannot check with Python 2 whether we are in a venv, + # creating a venv from a Nix env won't work as well with Python 2. + # Also, note that sysconfig does not like it when sys.prefix is set to None + sys.prefix = sys.exec_prefix = prefix + site.PREFIXES.insert(0, prefix) diff --git a/nixpkgs/pkgs/development/interpreters/python/tests.nix b/nixpkgs/pkgs/development/interpreters/python/tests.nix index 37fbe670114..55065c45d57 100644 --- a/nixpkgs/pkgs/development/interpreters/python/tests.nix +++ b/nixpkgs/pkgs/development/interpreters/python/tests.nix @@ -2,6 +2,7 @@ , runCommand , substituteAll , lib +, callPackage }: let @@ -36,6 +37,7 @@ let is_venv = "True"; is_nixenv = "False"; }; + # Venv built using Python Nix environment (python.buildEnv) # TODO: Cannot create venv from a nix env # Error: Command '['/nix/store/ddc8nqx73pda86ibvhzdmvdsqmwnbjf7-python3-3.7.6-venv/bin/python3.7', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1. @@ -49,6 +51,14 @@ let # }; }; + # All PyPy package builds are broken at the moment + integrationTests = lib.optionalAttrs (python.isPy3k && (!python.isPyPy)) rec { + # Before the addition of NIX_PYTHONPREFIX mypy was broken with typed packages + nix-pythonprefix-mypy = callPackage ./tests/test_nix_pythonprefix { + interpreter = python; + }; + }; + testfun = name: attrs: runCommand "${python.name}-tests-${name}" ({ inherit (python) pythonVersion; } // attrs) '' @@ -60,4 +70,4 @@ let touch $out/success ''; -in lib.mapAttrs testfun envs
\ No newline at end of file +in lib.mapAttrs testfun envs // integrationTests diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/default.nix b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/default.nix new file mode 100644 index 00000000000..05798cbaf1b --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/default.nix @@ -0,0 +1,25 @@ +{ interpreter, writeText, runCommandNoCC }: + +let + + python = let + packageOverrides = self: super: { + typeddep = super.callPackage ./typeddep {}; + }; + in interpreter.override {inherit packageOverrides; self = python;}; + + pythonEnv = python.withPackages(ps: [ + ps.typeddep + ps.mypy + ]); + + pythonScript = writeText "myscript.py" '' + from typeddep import util + s: str = util.echo("hello") + print(s) + ''; + +in runCommandNoCC "${interpreter.name}-site-prefix-mypy-test" {} '' + ${pythonEnv}/bin/mypy ${pythonScript} + touch $out +'' diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/default.nix b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/default.nix new file mode 100644 index 00000000000..06219a69fca --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/default.nix @@ -0,0 +1,11 @@ +{ buildPythonPackage }: + + +buildPythonPackage { + + pname = "typeddep"; + version = "1.3.3.7"; + + src = ./.; + +} diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/setup.py b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/setup.py new file mode 100644 index 00000000000..25bac69ea09 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/setup.py @@ -0,0 +1,18 @@ +from setuptools import setup + +setup(**{ + 'name': 'typeddep', + 'version': '1.3.3.7', + 'description': 'Minimal repro to test mypy and site prefixes with Nix', + 'long_description': None, + 'author': 'adisbladis', + 'author_email': 'adisbladis@gmail.com', + 'maintainer': None, + 'maintainer_email': None, + 'url': None, + 'packages': ['typeddep'], + 'package_data': {'': ['*']}, + 'install_requires': [], + 'entry_points': {}, + 'python_requires': '>=3.7,<4.0', +}) diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/__init__.py b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/__init__.py diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/py.typed b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/py.typed new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/py.typed diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/util.py b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/util.py new file mode 100644 index 00000000000..c1c3ffe7477 --- /dev/null +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_nix_pythonprefix/typeddep/typeddep/util.py @@ -0,0 +1,2 @@ +def echo(s: str) -> str: + return s diff --git a/nixpkgs/pkgs/development/interpreters/python/tests/test_python.py b/nixpkgs/pkgs/development/interpreters/python/tests/test_python.py index f631a172ccc..011978c6254 100644 --- a/nixpkgs/pkgs/development/interpreters/python/tests/test_python.py +++ b/nixpkgs/pkgs/development/interpreters/python/tests/test_python.py @@ -27,7 +27,7 @@ class TestCasePython(unittest.TestCase): def test_interpreter(self): self.assertEqual(sys.executable, INTERPRETER) - @unittest.skipIf(IS_NIXENV or IS_PYPY, "Prefix is incorrect and needs to be fixed.") + @unittest.skipIf(IS_PYPY, "Prefix is incorrect and needs to be fixed.") def test_prefix(self): self.assertEqual(sys.prefix, ENV) self.assertEqual(sys.prefix, sys.exec_prefix) @@ -35,9 +35,9 @@ class TestCasePython(unittest.TestCase): def test_site_prefix(self): self.assertTrue(sys.prefix in site.PREFIXES) - @unittest.skipIf(sys.version_info.major==2, "Python 2 does not have base_prefix") + @unittest.skipIf(IS_PYPY or sys.version_info.major==2, "Python 2 does not have base_prefix") def test_base_prefix(self): - if IS_VENV: + if IS_VENV or IS_NIXENV: self.assertNotEqual(sys.prefix, sys.base_prefix) else: self.assertEqual(sys.prefix, sys.base_prefix) diff --git a/nixpkgs/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py b/nixpkgs/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py index 7e0580ce063..b568ee6751d 100755 --- a/nixpkgs/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py +++ b/nixpkgs/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py @@ -315,11 +315,11 @@ def _update(path, target): return False -def _commit(path, pname, old_version, new_version, **kwargs): +def _commit(path, pname, old_version, new_version, pkgs_prefix="python: ", **kwargs): """Commit result. """ - msg = f'python: {pname}: {old_version} -> {new_version}' + msg = f'{pkgs_prefix}{pname}: {old_version} -> {new_version}' try: subprocess.check_call([GIT, 'add', path]) @@ -337,6 +337,7 @@ def main(): parser.add_argument('package', type=str, nargs='+') parser.add_argument('--target', type=str, choices=SEMVER.keys(), default='major') parser.add_argument('--commit', action='store_true', help='Create a commit for each package update') + parser.add_argument('--use-pkgs-prefix', action='store_true', help='Use python3Packages.${pname}: instead of python: ${pname}: when making commits') args = parser.parse_args() target = args.target @@ -347,17 +348,23 @@ def main(): # Use threads to update packages concurrently with Pool() as p: - results = list(p.map(lambda pkg: _update(pkg, target), packages)) + results = list(filter(bool, p.map(lambda pkg: _update(pkg, target), packages))) logging.info("Finished updating packages.") + commit_options = {} + if args.use_pkgs_prefix: + logging.info("Using python3Packages. prefix for commits") + commit_options["pkgs_prefix"] = "python3Packages." + # Commits are created sequentially. if args.commit: logging.info("Committing updates...") - list(map(lambda x: _commit(**x), filter(bool, results))) + # list forces evaluation + list(map(lambda x: _commit(**x, **commit_options), results)) logging.info("Finished committing updates") - count = sum(map(bool, results)) + count = len(results) logging.info("{} package(s) updated".format(count)) diff --git a/nixpkgs/pkgs/development/interpreters/python/wrapper.nix b/nixpkgs/pkgs/development/interpreters/python/wrapper.nix index b437584024f..dffad6b98f5 100644 --- a/nixpkgs/pkgs/development/interpreters/python/wrapper.nix +++ b/nixpkgs/pkgs/development/interpreters/python/wrapper.nix @@ -37,7 +37,7 @@ let if [ -f "$prg" ]; then rm -f "$out/bin/$prg" if [ -x "$prg" ]; then - makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs} + makeWrapper "$path/bin/$prg" "$out/bin/$prg" --set NIX_PYTHONPREFIX "$out" --set NIX_PYTHONEXECUTABLE ${pythonExecutable} --set NIX_PYTHONPATH ${pythonPath} ${if permitUserSite then "" else ''--set PYTHONNOUSERSITE "true"''} ${stdenv.lib.concatStringsSep " " makeWrapperArgs} fi fi done |