Skip to content

Commit

Permalink
Fix IsADirectoryError on include(optional(None)) (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn authored Jul 5, 2024
1 parent 1fb13ad commit 50fee42
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 218 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
We follow Semantic Version.


## 1.3.2

### Bugfixes

- Do not fail on `include(optional(None))`


## 1.3.1

### Bugfixes
Expand Down
379 changes: 176 additions & 203 deletions poetry.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ django = [
{ version = "^5.0", python = ">=3.10" },
]

mypy = "^1.9"
wemake-python-styleguide = "^0.18"
flake8-pytest-style = "^1.5"
mypy = "^1.10"
wemake-python-styleguide = "^0.19"
flake8-pytest-style = "^2.0"
nitpick = "^0.35"

doc8 = "^1.1"

pytest = "^8.0"
pytest-cov = ">=4.1,<6.0"
pytest = "^8.1"
pytest-cov = "^5.0"
pytest-randomly = "^3.12"

[tool.poetry.group.docs]
optional = true

[tool.poetry.group.docs.dependencies]
sphinx = ">=5.1,<8.0"
sphinx-autodoc-typehints = ">=1.12,<3.0"
sphinx = "^7.3"
sphinx-autodoc-typehints = "^2.2"
m2r2 = "^0.3"
tomli = "^2.0"

Expand Down
5 changes: 4 additions & 1 deletion split_settings/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def include( # noqa: WPS210, WPS231, C901
Args:
*args: File paths (``glob`` - compatible wildcards can be used).
**kwargs: Settings context: ``scope=globals()`` or ``None``.
scope: Settings context (``globals()`` or ``None``).
Raises:
OSError: if a required settings file is not found.
Expand Down Expand Up @@ -87,6 +87,9 @@ def include( # noqa: WPS210, WPS231, C901
conf_path = os.path.dirname(including_file)

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

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

Expand Down
10 changes: 5 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ def __init__(self, *args, **kwargs):

# Different util functions:

@pytest.fixture()
@pytest.fixture
def scope():
"""This fixture just returns the new instance of the test Scope class."""
return Scope()


@pytest.fixture()
@pytest.fixture
def fixture_file():
"""This fixture return a path to the test fixture file."""
return os.path.join(
Expand All @@ -34,21 +34,21 @@ def fixture_file():

# Settings files:

@pytest.fixture()
@pytest.fixture
def merged():
"""This fixture returns basic merged settings example."""
from tests.settings import merged as _merged # noqa: WPS433
return _merged


@pytest.fixture()
@pytest.fixture
def stacked():
"""This fixture returns stacked settings example."""
from tests.settings import stacked as _stacked # noqa: WPS433
return _stacked


@pytest.fixture()
@pytest.fixture
def recursion():
"""This fixture returns recursion settings example."""
from tests.settings import recursion as _recursion # noqa: WPS433
Expand Down
2 changes: 1 addition & 1 deletion tests/settings/merged/components/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
STATIC_ROOT = 'test_folder'


class TestingConfiguration(object):
class TestingConfiguration:
"""Test class."""

def __init__(self, testing_dir):
Expand Down
11 changes: 10 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from split_settings.tools import include
from split_settings.tools import include, optional

_FIXTURE_VALUE = 'FIXTURE_VALUE'

Expand Down Expand Up @@ -58,3 +58,12 @@ def test_caller_scope_automatically(fixture_file):
include(fixture_file)

assert _FIXTURE_VALUE in globals() # noqa: WPS421


def test_optional_none(fixture_file):
"""
Tests that calling optional on `None` and including the result is fine.
Previously it used to raise an error.
"""
include(optional(None)) # should not fail

0 comments on commit 50fee42

Please sign in to comment.