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

Automatic Inline Dependency Management with uv add and uv sync #10445

Closed
hmrc87 opened this issue Jan 9, 2025 · 3 comments
Closed

Automatic Inline Dependency Management with uv add and uv sync #10445

hmrc87 opened this issue Jan 9, 2025 · 3 comments
Assignees

Comments

@hmrc87
Copy link

hmrc87 commented Jan 9, 2025

I want to suggest a feature to allow UV to automatically manage packages as inline dependencies in a designated file (e.g., main.py).

  1. When a package is added with uv add, it will also be appended to the dependencies list in the designated file (if UV_AUTO_ADD_INLINE_DEPS is set).
  2. Integration with uv sync: A similar mechanism will apply to uv sync when a corresponding flag or environment variable is set.

The feature can be enabled via a CLI-Flag or as an environment variable UV_AUTO_MANAGE_INLINE_DEPS

Example

# uv
uv add  requests --auto-add-inline-deps 

# adds the following block to the py file that was added  with "uv init"
 

/// script  
 dependencies = [  
   "requests",  
 ]  
 ///  

This can be useful in scenarios where a developer wants to share the python file without providing the pyproject.toml.

Probably not the most common usecase but there might be additional benefits, can you think of one?

Open Questions

  • Should a specific file (e.g., main.py) always be targeted, or should this be configurable?
  • How should duplicate dependencies or conflicts be handled if they already exist in the inline list?
@zanieb
Copy link
Member

zanieb commented Jan 9, 2025

There's uv add --script <path>

I'm not sure we'll provide a way to automatically sync all the project dependencies to a script on every invocation.

@zanieb
Copy link
Member

zanieb commented Jan 9, 2025

Following #10447 the following will be allowed

uv export | uv add -r - --script main.py

@zanieb zanieb self-assigned this Jan 9, 2025
@zanieb zanieb closed this as completed Jan 9, 2025
@hmrc87
Copy link
Author

hmrc87 commented Jan 11, 2025

That's a great idea and already merged? You rock @zanieb!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants