Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for latest uv project management features #1405

Closed
clementpoiret opened this issue Aug 29, 2024 · 11 comments
Closed

Add support for latest uv project management features #1405

clementpoiret opened this issue Aug 29, 2024 · 11 comments
Labels
enhancement New feature or request

Comments

@clementpoiret
Copy link

The current script generated to init env with uv checks for requirements.txt. However, uv now supports uv sync to deal with pyproject.toml, similarly to poetry. Cf https://astral.sh/blog/uv-unified-python-packaging

Based on the presence of a pyproject.toml, would it be possible to replace the workflows around requirements.txt with a simple uv sync call?

If you validate the approach, maybe I can work on a PR?

@clementpoiret clementpoiret added the enhancement New feature or request label Aug 29, 2024
@domenkozar
Copy link
Member

domenkozar commented Aug 30, 2024

Maybe we should enable it if languages.python.poetry.enable is set to true?

@clementpoiret
Copy link
Author

clementpoiret commented Aug 30, 2024

Since last uv's update, there are nearly no reason to have both poetry and uv I think, as uv aims at being a complete alternative to poetry-like tools, so if you have uv.enabled = true, you will want poetry.enabled = false.
What about simply changing the behavior implicitly based on the presence of a pyproject.toml file? Or make it explicit such as

uv = {
  enabled = true;
  use_pyproject = true;
};

@domenkozar
Copy link
Member

Alright then let's make sure uv conflicts with poetry.

@lamalex
Copy link
Contributor

lamalex commented Sep 4, 2024

I've started hacking around on a PR for this and from what I can tell this is blocked on uv 0.4.4 making it into packages. This PR astral-sh/uv#6834 added support for UV_PROJECT_ENVIRONMENT to actually have uv sync work with the venv in .devenv/state/venv.

To be honest, while looking at the source, this could use a fair bit of refactoring. Before I just dive in, is there a good place to discus what the actual behavior should be for the python language given the messiness of the ecosystem?

@lamalex
Copy link
Contributor

lamalex commented Sep 4, 2024

My proposal:
venv, poetry and uv should all be mutually exclusive configuration blocks.
This would allow init-venv, init-poetry and init-uv to each make their own opinionated decisions best in line with their standards.

There's some useful bits which are shared across package management solutions

  • python interpeter changes
  • lock change detection (uv & poetry)

What would it take to make the change so that the package management configurations are mutually exclusive? Is there appetite for that, or is the current behaviour of venv configuration being shared actually desired?

@schlich
Copy link

schlich commented Sep 4, 2024

i wouldn't go so far as to make them mutually exclusive in config. in monorepo setups you might have a submodule that uses a different package manager. there are a bunch of other weird possibilities, like using poetry for your main package manager but using uv to run scripts.

@Bullish-Design
Copy link

Just piping in to say how much I already enjoy using devenv, and to add another voice to say this would be an awesome improvement.

One question - would devenv be able to support UV managing the python installation itself?

@schlich
Copy link

schlich commented Sep 5, 2024

Just piping in to say how much I already enjoy using devenv, and to add another voice to say this would be an awesome improvement.

One question - would devenv be able to support UV managing the python installation itself?

There's an interesting convo going on in the astral discord about dynamically linked binaries in NixOS as it relates to uv's installed binaries. From the NixOS docs: How to run non-nix executables?

NixOS cannot run dynamically linked executables intended for generic Linux environments out of the box. This is because, by design, it does not have a global library path, nor does it follow the Filesystem Hierarchy Standard (FHS).

There are a few ways to resolve this mismatch in environment expectations:
...

Write a Nix expression for the program to package it in your own configuration.
...
Build from source.
...
Modify the program’s ELF header to include paths to libraries using autoPatchelfHook.
...
Wrap the program to run in an FHS-like environment using buildFHSEnv.

This is a last resort, but sometimes necessary, for example if the program downloads and runs other executables.

Now, AFAICT this only applies to NixOS, i'm still learning about this issue/reasoning so i have no idea if it would be relevant to devenv given what I know, but just throwing it out there as a potential consideration.! I'll be curious to see what the astral team says about it. It's also possible the uv build command released today might address this? hmm

@clementpoiret
Copy link
Author

clementpoiret commented Sep 5, 2024

Awesome if you are preparing something @lamalex, that would be a huge improvement for python dev w/ devenv! Please let us know if you have difficulties or if you need more hands!

Small question, the default devenv init initializes devenv.yaml with Cachix Rolling nixpkgs channel, which sounds outdated of few months. The default config always installs uv 0.1.x. Why not defaulting to nixpkgs 24.05?

@domenkozar
Copy link
Member

See cachix/devenv-nixpkgs#2 (comment)

@schlich
Copy link

schlich commented Sep 12, 2024

Any WIP on this? I'm going to start digging into the code @lamalex let's throw something up if we can avoid duplicating work

lamalex added a commit to lamalex/devenv that referenced this issue Sep 15, 2024
Adds an initUvScript if `uv.sync` is enabled.
Calls `uv sync` to install python packages as defined in pyproject.toml

fixes: cachix#1405
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants