Skip to content

Commit

Permalink
Merge pull request #11 from illuin-tech/rename-to-enviparse
Browse files Browse the repository at this point in the history
feat: rename to enviparse
  • Loading branch information
AlexisFilipozzi authored Aug 23, 2024
2 parents 5979118 + d92ab85 commit 9857436
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 124 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
pip install -e '.[dev,attr,opyoid]'
- name: Test with pytest
run: |
py.test --cov-report xml --cov-report term --cov=envipy ./tests
py.test --cov-report xml --cov-report term --cov=enviparse ./tests
- name: Codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
black . --check -l 120
- name: Lint with pylint
run: |
pylint envipy
pylint enviparse
pylint tests --disable=too-many-public-methods,too-many-instance-attributes,too-many-lines
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
__pycache__
coverage.xml
.coverage
envipy.egg-info/*
enviparse.egg-info/*
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 2.0.0
### Breaking changes
- Update project name to `envipy`
- Update project name to `enviparse`

## 1.1.1
### Fixes
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
We welcome everyone to help us on this project.

All bug reports, feature requests and questions should be filed at the
[GitHub issues page](https://github.com/illuin-tech/envipy/issues).
[GitHub issues page](https://github.com/illuin-tech/enviparse/issues).

You can open your own Pull Request after discussing the need for those changes in an issue.

Expand All @@ -21,6 +21,6 @@ Run `python -m unitttest discover` to run the tests.

Run these commands to check the files linting:
```shell script
pylint envipy
pylint enviparse
pylint tests --disable=too-many-public-methods,too-many-instance-attributes
```
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Envipy
# Enviparse

![CI](https://github.com/illuin-tech/envipy/workflows/CI/badge.svg)
[![codecov](https://codecov.io/gh/illuin-tech/envipy/branch/main/graph/badge.svg)](https://codecov.io/gh/illuin-tech/envipy)
![CI](https://github.com/illuin-tech/enviparse/workflows/CI/badge.svg)
[![codecov](https://codecov.io/gh/illuin-tech/enviparse/branch/main/graph/badge.svg)](https://codecov.io/gh/illuin-tech/enviparse)


## Description

Envipy let you simply create dataclasses from environment variable.
Enviparse let you simply create dataclasses from environment variable.

Supported types are :
* int
Expand Down Expand Up @@ -34,7 +34,7 @@ You can parse environment variable with :

```python
import dataclasses
from envipy import Envipy
from enviparse import Enviparse


@dataclasses.dataclass
Expand All @@ -46,7 +46,7 @@ class DatabaseConfig:
database_name: str


db_config = Envipy().envipy("DATABASE_CONFIG", DatabaseConfig)
db_config = Enviparse().parse("DATABASE_CONFIG", DatabaseConfig)
print(db_config)
```

Expand Down
1 change: 1 addition & 0 deletions enviparse/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .enviparse import Enviparse
12 changes: 6 additions & 6 deletions envipy/envipy.py → enviparse/enviparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ClassTypeT = TypeVar("ClassTypeT")


class Envipy:
class Enviparse:
def __init__(
self,
concat_env_name_func: Optional[Callable[[str, str], str]] = None,
Expand All @@ -30,7 +30,7 @@ def __init__(
lambda prefix, suffix: f"{prefix.upper()}_{suffix.upper()}"
)

def envipy( # pylint: disable=too-many-return-statements
def parse( # pylint: disable=too-many-return-statements
self,
prefix: str,
t_type: Type[ClassTypeT],
Expand Down Expand Up @@ -127,7 +127,7 @@ def _get_list_type_from_env(
index = 0
while self._has_env_var_with_prefix(self._concat_env_name_func(prefix, str(index))):
list_item_env_var_name_prefix = self._concat_env_name_func(prefix, str(index))
item_env_var_value = self.envipy(list_item_env_var_name_prefix, list_item_type)
item_env_var_value = self.parse(list_item_env_var_name_prefix, list_item_type)
values.append(item_env_var_value)
index += 1
return values
Expand All @@ -140,7 +140,7 @@ def _get_optional_type_from_env(
type_hints = get_args(attr_class)
optional_type = type_hints[0]
if self._has_env_var_with_prefix(prefix):
return self.envipy(prefix, optional_type)
return self.parse(prefix, optional_type)
return None

def _get_dataclass_from_env(
Expand All @@ -154,7 +154,7 @@ def _get_dataclass_from_env(
field_env_var_prefix = self._concat_env_name_func(prefix, field.name)

try:
field_values[field.name] = self.envipy(prefix=field_env_var_prefix, t_type=field.type)
field_values[field.name] = self.parse(prefix=field_env_var_prefix, t_type=field.type)
except MissingEnvironmentVariableError as error:
if field.default is not None and field.default is not dataclasses.MISSING:
field_values[field.name] = field.default
Expand All @@ -174,7 +174,7 @@ def _get_attr_class_from_env(
field_env_var_prefix = self._concat_env_name_func(prefix, field_name)

try:
field_values[field_name] = self.envipy(prefix=field_env_var_prefix, t_type=field.type)
field_values[field_name] = self.parse(prefix=field_env_var_prefix, t_type=field.type)
except MissingEnvironmentVariableError as error:
if field.default is not None and field.default is not attr.NOTHING:
field_values[field_name] = field.default
Expand Down
12 changes: 6 additions & 6 deletions envipy/errors.py → enviparse/errors.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class EnvipyError(Exception):
class EnviparseError(Exception):
pass


class UnexpectedTypeError(EnvipyError):
class UnexpectedTypeError(EnviparseError):
def __init__(self, used_type: str, path: str):
super().__init__(f'Unsupported type "{used_type}" for property at path "{path}"')


class UnknownTypeError(EnvipyError):
class UnknownTypeError(EnviparseError):
def __init__(self, path: str):
super().__init__(f'Unknown generic type for property at path "{path}"')


class MissingEnvironmentVariableError(EnvipyError):
class MissingEnvironmentVariableError(EnviparseError):
def __init__(self, env_var_name: str):
super().__init__(f"Environment variable '{env_var_name}' is not set.")


class NestedMissingEnvironmentVariableError(EnvipyError):
class NestedMissingEnvironmentVariableError(EnviparseError):
def __init__(self, env_var_name: str):
super().__init__(f"Environment variable '{env_var_name}' is not set.")


class CastError(EnvipyError):
class CastError(EnviparseError):
def __init__(self, env_var_name: str, data_type: str):
super().__init__(f"Failed to convert '{env_var_name}' to {data_type}.")
16 changes: 16 additions & 0 deletions enviparse/opyoid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from typing import Type, Optional

from opyoid import Provider

from .enviparse import ClassTypeT, Enviparse


def enviparse_provider(prefix: str, config_type: Type[ClassTypeT]) -> Type[Provider[ClassTypeT]]:
class EnviparseProvider(Provider[ClassTypeT]):
def __init__(self, enviparse: Optional[Enviparse] = None):
self._parser = enviparse or Enviparse()

def get(self) -> ClassTypeT:
return self._parser.parse(prefix, config_type)

return EnviparseProvider
1 change: 0 additions & 1 deletion envipy/__init__.py

This file was deleted.

16 changes: 0 additions & 16 deletions envipy/opyoid.py

This file was deleted.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "envipy"
name = "enviparse"
dynamic = ["version"]
description = "envipy help you manage your application properties using environment variabl"
description = "enviparse help you manage your application properties using environment variabl"
authors = [
{name = "Illuin technology", email = "[email protected]"},
]
Expand Down
Loading

0 comments on commit 9857436

Please sign in to comment.