Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- name: set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: '3.10'

- run: pip install -r requirements/linting.txt -r requirements/pyproject.txt
- name: Install dependencies
# Installing pip is required for the pre-commit action:
run: |
uv sync --group linting --all-extras
uv pip install pip

- uses: pre-commit/[email protected].0
- uses: pre-commit/[email protected].1
with:
extra_args: --all-files

Expand All @@ -37,18 +41,21 @@ jobs:
env:
PYTHON: ${{ matrix.python }}
OS: ${{ matrix.os }}
UV_PYTHON_PREFERENCE: only-managed

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- name: set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python }}

- run: pip install -r requirements/testing.txt -r requirements/pyproject.txt
- name: Install dependencies
run: |
uv sync --group testing --all-extras

- name: test
run: make test
Expand All @@ -57,16 +64,16 @@ jobs:
CONTEXT: ${{ runner.os }}-py${{ matrix.python }}

- name: uninstall deps
run: pip uninstall -y PyYAML
run: uv pip uninstall PyYAML

- name: test without deps
run: make test
env:
COVERAGE_FILE: .coverage.${{ runner.os }}-py${{ matrix.python }}-without-deps
CONTEXT: ${{ runner.os }}-py${{ matrix.python }}-without-deps

- run: coverage combine
- run: coverage xml
- run: uv run coverage combine
- run: uv run coverage xml

- uses: codecov/codecov-action@v4
with:
Expand Down Expand Up @@ -98,21 +105,18 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- name: set up uv
uses: astral-sh/setup-uv@v5
with:
python-version: '3.10'

- name: install
run: pip install -U build

- name: check GITHUB_REF matches package version
uses: samuelcolvin/check-python-version@v3.1
uses: samuelcolvin/check-python-version@v4.1
with:
version_file_path: pydantic_settings/version.py

- name: build
run: python -m build
run: uv build
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not change the release part. as we are using the same thing in pydantic.


- name: Upload package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ venv/
env3*/
Pipfile
*.lock
!uv.lock
*.py[cod]
*.egg-info/
/build/
Expand Down
26 changes: 10 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,35 @@ sources = pydantic_settings tests

.PHONY: install
install:
python -m pip install -U pip
pip install -r requirements/all.txt
pip install -e .
uv sync --all-extras --all-groups

.PHONY: refresh-lockfiles
refresh-lockfiles:
@echo "Updating requirements/*.txt files using pip-compile"
find requirements/ -name '*.txt' ! -name 'all.txt' -type f -delete
pip-compile -q --no-emit-index-url --resolver backtracking -o requirements/linting.txt requirements/linting.in
pip-compile -q --no-emit-index-url --resolver backtracking -o requirements/testing.txt requirements/testing.in
pip-compile -q --no-emit-index-url --resolver backtracking --extra toml --extra yaml --extra azure-key-vault -o requirements/pyproject.txt pyproject.toml
pip install --dry-run -r requirements/all.txt
@echo "Updating uv.lock file"
uv lock -U

.PHONY: format
format:
ruff check --fix $(sources)
ruff format $(sources)
uv run ruff check --fix $(sources)
uv run ruff format $(sources)

.PHONY: lint
lint:
ruff check $(sources)
ruff format --check $(sources)
uv run ruff check $(sources)
uv run ruff format --check $(sources)

.PHONY: mypy
mypy:
mypy pydantic_settings
uv run mypy pydantic_settings

.PHONY: test
test:
coverage run -m pytest --durations=10
uv run coverage run -m pytest --durations=10

.PHONY: testcov
testcov: test
@echo "building coverage html"
@coverage html
@uv run coverage html

