Skip to content

Commit

Permalink
Skip empty Optional values
Browse files Browse the repository at this point in the history
  • Loading branch information
SukiCZ committed Dec 11, 2023
1 parent b701a71 commit e7ebe4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,16 @@ that contains all the files.
Here's a minimal example:

```python
from os import environ

from split_settings.tools import optional, include

ENV = environ.get('ENV', 'local')

include(
'components/base.py',
'components/database.py',
optional('local_settings.py')
optional('local_settings.py' if ENV == 'local' else None),
)
```

Expand Down
4 changes: 4 additions & 0 deletions split_settings/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ def include(*args: str, **kwargs) -> None: # noqa: WPS210, WPS231, C901
conf_path = os.path.dirname(including_file)

for conf_file in args:
# skip optional empty values
if not conf_file and isinstance(conf_file, _Optional):
continue

saved_included_file = scope.get(_INCLUDED_FILE)
pattern = os.path.join(conf_path, conf_file)

Expand Down
3 changes: 3 additions & 0 deletions tests/settings/merged/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# Missing file:
optional('components/missing_file.py'),

# Conditional inclusion:
optional('components/conditional.py' if False else None), # noqa: WPS314

# Scope:
scope=globals(), # noqa: WPS421
)

0 comments on commit e7ebe4a

Please sign in to comment.