Skip to content

Commit

Permalink
Merge branch 'release/0.6.1.post1'
Browse files Browse the repository at this point in the history
  • Loading branch information
tanbro committed Apr 9, 2024
2 parents 36c6f06 + f499dd9 commit 8def582
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 23 deletions.
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
exclude: ^src/sqlalchemy_dlock(/asyncio)?/_sa_types(_backward)?\.py$
exclude: ^(src/sqlalchemy_dlock(/asyncio)?/_sa_types(_backward)?\.py)|(tests/.+)$

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-case-conflict
- id: check-added-large-files
Expand Down Expand Up @@ -31,6 +31,12 @@ repos:
- id: ruff-format
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
additional_dependencies: []

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: "0.28.1"
hooks:
Expand Down
2 changes: 1 addition & 1 deletion docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ README
:parser: myst_parser.sphinx_

How to build docs
=================
-----------------

#. This documentation is made with `Sphinx <https://www.sphinx-doc.org/>`_, be sure to install it's dependencies:

Expand Down
5 changes: 3 additions & 2 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ sqlalchemy-dlock

*
.. image:: https://github.com/tanbro/sqlalchemy-dlock/actions/workflows/python-package.yml/badge.svg
:alt: github workflow
:alt: Python package
:target: https://github.com/tanbro/sqlalchemy-dlock/actions/workflows/python-package.yml

.. image:: https://img.shields.io/pypi/v/sqlalchemy-dlock
:alt: PyPI
:target: https://pypi.org/project/sqlalchemy-dlock/

.. image:: https://readthedocs.org/projects/sqlalchemy-dlock/badge/?version=latest
:alt: Read the docs
:alt: Documentation Status
:target: https://sqlalchemy-dlock.readthedocs.io/en/latest/

.. image:: https://codecov.io/gh/tanbro/sqlalchemy-dlock/branch/main/graph/badge.svg
Expand All @@ -44,6 +44,7 @@ Contents
.. toctree::
:caption: Documentation
:titlesonly:
:maxdepth: 1

README
AUTHORS
Expand Down
2 changes: 2 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
exclude = ^src/sqlalchemy_dlock(/asyncio)?/_sa_types(_backward)?\.py$
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,5 @@ where = ["src"]
[tool.setuptools_scm]
write_to = "src/sqlalchemy_dlock/_version.py"

[tool.black]
line-length = 128
[tool.isort]
profile = "black"
[tool.setuptools.package-data]
sqlalchemy_dlock = ["sqlalchemy_dlock/py.typed"]
5 changes: 4 additions & 1 deletion src/sqlalchemy_dlock/asyncio/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


def create_async_sadlock(
connection_or_session: TAsyncConnectionOrSession, key, contextual_timeout: Union[float, int, None] = None, **kwargs
connection_or_session: TAsyncConnectionOrSession,
key,
contextual_timeout: Union[float, int, None] = None,
**kwargs,
) -> BaseAsyncSadLock:
if isinstance(connection_or_session, AsyncConnection):
sync_engine = connection_or_session.sync_engine
Expand Down
11 changes: 9 additions & 2 deletions src/sqlalchemy_dlock/asyncio/lock/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ async def __aexit__(self, exc_type, exc_value, exc_tb):

def __str__(self): # pragma: no cover
return "<{} {} key={} at 0x{:x}>".format(
"locked" if self._acquired else "unlocked", self.__class__.__name__, self._key, id(self)
"locked" if self._acquired else "unlocked",
self.__class__.__name__,
self._key,
id(self),
)

@property
Expand All @@ -49,7 +52,11 @@ def locked(self) -> bool:
return self._acquired

async def acquire(
self, block: bool = True, timeout: Union[float, int, None] = None, *args, **kwargs
self,
block: bool = True,
timeout: Union[float, int, None] = None,
*args,
**kwargs,
) -> bool: # pragma: no cover
raise NotImplementedError()

Expand Down
6 changes: 5 additions & 1 deletion src/sqlalchemy_dlock/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@


