Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/build/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: build
inputs:
package-version:
required: true
description: The python package version
runs:
using: "composite"
steps:
- uses: astral-sh/setup-uv@v5

- name: Build
shell: bash
run: |
uvx --from=toml-cli toml set --toml-path=pyproject.toml project.version ${{ inputs.package-version }}
uv build

- name: Upload package
uses: actions/upload-artifact@v4
with:
path: dist/
name: dist
43 changes: 43 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: CD Pipeline

on:
create:

jobs:
build:
name: Build
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:
- name: Load version into env
shell: bash
run: |
[[ $GITHUB_REF =~ refs/tags/(.*) ]]
version="${BASH_REMATCH[1]}"
[ -z "${version}" ] && exit 1
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV

- uses: actions/checkout@v4

- uses: ./.github/build
with:
package-version: ${RELEASE_VERSION}

pypi-publish:
name: Publish to pypi
needs: build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: pypi
permissions:
# IMPORTANT: this permission is mandatory for Trusted Publishing
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ vars.REPOSITORY_URL }}
79 changes: 79 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
on:
pull_request:
branches:
- master

push:
branches:
- master

name: CI

jobs:
test:
name: Test
strategy:
matrix:
python-version: ["3.13", "3.12", "3.11", "3.10", "3.9"]
runs-on: ubuntu-latest
environment: pypi-test
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
- uses: extractions/setup-just@v2
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: "Install python venv"
run: "uv sync"

- name: "Lint and test"
run: |
source .venv/bin/activate
just lint
just test
coverage xml

- uses: codecov/codecov-action@v5
if: ${{ contains(matrix.python-version, '3.13') }}
with:
fail_ci_if_error: true
token: ${{ secrets.CODECOV_TOKEN }}

build:
name: Build
if: ${{ github.event_name == 'pull_request' }}
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Load version into env
shell: bash
run: |
dev_version=$(date '+%Y%m%d%H%M%S')
echo "RELEASE_VERSION=0.1.0${{ github.head_ref }}${dev_version}" >> $GITHUB_ENV

- uses: ./.github/build
with:
package-version: ${RELEASE_VERSION}

pypi-publish:
name: Publish to test-pypi
if: ${{ github.event_name == 'pull_request' }}
needs: [test, build]
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: pypi-test
permissions:
# IMPORTANT: this permission is mandatory for Trusted Publishing
id-token: write
steps:
- uses: actions/download-artifact@v4
with:
name: dist
path: dist/
- uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: ${{ vars.REPOSITORY_URL }}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ __pycache__/
.mypy_cache/
.ruff_cache/
*.py[oc]
build/
dist/
./build/
./dist/
wheels/
*.egg-info
.coverage
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![codecov](https://codecov.io/gh/DAtek/datek-app-utils/graph/badge.svg?token=UR0G0I41LD)](https://codecov.io/gh/DAtek/datek-app-utils)
[![codecov](https://codecov.io/gh/DAtek/enfig/graph/badge.svg?token=IJOcBg0LZ8)](https://codecov.io/gh/DAtek/enfig)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
<a href="https://github.com/psf/black/blob/main/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>

Expand Down
3 changes: 1 addition & 2 deletions enfig/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from enfig.base import BaseConfig
from enfig.errors import ValidationError, ConfigAttributeError
from enfig.errors import ConfigAttributeError, ValidationError

__all__ = [
BaseConfig.__name__,
ValidationError.__name__,
ConfigAttributeError.__name__,
]

7 changes: 4 additions & 3 deletions enfig/errors.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from enum import Enum, StrEnum
from enum import Enum

from enfig.bool_type import _Bool

Expand All @@ -11,7 +11,7 @@ class InstantiationForbiddenError(EnfigError):
pass


class ConfigAttributeErrorType(StrEnum):
class ConfigAttributeErrorType(str, Enum):
NOT_SET = "Not set"
INVALID_VALUE = "Invalid value"

Expand All @@ -35,7 +35,8 @@ def __repr__(self):
def __str__(self) -> str:
required_type = bool if self.required_type is _Bool else self.required_type
return (
f"{self.attribute_name}: {self.error_type}, required type: `{required_type.__name__}`"
f"{self.attribute_name}: {self.error_type}, "
f"required type: `{required_type.__name__}`"
)


Expand Down
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
[project.urls]
Source = "https://github.com/datek/enfig"

[project]
authors = [
{name = "Attila Dudás", email = "attila.dudas@protonmail.com"},
]
name = "enfig"
version = "0.1.0"
description = "Add your description here"
description = "Lean, zero dependency environment parsing library."
readme = "README.md"
requires-python = "^3.8"
requires-python = ">=3.9"
license = "MIT"
license-files = ["LICENSE"]
dependencies = []

[dependency-groups]
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

from pytest import fixture

from enfig.base import BaseConfig
Expand All @@ -9,7 +11,7 @@ class VolumeConfig(BaseConfig):
VOLUME: int
FIELD_WITH_DEFAULT_VALUE: str = "C"
NON_MANDATORY_FIELD: str = None # type: ignore
TYPED_NON_MANDATORY_FIELD: str | None = None
TYPED_NON_MANDATORY_FIELD: Optional[str] = None

return VolumeConfig

Expand Down
Loading
Loading