DavHau / mach-nix

Create highly reproducible python environments
MIT License
853 stars 105 forks source link

direct references in setup.cfg break mach-nix's requirements parser #352

Open exarkun opened 2 years ago

exarkun commented 2 years ago

If I have a setup.cfg that contains a "direct reference" (https://www.python.org/dev/peps/pep-0440/#direct-references) like

[options]
install_requires =
    tahoe-lafs @ https://github.com/tahoe-lafs/tahoe-lafs/archive/refs/heads/3842.allocate_buckets-without-lease-renewal.zip

and I point mach-nix.buildPythonPackage at it then the build fails like:

Traceback (most recent call last):
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/generate.py", line 110, in <module>
    main()
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/generate.py", line 103, in main
    do()
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/generate.py", line 64, in do
    reqs = filter_reqs_by_eval_marker(parse_reqs(requirements), context(py_ver, platform, system))
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/cache.py", line 14, in cache_wrapper
    result = tuple(result)
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/requirements.py", line 77, in parse_reqs
    yield Requirement(*parse_reqs_line(line))
  File "/nix/store/ix51kp7zrjp8b0k3x40hcpn8l9aifj55-0qgkv0q5sl216nhvbc62h7fzkrcyd1n7-mach-nix-src/mach_nix/requirements.py", line 136, in parse_reqs_line
    raise Exception(f"couldn't parse: '{line}'")
Exception: couldn't parse: 'tahoe-lafs@ https://github.com/tahoe-lafs/tahoe-lafs/archive/refs/heads/3842.allocate_buckets-without-lease-renewal.zip'
builder for '/nix/store/m1zpn713di22h5wm0nrpz3498vibvwsp-mach_nix_file.drv' failed with exit code 1
error: build of '/nix/store/m1zpn713di22h5wm0nrpz3498vibvwsp-mach_nix_file.drv' failed

I don't know exactly what mach-nix could do with requirements of this type. Maybe it could get the archive at the given location and apply the chosen (or defaulted) provider to the contents? Or maybe it could require that a provider like nixpkgs be used for such dependencies (which I believe would essentially tell mach-nix to ignore the value of the direct reference and just provide whatever version is in nixpkgs).

This might take some care by the packager to ensure a correct version of the dependency is supplied to the build but at least it would give the packager an option to make a working package rather than having the direct reference blow up the whole process.

exarkun commented 2 years ago

Since #354 was merged maybe this is fixed.