···
#### Using pytestCheckHook {#using-pytestcheckhook}
`pytestCheckHook` is a convenient hook which will substitute the setuptools
+
`test` command for a `checkPhase` which runs `pytest`. This is also beneficial
when a package may need many items disabled to run the test suite.
+
Using the example above, the analagous `pytestCheckHook` usage would be:
checkInputs = [ pytestCheckHook ];
···
+
This is expecially useful when tests need to be conditionally disabled,
···
+
Trying to concatenate the related strings to disable tests in a regular
+
`checkPhase` would be much harder to read. This also enables us to comment on
+
why specific tests are disabled.
#### Using pythonImportsCheck {#using-pythonimportscheck}
+
Although unit tests are highly preferred to validate correctness of a package, not
+
all packages have test suites that can be run easily, and some have none at all.
To help ensure the package still works, `pythonImportsCheck` can attempt to import
pythonImportsCheck = [ "requests" "urllib" ];
PYTHONPATH=$out/${python.sitePackages}:$PYTHONPATH
python -c "import requests; import urllib"
+
However, this is done in its own phase, and not dependent on whether `doCheck = true;`.
This can also be useful in verifying that the package doesn't assume commonly
+
present packages (e.g. `setuptools`).
#### Using pythonRelaxDepsHook {#using-pythonrelaxdepshook}
···
In general you should always use `pythonRelaxDeps`, because `pythonRemoveDeps`
+
will convert build errors into runtime errors. However `pythonRemoveDeps` may
still be useful in exceptional cases, and also to remove dependencies wrongly
declared by upstream (for example, declaring `black` as a runtime dependency
instead of a dev dependency).
···
without having to reinstall after each and every change you make. Development
mode is also available. Let's see how you can use it.
+
In the previous Nix expression the source was fetched from a url. We can also
refer to a local source instead using `src = ./path/to/source/tree;`
If we create a `shell.nix` file which calls `buildPythonPackage`, and if `src`
is a local source, and if the local source has a `setup.py`, then development
+
In the following example, we create a simple environment that has a Python 3.9
version of our package in it, as well as its dependencies and other packages we
like to have in the environment, all specified with `propagatedBuildInputs`.
Indeed, we can just add any package we like to have in our environment to
···
### Optimizations {#optimizations}
+
The Python interpreters are by default not built with optimizations enabled, because
the builds are in that case not reproducible. To enable optimizations, override the
interpreter of interest, e.g using
···
#### `buildPythonPackage` function {#buildpythonpackage-function}
The `buildPythonPackage` function is implemented in
+
`pkgs/development/interpreters/python/mk-python-derivation.nix`
The following is an example:
···
* In the `postFixup` phase, the `wrapPythonPrograms` bash function is called to
wrap all programs in the `$out/bin/*` directory to include `$PATH`
environment variable and add dependent libraries to script's `sys.path`.
+
* In the `installCheck` phase, `${python.interpreter} setup.py test` is run.
By default tests are run because `doCheck = true`. Test dependencies, like
e.g. the test runner, should be added to `checkInputs`.
···
* `catchConflicts ? true`: If `true`, abort package build if a package name
appears more than once in dependency tree. Default is `true`.
+
* `disabled ? false`: If `true`, package is not built for the particular Python
* `dontWrapPythonPrograms ? false`: Skip wrapping of Python programs.
* `permitUserSite ? false`: Skip setting the `PYTHONNOUSERSITE` environment
···
### `python setup.py bdist_wheel` cannot create .whl {#python-setup.py-bdist_wheel-cannot-create-.whl}
+
Executing `python setup.py bdist_wheel` in a `nix-shell`fails with
ValueError: ZIP does not support timestamps before 1980
···
+
# This executes some shell code to initialize a venv in $venvDir before
# dropping into the shell
pythonPackages.venvShellHook