Building a Python Package Before Contributing

I am trying to contribute a new python package to nixpkgs: appengine-python-standard.

I have created a draft PR here: python-modules.appengine-python-standard: init by ollyfg · Pull Request #380457 · NixOS/nixpkgs · GitHub

The bit I’m stuck on (which probably seems a bit silly) is testing that the new package gets built and made available to Python correctly.

I have tried the following without success from my local nixpkgs root directory:

  • nix build -A appengine-python-standard
  • nix build -A python-modules.appengine-python-standard
  • nix build -A python312Packages.appengine-python-standard

In addition, can I please have some advice on testing? I see that most python modules don’t have tests. Am I required to write any?

Ideally I would like to add an automated test like the one I’m trying to do here (start up a python interpreter and make sure that import appengine-python-standard doesn’t throw an error.

Thank you for all your help!

Aha! It turns out I needed to add the package to pkgs/top-level/python-packages.nix. After that I can use nix build -A python312Packages.appengine-python-standard.

In terms of tests I added nativeCheckInputs = [ pytestCheckHook ]; which I suppose is better than nothing - I’d still love some advice on adding a test to make sure the package is correctly added to the python interpreter.

Ah, looks like I’m being daft again. I assume the test I’m looking for is covered by the pythonImportsCheck property of python packages.

Ok, next question:

This package depends on urllib3, another python package. It requires a version between 1.26.2 and 2.
Unfortunately the current version of urllib3 (both in pypi and so the one packaged in nix) is 2.3.0.

I know how to make a new version of urllib3 pinned to the oldest 1.x version, but I imagine there are conventions around this:

  • Do I put it in the urlllib3 package as some other kind of export?
  • Do I build it inside my package (so put a second buildPythonPackage call in my package)?