semvec/pypi-packages huggingface dataset:
poltergeist 0.10.0
Rust-like error handling in Python, with type-safety in mind.
License: MIT
Requires Python: <4.0,>=3.10

# poltergeist

[![pypi](https://img.shields.io/pypi/v/poltergeist.svg)](https://pypi.python.org/pypi/poltergeist)
[![versions](https://img.shields.io/pypi/pyversions/poltergeist.svg)](https://github.com/alexandermalyga/poltergeist)

[Rust-like error handling](https://doc.rust-lang.org/book/ch09-00-error-handling.html) in Python, with type-safety in mind.

## Installation

```
pip install poltergeist
```

## Examples

Use the `@catch` decorator on any function:

```python
from poltergeist import catch

# Handle an exception type potentially raised within the function
@catch(OSError)
def read_text(path: str) -> str:
    with open(path) as f:
        return f.read()

# Returns an object of type Result[str, OSError]
result = read_text("my_file.txt")
```

Or wrap errors manually:

```python
from poltergeist import Result, Ok, Err

# Equivalent to the decorated function above
def read_text(path: str) -> Result[str, OSError]:
    try:
        with open(path) as f:
            return Ok(f.read())
    except OSError as e:
        return Err(e)
```

Then handle the result in a type-safe way:

```python
# Get the Ok value or re-raise the Err exception
content: str = result.unwrap()

# Get the Ok value or a default if it's an Err
content: str = result.unwrap_or("lorem ipsum")
content: str | None = result.unwrap_or()

# Get the Ok value or compute it from the exception
content: str = result.unwrap_or_else(lambda e: f"The exception was: {e}")

# Get the Err exception or None if it's an Ok
err: OSError | None = result.err()

# Handle the result using structural pattern matching
match result:
    case Ok(content):
        print("Text in upper:", content.upper())
    case Err(FileNotFoundError() as e):
        print("File not found:", e.filename)
```

It's also possible to wrap multiple exception types with the decorator:

```python
@catch(OSError, UnicodeDecodeError)
def read_text(path: str) -> str:
    with open(path) as f:
        return f.read()
```

Or manually:

```python
def read_text(path: str) -> Result[str, OSError | UnicodeDecodeError]:
    try:
        with open(path) as f:
            return Ok(f.read())
    except (OSError, UnicodeDecodeError) as e:
        return Err(e)
```

There is also an async-compatible decorator:

```python
from poltergeist import catch_async

@catch_async(OSError)
async def read_text(path: str) -> str:
    with open(path) as f:
        return f.read()

# Returns an object of type Result[str, OSError]
result = await read_text("my_file.txt")
```

## Contributing

Set up the project using [Poetry](https://python-poetry.org/):

```
poetry install
```

Format the code:

```
make lint
```

Run tests:

```
make test
```

Check for typing and format issues:

```
make check
```
python-signal-edges 1.0.5
Extract state levels and edges from signals, among others
License: MIT
Requires Python: <4.0,>=3.10
Keywords: python, signal, edges, automation, hardware, pwm, acquisition

Signal Edges
------------------------------------------------------------------------------------------------------------------------

**Signal Edges** is a Python package capable of filtering, extracting state levels and edges of signals with millions
of samples, among other things. It is specially suited for analysis of analog signals obtained through recorders, such
as oscilloscopes or data recorders, and hardware automation in CI/CD environments, although it is flexible enough to
be used for many other different purposes.

.. figure:: https://github.com/dmg0345/python-signal-edges/blob/master/doc/.assets/img/007_example_complex_plot_1.png
    :align: center

Find **Signal Edges** on `PyPi <https://pypi.org/project/python-signal-edges/>`_, or install it as follows:

.. code-block::

    pip install python-signal-edges

Refer to the documentation `here <https://dmg0345-python-signal-edges.netlify.app/>`_ for more details.

Development
------------------------------------------------------------------------------------------------------------------------

Clone the repository as:

.. code-block:: powershell

    git clone https://github.com/dmg0345/python-signal-edges

Ensure the *Github* file with the relevant environment variables exist as expected in the *compose.yaml* file and the
correct paths are set in the *manage.ps1* file for your environment. Afterwards, find the base Docker image for the
development container at `DockerHub <https://hub.docker.com/r/dmg00345/python_signal_edges>`_.

To develop using `devcontainers` and `Visual Studio Code`:

.. code-block:: powershell

    docker pull dmg00345/python_signal_edges:latest
    ./manage.ps1 run

Create a release
------------------------------------------------------------------------------------------------------------------------

To generate a release follow the steps below:

1. Create a ``release`` branch from ``develop`` branch, e.g. ``release/X.Y.Z``.
2. Update version in *conf.py* file and in *pyproject.toml* file.
3. Create pull request from ``release`` branch to ``master`` with the changes with title *Release X.Y.Z*.
4. When merged in ``master`` create release and tag from *Github*, review production workflow passes for deployment.
5. Delete the ``release/X.Y.Z`` branch.