Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

doc/python: cleanup examples, references

(cherry picked from commit 63f244193b11be3993c0c93a2e24af2d20863248)
(cherry picked from commit 94a409450a1773d12b44e0bec40fbd099f9fb883)
(cherry picked from commit 0ccfebf9f26f87b13e933c67e74cf4895cfa2fdf)

Changed files
+76 -80
doc
languages-frameworks
+76 -80
doc/languages-frameworks/python.section.md
··· 278 278 order to build [`datashape`](https://github.com/blaze/datashape). 279 279 280 280 ```nix 281 - { # ... 281 + { lib, buildPythonPackage, fetchPypi, numpy, multipledispatch, dateutil, pytest }: 282 282 283 - datashape = buildPythonPackage rec { 284 - pname = "datashape"; 285 - version = "0.4.7"; 283 + buildPythonPackage rec { 284 + pname = "datashape"; 285 + version = "0.4.7"; 286 286 287 - src = fetchPypi { 288 - inherit pname version; 289 - sha256 = "14b2ef766d4c9652ab813182e866f493475e65e558bed0822e38bf07bba1a278"; 290 - }; 287 + src = fetchPypi { 288 + inherit pname version; 289 + sha256 = "14b2ef766d4c9652ab813182e866f493475e65e558bed0822e38bf07bba1a278"; 290 + }; 291 291 292 - checkInputs = with self; [ pytest ]; 293 - propagatedBuildInputs = with self; [ numpy multipledispatch dateutil ]; 292 + checkInputs = [ pytest ]; 293 + propagatedBuildInputs = [ numpy multipledispatch dateutil ]; 294 294 295 - meta = with lib; { 296 - homepage = https://github.com/ContinuumIO/datashape; 297 - description = "A data description language"; 298 - license = licenses.bsd2; 299 - maintainers = with maintainers; [ fridh ]; 300 - }; 295 + meta = with lib; { 296 + homepage = https://github.com/ContinuumIO/datashape; 297 + description = "A data description language"; 298 + license = licenses.bsd2; 299 + maintainers = with maintainers; [ fridh ]; 301 300 }; 302 301 } 303 302 ``` 304 303 305 304 We can see several runtime dependencies, `numpy`, `multipledispatch`, and 306 - `dateutil`. Furthermore, we have one `buildInput`, i.e. `pytest`. `pytest` is a 305 + `dateutil`. Furthermore, we have one `checkInputs`, i.e. `pytest`. `pytest` is a 307 306 test runner and is only used during the `checkPhase` and is therefore not added 308 307 to `propagatedBuildInputs`. 309 308 ··· 313 312 when building the bindings and are therefore added as `buildInputs`. 314 313 315 314 ```nix 316 - { # ... 315 + { lib, pkgs, buildPythonPackage, fetchPypi }: 317 316 318 - lxml = buildPythonPackage rec { 319 - pname = "lxml"; 320 - version = "3.4.4"; 317 + buildPythonPackage rec { 318 + pname = "lxml"; 319 + version = "3.4.4"; 321 320 322 - src = fetchPypi { 323 - inherit pname version; 324 - sha256 = "16a0fa97hym9ysdk3rmqz32xdjqmy4w34ld3rm3jf5viqjx65lxk"; 325 - }; 321 + src = fetchPypi { 322 + inherit pname version; 323 + sha256 = "16a0fa97hym9ysdk3rmqz32xdjqmy4w34ld3rm3jf5viqjx65lxk"; 324 + }; 326 325 327 - buildInputs = with self; [ pkgs.libxml2 pkgs.libxslt ]; 326 + buildInputs = [ pkgs.libxml2 pkgs.libxslt ]; 328 327 329 - meta = with lib; { 330 - description = "Pythonic binding for the libxml2 and libxslt libraries"; 331 - homepage = https://lxml.de; 332 - license = licenses.bsd3; 333 - maintainers = with maintainers; [ sjourdois ]; 334 - }; 328 + meta = with lib; { 329 + description = "Pythonic binding for the libxml2 and libxslt libraries"; 330 + homepage = https://lxml.de; 331 + license = licenses.bsd3; 332 + maintainers = with maintainers; [ sjourdois ]; 335 333 }; 336 334 } 337 335 ``` ··· 347 345 and `CFLAGS`. 348 346 349 347 ```nix 350 - { # ... 348 + { lib, pkgs, buildPythonPackage, fetchPypi, numpy, scipy }: 351 349 352 - pyfftw = buildPythonPackage rec { 353 - pname = "pyFFTW"; 354 - version = "0.9.2"; 350 + buildPythonPackage rec { 351 + pname = "pyFFTW"; 352 + version = "0.9.2"; 355 353 356 - src = fetchPypi { 357 - inherit pname version; 358 - sha256 = "f6bbb6afa93085409ab24885a1a3cdb8909f095a142f4d49e346f2bd1b789074"; 359 - }; 354 + src = fetchPypi { 355 + inherit pname version; 356 + sha256 = "f6bbb6afa93085409ab24885a1a3cdb8909f095a142f4d49e346f2bd1b789074"; 357 + }; 360 358 361 - buildInputs = [ pkgs.fftw pkgs.fftwFloat pkgs.fftwLongDouble]; 359 + buildInputs = [ pkgs.fftw pkgs.fftwFloat pkgs.fftwLongDouble]; 362 360 363 - propagatedBuildInputs = with self; [ numpy scipy ]; 361 + propagatedBuildInputs = [ numpy scipy ]; 364 362 365 - # Tests cannot import pyfftw. pyfftw works fine though. 366 - doCheck = false; 363 + # Tests cannot import pyfftw. pyfftw works fine though. 364 + doCheck = false; 367 365 368 - preConfigure = '' 369 - export LDFLAGS="-L${pkgs.fftw.dev}/lib -L${pkgs.fftwFloat.out}/lib -L${pkgs.fftwLongDouble.out}/lib" 370 - export CFLAGS="-I${pkgs.fftw.dev}/include -I${pkgs.fftwFloat.dev}/include -I${pkgs.fftwLongDouble.dev}/include" 371 - ''; 366 + preConfigure = '' 367 + export LDFLAGS="-L${pkgs.fftw.dev}/lib -L${pkgs.fftwFloat.out}/lib -L${pkgs.fftwLongDouble.out}/lib" 368 + export CFLAGS="-I${pkgs.fftw.dev}/include -I${pkgs.fftwFloat.dev}/include -I${pkgs.fftwLongDouble.dev}/include" 369 + ''; 372 370 373 - meta = with lib; { 374 - description = "A pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms"; 375 - homepage = http://hgomersall.github.com/pyFFTW; 376 - license = with licenses; [ bsd2 bsd3 ]; 377 - maintainers = with maintainers; [ fridh ]; 378 - }; 371 + meta = with lib; { 372 + description = "A pythonic wrapper around FFTW, the FFT library, presenting a unified interface for all the supported transforms"; 373 + homepage = http://hgomersall.github.com/pyFFTW; 374 + license = with licenses; [ bsd2 bsd3 ]; 375 + maintainers = with maintainers; [ fridh ]; 379 376 }; 380 377 } 381 378 ``` ··· 403 400 404 401 ```nix 405 402 with import <nixpkgs> {}; 406 - with pkgs.python35Packages; 403 + with python35Packages; 407 404 408 405 buildPythonPackage rec { 409 406 name = "mypackage"; ··· 436 433 We first create a function that builds `toolz` in `~/path/to/toolz/release.nix` 437 434 438 435 ```nix 439 - { lib, pkgs, buildPythonPackage }: 436 + { lib, buildPythonPackage }: 440 437 441 438 buildPythonPackage rec { 442 439 pname = "toolz"; ··· 456 453 } 457 454 ``` 458 455 459 - It takes two arguments, `pkgs` and `buildPythonPackage`. 456 + It takes an argument `buildPythonPackage`. 460 457 We now call this function using `callPackage` in the definition of our environment 461 458 462 459 ```nix 463 460 with import <nixpkgs> {}; 464 461 465 462 ( let 466 - toolz = pkgs.callPackage /path/to/toolz/release.nix { 467 - pkgs = pkgs; 468 - buildPythonPackage = pkgs.python35Packages.buildPythonPackage; 463 + toolz = callPackage /path/to/toolz/release.nix { 464 + buildPythonPackage = python35Packages.buildPythonPackage; 469 465 }; 470 - in pkgs.python35.withPackages (ps: [ ps.numpy toolz ]) 466 + in python35.withPackages (ps: [ ps.numpy toolz ]) 471 467 ).env 472 468 ``` 473 469 ··· 565 561 ''; 566 562 567 563 checkInputs = [ hypothesis ]; 568 - buildInputs = [ setuptools_scm ]; 564 + nativeBuildInputs = [ setuptools_scm ]; 569 565 propagatedBuildInputs = [ attrs py setuptools six pluggy ]; 570 566 571 567 meta = with lib; { ··· 584 580 wrap all programs in the `$out/bin/*` directory to include `$PATH` 585 581 environment variable and add dependent libraries to script's `sys.path`. 586 582 * In the `installCheck` phase, `${python.interpreter} setup.py test` is ran. 587 - 588 - As in Perl, dependencies on other Python packages can be specified in the 589 - `buildInputs` and `propagatedBuildInputs` attributes. If something is 590 - exclusively a build-time dependency, use `buildInputs`; if it is (also) a runtime 591 - dependency, use `propagatedBuildInputs`. 592 583 593 584 By default tests are run because `doCheck = true`. Test dependencies, like 594 585 e.g. the test runner, should be added to `checkInputs`. ··· 733 724 with import <nixpkgs> {}; 734 725 735 726 python.buildEnv.override { 736 - extraLibs = [ pkgs.pythonPackages.pyramid ]; 727 + extraLibs = [ pythonPackages.pyramid ]; 737 728 ignoreCollisions = true; 738 729 } 739 730 ``` ··· 815 806 ```nix 816 807 with import <nixpkgs> {}; 817 808 818 - buildPythonPackage { name = "myproject"; 809 + pythonPackages.buildPythonPackage { 810 + name = "myproject"; 811 + buildInputs = with pythonPackages; [ pyramid ]; 819 812 820 - buildInputs = with pkgs.pythonPackages; [ pyramid ]; 821 - 822 - src = ./.; } 813 + src = ./.; 814 + } 823 815 ``` 824 816 825 817 Running `nix-shell` with no arguments should give you ··· 1005 997 1006 998 ```nix 1007 999 with import <nixpkgs> {}; 1008 - with pkgs.python27Packages; 1000 + with python27Packages; 1009 1001 1010 1002 stdenv.mkDerivation { 1011 1003 name = "impurePythonEnv"; 1004 + 1005 + src = null; 1006 + 1012 1007 buildInputs = [ 1013 1008 # these packages are required for virtualenv and pip to work: 1014 1009 # ··· 1028 1023 libxslt 1029 1024 libzip 1030 1025 stdenv 1031 - zlib ]; 1032 - src = null; 1026 + zlib 1027 + ]; 1028 + 1033 1029 shellHook = '' 1034 - # set SOURCE_DATE_EPOCH so that we can use python wheels 1035 - SOURCE_DATE_EPOCH=$(date +%s) 1036 - virtualenv --no-setuptools venv 1037 - export PATH=$PWD/venv/bin:$PATH 1038 - pip install -r requirements.txt 1030 + # set SOURCE_DATE_EPOCH so that we can use python wheels 1031 + SOURCE_DATE_EPOCH=$(date +%s) 1032 + virtualenv --no-setuptools venv 1033 + export PATH=$PWD/venv/bin:$PATH 1034 + pip install -r requirements.txt 1039 1035 ''; 1040 1036 } 1041 1037 ```