Skip to content

Commit

Permalink
Release 0.1.3 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
pyprogrammerblog committed Sep 11, 2022
1 parent d607b7d commit fe77e89
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 73 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
===================================

0.1.3 (2022-09-11)
-------------------

- Improvement in output string.
- Documentation.

0.1.2 (2022-09-11)
-------------------

Expand Down
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Installation
Install it using ``pip``

```shell
pip install progress-progress_updater
pip install progress-updater
```

Basic usage
Expand All @@ -23,10 +23,9 @@ Basic usage
```python
from progress_updater import ProgressUpdater

# create an progress_updater object
updater = ProgressUpdater(task_name="My Task")

with updater(block_name="First part") as updater:
with updater(block_name="First part"):
# doing things
updater.notify("doing first block...")
# doing more things
Expand All @@ -36,16 +35,40 @@ with updater(block_name="Second part"):
updater.notify("doing second block...")
# doing more things

updater.raise_latest_exception()
updater.raise_latest_exception() # if exists
```

The output is:
```shell
- Task: My task

- Entering First part
doing first block...
Time spent: 0h0m
Successfully completed

- Entering Second part
doing second block...
Time spent: 0h0m
Successfully completed
```

Backends
----------
There are three backends available to save our logs.
If you want to save the output in a Database you will need to define
a backend. There are three backends available to save our logs.

1. Mongo. See [documentation]().
2. Redis. See [documentation]().
3. SQL. See [documentation]().
1. Mongo.
2. Redis.
3. SQL.

```python
from progress_updater.backends import MongoLog
from uuid import UUID

log = MongoLog.get(uuid=UUID("<your task uuid>"))
assert log.status == "SUCCESS"
```


Settings
Expand All @@ -67,10 +90,11 @@ settings = MongoSettings(
)

with ProgressUpdater(task_name="My Task", settings=settings) as updater:
...
pass
```

2. Environment variables.
2. Environment variables.

The `PU__` prefix indicates that it belongs to `ProgressUpdater`.
```shell
export PU__SQL_DSN=postgresql+psycopg2://user:pass@postgres:5432/db
Expand Down
10 changes: 5 additions & 5 deletions docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ Backends
:mod:`Settings`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.backends
.. automodule:: progress_updater.backends
:members: Settings
:exclude-members: Config, backend


:mod:`Mongo`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.backends.mongo
.. automodule:: progress_updater.backends.mongo
:members: MongoLog, MongoSettings
:exclude-members: mongo_collection, backend


:mod:`Redis`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.backends.redis
.. automodule:: progress_updater.backends.redis
:members: RedisLog, RedisSettings
:exclude-members: redis_connection, backend


:mod:`SQL`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.backends.sql
.. automodule:: progress_updater.backends.sql
:members: SQLLog, SQLSettings
:exclude-members: sql_session, backend


:mod:`Base Log`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.backends.log
.. automodule:: progress_updater.backends.log
:members: Log, Logs
:exclude-members:
60 changes: 45 additions & 15 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ Welcome to progress-updater' documentation!
=============================================


Writing the progress of a task to a backend!

Installation
-------------

Install it using `pip`::

pip install progress-updater

Basic usage
-------------

Make sure you had install the package by doing ``pip install progress-updater`` and then::
Make sure you have the `progress-updater` installed::

from updater import ProgressUpdater
from progress_updater import ProgressUpdater

# create an updater object
updater = ProgressUpdater(task_name="My Task")
updater = ProgressUpdater(task_name="My Task", write_on_backend=False, verbose=True)

with updater(block_name="First part") as updater:
with updater(block_name="First part"):
# doing things
updater.notify("doing first block...")
# doing more things
Expand All @@ -28,43 +36,65 @@ Make sure you had install the package by doing ``pip install progress-updater``
updater.notify("doing second block...")
# doing more things

updater.raise_latest_exception()
updater.raise_latest_exception() # if exists

The output is::

- Task: My task

- Entering First part
doing first block...
Time spent: 0h0m
Successfully completed

- Entering Second part
doing second block...
Time spent: 0h0m
Successfully completed

Backends
----------
There are three backends available to save our logs.
If you want to save the output in a Database you will need to define
a backend. There are three backends available to save our logs.

1. Mongo.
2. Redis.
3. SQL.

In you console::

from progress_updater.backends import MongoLog
from uuid import UUID

log = MongoLog.get(uuid=UUID("<your task uuid>"))
assert log.status == "SUCCESS"


Settings
----------

There are some possible ways to pass settings to the updater.
This is the priority.

1. Passing settings as parameters when creating a `ProgressUpdater` object.
Example ::
1. Passing settings as parameters when creating a `ProgressUpdater` object::

from updater import ProgressUpdater
from updater.backends.mongo import MongoSettings
from progress_updater import ProgressUpdater
from progress_updater.backends.mongo import MongoSettings

settings = MongoSettings(
mongo_connection="mongodb://user:pass@mongo:27017",
mongo_db="db",
mongo_collection="logs",
)

with ProgressUpdater(task_name="My Task", settings=settings) as updater:
pass

2. Environment variables. The `PU__` prefix indicates that it belongs to `ProgressUpdater`.
Example::
2. Environment variables::
The `PU__` prefix indicates that it belongs to `ProgressUpdater`::

export PU__SQL_DSN='postgresql+psycopg2://user:pass@postgres:5432/db'
export PU__SQL_TABLE='logs'
export PU__SQL_DSN=postgresql+psycopg2://user:pass@postgres:5432/db
export PU__SQL_TABLE=logs


.. toctree::
Expand Down
4 changes: 2 additions & 2 deletions docs/updater.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Progress Updater
:mod:`Progress Updater`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.updater
.. automodule:: progress_updater.updater
:members: ProgressUpdater
:exclude-members:


:mod:`Decorator`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. automodule:: updater.utils
.. automodule:: progress_updater.utils
:members: progress_updater
:exclude-members:
4 changes: 2 additions & 2 deletions progress_updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ def __init__(
self.notify(f"- Task: {self.task_name}")

def __enter__(self, block_name: str = None) -> "ProgressUpdater":
self.block_name = block_name or "..."
self.block_name = self.__dict__.get("block_name") or "..."
self.start_t = datetime.datetime.utcnow()
self.notify(f"- Entering {self.block_name}")
self.notify(f"\n- Entering {self.block_name}")
return self

def __exit__(self, exc_type, exc_val, exc_tb) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "progress_updater"
version = "0.1.2"
version = "0.1.3"
description = "Progress Updater"
readme = "README.md"
license = "LICENSE"
Expand Down
Loading

0 comments on commit fe77e89

Please sign in to comment.