-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Support .env-files #1384
Comments
Thanks for engaging with the project! Specifically, you would like us to read |
pip supports a config-file pip.ini / pip.conf I have not yet seen a reference that some examples:
so my request is to support .env-files in $CWD, |
I always try to setup projects in an isolated way:
to make ruff use the my .env to read RUFF_CACHE_DIR, I use my package https://github.com/libranet/autoread-dotenv to read the .env via sitecustomize-hooks, |
I'm going to mark this as not-planned for now. We may revisit in the future. If people have additional use-cases or thoughts please feel free to share! |
I have a similar use case. I am launching machine learning demos for students, and I am currently using Pipenv which loads environment variables from a file named As a workaround, I can define them in my shell profile, but it would be great to have it natively supported by uv. |
I am also migrating from pipenv which uses |
Willing to consider this further, i.e., we'd read it in |
This might of inspiration, PDM supports something like this: https://pdm-project.org/en/latest/usage/scripts/#env_file I've personally used this as a way to not use tools like dotenv, since I usually need them locally and not on production 😊 (plus is one less thing to worry about) |
We would really love teh ability to load from a .env file for the same reason as above - we use a lot of our applications configuration in .env files. |
Supporting this in |
I am also interested in the |
I think it would be useful to have a flag like But why limit it to |
Hi, I was also migrating from poetry to uv, and currently use taskfile to handle .env variable passing to uv run Example of the taskfile
and then i can run stuff like |
Another user-case: I supply environment variables to my dev server with a .env file. I've been using
|
After the migration from @zanieb @charliermarsh After reading this thread it looks like that missing feature is a real showstopper? |
Here's a non-Python example: Node JS added native support to this feature in September 2023 (changelog) and it has been supported by Bun/Deno for a while now. |
My use case is to use a separate project-specific Conan Local Cache when entering the respective venv. This simply means setting the |
I'm not sure if my use case is related, but I really enjoy |
It shouldn't be needed if you use |
I like Brett Cannon's and Jeff Triplett's takes on Brett posed the question, could we standardize on TOML for this? I think if Secrets management is it's own beast, of course. The upside to |
@blakeNaccarato IMHO it is widely understood that .env-files should have a bash-compatible syntax. Besides that, there should not be anything language or tool specific. |
The great thing about ruff is that it's essentially a drop-in replacement for pylint and other tools you were probably using before. Doing the same with .env files would be a DX win. Championing an emergent new format would be an interesting idea, as a separate and second step, but until it becomes comparable to .env in terms of adoption, it seems like a DX loss to deprecate .env. |
I use direnv for this exact use-case. It is installed as a global binary on pretty much any OS, then activates any The big plus for me is that you need to explicitly enable the file for each folder (once off check) so it will not activate any random file you get in a cloned repo.
|
Unfortunately i have to use Windows so direnv won't work for me. |
We're switching from pipenv to uv, so in order to maintain our current workflows, I'd like to add my vote to the "include .env files by default" option. |
Another vote for load .env by default in build and run cases. A Pipenv has a nice |
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I don't know if it's too late now since that MR is merged. But, I'll try to outline a few arguments against making it a default:
|
(It's not too late, this was just merged into a feature branch for v0.5, but may still change between now and the actual v0.5 release.) |
Is this issue also being used for tracking .env support in tools like |
A few points raised in this thread that I want to respond to:
These "purely preferential" variables probably do belong in each developer's personal setup rather than having to be defined in every project he works on. So, I don't think this should be considered just a "workaround". If you are making an application where some variables must always be set, you should probably make it part of the code.
While it seems Bun does automatically load the
This would be a good way to also satisfy those who want it "always on", but I think it should probably be a string option, i.e. |
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
you can hack it. part of me says that this is best left to direnv. direnv should work on windows. this issue shouldn't have to do with a programming language. but it's in pixi's field. |
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I've decided to make this opt-in for now. I'm going to remove it from the v0.5 branch and PR it to main, since it's no longer a "breaking" change in any sense -- we can ship it in a patch release. |
I have been reading discussion #1384 about .env and how to include it in the `uv run` command. I have always wanted to include this possibility in `uv`, so I was interested in the latest changes. Following @charliermarsh's [advice ](#1384 (comment)) I have tried to respect the philosophy that `uv run` uses the default `.env` and this can be discarded or changed via terminal or environment variables. The behaviour is as follows: - `uv run file.py` executes file.py using the `.env` (if it exists). - `uv run --env-file .env.development file.py` uses the `.env.development` file to load the variables and then runs file.py. In this case the program fails if the file does not exist. - `uv run --no-env-file file.py` skips reading the `.env` file. Equivalently, I have included the `UV_ENV_FILE` and `UV_NO_ENV_FILE` environment variables. I haven't got into including automated tests, I would need help with this. I have tried the above commands, with a python script that prints environment variables. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
I'm in this camp. I just lost an hour of my time trying to sort of this discrepancy. I'd be much more happy switching to uv and recommending it to others if it "just worked" as a pipenv replacement. |
I understand the decision to make this an opt-in feature, but can we also make it configurable via |
Ii would be nice to also enable the env-file via uv.toml. |
Hi! I'd like to know what to know what are the actual best security practices when it comes to publishing to a private index. I know we can do it with one of the following ways:
I recognize this might be delving into the extreme side of security concerns, I’m curious about what would be considered the best practice in this context. Would implementing support for a I guess we can always come up with a way to set up the environment variables from an You can consider my comment useless 😅 |
Opt-in through CLI flags should be made illegal please. It is really bad UX design (imo at least, if there are argument for it and against config in config file I would love to hear them), configuration should be defined in the config file it seems quite logical and intuitive and reproducible. Is it complex to add a new field to the |
We use several private package indexes and are currently migrating from pipenv to uv. With |
Interested in .env support for exposing API keys for local testing. |
Since writing this I've moved to |
In a virtualenv-based project I'd like to be independent from a user's $HOME-dir. |
Yea, I put a REPO_ROOT=$(expand_path .)
export NETRC=$REPO_ROOT/.netrc
dotenv $REPO_ROOT/.env Inside each project folder (in our case # Load root .envrc first
source_env ../../.envrc
# Load .env file
dotenv_if_exists .env Which loads the root Alternatively you could also just put the UV_INDEX_BLAH env vars in the root |
In my workflow I make heavy use of env-files.
several tools support .env out of the box:
It would be nice if uv could support .env-files in the $CWD or parent-dirs.
see https://crates.io/crates/dotenv
The text was updated successfully, but these errors were encountered: