Skip to content

V1.8.0 #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 26, 2024
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
53 changes: 53 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: lint

on:
push:
pull_request:
workflow_dispatch:
inputs:
debug:
description: 'Set to on, to open ssh debug session.'
required: true
default: 'off'

jobs:

linting:
runs-on: ubuntu-latest
strategy:
matrix:
# run static analysis on bleeding and trailing edges
python-version: [ '3.8', '3.10', '3.12', '3.13.0-rc.1' ]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
- name: Install Dependencies
run: |
poetry config virtualenvs.in-project true
poetry run pip install --upgrade pip
poetry install
- name: Install Emacs
if: ${{ github.event.inputs.debug == 'on' }}
run: |
sudo apt install emacs
- name: Setup tmate session
if: ${{ github.event.inputs.debug == 'on' }}
uses: mxschmitt/action-tmate@v3
with:
detached: true
timeout-minutes: 60
- name: Run Static Analysis
run: |
source .venv/bin/activate
./check.sh --no-fix
python -m readme_renderer ./README.md -o /tmp/README.html
echo "$(poetry env info --path)/bin" >> $GITHUB_PATH
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13.0-rc.1']

steps:
- uses: actions/checkout@v3
Expand All @@ -30,14 +30,6 @@ jobs:
run: |
poetry run pytest
mv .coverage py${{ matrix.python-version }}.coverage
- name: Run Static Analysis
run: |
poetry run black enum_properties --check
poetry run pylint enum_properties
poetry run doc8 -q doc
poetry check
poetry run pip check
poetry run python -m readme_renderer ./README.rst -o /tmp/README.html

- name: Store coverage files
uses: actions/upload-artifact@v4
Expand Down
85 changes: 32 additions & 53 deletions README.rst → README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,18 @@
|MIT license| |PyPI version fury.io| |PyPI pyversions| |PyPI status| |Documentation Status|
|Code Cov| |Test Status| |Code Style|
# Enum Properties

