-
-
Notifications
You must be signed in to change notification settings - Fork 39.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Python dependencies for Nix #12855
Conversation
It turned out that one Also
(However, this PR is not compatible with the code in the master branch at the moment, because |
In case keeping |
Thanks, this looks thoroughly reasonable, though I'm -1 on the fiddly further workaround in sigprof@928b945, which I think we can/should arrange to be unnecessary by ensuring that (Separately we should upstream the overrides to poetry2nix, and then use that directly via niv too: it periodically gets synched into nixpkgs itself, so using it directly gets us the latest overrides more directly. Once upstreamed, the overrides here can be deleted. Ideally we shouldn't need any local overrides at all.) |
Overrides submitted upstream in nix-community/poetry2nix#300 |
Here's a follow-up patch you can add to your PR which eliminates the local overrides now that they are upstreamed: https://gist.github.com/56f4434e3514e37fd0b88e34f0e04575
|
Thanks, applied your patch, and now shell.nix appears to work without any local overrides, including the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good to me 👍
74228e9
to
53c7b61
Compare
OK, I updated the Python dependencies, but apparently I missed another problem:
So apparently some workaround for calling Another command which fails is
There are many other scripts which also start with |
Sounds like it shouldn't do that? I wouldn't consider that a blocker for this PR at least.
I think it would be entirely reasonable to make that change tree-wide in a separate PR for NixOS compatibility, or use Overall what I'm getting from this is that there's not necessarily more to be done in the PR, and that it is a step forward in terms of having things working correctly via Nix, so I feel we can safely go ahead and merge. |
Actually the version from qmk/qmk_firmware#12855 is used, because it has updates which are required for the recent `qmk_firmware` code. The original LICENSE (GNU GPL v2) of `qmk_firmware` is assumed to apply to those files, because they don't have explicit copyright headers.
Some testing feedback: |
The lock file already contained milc 1.3.0, but pyproject.toml still specified the minimum required version as 1.1.0, which is not compatible with the current Python code.
Apparenty the `wave` entry was added to requirements-dev.txt by mistake (the code actually uses the builtin `wave` package, not the `Wave` project that is available on PyPi). That entry has already been removed from requirements-dev.txt; remove it from pyproject.toml too.
Recent updated added `hid` and `pyusb` to requirements-dev.txt; update pyproject.toml accordingly. In addition, these Python modules use native libraries (`hidapi` and `libusb1`), and need Nix-specific changes to find those libraries; add the needed changes to shell.nix as overrides. The `pyusb` override was copied from the corresponding nixpkgs package; the `hid` override is new, because that Python package is not in nixpkgs at the moment.
The `qmk` name collides with the name of the QMK CLI package.
Current QMK build scripts loudly complain about the missing QMK CLI. The obvious solution is to include `qmk` in the list of Python dependencies in pyproject.toml; this makes the `qmk` executable available in the nix-shell environment, and stops the warnings. Note that any leftover `bin/qmk` uses may become errors after this change, because apparently the Nix wrapper for the `qmk` executable prepends a directory containing some `python3` version to `$PATH`, but that `python3` cannot find the Python packages required by `bin/qmk`. However, if the code uses `$(QMK_BIN)` correctly, it would run the `qmk` executable from `$PATH` instead, which would run properly.
The `qmk = "^0.0.46"` dependency specification automatically added by `poetry add qmk` is not suitable, because it prevents any version upgrades for the `qmk` package due to the special handling of `0.0` for caret requirements. Replace this specification with `"*"`, so that `poetry update --lock` could be used to bump the locked version to the latest available without the need to change `pyproject.toml`. Co-authored-by: Steve Purcell <[email protected]>
Use the latest QMK CLI (0.0.46 -> 0.0.48) and other packages: - argcomplete: 1.12.2 -> 1.12.3 - attrs: 20.3.0 -> 21.2.0 - flake8: 3.9.0 -> 3.9.2 - six: 1.15.0 -> 1.16.0 - pygments: 2.8.1 -> 2.9.0
Use `( cd nix && poetry update --lock; )` to update all Python dependencies to their most recent versions (although `requirements.txt` has not been changed, the actual code is no longer compatible with older versions of some Python packages). Dependency changes: - halo: 0.0.31 (new) - log-symbols: 0.0.14 (new) - milc: 1.3.0 -> 1.4.2 - qmk: 0.0.48 -> 0.0.51 - spinners: 0.0.24 (new) - termcolor: 1.1.0 (new)
I don't see any reason this PR couldn't be merged for now: it at least moves the current state forwards for us Nix users.
I don't think there's any limit there for open source projects which we would need to worry about. I've got a cachix cache for another popular github project which seems to routinely serve terabytes (apologies to Domen). I'd quite like to add a secondary GitHub Actions workflow here that would build qmk with cachix enabled, and serve to give an automated check for the nix build rules. |
I did exactly that, but in my own repository (currently the workflow is disabled, because there is no point testing what is known to be broken); on the first run it populated the cache (the build took about 2 hours on BTW, another option that could be possible in theory is to build that
|
Yeah, there's already a |
Apparently it does not actually work: NixOS/nixpkgs#118340 (comment) (and the person who packaged it does not actually use it). Given that QMK often changes the required versions of Python modules (and, even worse, updated versions of those modules are not really backwards compatible), the best way is to have the dependency information stored in the |
I found a much simpler way to make calls to diff --git a/shell.nix b/shell.nix
index a04e251b5..4db217196 100644
--- a/shell.nix
+++ b/shell.nix
@@ -12,6 +12,13 @@ let
# files if the requirements*.txt files change
pythonEnv = poetry2nix.mkPoetryEnv {
projectDir = ./nix;
+ overrides = poetry2nix.overrides.withDefaults (self: super: {
+ qmk = super.qmk.overridePythonAttrs(old: {
+ # Allow QMK CLI to run "bin/qmk" as a subprocess (the wrapper changes
+ # $PATH and breaks these invocations).
+ dontWrapPythonPrograms = true;
+ });
+ });
};
in @purcell What do you think about this workaround? It fixes the I'm not sure whether this override should be upstreamed into poetry2nix though — the |
Probably fine.
Correct, it's just a local hack, not a widely applicable override for a package on pypi. |
I just want to chime in to say that since the nix-shell is currently broken in master it would be great if this could be merged in its current form. |
Totally agree. Could somebody with the appropriate permissions help make that happen please? Perhaps @fauxpark? |
+1 to merging this: I have tested building and it works with a few minor annoyances: There is a warning about the But it is able to build firmware no problem regardless |
This also works for me, without any of the annoyances. |
Thanks @Erovia |
Co-authored-by: Steve Purcell <[email protected]>
Co-authored-by: Steve Purcell <[email protected]>
Co-authored-by: Steve Purcell <[email protected]>
Co-authored-by: Steve Purcell <[email protected]>
Co-authored-by: Steve Purcell <[email protected]>
Co-authored-by: Steve Purcell <[email protected]>
Description
Update Python dependencies for Nix to account for the recent changes:
qmk console
command implementation now requires thehid
andpyusb
Python modules.Wave
Python dependency was a mistake; it was already removed fromrequirements-dev.txt
, but still left innix/pyproject.toml
.bin/qmk
is deprecated, therefore the QMK CLI should be provided in the nix-shell environment.The
hid
andpyusb
Python modules required adding some overrides toshell.nix
to make them actually work (without those overrides the packages seem to build, but break at runtime, because they cannot find the needed native libraries in Nix-specific directories). The override forpyusb
was copied from nixpkgs; the override forhid
is written by me based on thepyusb
example.I tested these changes on NixOS (
x86_64-linux
); the override forhid
might also work on MacOS, but I cannot actually test it. Withnix-direnv
things likeqmk compile
orqmk info -m
transparently work in theqmk_firmware
directory or any subdirectories without any other configuration.There is one potential problem that I noticed: The Nix-generated wrapper for the
qmk
executable from QMK CLI prepends some directories to$PATH
before running the actual Python code, and one of those directories contains apython3
executable which does not have the Python module path configured to find the packages included in the Python environment. The QMK CLI itself still works because of yet another Nix-specific modification which adds the required directories to the Python path in the executable script itself; however, when thatqmk
executable finally callsmake
, any calls tobin/qmk
from makefiles would fail, becausebin/qmk
would try to use that unconfiguredpython3
interpreter instead of the one that is provided by the nix-shell environment. One such error was recently fixed in #12832; in the nix-shell environment it would be a hard error instead of just a warning. It is possible to make a workaround for this inshell.nix
, but I'm not sure if the added complexity is worth it, especially if it's just for supporting some broken code.Hope that other people who touched the Nix-specific code recently (@purcell, @andresilva, @pepyakin) could test and add their comments on this.
Types of Changes
Checklist