···602602#### Using pytestCheckHook {#using-pytestcheckhook}
603603604604`pytestCheckHook` is a convenient hook which will substitute the setuptools
605605-`test` command for a checkPhase which runs `pytest`. This is also beneficial
605605+`test` command for a `checkPhase` which runs `pytest`. This is also beneficial
606606when a package may need many items disabled to run the test suite.
607607608608-Using the example above, the analagous pytestCheckHook usage would be:
608608+Using the example above, the analagous `pytestCheckHook` usage would be:
609609610610```
611611 checkInputs = [ pytestCheckHook ];
···624624 ];
625625```
626626627627-This is expecially useful when tests need to be conditionallydisabled,
627627+This is expecially useful when tests need to be conditionally disabled,
628628for example:
629629630630```
···640640 "socket"
641641 ];
642642```
643643-Trying to concatenate the related strings to disable tests in a regular checkPhase
644644-would be much harder to read. This also enables us to comment on why specific tests
645645-are disabled.
643643+644644+Trying to concatenate the related strings to disable tests in a regular
645645+`checkPhase` would be much harder to read. This also enables us to comment on
646646+why specific tests are disabled.
646647647648#### Using pythonImportsCheck {#using-pythonimportscheck}
648649649649-Although unit tests are highly prefered to validate correctness of a package, not
650650-all packages have test suites that can be ran easily, and some have none at all.
650650+Although unit tests are highly preferred to validate correctness of a package, not
651651+all packages have test suites that can be run easily, and some have none at all.
651652To help ensure the package still works, `pythonImportsCheck` can attempt to import
652653the listed modules.
653654654655```
655656 pythonImportsCheck = [ "requests" "urllib" ];
656657```
658658+657659roughly translates to:
660660+658661```
659662 postCheck = ''
660663 PYTHONPATH=$out/${python.sitePackages}:$PYTHONPATH
661664 python -c "import requests; import urllib"
662665 '';
663666```
664664-However, this is done in it's own phase, and not dependent on whether `doCheck = true;`
667667+668668+However, this is done in its own phase, and not dependent on whether `doCheck = true;`.
665669666670This can also be useful in verifying that the package doesn't assume commonly
667667-present packages (e.g. `setuptools`)
671671+present packages (e.g. `setuptools`).
668672669673#### Using pythonRelaxDepsHook {#using-pythonrelaxdepshook}
670674···719723```
720724721725In general you should always use `pythonRelaxDeps`, because `pythonRemoveDeps`
722722-will convert build errors in runtime errors. However `pythonRemoveDeps` may
726726+will convert build errors into runtime errors. However `pythonRemoveDeps` may
723727still be useful in exceptional cases, and also to remove dependencies wrongly
724728declared by upstream (for example, declaring `black` as a runtime dependency
725729instead of a dev dependency).
···738742without having to reinstall after each and every change you make. Development
739743mode is also available. Let's see how you can use it.
740744741741-In the previous Nix expression the source was fetched from an url. We can also
745745+In the previous Nix expression the source was fetched from a url. We can also
742746refer to a local source instead using `src = ./path/to/source/tree;`
743747744748If we create a `shell.nix` file which calls `buildPythonPackage`, and if `src`
745749is a local source, and if the local source has a `setup.py`, then development
746750mode is activated.
747751748748-In the following example we create a simple environment that has a Python 3.9
752752+In the following example, we create a simple environment that has a Python 3.9
749753version of our package in it, as well as its dependencies and other packages we
750754like to have in the environment, all specified with `propagatedBuildInputs`.
751755Indeed, we can just add any package we like to have in our environment to
···862866863867### Optimizations {#optimizations}
864868865865-The Python interpreters are by default not build with optimizations enabled, because
869869+The Python interpreters are by default not built with optimizations enabled, because
866870the builds are in that case not reproducible. To enable optimizations, override the
867871interpreter of interest, e.g using
868872···913917#### `buildPythonPackage` function {#buildpythonpackage-function}
914918915919The `buildPythonPackage` function is implemented in
916916-`pkgs/development/interpreters/python/mk-python-derivation`
920920+`pkgs/development/interpreters/python/mk-python-derivation.nix`
917921using setup hooks.
918922919923The following is an example:
···954958* In the `postFixup` phase, the `wrapPythonPrograms` bash function is called to
955959 wrap all programs in the `$out/bin/*` directory to include `$PATH`
956960 environment variable and add dependent libraries to script's `sys.path`.
957957-* In the `installCheck` phase, `${python.interpreter} setup.py test` is ran.
961961+* In the `installCheck` phase, `${python.interpreter} setup.py test` is run.
958962959963By default tests are run because `doCheck = true`. Test dependencies, like
960964e.g. the test runner, should be added to `checkInputs`.
···969973970974* `catchConflicts ? true`: If `true`, abort package build if a package name
971975 appears more than once in dependency tree. Default is `true`.
972972-* `disabled` ? false: If `true`, package is not built for the particular Python
976976+* `disabled ? false`: If `true`, package is not built for the particular Python
973977 interpreter version.
974978* `dontWrapPythonPrograms ? false`: Skip wrapping of Python programs.
975979* `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment
···1421142514221426### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl}
1423142714241424-Executing `python setup.py bdist_wheel` in a `nix-shell `fails with
14281428+Executing `python setup.py bdist_wheel` in a `nix-shell`fails with
14291429+14251430```
14261431ValueError: ZIP does not support timestamps before 1980
14271432```
···15131518 # the environment.
15141519 pythonPackages.python
1515152015161516- # This execute some shell code to initialize a venv in $venvDir before
15211521+ # This executes some shell code to initialize a venv in $venvDir before
15171522 # dropping into the shell
15181523 pythonPackages.venvShellHook
15191524