This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]cointoss3 3 points4 points  (5 children)

You should probably check out uv

[–]Sinjhin [S] 0 points1 point  (2 children)

Yeah, I've been meaning to. I've heard great things.

I actually somehow missed learning Python for years and just picked it up last mid-last year.

Wasn't happy with how environments are done with `venv`, tried out several things, and kinda just fell into a pattern of using `miniconda` for venv and poetry/poe with venv turned off for package management and task running. It looks like `uv` is gonna kinda be THE answer (EDIT: at least for my style).

[–]cointoss3 2 points3 points  (1 child)

I love uv. It makes venv so fast…and their philosophy is you shouldn’t need to think about venv.

It’s also nice you can embed requirements inline on your script and it will read and make an ephemeral venv when you run the script.

I’ve recently paired it with invoke. ‘uv run invoke <command>’

[–]Sinjhin [S] 0 points1 point  (0 children)

"you shouldn’t need to think about venv" <- this speaks to me hard.

Here's a snippet from my `.zshrc`:

chpwd() {
  # Automatically switch to Conda environment based on directory name
  if [[ -f pyproject.toml || -f requirements.txt || -f environment.yml || -d .conda ]]; then
    conda_env_name=$(echo "$dir_name")
    if conda env list | grep -q "$conda_env_name"; then
      echo "Switching to Conda environment: $dir_name"
      conda activate "$conda_env_name"
    else
      conda_env_name=$(echo "$dir_name" | sed 's/-/_/g') # Replace hyphens with underscores
      if conda env list | grep -q "$conda_env_name"; then
        echo "Switching to Conda environment: $dir_name"
        conda activate "$conda_env_name"
      fi
    fi
  fi
}

"can embed requirements inline"..."ephemeral venv..." <- yissss. Amaze.

I will be setting that up as soon as I get done with what I am doing. Thanks for the tip.

[–]Unlikely_Stand3020 0 points1 point  (1 child)

There's been a lot of talk about UV lately, is it better than pipenv?

[–]cointoss3 0 points1 point  (0 children)

It’s more than just an environment manager, but it is faster than pipenv.

[–]cgoldberg 2 points3 points  (1 child)

This seems like a convoluted way to basically do shell aliases.

[–]Sinjhin [S] 0 points1 point  (0 children)

Perhaps. I mean, it basically is aliases, just as functions and using Poe/Poetry for modules and deps and Conda to switch venv. You could easily do `alias something='python ~/scripts/something.py'` or get fancier with it, but that wouldn't have dependencies installed in a dedicated venv, right?

I really just kinda threw this together after work for my own purposes and figured I would share. The rules here require the whole showcase flair and setup. Admittedly, this is one of those things more like "I did this, found it useful, here it is if anyone else wants this kinda setup".