←back to thread

129 points NeutralForest | 1 comments | | HN request time: 0s | source
Show context
the_mitsuhiko ◴[] No.44454647[source]
Turns out you can just do things. The astral tooling is by far the best thing that has happened to Python in years and it makes me very happy.
replies(2): >>44454774 #>>44454890 #
TechDebtDevin ◴[] No.44454890[source]
Interesting. I basically dont touch python unless I have too becayse the lack of tooling. How does this tooling compare to an experience like working in Go?
replies(1): >>44455057 #
CraigJPerry ◴[] No.44455057[source]
It's not rivaling Go anytime soon but there have been leaps and bounds.

E.g.

  uv init --script foo.py
  uv add --script foo.py httpx 
  cat foo.py
  ...
  dependencies = ['httpx']
  ...
Then on another machine:

  uv run foo.py
  # creates a virtual env, reads foo.py to see httpx is a dependency, installs in the ephemeral venv then runs the script
The above is from memory typed on a phone so maybe some minor syntax issues but the point i tried to make was we can kinda emulate the convenience of statically compiled binaries a-la Go these days
replies(2): >>44455204 #>>44462832 #
cssanchez ◴[] No.44455204{3}[source]
I don't mean to be rude, but I don't get how this is any better. Feels too manual to type "uv -add dep script.py" instead, I feel the automation tool I'm waiting for will scan my script, auto-import all the deps I'm calling in the script while ignoring the ones that I forget to use, AND set up the env with all the deps AND run the code in the same one liner. To me, uv add X is no different than running env/pip install requirements.txt.
replies(2): >>44455371 #>>44455820 #
1. CraigJPerry ◴[] No.44455820{4}[source]
Compare the before vs after

Before (analogous to go mod init):

    python -m venv venv
    source venv/bin/activate
    python -m pip install -U pip
    pip install httpx
    pip freeze > requirements.txt
    nvim foo.py
    # find a way to share foo.py and requirements.txt
On another machine (still the before scenario, this time analogous to maybe go run):

    python -m venv venv
    source venv/bin/activate
    python -m pip install -U pip
    pip install -r requirements.txt
    python foo.py
In the after scenario:

    uv run foo.py
That's it. Comparable to

    ./my-go-binary