Admins will be upgrading ORNL GitLab Servers on Saturday, 16 May 2026, from 7 AM until 11 AM EST. Repositories will experience intermittent outages during this time.
@@ -707,12 +703,12 @@ create a single script with Python dependencies, but in the course of normal
development we're usually working in an entire package repository.
As explained [in the `nix-shell` section](https://nixos.org/manual/nix/stable/command-ref/nix-shell) of the Nix manual, `nix-shell` can also load an expression from a `.nix` file.
Say we want to have Python 3.11, `numpy` and `toolz`, like before,
Say we want to have Python 3.12, `numpy` and `toolz`, like before,
in an environment. We can add a `shell.nix` file describing our dependencies:
```nix
withimport<nixpkgs>{};
(python311.withPackages(ps:withps;[
(python312.withPackages(ps:withps;[
numpy
toolz
])).env
@@ -729,7 +725,7 @@ What's happening here?
imports the `<nixpkgs>` function, `{}` calls it and the `with` statement
brings all attributes of `nixpkgs` in the local scope. These attributes form
the main package set.
2. Then we create a Python 3.11 environment with the [`withPackages`](#python.withpackages-function) function, as before.
2. Then we create a Python 3.12 environment with the [`withPackages`](#python.withpackages-function) function, as before.
3. The [`withPackages`](#python.withpackages-function) function expects us to provide a function as an argument
that takes the set of all Python packages and returns a list of packages to
include in the environment. Here, we select the packages `numpy` and `toolz`
@@ -740,7 +736,7 @@ To combine this with `mkShell` you can:
```nix
withimport<nixpkgs>{};
let
pythonEnv=python311.withPackages(ps:[
pythonEnv=python312.withPackages(ps:[
ps.numpy
ps.toolz
]);
@@ -894,8 +890,8 @@ information. The output of the function is a derivation.
An expression for `toolz` can be found in the Nixpkgs repository. As explained
in the introduction of this Python section, a derivation of `toolz` is available
for each interpreter version, e.g. `python311.pkgs.toolz` refers to the `toolz`
derivation corresponding to the CPython 3.11 interpreter.
for each interpreter version, e.g. `python312.pkgs.toolz` refers to the `toolz`
derivation corresponding to the CPython 3.12 interpreter.
The above example works when you're directly working on
`pkgs/top-level/python-packages.nix` in the Nixpkgs repository. Often though,
@@ -908,7 +904,7 @@ and adds it along with a `numpy` package to a Python environment.
withimport<nixpkgs>{};
(let
my_toolz=python311.pkgs.buildPythonPackagerec{
my_toolz=python312.pkgs.buildPythonPackagerec{
pname="toolz";
version="0.10.0";
pyproject=true;
@@ -919,7 +915,7 @@ with import <nixpkgs> {};
};
build-system=[
python311.pkgs.setuptools
python312.pkgs.setuptools
];
# has no tests
@@ -932,7 +928,7 @@ with import <nixpkgs> {};
};
};
inpython311.withPackages(ps:withps;[
inpython312.withPackages(ps:withps;[
numpy
my_toolz
])
@@ -940,7 +936,7 @@ with import <nixpkgs> {};
```
Executing `nix-shell` will result in an environment in which you can use
Python 3.11 and the `toolz` package. As you can see we had to explicitly mention
Python 3.12 and the `toolz` package. As you can see we had to explicitly mention
for which Python version we want to build a package.
So, what did we do here? Well, we took the Nix expression that we used earlier
@@ -1946,7 +1942,7 @@ has security implications and is relevant for those using Python in a
When the environment variable `DETERMINISTIC_BUILD` is set, all bytecode will
have timestamp 1. The [`buildPythonPackage`](#buildpythonpackage-function) function sets `DETERMINISTIC_BUILD=1`
and [PYTHONHASHSEED=0](https://docs.python.org/3.11/using/cmdline.html#envvar-PYTHONHASHSEED).
and [PYTHONHASHSEED=0](https://docs.python.org/3.12/using/cmdline.html#envvar-PYTHONHASHSEED).
Both are also exported in `nix-shell`.
### How to provide automatic tests to Python packages? {#automatic-tests}
@@ -2018,10 +2014,10 @@ The following rules are desired to be respected:
It does not need to be set explicitly unless the package requires a specific platform.
* The file is formatted with `nixfmt-rfc-style`.
* Commit names of Python libraries must reflect that they are Python
libraries (e.g. `python311Packages.numpy: 1.11 -> 1.12` rather than `numpy: 1.11 -> 1.12`).
libraries (e.g. `python312Packages.numpy: 1.11 -> 1.12` rather than `numpy: 1.11 -> 1.12`).
* The current default version of python should be included
in commit messages to enable automatic builds by ofborg.
For example `python311Packages.numpy: 1.11 -> 1.12` should be used rather
For example `python312Packages.numpy: 1.11 -> 1.12` should be used rather
than `python3Packages.numpy: 1.11 -> 1.12`.
Note that `pythonPackages` is an alias for `python27Packages`.
* Attribute names in `python-packages.nix` as well as `pname`s should match the