Closed svdarren closed 1 month ago
I think FastAPI CLI was introduced in fastapi 0.111.0, but currently nixpkgs has fastapi 0.110.2
I think FastAPI CLI was introduced in fastapi 0.111.0, but currently nixpkgs has fastapi 0.110.2
Good catch! I just started testing FastAPI within the last few weeks so I didn't realize the CLI was so new.
Just ran into this as well, worked around it by making a python venv and installing fastapi in the venv via pip temporarily (remember to use virtualenv venv
so it contains its own pip and installs properly within the venv install of trying to install in your store)
Done in #320924 (d18d3b227a4c3)
Requires https://github.com/NixOS/nixpkgs/pull/325223 to work
Note that Nix now exposes fastapi
twice: via pkgs/by-name/fa/fastapi-cli
and via python-packages @drupol
Hum?
❯ nix shell nixpkgs#python3Packages.fastapi
❯ fastapi
fish: Unknown command: fastapi
❯ nix shell nixpkgs#fastapi-cli
❯ fastapi --help
Usage: fastapi [OPTIONS] COMMAND [ARGS]...
FastAPI CLI - The fastapi command line app. 😎
Manage your FastAPI projects, run your FastAPI apps, and more.
Read more in the docs: https://fastapi.tiangolo.com/fastapi-cli/.
╭─ Options ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --version Show the version and exit. │
│ --install-completion [bash|zsh|fish|powershell|pwsh] Install completion for the specified shell. [default: None] │
│ --show-completion [bash|zsh|fish|powershell|pwsh] Show completion for the specified shell, to copy it or customize the installation. [default: None] │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ dev Run a FastAPI app in development mode. 🧪 │
│ run Run a FastAPI app in production mode. 🚀 │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
❯
OK you did it in 3.12 which has just been merged ?
Looks like there's an issue with it:
~/C/N/nixpkgs > master ❯ 192.168.1.24 | | ❄
❯ nix shell .#python3Packages.fastapi-cli -L
Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
❯ fastapi --help
Traceback (most recent call last):
File "/nix/store/k8hw97yprx3fcvsr8y1dz73qdsppb8sj-python3.12-fastapi-cli-0.0.4/bin/.fastapi-wrapped", line 6, in <module>
from fastapi_cli.cli import main
File "/nix/store/k8hw97yprx3fcvsr8y1dz73qdsppb8sj-python3.12-fastapi-cli-0.0.4/lib/python3.12/site-packages/fastapi_cli/cli.py", line 6, in <module>
from rich import print
ModuleNotFoundError: No module named 'rich'
~/C/N/nixpkgs > master ✘
As mweinelt mentioned waiting for https://github.com/NixOS/nixpkgs/issues/311161#issuecomment-2212403028 to be unbroken
Also see #325314
OK, how do I proceed, should I provide a PR to delete fastapi-cli
?
I think it depends whether we want a nixpkgs#fastapi-cli or not (not sure whether it can work with launching fastapi programs using e.g. other Python versions, in which case it might not be very useful)? If so then using toPythonApplication to wrap the code in python-packages would make sense, if not then delete?
Happy to make a PR as well.
I think the approach using python3Packages.fastapi
is better indeed.
What confuses me is that it is not called fastapi-cli
just like the pypi package
I guess we can close this issue?
Still not backported to 24.05 afaict. So might be worth keeping around until that's result. I just tested it on my system with
nix-shell -p python311Packages.fastapi
and the result is still
[nix-shell:~/test_fastapi_issue]$ fastapi
fastapi: command not found
with my system flake.lock nixpackages being:
"nixpkgs": {
"locked": {
"lastModified": 1721686456,
"narHash": "sha256-nw/BnNzATDPfzpJVTnY8mcSKKsz6BJMEFRkJ332QSN0=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "575f3027caa1e291d24f1e9fb0e3a19c2f26d96b",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-24.05",
"repo": "nixpkgs",
"type": "github"
}
}
which as far as i can tell is the most recent commit.
Very unlikely to be backported.
I'm getting a collision error when adding fastapi from python packages.
pkgs.python312.withPackages (pp: [
pp.fastapi
]);
> error: collision between `/nix/store/jjlprf16a0skl1pmqxkgbzg96f59mr38-python3.12-fastapi-cli-0.0.4/bin/fastapi' and `/nix/store/zm8in64c2gzbnfc6cajc2v5v14l5q8fv-python3.12-fastapi-0.112.0/bin/fastapi'
is there a workaround?
Yes, fastapi can't be installed. I tried to remove fastai-cli
from the dependencies (.override { fastapi-cli = null; }
) and that seems to have eliminated the collision.
Describe the bug
FastAPI is implemented as a python module. However, the upstream project includes a CLI program that is not currently supported by the nix package.
Steps To Reproduce
Steps to reproduce the behavior:
nix-shell -p python311Packages.fastapi
fastapi
fastapi: command not found
Alternately, this is documented here --> https://search.nixos.org/packages?channel=23.11&show=python311Packages.fastapi&from=0&size=50&sort=relevance&type=packages&query=fastapi
Expected behavior
Add the CLI program to the current package definition
Screenshots
N/A
Additional context
N/A
Notify maintainers
@charlesbaynham @wd15
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"
and paste the result."x86_64-linux"
Linux 5.15.146.1-microsoft-standard-WSL2, NixOS, 23.11 (Tapir), 23.11.20240501.0638fe2
yes
yes
nix-env (Nix) 2.18.1
"nixos-23.11, nixos-wsl"
/nix/var/nix/profiles/per-user/root/channels/nixos
Add a :+1: reaction to issues you find important.