57
submitted 2 months ago by [email protected] to c/[email protected]
you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 12 points 2 months ago

Unfortunately, pip, the obvious way, kind of sucks. So I use poetry, which seems to work nicely.

[-] [email protected] 4 points 2 months ago* (last edited 2 months ago)

Wait, what’s wrong with pip?

(Disclaimer: I grade my Python proficiency slightly above beginner. I used it for some research in college and grad school, and I’ve made a few helpful scripts at work, but I am not anything approaching an expert)

[-] [email protected] 14 points 2 months ago

It does its job well, but it doesn't do much more than that.

The main workflow w/ Pip is:

  1. install whatever you need to get your app working
  2. pip freeze > requirements.txt so the next person can just pip install -r requirements.txt instead of figuring out the requirements
  3. either edit requirements.txt manually to do updates, or pip freeze again later

There are some issues with this:

  • dependencies that are no longer needed tend to stick around since they're in the requirements.txt
  • updating dependencies is a manual process and pretty annoying, especially when different packages have different dependencies
  • requirements.txt doesn't have any structure, so to do something like separating dev vs prod dependencies, you need two (or more) requirements.txt files

It's totally fine for one-off scripts and whatnot, but it gets pretty annoying when working across multiple repositories on a larger project (i.e. what I do at work with microservices).

Poetry improves this in a few ways:

  • poetry.lock - similar to requirements.txt, in that it locks all dependencies to specific versions
  • pyproject.toml - lists only your direct dependencies and certain exceptions (i.e. if you want to force a specific dependency version)
  • package groups - we tend to have local (linters and whatnot), test (deps for unit tests), and the default group (prod deps), so you can install only what you need (e.g. our CI uses test, prod uses no groups, and local uses everything)

There's a simple command to update all dependencies, and another command to try to add a dependency with minimal impact. It makes doing package updates a lot nicer, and I can easily compare direct dependencies between repositories since there's minimal noise in the pyproject.toml (great when doing bulk updates of some critical dependency).

TL;DR - pip is fine for small projects, alternatives are nice when dealing with large, complex projects because it gives you nicer control over dependencies.

[-] [email protected] 5 points 2 months ago

Good to know, thank you for educating me!

[-] [email protected] 4 points 2 months ago

... except for the part where the dependency definition doesn't follow the latest approved PEP, and the default constraint with ^ add an upper limit that causes problems.

I moved to PDM.

[-] [email protected] 4 points 2 months ago

Eh, by the time I get everyone on board and convert all of our repos, poetry will probably have support for the latest PEP.

[-] [email protected] 2 points 2 months ago

Given the glacial pace I've been seeing, I would't be so sure... But understandable if you have many repos and need to reach consensus.

You can reduce some impacts adding explicit >= constraints instead of ^.

[-] [email protected] 3 points 2 months ago* (last edited 2 months ago)

I don't know what the solution is but like 50% of everything on github that's in python is broken from dependencies and of those, half of them are fixable if you put a substantial amount of effort into it. It sucks. I've spent 2 entire days trying to get any AI tts to work and have gotten nowhere. I've tried 'em all, just about. None of them work on Debian.

[-] [email protected] 3 points 2 months ago

I'm using Poetry as well. But I really hope Rye works out so we can finally end this madness.

[-] [email protected] 3 points 2 months ago

Interesting. I just learned about Rye today. Has anybody tried it? Does it live up to the promise?

[-] [email protected] 2 points 2 months ago

Haven't tried Rye but I have used uv (which Rye uses to replace pip). Pip install time went down from 58s to 7s. Yes really. Python is fucking slow!

[-] [email protected] 1 points 2 months ago

I tried it a little - being able to run rye sync and not even having to worry about Python versioning is sooooo nice.

[-] [email protected] 1 points 2 months ago

Check "uv". Builds on top, is coming good.

this post was submitted on 08 Jul 2024
57 points (92.5% liked)

Python

6231 readers
4 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

📅 Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
💓 Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS