Skip to content
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
3 changes: 3 additions & 0 deletions docs/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nav:
- ...
- package: package
14 changes: 9 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
![versions](https://img.shields.io/pypi/pyversions/pycommons-base.svg)
![PyPI - License](https://img.shields.io/pypi/l/pycommons-base)
![PyPI - Downloads](https://img.shields.io/pypi/dw/pycommons-base)
[![codecov](https://codecov.io/gh/pycommons/pycommons-base/branch/main/graph/badge.svg?token=uXZGA4h4sH)](https://codecov.io/gh/pycommons/pycommons-base)

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Python Commons Base package that serves as the base package for all the other

Visit the [documentation](https://pycommons.github.io/pycommons-base) to view
the usage of each and every class and feature provided by this library.
Python Commons Base package that serves as the base package for all the other pycommons libraries like
[pycommons-lang](https://github.com/pycommons/pycommons-lang)
and [pycommons-collections](https://github.com/pycommons/pycommons-collections).

## Get Started

Expand All @@ -28,9 +28,13 @@ project
poetry add pycommons-base
```

!!! Note
To install alpha, beta and release candidate versions of the package use the package
published to [https://test.pypi.org](https://test.pypi.org/project/pycommons-base/)

## License

Apache-2.0 (See [License](LICENSE))
Apache-2.0 (See [License](https://github.com/pycommons/pycommons-base/blob/main/LICENSE))

## Author

Expand Down
4 changes: 4 additions & 0 deletions docs/package/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nav:
- ...

title: Package Documentation
2 changes: 2 additions & 0 deletions docs/package/atomic/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nav:
- pycommons.base.atomic: atomic.md
1 change: 1 addition & 0 deletions docs/package/atomic/atomic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pycommons.base.atomic
2 changes: 2 additions & 0 deletions docs/package/container/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nav:
- pycommons.base.container: container.md
1 change: 1 addition & 0 deletions docs/package/container/container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pycommons.base.container
2 changes: 2 additions & 0 deletions docs/package/function/.pages
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nav:
- pycommons.base.function: function.md
1 change: 1 addition & 0 deletions docs/package/function/function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: pycommons.base.function
32 changes: 29 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
# Project Information
site_name: PyCommons Lang
site_name: pycommons-base
site_author: Shashank Sharma
site_description: Python Commons Lang
site_description: Python Commons Base
remote_branch: gh-pages
remote_name: origin
site_url: https://pycommons.github.io/pycommons-base
Expand Down Expand Up @@ -38,6 +38,9 @@ markdown_extensions:
- pymdownx.mark
- pymdownx.smartsymbols
- pymdownx.superfences
- pymdownx.highlight
- pymdownx.snippets
- pymdownx.superfences
- pymdownx.emoji:
emoji_generator: !!python/name:pymdownx.emoji.to_png
- pymdownx.tasklist:
Expand All @@ -59,7 +62,21 @@ theme:
language: en
base_url: https://github.com/pycommons/pycommons-base
palette:
primary: 'white'
# Palette toggle for light mode
- scheme: default
primary: blue grey
accent: red
toggle:
icon: material/brightness-7
name: Switch to dark mode

# Palette toggle for dark mode
- scheme: slate
primary: blue grey
accent: red
toggle:
icon: material/brightness-4
name: Switch to light mode
# Footer
extra:
config_override: false
Expand All @@ -71,6 +88,15 @@ extra:
- icon: fontawesome/brands/github
link: https://github.com/shashankrnr32
name: shashankrnr32 on GitHub
- icon: fontawesome/brands/twitter
link: https://twitter.com/shashankrnr32
name: shashankrnr32 on Twitter
- icon: fontawesome/brands/linkedin
link: https://linkedin.com/in/shashankrnr32
name: shashankrnr32 on LinkedIn
- icon: fontawesome/brands/mastodon
link: https://fosstodon.org/@shashankrnr32
name: shashankrnr32 on fosstodon

plugins:
- search
Expand Down
84 changes: 26 additions & 58 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion pycommons/base/atomic/atomic.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
from typing import TypeVar, Generic, Optional

from pycommons.base.synchronized import RLockSynchronized, synchronized
from pycommons.base.container import Container
from pycommons.base.synchronized import RLockSynchronized, synchronized

_T = TypeVar("_T")


class Atomic(Container[_T], RLockSynchronized, Generic[_T]):
"""
Atomic mutable container, that holds a value in the object
and only allows synchronized read and write.
This implementation is thread-safe and can be used across multiple threads.
If the container is used only on a single thread, consider
using the [Container][pycommons.base.container], and it's derived classes.

The object is held on a re-entrant lock during reads and writes
and is unlocked after the operation is complete.

References:
https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html
"""

def __init__(self, t: Optional[_T] = None):
super().__init__(t)
RLockSynchronized.__init__(self)
Expand Down
11 changes: 10 additions & 1 deletion pycommons/base/atomic/boolean.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from __future__ import annotations

from pycommons.base.atomic.atomic import Atomic
from pycommons.base.synchronized import synchronized
from pycommons.base.container.boolean import BooleanContainer
from pycommons.base.synchronized import synchronized


class AtomicBoolean(BooleanContainer, Atomic[bool]): # pylint: disable=R0901
"""
Atomic Boolean Container that allows atomic update of the container value.
The object is synchronized for read and write operations so that only one read/write
happens at a time. This is ensured using re-entrant locks. Provides
all the functionalities provided by the
[BooleanContainer][pycommons.base.container.BooleanContainer]

"""

@synchronized
def true(self) -> bool:
return super().true()
Expand Down
Loading