Commit Graph

32 Commits

Author SHA1 Message Date
mdgilene 30cd121cfe Add ability to read secrets from files (#1820)
* Add ability to read secrets from files

* Added docs and updated tests to handle new _build_values argument

* Updated docs to note which types are loaded

* Updated deep_update to take a list of update mappings

* Added warning when fields are not defined as a secret type

* Address additional PR feedback

* improve documentation

* remove redundant UserWarning lines

* allow any field type, not just SecretStr

* regex escape paths in windows 😴

* skip tests on windows 😧 🔫

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-26 10:06:25 +00:00
Louis Sautier d2972362c5 test_config_file_settings_nornir: use less common env. var names (#1977)
Gentoo's Portage sets A during the test phase, switching to less common
environment variable names reduces the likelihood of something similar
happening.
2020-10-09 13:23:31 +01:00
PrettyWood 76fdbe92be feat(dotenv): support home directory relative paths (e.g. ~/.env) (#1804)
closes #1803

Co-authored-by: Samuel Colvin <s@muelcolvin.com>
2020-10-09 10:23:28 +01:00
Yury Paykov 0a465b6216 Fix #1561 - apply Config env names for fields defined in the parent c… (#1585)
* Fix #1561 - apply Config env names for fields defined in the parent class

* Changes

* Fix lint

* Fix typing

* More tests
2020-09-06 16:51:38 +01:00
PrettyWood 0cee311be5 feat(settings): allow custom encoding for dotenv files (#1620)
closes #1615
2020-06-11 11:04:08 +01:00
Connor 730d84217d allow use of a .env-style files in BaseSettings (#607) (#1011)
* allow use of a `.env`-style files in BaseSettings (#607)

* address various issues with initial implementation

- allow specifying `_env_file` kwarg in instantiation
  * overrides any `env_file` specified in the `Config` class
- cast `os.environ` as a dict for better consistenty of behavior
- `env_path` should be a `Path` type
- replace `with open()` with `read_text`
- use regex for parsing the dotenv files and throw error on invalid line
- factor out `read_env_file` into separate file for easier testing

* move back into a single file; revert typing changes; use regex better

* pass `_env_file` argument around instead of setting a class attribute

* add dotenv docs

* add dotenv tests

* Add changes file

* Flesh out the docs a bit

* Apply suggestions from @samuelcolvin's code review

Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>

* wrap docs

* add not about priority

* fix tests and imports

* fix tests

* switch to python-dotenv

* cleanup, test example

* more docs tweaks

* typo

* fix tests for dotenv

Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
2020-01-19 16:45:36 +00:00
Samuel Colvin e1ae058afb Consistent checks for sequence like objects (#1111) 2019-12-20 15:08:45 +00:00
Samuel Colvin de6bd1b469 Settings config inheritance fix #1091 (#1093) 2019-12-11 11:58:03 +00:00
Ivan Dmitrievsky 806eba3810 Merge init_kwargs with env variables recursively to handle nested values (#891)
* Merge init_kwargs with env variables recursively to handle nested values

This commit implements `deep_update` function that works as standard
`update` method on dicts, but also recursively updates all the nested
dict values. It allows splitting init arguments between environment
variables and in-code values, as long as they create a valid object
when merged together.

* Add entry to changes directory

* Fix CI/CD checks

* Make deep_copy not mutating, improve tests and type annotations
2019-10-15 11:24:46 +01:00
Samuel Colvin d381fe84c6 deprecate case_insensitive on BaseSettings config (#885) 2019-10-11 15:59:02 +01:00
Samuel Colvin 41d79de3a9 fix subtle issue with settings env variables (#882) 2019-10-10 13:24:50 +01:00
Samuel Colvin bd8918bfab use FutureWarning in settings so it's printed (#881)
* use FutureWarning in settings so it's printed

* fix tests

* better warning link

* change warning link
2019-10-10 13:24:23 +01:00
Samuel Colvin 9a5b411016 change how env variables work with settings (#847)
* change how env variables work with settings, fix #721

* inheritance and alias warnings

* update docs

* tweak env_settings.py
2019-10-01 16:32:02 +01:00
Samuel Colvin 12f4e0d082 rename Schema to Field (#824)
* rename Schema to Field

* add Schema function with deprecation warning

* mypy tests and other tweaks

* tweaks and cleanup

* Update pydantic/fields.py

Co-Authored-By: Sebastián Ramírez <tiangolo@gmail.com>
2019-09-30 17:49:59 +01:00
dmontagu 756454fb58 Change defaults for BaseSettings (#747)
* Change defaults for BaseSettings

* Update docs and fix build

* Minor documentation fixes

* Fix lowercase issues

* Update docs and fix build

* Fix formatting

* Try with monkeypatched test

* Fix doublequotes

* Change case_insensitive to case_sensitive

* more change details.
2019-08-21 12:48:28 +01:00
Samuel Colvin 04391da318 fix for 'missing' error with validate_all or validate_always (#381)
* fix for 'missing' error with validate_all or validate_always

* update HISTORY
2019-02-04 21:57:44 +00:00
Samuel Colvin 19320bf775 improve settings priority, (#343)
* improve settings priority, ref #341

* add HISTORY.rst

* move is_complex and rename _build_environ

* tweak
2018-12-29 12:31:53 +00:00
Jason Kuhrt a0aa9e78cd feat: add support for case insensitive env names (#313)
* feat: add support for case insensitive env names

Closes #277

* feedback: just alias os.environ

* doc: update history

* doc: mention case_insensitive option

* refactor: feedback if-else expression assignment

* fix: formatting

* chore: encode black configuration in file to support IDEs

* docs: fix example

* feedback: no suppport for IDEs in this PR

* feedback: style
2018-11-26 14:57:09 +00:00
Samuel Colvin 64ada930fc aliases, fix #275, replace #282 (#286) 2018-11-15 12:01:05 +00:00
Samuel Colvin 15850a43c5 moving to black (#287)
* moving to black

* put back flake8

* remove isort option

* putting back isort

* uprev pycodestyle

* remove black from docs/examples

* tweak parse.py
2018-11-15 11:30:07 +00:00
Samuel Colvin f0f9de5f96 improve docs on error handling (#198)
* improve docs on error handling

* change ValidationError signature

* cleanup

* rename _raw_errors > raw_errors

* improve _display_error_type_and_ctx
2018-06-11 13:06:50 +01:00
Nikita Grishko 4f4e22ef47 Error context and message (#183)
* POC of error context and message

* Move type errors to the `errors.py` module; Change errors interface a bit

* Rename `.as_dict()` to `.dict()`

* Fix `PydanticErrorMixin` constructor

* Rename `exceptions.py` to `error_wrappers.py`

* Do not include nullable `ctx`

* Fix tests

* Added `int_validator`; Added `IntegerError`

* Added `float_validator`; Added `FloatError`

* Get rid of `__mro__` in prior of `exc.code`

* Removed `min_number_size` and `max_number_size` from config (#174)

* Added `NumberMinSizeError` and `NumberMaxSizeError`

* Added `NoneIsNotAllowedError`

* Added `EnumError`

* Added `path_validator`; Added `PathError`

* Added `DictError`

* Added `ListError`

* Added `TupleError`

* Added `SetError`

* Added `datetime` related errors

* Added `bytes` and `str` related errors

* Added `SequenceError`

* Improved code coverage

* Display error context in string representation of validation error

* Redefine error message templates using config

* Review fixes

* Updated changelog
2018-05-31 14:35:38 +01:00
Nikita Grishko 31683f8dc4 Errors format (#179)
* Get rid of `track` in errors

* Move `display_as_type` func into utils module

* Get rid of error as `namedtuple`

* Renamed `Error.index` to `Error.loc`

* New way to get error type

* New way to get error message

* New errors format

* Renamed `flatten_errors` property to `flat_errors`

* `__slots__` for `Error` and `ValidationError`

* `loc` as `tuple`

* Tests

* Review fixes

* `flatten_errors` as generator
2018-05-23 14:50:04 +01:00
Samuel Colvin bc931ba790 safe check for complex models with env settings 2017-11-13 15:12:23 +00:00
Samuel Colvin 02dc2f2697 allow json env vars (#96)
* allow json env vars

* add docs
2017-11-07 11:26:16 +00:00
Samuel Colvin 378c96888e simplifying errors 2017-07-08 18:22:57 +01:00
Samuel Colvin ea88afb212 allow aliases 2017-05-31 13:41:53 +01:00
Samuel Colvin 90a2b6bfe3 fix enum validators ignore_extra on settings, fix #13 2017-05-11 22:19:11 +01:00
Samuel Colvin 35add310cc improve error display 2017-05-10 12:43:29 +01:00
Samuel Colvin 24b9fdcd86 removing 'validator' from exception message 2017-05-08 17:43:39 +01:00
Samuel Colvin 3673c11d53 improving coverage 2017-05-08 11:54:43 +01:00
Samuel Colvin 003c0a747b adding basic tests 2017-05-05 13:34:59 +01:00