Python Package Index

local Python Package Index (PyPI)

corelibs-enum-base (1.0.0)

Published 2025-11-19 11:58:42 +09:00 by clemens

Installation

pip install --index-url  --extra-index-url https://pypi.org/simple corelibs-enum-base

About this package

CoreLibs Enum Base

CoreLibs PROJECT_NAME

This is part of the Python CoreLibs

Overview

Enum Base class to use with any kinde of enum type to be declared

Install

uv add --index=opj-pypi=https://git.egplusww.jp/api/packages/PyPI/pypi/simple corelibs-enum-base

Usage

This module constains a base class for Enum declarations

  • corelibs_enum_base.enum_base

EnumBase class

This class contains basic elements for creating Enum type entries

On any error ValueError will be thrown

Lookup a key based on a string, this would search for key name, which has to be string

@classmethod
def lookup_key(cls, enum_key: str):

Find the entry by the value

@classmethod
def lookup_value(cls, enum_value: Any):

Try to find an entry by either key or value

@classmethod
def from_any(cls, enum_any: Any):

Convert the name entry to the value, equal to "CONTENT.value"

def to_value(self) -> Any:

Convert the key to lower case

def to_lower_case(self) -> str:

Return the content as it would be valled by "CONTENT.name"

def __str__(self) -> str:

Implementation example

from corelibs_enum_base.enum_base import EnumBase


class TestBlock(EnumBase):
    """Test block enum"""
    SOMETHING = "Visible Text"
    HAS_NUM = 5

# get value
TestBlock.HAS_NUM.value  # prints 5

# get the name
TestBlock.HAS_NUM  # prints "HAS_NUM"
TestBlock.HAS_NUM.name  # prints "HAS_NUM"

# find entry by anything
TestBlock.from_any('HAS_NUM')  # gets TestBlock.HAS_NUM
TestBlock.from_any(5)  # gets TestBlock.HAS_NUM

Development

UV setup

uv must be installed

Python venv setup

After clone, run the command below to install all dependenciss

uv sync

Build and Publish

uv build
uv publish --index opj-pypi --token <gitea token>

Python tests

All python tests are the tests/ folder. They are structured by the source folder layout

run them with

uv run pytest

Get a coverate report

uv run pytest --cov=corelibs_enum_base
uv run pytest --cov=corelibs_enum_base --cov-report=term-missing

Other tests

In the test-run folder usage and run tests are located, runt them below

uv run test-run/<script>

Requirements

Requires Python: >=3.13
Details
PyPI
2025-11-19 11:58:42 +09:00
0
Clemens Schwaighofer
6.3 KiB
Assets (2)
Versions (2) View all
1.0.0 2025-11-19
0.2.0 2025-11-19