.. |MIT license| image:: https://img.shields.io/badge/License-MIT-blue.svg
:target: https://lbesson.mit-license.org/
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![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)
[![PyPI version](https://badge.fury.io/py/enum-properties.svg)](https://pypi.python.org/pypi/enum-properties/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/enum-properties.svg)](https://pypi.python.org/pypi/enum-properties/)
[![PyPI status](https://img.shields.io/pypi/status/enum-properties.svg)](https://pypi.python.org/pypi/enum-properties)
[![Documentation Status](https://readthedocs.org/projects/enum-properties/badge/?version=latest)](http://enum-properties.readthedocs.io/?badge=latest/)
[![Code Cov](https://codecov.io/gh/bckohan/enum-properties/branch/main/graph/badge.svg?token=0IZOKN2DYL)](https://codecov.io/gh/bckohan/enum-properties)
[![Test Status](https://github.com/bckohan/enum-properties/workflows/test/badge.svg)](https://github.com/bckohan/enum-properties/actions/workflows/test.yml)
[![Lint Status](https://github.com/bckohan/enum-properties/workflows/lint/badge.svg)](https://github.com/bckohan/enum-properties/actions/workflows/lint.yml)

.. |PyPI version fury.io| image:: https://badge.fury.io/py/enum-properties.svg
:target: https://pypi.python.org/pypi/enum-properties/
Add properties to Python enumeration values with a simple declarative syntax. [Enum Properties](https://enum-properties.readthedocs.io/en/latest) is a lightweight extension to [Python's Enum class](https://docs.python.org/3/library/enum.html). Example:

.. |PyPI pyversions| image:: https://img.shields.io/pypi/pyversions/enum-properties.svg
:target: https://pypi.python.org/pypi/enum-properties/

.. |PyPI status| image:: https://img.shields.io/pypi/status/enum-properties.svg
:target: https://pypi.python.org/pypi/enum-properties

.. |Documentation Status| image:: https://readthedocs.org/projects/enum-properties/badge/?version=latest
:target: http://enum-properties.readthedocs.io/?badge=latest/

.. |Code Cov| image:: https://codecov.io/gh/bckohan/enum-properties/branch/main/graph/badge.svg?token=0IZOKN2DYL
:target: https://codecov.io/gh/bckohan/enum-properties

.. |Test Status| image:: https://github.com/bckohan/enum-properties/workflows/test/badge.svg
:target: https://github.com/bckohan/enum-properties/actions

.. |Code Style| image:: https://img.shields.io/badge/code%20style-black-000000.svg
:target: https://github.com/psf/black


Enum Properties
#######################

Add properties to Python enumeration values with a simple declarative syntax.
`Enum Properties <https://enum-properties.readthedocs.io/en/latest/>`_ is a
lightweight extension to
`Python's Enum class <https://docs.python.org/3/library/enum.html>`_. Example:

.. code:: python
```python

from enum_properties import EnumProperties, p
from enum import auto
Expand All @@ -57,16 +35,22 @@ lightweight extension to
Color.GREEN.hex == '00ff00'
Color.BLUE.hex == '0000ff'

Properties may also be symmetrically mapped to enumeration values, using
s() values:
```

Properties may also be symmetrically mapped to enumeration values using s() values and type hints
are optional for better dev experience:

.. code:: python
```python

import typing as t
from enum_properties import EnumProperties, s
from enum import auto

class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):

rgb: t.Tuple[int, int, int]
hex: str

RED = auto(), (1, 0, 0), 'ff0000'
GREEN = auto(), (0, 1, 0), '00ff00'
BLUE = auto(), (0, 0, 1), '0000ff'
Expand All @@ -88,11 +72,11 @@ s() values:

Color.RED.hex == 'ff0000'

```

Member functions may also be specialized to each enumeration value, using the
@specialize decorator.
Member functions may also be specialized to each enumeration value, using the ``@specialize`` decorator.

.. code:: python
```python

from enum_properties import EnumProperties, specialize

Expand All @@ -118,23 +102,18 @@ Member functions may also be specialized to each enumeration value, using the
SpecializedEnum.TWO.method() == 'method_two()'
SpecializedEnum.THREE.method() == 'method_three()'

Please report bugs and discuss features on the
`issues page <https://github.com/bckohan/enum-properties/issues>`_.
```

`Contributions <https://github.com/bckohan/enum-properties/blob/main/CONTRIBUTING.rst>`_ are
encouraged!
Please report bugs and discuss features on the [issues page](https://github.com/bckohan/enum-properties/issues).

`Full documentation at read the docs. <https://enum-properties.readthedocs.io/en/latest/>`_
[Contributions](https://github.com/bckohan/enum-properties/blob/main/CONTRIBUTING.rst) are encouraged!

Installation
------------
[Full documentation at read the docs.](https://enum-properties.readthedocs.io/en/latest)

1. Clone enum-properties from GitHub_ or install a release off PyPI_ :
## Installation

.. code:: bash
1. Clone enum-properties from GitHub_ or install a release off PyPI_ :

```bash
pip install enum-properties


.. _GitHub: http://github.com/bckohan/enum-properties
.. _PyPI: http://pypi.python.org/pypi/enum-properties
```
31 changes: 31 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
set -e # Exit immediately if a command exits with a non-zero status.

if [ "$1" == "--no-fix" ]; then
poetry run ruff format --check
poetry run ruff check --select I
poetry run ruff check
else
poetry run ruff format
poetry run ruff check --fix --select I
poetry run ruff check --fix
fi

poetry run mypy enum_properties
poetry run pyright
poetry check
poetry run pip check
cd ./doc
poetry run doc8 --ignore-path build --max-line-length 100 -q
# check for broken links in the docs ############
set +e

# do not run this in CI - too spurious
if [ "$1" != "--no-fix" ]; then
poetry run sphinx-build -b linkcheck -q ./source ./build > /dev/null 2>&1
if [ $? -ne 0 ]; then
cat ./build/output.txt | grep broken
exit 1
fi
fi
#################################################
cd ..
8 changes: 8 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Change Log
==========

v1.8.0
======

* Implemented `Drop support for Python 3.7 <https://github.com/bckohan/enum-properties/issues/59>`_
* Implemented `Support Python 3.13 <https://github.com/bckohan/enum-properties/issues/58>`_
* Implemented `Move to ruff for linting and formatting. <https://github.com/bckohan/enum-properties/issues/57>`_
* Documented `Support type hinting for properties <https://github.com/bckohan/enum-properties/issues/42>`_

v1.7.0
======
* Implemented `Add a StrEnumProperties type to match StrEnum. <https://github.com/bckohan/enum-properties/issues/54>`_
Expand Down
8 changes: 6 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx_rtd_theme',
'sphinx.ext.autodoc',
'sphinxarg.ext',
'sphinx.ext.todo'
Expand All @@ -59,7 +58,12 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
html_theme = 'furo'
html_theme_options = {
"source_repository": "https://github.com/bckohan/enum-properties/",
"source_branch": "main",
"source_directory": "doc/source",
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
Expand Down
6 changes: 5 additions & 1 deletion doc/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ implement our style enumeration like so:
"""
_symmetric_builtins_ = ['name', 'uri']

# type hints are optional for better dev experience
label: str
version: int

# name value label version
STREETS = 'streets', 'Streets', 11
OUTDOORS = 'outdoors', 'Outdoors', 11
Expand All @@ -94,7 +98,7 @@ implement our style enumeration like so:
NAVIGATION_NIGHT = 'navigation-night', 'Navigation Night', 1

@property
def uri(self):
def uri(self) -> str:
return f'mapbox://styles/mapbox/{self.value}-v{self.version}'

def __str__(self):
Expand Down
8 changes: 6 additions & 2 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ Enum Properties is a lightweight extension to Python's Enum_ class. Example:
Color.GREEN.hex == '00ff00'
Color.BLUE.hex == '0000ff'

Properties may also be symmetrically mapped to enumeration values, using
s() values:
Properties may also be symmetrically mapped to enumeration values using
s() values and type hints are optional for better dev experience:

.. code:: python

import typing as t
from enum_properties import EnumProperties, s
from enum import auto

class Color(EnumProperties, s('rgb'), s('hex', case_fold=True)):

rgb: t.Tuple[int, int, int]
hex: str

RED = auto(), (1, 0, 0), 'ff0000'
GREEN = auto(), (0, 1, 0), '00ff00'
BLUE = auto(), (0, 0, 1), '0000ff'
Expand Down
Loading
Loading