Skip to content

Commit

Permalink
remove case sensitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron committed Mar 15, 2024
1 parent 01e71d7 commit 2c08a9e
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 674 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ repos:
hooks:
- id: isort

default_language_version:
python: python3.11
777 changes: 147 additions & 630 deletions poetry.lock

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ repository = "https://github.com/rabbit-aaron/ragdoll.git"
python = "^3.6.2"

[tool.poetry.dev-dependencies]
black = "^21.7b0"
pytest = "^6.2.4"
flake8 = "^3.9.2"
pytest-cov = "^2.12.1"
bump2version = "^1.0.1"
pre-commit = "^2.14.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
target-version = ["py36", "py37", "py38", "py39"]
target-version = ["py36", "py37", "py38", "py39", "py310", "py311"]
10 changes: 3 additions & 7 deletions ragdoll/base.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import abc
from typing import Any, Mapping, Optional, Type, Union

from ragdoll import errors, utils
from ragdoll import errors


class BaseEntry(abc.ABC):

_NOT_SET = object()
DEFAULT_EXPORT = False
source: dict
source: Mapping

def __init__(
self,
Expand Down Expand Up @@ -89,11 +89,7 @@ def __init__(cls: Type["BaseSetting"], *args, **kwargs):
class BaseSetting(metaclass=SettingMeta):

auto_configure = True

@abc.abstractmethod
@utils.classproperty
def source(cls) -> Mapping: # pragma: no cover
raise NotImplementedError
source: Mapping

@classmethod
def configure_entry(cls, entry: BaseEntry, name: str, value: str):
Expand Down
17 changes: 2 additions & 15 deletions ragdoll/env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import typing

from ragdoll import errors, utils
from ragdoll import errors
from ragdoll.base import BaseEntry, BaseSetting

__all__ = ["EnvSetting", "BaseEnvEntry", "StrEnv", "BoolEnv", "IntEnv"]
Expand All @@ -13,8 +13,6 @@ def get_raw_value(self) -> str:

def __set_name__(self, owner: typing.Type["EnvSetting"], name: str):
super().__set_name__(owner, name)
if not owner.case_sensitive:
self._name = name.lower()


class StrEnv(BaseEnvEntry):
Expand Down Expand Up @@ -68,15 +66,4 @@ def __get__(self, *args, **kwargs) -> bool: ...


class EnvSetting(BaseSetting):
case_sensitive = True
_source: typing.Optional[typing.Mapping] = None

@utils.classproperty
def source(cls) -> typing.Mapping:
if not cls._source:
if cls.case_sensitive:
cls._source = os.environ
else:
cls._source = {k.lower(): v for k, v in os.environ.items()}

return cls._source
source = os.environ
2 changes: 1 addition & 1 deletion tests/test_env/test_bool_env.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest

from ragdoll import errors
from ragdoll.env import EnvSetting, BoolEnv
from ragdoll.env import BoolEnv, EnvSetting


def test_bool_env(monkeypatch):
Expand Down
16 changes: 1 addition & 15 deletions tests/test_env/test_str_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ragdoll.env import EnvSetting, StrEnv


def test_str_env_case_sensitive(monkeypatch):
def test_str_env(monkeypatch):
monkeypatch.setenv("FOO", "FOO")
monkeypatch.setenv("BAR", "BAR")

Expand All @@ -16,20 +16,6 @@ class MyEnvSetting(EnvSetting):
assert MyEnvSetting.bar is None


def test_str_env_case_insensitive(monkeypatch):
monkeypatch.setenv("FOO", "FOO")
monkeypatch.setenv("BAR", "BAR")

class MyEnvSetting(EnvSetting):
case_sensitive = False

FOO = StrEnv()
bar = StrEnv()

assert MyEnvSetting.FOO == "FOO"
assert MyEnvSetting.bar == "BAR"


def test_str_env_default_not_in_choice():
with pytest.raises(AssertionError):
StrEnv(default_value="foo", choices={"hello", "world"})
Expand Down

0 comments on commit 2c08a9e

Please sign in to comment.