NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.64k stars 13.79k forks source link

python_module/fastapi does not expose the CLI program #311161

Closed svdarren closed 1 month ago

svdarren commented 4 months ago

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:

  1. nix-shell -p python311Packages.fastapi
  2. fastapi
  3. 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.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
output here

Add a :+1: reaction to issues you find important.

marsam commented 4 months ago

I think FastAPI CLI was introduced in fastapi 0.111.0, but currently nixpkgs has fastapi 0.110.2

svdarren commented 4 months ago

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.

bcdarwin commented 4 months ago

317028.

wxyangf commented 3 months ago

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)

bcdarwin commented 3 months ago

Done in #320924 (d18d3b227a4c3)

mweinelt commented 3 months ago

Requires https://github.com/NixOS/nixpkgs/pull/325223 to work

bcdarwin commented 3 months ago

Note that Nix now exposes fastapi twice: via pkgs/by-name/fa/fastapi-cli and via python-packages @drupol

drupol commented 3 months ago

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. 🚀                                                                                                                                                                                                                            │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

❯         
drupol commented 3 months ago

OK you did it in 3.12 which has just been merged ?

drupol commented 3 months ago

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 ✘          
bcdarwin commented 3 months ago

As mweinelt mentioned waiting for https://github.com/NixOS/nixpkgs/issues/311161#issuecomment-2212403028 to be unbroken

bcdarwin commented 3 months ago

Also see #325314

drupol commented 3 months ago

OK, how do I proceed, should I provide a PR to delete fastapi-cli ?

bcdarwin commented 3 months ago

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.

drupol commented 3 months ago

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

drupol commented 2 months ago

I guess we can close this issue?

wxyangf commented 2 months ago

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.

mweinelt commented 2 months ago

Very unlikely to be backported.

garethstokes commented 1 month ago

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?

alexvorobiev commented 2 weeks ago

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.