.PHONY: all
all: lint mypy testcov
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ print(Settings().model_dump())
{
'auth_key': 'xxx',
'api_key': 'xxx',
'redis_dsn': Url('redis://user:pass@localhost:6379/1'),
'pg_dsn': MultiHostUrl('postgres://user:pass@localhost:5432/foobar'),
'amqp_dsn': Url('amqp://user:pass@localhost:5672/'),
'redis_dsn': RedisDsn('redis://user:pass@localhost:6379/1'),
'pg_dsn': PostgresDsn('postgres://user:pass@localhost:5432/foobar'),
'amqp_dsn': AmqpDsn('amqp://user:pass@localhost:5672/'),
'special_function': math.cos,
'domains': set(),
'more_settings': {'foo': 'bar', 'apple': 1},
Expand Down Expand Up @@ -2055,7 +2055,7 @@ class Settings(BaseSettings):


print(Settings(database_dsn='postgres://postgres@localhost:5432/kwargs_db'))
#> database_dsn=MultiHostUrl('postgres://postgres@localhost:5432/kwargs_db')
#> database_dsn=PostgresDsn('postgres://postgres@localhost:5432/kwargs_db')
```

By flipping `env_settings` and `init_settings`, environment variables now have precedence over `__init__` kwargs.
Expand Down
10 changes: 6 additions & 4 deletions pydantic_settings/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ class Cfg(BaseSettings):
type_has_key = self.next_field(type_, key, case_sensitive)
if type_has_key:
return type_has_key
if is_model_class(annotation) or is_pydantic_dataclass(annotation):
if is_model_class(annotation) or is_pydantic_dataclass(annotation): # type: ignore[arg-type]
fields = _get_model_fields(annotation)
# `case_sensitive is None` is here to be compatible with the old behavior.
# Has to be removed in V3.
Expand Down Expand Up @@ -1793,11 +1793,13 @@ def _add_parser_args(
if isinstance(group, dict):
group = self._add_group(parser, **group)
added_args += list(arg_names)
self._add_argument(group, *(f'{flag_prefix[:len(name)]}{name}' for name in arg_names), **kwargs)
self._add_argument(
group, *(f'{flag_prefix[: len(name)]}{name}' for name in arg_names), **kwargs
)
else:
added_args += list(arg_names)
self._add_argument(
parser, *(f'{flag_prefix[:len(name)]}{name}' for name in arg_names), **kwargs
parser, *(f'{flag_prefix[: len(name)]}{name}' for name in arg_names), **kwargs
)

self._add_parser_alias_paths(parser, alias_path_args, added_args, arg_prefix, subcommand_prefix, group)
Expand Down Expand Up @@ -2247,7 +2249,7 @@ def _load_env_vars(self) -> Mapping[str, Optional[str]]:
return AzureKeyVaultMapping(secret_client)

def __repr__(self) -> str:
return f'{self.__class__.__name__}(url={self._url!r}, ' f'env_nested_delimiter={self.env_nested_delimiter!r})'
return f'{self.__class__.__name__}(url={self._url!r}, env_nested_delimiter={self.env_nested_delimiter!r})'


def _get_env_var_key(key: str, case_sensitive: bool = False) -> str:
Expand Down
17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ Source = 'https://github.com/pydantic/pydantic-settings'
Changelog = 'https://github.com/pydantic/pydantic-settings/releases'
Documentation = 'https://docs.pydantic.dev/dev-v2/concepts/pydantic_settings/'

[dependency-groups]
linting = [
"black",
"mypy",
"pre-commit",
"pyyaml",
"ruff",
"types-pyyaml",
]
testing = [
"coverage[toml]",
"pytest",
"pytest-examples",
"pytest-mock",
"pytest-pretty",
]

[tool.pytest.ini_options]
testpaths = 'tests'
filterwarnings = [
Expand Down
3 changes: 0 additions & 3 deletions requirements/all.txt

This file was deleted.

7 changes: 0 additions & 7 deletions requirements/linting.in

This file was deleted.

58 changes: 0 additions & 58 deletions requirements/linting.txt

This file was deleted.

75 changes: 0 additions & 75 deletions requirements/pyproject.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements/testing.in

This file was deleted.

Loading