mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 18:25:00 +00:00
Load .env from home, git, cwd, cmd line arg
This commit is contained in:
parent
8a0480a56d
commit
46374fb07a
5 changed files with 32 additions and 11 deletions
|
@ -220,9 +220,9 @@ def generate_search_path_list(default_fname, git_root, command_line_file):
|
||||||
files.append(Path.home() / default_file) # homedir
|
files.append(Path.home() / default_file) # homedir
|
||||||
if git_root:
|
if git_root:
|
||||||
files.append(Path(git_root) / default_file) # git root
|
files.append(Path(git_root) / default_file) # git root
|
||||||
|
files.append(default_file.resolve())
|
||||||
if command_line_file:
|
if command_line_file:
|
||||||
files.append(command_line_file)
|
files.append(command_line_file)
|
||||||
files.append(default_file.resolve())
|
|
||||||
files = [Path(fn).resolve() for fn in files]
|
files = [Path(fn).resolve() for fn in files]
|
||||||
files.reverse()
|
files.reverse()
|
||||||
uniq = []
|
uniq = []
|
||||||
|
@ -255,6 +255,20 @@ def register_models(git_root, model_settings_fname, io):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def load_dotenv_files(git_root, dotenv_fname):
|
||||||
|
dotenv_files = generate_search_path_list(
|
||||||
|
".env",
|
||||||
|
git_root,
|
||||||
|
dotenv_fname,
|
||||||
|
)
|
||||||
|
loaded = []
|
||||||
|
for fname in dotenv_files:
|
||||||
|
if Path(fname).exists():
|
||||||
|
loaded.append(fname)
|
||||||
|
load_dotenv(fname)
|
||||||
|
return loaded
|
||||||
|
|
||||||
|
|
||||||
def register_litellm_models(git_root, model_metadata_fname, io):
|
def register_litellm_models(git_root, model_metadata_fname, io):
|
||||||
model_metatdata_files = generate_search_path_list(
|
model_metatdata_files = generate_search_path_list(
|
||||||
".aider.model.metadata.json", git_root, model_metadata_fname
|
".aider.model.metadata.json", git_root, model_metadata_fname
|
||||||
|
@ -294,8 +308,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
args, unknown = parser.parse_known_args(argv)
|
args, unknown = parser.parse_known_args(argv)
|
||||||
|
|
||||||
# Load the .env file specified in the arguments
|
# Load the .env file specified in the arguments
|
||||||
if hasattr(args, "env_file"):
|
loaded_dotenvs = load_dotenv_files(git_root, args.env_file)
|
||||||
load_dotenv(args.env_file)
|
|
||||||
|
|
||||||
# Parse again to include any arguments that might have been defined in .env
|
# Parse again to include any arguments that might have been defined in .env
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
@ -342,6 +355,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
editingmode=editing_mode,
|
editingmode=editing_mode,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for fname in loaded_dotenvs:
|
||||||
|
io.tool_output(f"Loaded {fname}")
|
||||||
|
|
||||||
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
fnames = [str(Path(fn).resolve()) for fn in args.files]
|
||||||
if len(args.files) > 1:
|
if len(args.files) > 1:
|
||||||
good = True
|
good = True
|
||||||
|
|
|
@ -6,4 +6,4 @@ have their keys and settings
|
||||||
specified in environment variables.
|
specified in environment variables.
|
||||||
This can be done in your shell,
|
This can be done in your shell,
|
||||||
or by using a
|
or by using a
|
||||||
[`.env` file](/docs/config/dotenv.html).
|
[.env file](/docs/config/dotenv.html).
|
||||||
|
|
|
@ -12,12 +12,12 @@ your git repo.
|
||||||
|
|
||||||
{% include special-keys.md %}
|
{% include special-keys.md %}
|
||||||
|
|
||||||
Below is a sample of the file, which you
|
{% include env-keys-tip.md %}
|
||||||
|
|
||||||
|
Below is a sample of the YAML config file, which you
|
||||||
can also
|
can also
|
||||||
[download from GitHub](https://github.com/paul-gauthier/aider/blob/main/aider/website/assets/sample.aider.conf.yml).
|
[download from GitHub](https://github.com/paul-gauthier/aider/blob/main/aider/website/assets/sample.aider.conf.yml).
|
||||||
|
|
||||||
{% include env-keys-tip.md %}
|
|
||||||
|
|
||||||
<!--[[[cog
|
<!--[[[cog
|
||||||
from aider.args import get_sample_yaml
|
from aider.args import get_sample_yaml
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
|
@ -13,9 +13,14 @@ in the `.env` file.
|
||||||
|
|
||||||
{% include special-keys.md %}
|
{% include special-keys.md %}
|
||||||
|
|
||||||
Aider will look for a `.env` file in the
|
Aider will look for a `.env` file in these locations:
|
||||||
root of your git repo or in the current directory.
|
|
||||||
You can give it an explicit file to load with the `--env-file <filename>` parameter.
|
- Your home directory.
|
||||||
|
- The root of your git repo.
|
||||||
|
- The current directory.
|
||||||
|
- As specified with the `--env-file <filename>` parameter.
|
||||||
|
|
||||||
|
If the files above exist, they will be loaded in that order. Files loaded last will take priority.
|
||||||
|
|
||||||
Below is a sample `.env` file, which you
|
Below is a sample `.env` file, which you
|
||||||
can also
|
can also
|
||||||
|
|
|
@ -14,7 +14,7 @@ The steps below are completely optional.
|
||||||
|
|
||||||
## Store your api keys
|
## Store your api keys
|
||||||
|
|
||||||
You can place your [api keys in a `.env` file](/docs/config/dotenv.html)
|
You can [store your api keys in a .env file](/docs/config/dotenv.html)
|
||||||
and they will be loaded automatically whenever you run aider.
|
and they will be loaded automatically whenever you run aider.
|
||||||
|
|
||||||
## Enable Playwright
|
## Enable Playwright
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue