Skip to content

Commit

Permalink
resolve nested code fence line numbering (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
johndutchover committed Nov 6, 2023
1 parent e529615 commit b850ad1
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ print(Settings().model_dump())
1. Sub model has to inherit from `pydantic.BaseModel`, Otherwise `pydantic-settings` will initialize sub model,
collects values for sub model fields separately, and you may get unexpected results.

1. Sub model has to inherit from `pydantic.BaseModel`, Otherwise `pydantic-settings` will initialize sub model,
2. Sub model has to inherit from `pydantic.BaseModel`, Otherwise `pydantic-settings` will initialize sub model,
collects values for sub model fields separately, and you may get unexpected results.

`env_nested_delimiter` can be configured via the `model_config` as shown above, or via the
Expand Down Expand Up @@ -389,29 +389,25 @@ Once you have your `.env` file filled with variables, *pydantic* supports loadin

1. Setting the `env_file` (and `env_file_encoding` if you don't want the default encoding of your OS) on `model_config`
in the `BaseSettings` class:
````py hl_lines="4 5"
from pydantic_settings import BaseSettings, SettingsConfigDict

```py hl_lines="4 5"
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
```

class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
````
2. Instantiating the `BaseSettings` derived class with the `_env_file` keyword argument
(and the `_env_file_encoding` if needed):
````py hl_lines="8"
from pydantic_settings import BaseSettings, SettingsConfigDict

```py hl_lines="8"
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')

class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')

settings = Settings(_env_file='prod.env', _env_file_encoding='utf-8')
```

settings = Settings(_env_file='prod.env', _env_file_encoding='utf-8')
````
In either case, the value of the passed argument can be any valid path or filename, either absolute or relative to the
current working directory. From there, *pydantic* will handle everything for you by loading in your variables and
validating them.
Expand Down Expand Up @@ -476,22 +472,19 @@ super_secret_database_password
Once you have your secret files, *pydantic* supports loading it in two ways:

1. Setting the `secrets_dir` on `model_config` in a `BaseSettings` class to the directory where your secret files are stored.
````py hl_lines="4 5 6 7"
from pydantic_settings import BaseSettings, SettingsConfigDict

```py hl_lines="4 5 6 7"
from pydantic_settings import BaseSettings, SettingsConfigDict


class Settings(BaseSettings):
model_config = SettingsConfigDict(secrets_dir='/var/run')

database_password: str
```
class Settings(BaseSettings):
model_config = SettingsConfigDict(secrets_dir='/var/run')

database_password: str
````
2. Instantiating the `BaseSettings` derived class with the `_secrets_dir` keyword argument:

```
settings = Settings(_secrets_dir='/var/run')
```
````
settings = Settings(_secrets_dir='/var/run')
````

In either case, the value of the passed argument can be any valid directory, either absolute or relative to the
current working directory. **Note that a non existent directory will only generate a warning**.
Expand Down

0 comments on commit b850ad1

Please sign in to comment.