def create_sadlock(
connection_or_session: TConnectionOrSession, key, /, contextual_timeout: Union[float, int, None] = None, **kwargs
connection_or_session: TConnectionOrSession,
key,
/,
contextual_timeout: Union[float, int, None] = None,
**kwargs,
) -> BaseSadLock:
"""Create a database distributed lock object
Expand Down
13 changes: 11 additions & 2 deletions src/sqlalchemy_dlock/lock/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def __exit__(self, exc_type, exc_value, exc_tb):

def __str__(self): # pragma: no cover
return "<{} {} key={} at 0x{:x}>".format(
"locked" if self._acquired else "unlocked", self.__class__.__name__, self._key, id(self)
"locked" if self._acquired else "unlocked",
self.__class__.__name__,
self._key,
id(self),
)

@property
Expand All @@ -115,7 +118,13 @@ def locked(self) -> bool:
"""
return self._acquired

def acquire(self, block: bool = True, timeout: Union[float, int, None] = None, *args, **kwargs) -> bool: # pragma: no cover
def acquire(
self,
block: bool = True,
timeout: Union[float, int, None] = None,
*args,
**kwargs,
) -> bool: # pragma: no cover
"""Acquire a lock, blocking or non-blocking.
* With the ``block`` argument set to :data:`True` (the default), the method call will block until the lock is in an unlocked state, then set it to locked and return :data:`True`.
Expand Down
11 changes: 8 additions & 3 deletions src/sqlalchemy_dlock/lock/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ class PostgresqlSadLockMixin:
"""A Mix-in class for PostgreSQL advisory lock"""

def __init__(
self, *, key, shared: bool = False, xact: bool = False, convert: Optional[Callable[[Any], int]] = None, **kwargs
self,
*,
key,
shared: bool = False,
xact: bool = False,
convert: Optional[Callable[[Any], int]] = None,
**kwargs,
):
"""
Args:
Expand Down Expand Up @@ -68,6 +74,7 @@ def convert(val: Any) -> int:
self._shared = bool(shared)
self._xact = bool(xact)
#
self._stmt_unlock = None
if not shared and not xact:
self._stmt_lock = LOCK.params(key=key)
self._stmt_try_lock = TRY_LOCK.params(key=key)
Expand All @@ -79,11 +86,9 @@ def convert(val: Any) -> int:
elif not shared and xact:
self._stmt_lock = LOCK_XACT.params(key=key)
self._stmt_try_lock = TRY_LOCK_XACT.params(key=key)
self._stmt_unlock = None
else:
self._stmt_lock = LOCK_XACT_SHARED.params(key=key)
self._stmt_try_lock = TRY_LOCK_XACT_SHARED.params(key=key)
self._stmt_unlock = None

@property
def shared(self):
Expand Down
Empty file added src/sqlalchemy_dlock/py.typed
Empty file.
9 changes: 4 additions & 5 deletions src/sqlalchemy_dlock/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ def camel_case(s: str) -> str:
Returns:
Camel case string.
"""
s = re.sub(r"\w[\s\W]+\w", "", str(s))
s = re.sub(r"\w[\s\W]+\w", "", s)
if not s:
return s
return lower_case(s[0]) + re.sub(r"[\-_\.\s]([a-z])", lambda matched: upper_case(matched.group(1)), s[1:])
return lower_case(s[0]) + re.sub(r"[\-_\.\s]([a-z])", lambda x: upper_case(str(x.group(1))), s[1:])


def lower_case(s: str) -> str:
Expand All @@ -62,7 +62,7 @@ def lower_case(s: str) -> str:
Returns:
Lowercase case string.
"""
return str(s).lower()
return s.lower()


def upper_case(s: str) -> str:
Expand All @@ -74,7 +74,7 @@ def upper_case(s: str) -> str:
Returns:
Uppercase case string.
"""
return str(s).upper()
return s.upper()


def capital_case(s: str) -> str:
Expand All @@ -87,7 +87,6 @@ def capital_case(s: str) -> str:
Returns:
Capital case string.
"""
s = str(s)
if not s:
return s
return upper_case(s[0]) + s[1:]
Expand Down

0 comments on commit 8def582

Please sign in to comment.