summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--python-data-enum.spec471
-rw-r--r--sources1
3 files changed, 473 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e69de29..218cb69 100644
--- a/.gitignore
+++ b/.gitignore
@@ -0,0 +1 @@
+/data-enum-2.0.1.tar.gz
diff --git a/python-data-enum.spec b/python-data-enum.spec
new file mode 100644
index 0000000..2c97e7a
--- /dev/null
+++ b/python-data-enum.spec
@@ -0,0 +1,471 @@
+%global _empty_manifest_terminate_build 0
+Name: python-data-enum
+Version: 2.0.1
+Release: 1
+Summary: An alternative to the built-in Python `enum` implementation
+License: Apache Software License
+URL: https://github.com/chasefinch/data-enum
+Source0: https://mirrors.nju.edu.cn/pypi/web/packages/8f/e5/c5647bf1f0dad89fc4e1c1e4a3275c8d56a5dcd7c0a46d78a554aa16dba3/data-enum-2.0.1.tar.gz
+BuildArch: noarch
+
+
+%description
+# Data Enums
+
+![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue) [![Build Status](https://travis-ci.com/chasefinch/amp-renderer.svg?branch=main)](https://travis-ci.com/chasefinch/data-enum) ![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
+
+An alternative to the built-in Python `enum` implementation. Tested in Python 3.6 and above.
+
+Data enums allow you to:
+
+- Associate data with enum members without using tuple-based initialization
+- Use an intuitive initialization syntax to define members
+- Define pure enums without using `auto()`
+- Define value-based enums without storing them as class attributes
+- Define secondary unique keys & use them to look up enum members
+- Use classmethod syntax (`.get(…)`) to look up members, instead of using initializers
+
+## Usage
+
+Install via PyPI:
+
+ pip install data-enum
+
+Minimal usage:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Access the members by value:
+
+ Currency.get('USD')
+ Currency.get('CAD')
+ Currency.get('EUR')
+
+Store the members as attributes:
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency.USD = Currency('USD', symbol='$', name='United States dollar')
+ Currency.EUR = Currency('EUR', symbol='€', name='Euro')
+
+Use a custom attribute as the primary ID:
+
+ class Currency(DataEnum):
+ primary_attribute = 'code'
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Use integers as primary IDs:
+
+ class Door(DataEnum):
+ data_attributes = ('description',)
+
+ Door(1, description='Door #1')
+ Door(2, description='Door #2')
+ Door(3, description='Door #3')
+
+ d2 = Door(2) # returns Door(2, description='Door #2')
+
+ int(d2) # returns 2
+
+Or, skip primary IDs altogether for a pure enumeration:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency(symbol='$', name='Canadian dollar')
+ Currency.USD = Currency(symbol='$', name='United States dollar')
+ Currency.EUR = Currency(symbol='€', name='Euro')
+
+Access the attached data:
+
+ print(Currency.USD.name) # prints 'United States dollar'
+ print(Currency.EUR.symbol) # prints '€'
+
+ print(Currency.USD) # prints 'USD'
+
+Compare directly:
+
+ Currency.USD == Currency.CAD # returns False
+ Currency.EUR == Currency.EUR # returns True
+
+Enforce unique secondary attributes:
+
+ class Currency(DataEnum):
+ # Use a tuple with the second value as True for unique keys
+ data_attributes = (('symbol', True), 'name')
+
+ # Throws ValueError
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+
+Look up members by unique secondary attributes:
+
+ Currency.get(symbol='€') # returns Currency.EUR
+ Currency.get(symbol='&') # throws MemberDoesNotExistError
+
+Look up with members with defaults:
+
+ Currency.get('ZZZ', Currency.USD) # returns Currency.USD
+ Currency.get('ZZZ', default=Currency.USD) # returns Currency.USD
+ Currency.get(symbol='&', default=Currency.USD) # returns Currency.USD
+
+## Testing, etc.
+
+Install requrements:
+
+ make install
+
+Sort imports (Requires Python >= 3.6):
+
+ make format
+
+Lint (Requires Python >= 3.6):
+
+ make lint
+
+Test:
+
+ make test
+
+
+
+
+%package -n python3-data-enum
+Summary: An alternative to the built-in Python `enum` implementation
+Provides: python-data-enum
+BuildRequires: python3-devel
+BuildRequires: python3-setuptools
+BuildRequires: python3-pip
+%description -n python3-data-enum
+# Data Enums
+
+![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue) [![Build Status](https://travis-ci.com/chasefinch/amp-renderer.svg?branch=main)](https://travis-ci.com/chasefinch/data-enum) ![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
+
+An alternative to the built-in Python `enum` implementation. Tested in Python 3.6 and above.
+
+Data enums allow you to:
+
+- Associate data with enum members without using tuple-based initialization
+- Use an intuitive initialization syntax to define members
+- Define pure enums without using `auto()`
+- Define value-based enums without storing them as class attributes
+- Define secondary unique keys & use them to look up enum members
+- Use classmethod syntax (`.get(…)`) to look up members, instead of using initializers
+
+## Usage
+
+Install via PyPI:
+
+ pip install data-enum
+
+Minimal usage:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Access the members by value:
+
+ Currency.get('USD')
+ Currency.get('CAD')
+ Currency.get('EUR')
+
+Store the members as attributes:
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency.USD = Currency('USD', symbol='$', name='United States dollar')
+ Currency.EUR = Currency('EUR', symbol='€', name='Euro')
+
+Use a custom attribute as the primary ID:
+
+ class Currency(DataEnum):
+ primary_attribute = 'code'
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Use integers as primary IDs:
+
+ class Door(DataEnum):
+ data_attributes = ('description',)
+
+ Door(1, description='Door #1')
+ Door(2, description='Door #2')
+ Door(3, description='Door #3')
+
+ d2 = Door(2) # returns Door(2, description='Door #2')
+
+ int(d2) # returns 2
+
+Or, skip primary IDs altogether for a pure enumeration:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency(symbol='$', name='Canadian dollar')
+ Currency.USD = Currency(symbol='$', name='United States dollar')
+ Currency.EUR = Currency(symbol='€', name='Euro')
+
+Access the attached data:
+
+ print(Currency.USD.name) # prints 'United States dollar'
+ print(Currency.EUR.symbol) # prints '€'
+
+ print(Currency.USD) # prints 'USD'
+
+Compare directly:
+
+ Currency.USD == Currency.CAD # returns False
+ Currency.EUR == Currency.EUR # returns True
+
+Enforce unique secondary attributes:
+
+ class Currency(DataEnum):
+ # Use a tuple with the second value as True for unique keys
+ data_attributes = (('symbol', True), 'name')
+
+ # Throws ValueError
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+
+Look up members by unique secondary attributes:
+
+ Currency.get(symbol='€') # returns Currency.EUR
+ Currency.get(symbol='&') # throws MemberDoesNotExistError
+
+Look up with members with defaults:
+
+ Currency.get('ZZZ', Currency.USD) # returns Currency.USD
+ Currency.get('ZZZ', default=Currency.USD) # returns Currency.USD
+ Currency.get(symbol='&', default=Currency.USD) # returns Currency.USD
+
+## Testing, etc.
+
+Install requrements:
+
+ make install
+
+Sort imports (Requires Python >= 3.6):
+
+ make format
+
+Lint (Requires Python >= 3.6):
+
+ make lint
+
+Test:
+
+ make test
+
+
+
+
+%package help
+Summary: Development documents and examples for data-enum
+Provides: python3-data-enum-doc
+%description help
+# Data Enums
+
+![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue) [![Build Status](https://travis-ci.com/chasefinch/amp-renderer.svg?branch=main)](https://travis-ci.com/chasefinch/data-enum) ![Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)
+
+An alternative to the built-in Python `enum` implementation. Tested in Python 3.6 and above.
+
+Data enums allow you to:
+
+- Associate data with enum members without using tuple-based initialization
+- Use an intuitive initialization syntax to define members
+- Define pure enums without using `auto()`
+- Define value-based enums without storing them as class attributes
+- Define secondary unique keys & use them to look up enum members
+- Use classmethod syntax (`.get(…)`) to look up members, instead of using initializers
+
+## Usage
+
+Install via PyPI:
+
+ pip install data-enum
+
+Minimal usage:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Access the members by value:
+
+ Currency.get('USD')
+ Currency.get('CAD')
+ Currency.get('EUR')
+
+Store the members as attributes:
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency.USD = Currency('USD', symbol='$', name='United States dollar')
+ Currency.EUR = Currency('EUR', symbol='€', name='Euro')
+
+Use a custom attribute as the primary ID:
+
+ class Currency(DataEnum):
+ primary_attribute = 'code'
+ data_attributes = ('symbol', 'name')
+
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+ Currency('EUR', symbol='€', name='Euro')
+
+Use integers as primary IDs:
+
+ class Door(DataEnum):
+ data_attributes = ('description',)
+
+ Door(1, description='Door #1')
+ Door(2, description='Door #2')
+ Door(3, description='Door #3')
+
+ d2 = Door(2) # returns Door(2, description='Door #2')
+
+ int(d2) # returns 2
+
+Or, skip primary IDs altogether for a pure enumeration:
+
+ from data_enum import DataEnum
+
+ class Currency(DataEnum):
+ data_attributes = ('symbol', 'name')
+
+ Currency.CAD = Currency(symbol='$', name='Canadian dollar')
+ Currency.USD = Currency(symbol='$', name='United States dollar')
+ Currency.EUR = Currency(symbol='€', name='Euro')
+
+Access the attached data:
+
+ print(Currency.USD.name) # prints 'United States dollar'
+ print(Currency.EUR.symbol) # prints '€'
+
+ print(Currency.USD) # prints 'USD'
+
+Compare directly:
+
+ Currency.USD == Currency.CAD # returns False
+ Currency.EUR == Currency.EUR # returns True
+
+Enforce unique secondary attributes:
+
+ class Currency(DataEnum):
+ # Use a tuple with the second value as True for unique keys
+ data_attributes = (('symbol', True), 'name')
+
+ # Throws ValueError
+ Currency('CAD', symbol='$', name='Canadian dollar')
+ Currency('USD', symbol='$', name='United States dollar')
+
+Look up members by unique secondary attributes:
+
+ Currency.get(symbol='€') # returns Currency.EUR
+ Currency.get(symbol='&') # throws MemberDoesNotExistError
+
+Look up with members with defaults:
+
+ Currency.get('ZZZ', Currency.USD) # returns Currency.USD
+ Currency.get('ZZZ', default=Currency.USD) # returns Currency.USD
+ Currency.get(symbol='&', default=Currency.USD) # returns Currency.USD
+
+## Testing, etc.
+
+Install requrements:
+
+ make install
+
+Sort imports (Requires Python >= 3.6):
+
+ make format
+
+Lint (Requires Python >= 3.6):
+
+ make lint
+
+Test:
+
+ make test
+
+
+
+
+%prep
+%autosetup -n data-enum-2.0.1
+
+%build
+%py3_build
+
+%install
+%py3_install
+install -d -m755 %{buildroot}/%{_pkgdocdir}
+if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
+if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
+if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
+if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
+pushd %{buildroot}
+if [ -d usr/lib ]; then
+ find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/lib64 ]; then
+ find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/bin ]; then
+ find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+if [ -d usr/sbin ]; then
+ find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
+fi
+touch doclist.lst
+if [ -d usr/share/man ]; then
+ find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
+fi
+popd
+mv %{buildroot}/filelist.lst .
+mv %{buildroot}/doclist.lst .
+
+%files -n python3-data-enum -f filelist.lst
+%dir %{python3_sitelib}/*
+
+%files help -f doclist.lst
+%{_docdir}/*
+
+%changelog
+* Mon May 29 2023 Python_Bot <Python_Bot@openeuler.org> - 2.0.1-1
+- Package Spec generated
diff --git a/sources b/sources
new file mode 100644
index 0000000..e6fac8d
--- /dev/null
+++ b/sources
@@ -0,0 +1 @@
+fef982850841f8af7b7599977f0eb13b data-enum-2.0.1.tar.gz