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

"on venv creation" script #10264

Open
majidaldo opened this issue Jan 1, 2025 · 13 comments
Open

"on venv creation" script #10264

majidaldo opened this issue Jan 1, 2025 · 13 comments

Comments

@majidaldo
Copy link

close to #10211.

Use cases: pre-commit install and environment variable setting.

@zanieb
Copy link
Member

zanieb commented Jan 1, 2025

On activate as in source .venv/bin/activate or during uv run? I think I need more details here.

@majidaldo majidaldo changed the title "on venv activate" script "on venv creation" script Jan 2, 2025
@majidaldo
Copy link
Author

On activate as in source .venv/bin/activate or during uv run? I think I need more details here.

errr sorry changed the issue title. uv run variations can be handled but there is no 'hook' to do something on env creation with the driving use case being a place to put pre-commit install.

@sayandipdutta
Copy link

+1
Such a on venv creation hook will also let me set the venv --prompt to something other than .venv.

@brunomjm
Copy link

brunomjm commented Feb 6, 2025

+1
If I may rephrase: a way to include custom actions in the uv sync process (my use case is also pre-commit install).
Benefits:

  • Less boilerplate / manual steps until a developer can start working on a fresh clone or after a pull where pre-commits where changed,
  • Less risk of developers bypassing or forgetting about required pre-commit hooks in a project.

@majidaldo maybe mention uv sync in the title?

@majidaldo
Copy link
Author

+1 If I may rephrase: a way to include custom actions in the uv sync process (my use case is also pre-commit install). Benefits:

  • Less boilerplate / manual steps until a developer can start working on a fresh clone or after a pull where pre-commits where changed,
  • Less risk of developers bypassing or forgetting about required pre-commit hooks in a project.

@majidaldo maybe mention uv sync in the title?

my suggestion isn't on uv sync but on venv activation though. let uv sync just be about creating the env (not activating it).

@zanieb
Copy link
Member

zanieb commented Feb 6, 2025

Such a on venv creation hook will also let me set the venv --prompt to something other than .venv.

Why not just set the prompt when you create the venv? Is this when the venv is created via a specific command or.. ?

@sayandipdutta
Copy link

sayandipdutta commented Feb 7, 2025

No, not using the explicit command. For things like uv sync, uv run, nd uv add. I am thinking more along the lines of a hook.

@zanieb
Copy link
Member

zanieb commented Feb 7, 2025

But... with those commands the --prompt should be the name of the directory / project not .venv?

@sayandipdutta
Copy link

Well... I checked, and this is embarrassing 😅

Either this wasn't the default behavior in some previous version, or I had messed up somewhere. I remember scouring the issues for such a request. And I ended up writing a custom script to do this. Although I have been seeing the correct prompt ever since, I figured this was solely due to my script, and didn't bother to check thoroughly.

Sorry for the trouble! Thanks a lot!

@zanieb
Copy link
Member

zanieb commented Feb 7, 2025

Haha thanks for following up, that's helpful. Just trying to understand the use-cases :)

@majidaldo
Copy link
Author

majidaldo commented Feb 7, 2025

since we're developing python, i can get something functionally close if i hook stuff into a __init__.py, but such code shouldn't really be in distributed code:

if dev(): # figure out if in dev mode
   # setup steps
   ...

something more involved would be to hook into a build script for some 'dev' package.

@brunomjm
Copy link

my suggestion isn't on uv sync but on venv activation though. let uv sync just be about creating the env (not activating it).

Not sure I understand, since uv abstracts away venv activation no? But I don't wanna hijack your issue 😄 Maybe I will create a separate one.

@zanieb I would be curious to hear your opinion on the intent behind uv sync though: is it strictly meant for syncing dependencies in a virtual environment or could it be extended to a broader definition of "environment" (i.e. prepare the environment for development) which could include installing pre-commit hooks?

@majidaldo
Copy link
Author

my suggestion isn't on uv sync but on venv activation though. let uv sync just be about creating the env (not activating it).

Not sure I understand, since uv abstracts away venv activation no? But I don't wanna hijack your issue 😄 Maybe I will create a separate one.

@zanieb I would be curious to hear your opinion on the intent behind uv sync though: is it strictly meant for syncing dependencies in a virtual environment or could it be extended to a broader definition of "environment" (i.e. prepare the environment for development) which could include installing pre-commit hooks?

that would be uv run.

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

4 participants