Skip to content

Commit

Permalink
Merge pull request #18 from pomponchik/develop
Browse files Browse the repository at this point in the history
0.0.16
  • Loading branch information
pomponchik authored Sep 6, 2024
2 parents 1e4ee4d + 83d8739 commit f625f02
Show file tree
Hide file tree
Showing 12 changed files with 161 additions and 26 deletions.
32 changes: 32 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: pomponchik

---

## Short description

Replace this text with a short description of the error and the behavior that you expected to see instead.


## Describe the bug in detail

Please add this test in such a way that it reproduces the bug you found and does not pass:

```python
def test_your_bug():
...
```

Writing the test, please keep compatibility with the [`pytest`](https://docs.pytest.org/) framework.

If for some reason you cannot describe the error in the test format, describe here the steps to reproduce it.


## Environment
- OS: ...
- Python version (the output of the `python --version` command): ...
- Version of this package: ...
26 changes: 26 additions & 0 deletions .github/ISSUE_TEMPLATE/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
name: Documentation fix
about: Add something to the documentation, delete it, or change it
title: ''
labels: documentation
assignees: pomponchik
---

## It's cool that you're here!

Documentation is an important part of the project, we strive to make it high-quality and keep it up to date. Please adjust this template by outlining your proposal.


## Type of action

What do you want to do: remove something, add it, or change it?


## Where?

Specify which part of the documentation you want to make a change to? For example, the name of an existing documentation section or the line number in a file `README.md`.


## The essence

Please describe the essence of the proposed change
17 changes: 17 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: pomponchik

---

## Short description

What do you propose and why do you consider it important?


## Some details

If you can, provide code examples that will show how your proposal will work. Also, if you can, indicate which alternatives to this behavior you have considered. And finally, how do you propose to test the correctness of the implementation of your idea, if at all possible?
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Question or consultation
about: Ask anything about this project
title: ''
labels: guestion
assignees: pomponchik

---

## Your question

Here you can freely describe your question about the project. Please, before doing this, read the documentation provided, and ask the question only if the necessary answer is not there. In addition, please keep in mind that this is a free non-commercial project and user support is optional for its author. The response time is not guaranteed in any way.
9 changes: 6 additions & 3 deletions .github/workflows/tests_and_coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Tests
name: New tests

on:
push
Expand All @@ -10,7 +10,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
Expand All @@ -27,7 +27,7 @@ jobs:
run: pip install .

- name: Run tests and show coverage on the command line
run: coverage run --source=locklib --omit="*tests*" -m pytest --cache-clear && coverage report -m
run: coverage run --source=locklib --omit="*tests*" -m pytest --cache-clear && coverage report -m --fail-under=100

- name: Upload reports to codecov
env:
Expand All @@ -38,3 +38,6 @@ jobs:
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --branch --source=locklib --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100
48 changes: 48 additions & 0 deletions .github/workflows/tests_and_coverage_old.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Old tests

on:
push

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [macos-13, ubuntu-latest, windows-latest]
python-version: ['3.7']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install the library
shell: bash
run: pip install .

- name: Install dependencies
shell: bash
run: pip install -r requirements_dev.txt

- name: Print all libs
shell: bash
run: pip list

- name: Run tests and show coverage on the command line
run: coverage run --source=locklib --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100

- name: Upload reports to codecov
env:
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
if: runner.os == 'Linux'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
find . -iregex "codecov.*"
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
- name: Run tests and show the branch coverage on the command line
run: coverage run --branch --source=locklib --omit="*tests*" -m pytest --cache-clear --assert=plain && coverage report -m --fail-under=100
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ If you use type hints and static verification tools like [mypy](https://github.c
from threading import Thread
from locklib import SmartLock


lock = SmartLock()
counter = 0

Expand All @@ -136,7 +135,6 @@ Yeah, in this case the lock helps us not to get a race condition, as the standar
from threading import Thread
from locklib import SmartLock


lock_1 = SmartLock()
lock_2 = SmartLock()

Expand Down
4 changes: 2 additions & 2 deletions locklib/protocols/async_context_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class AsyncContextLockProtocol(LockProtocol, Protocol):
def __aenter__(self) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover

def __aexit__(self, exception_type: Optional[Type[BaseException]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover
4 changes: 2 additions & 2 deletions locklib/protocols/context_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class ContextLockProtocol(LockProtocol, Protocol):
def __enter__(self) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover

def __exit__(self, exception_type: Optional[Type[BaseException]], exception_value: Optional[BaseException], traceback: Optional[TracebackType]) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover
4 changes: 2 additions & 2 deletions locklib/protocols/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class LockProtocol(Protocol):
def acquire(self) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover

def release(self) -> Any:
raise NotImplementedError('Do not use the protocol as a lock.')
return None
return None # pragma: no cover
8 changes: 7 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'

[project]
name = 'locklib'
version = '0.0.15'
version = '0.0.16'
authors = [
{ name='Evgeniy Blinov', email='[email protected]' },
]
Expand All @@ -27,6 +27,12 @@ classifiers = [
'Intended Audience :: Developers',
'Typing :: Typed',
]
keywords = [
'locks',
'mutexes',
'threading',
'protocols'
]

[tool.setuptools.package-data]
"locklib" = ["py.typed"]
Expand Down
21 changes: 7 additions & 14 deletions tests/units/locks/smart_lock/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def function() -> None:
assert index == number_of_threads * number_of_attempts_per_thread


@pytest.mark.timeout(3)
@pytest.mark.timeout(5)
def test_raise_when_simple_deadlock():
number_of_attempts = 50

Expand All @@ -58,10 +58,9 @@ def function_1():
with lock_2:
if flag:
break
except DeadLockError as e:
except DeadLockError:
flag = True
queue.put(True)
raise e

def function_2():
nonlocal flag
Expand All @@ -71,11 +70,9 @@ def function_2():
with lock_1:
if flag:
break
except DeadLockError as e:
except DeadLockError:
flag = True
queue.put(True)
raise e


thread_1 = Thread(target=function_1)
thread_2 = Thread(target=function_2)
Expand All @@ -88,7 +85,7 @@ def function_2():
assert queue.get()


@pytest.mark.timeout(3)
@pytest.mark.timeout(5)
def test_raise_when_not_so_simple_deadlock():
number_of_attempts = 50

Expand All @@ -114,13 +111,12 @@ def function_1():
with lock_3:
if flag:
break
except DeadLockError as e:
except DeadLockError:
with lock:
cycles += 1
if cycles == 2:
flag = True
queue.put(True)
raise e

def function_2():
nonlocal flag
Expand All @@ -134,13 +130,12 @@ def function_2():
with lock_1:
if flag:
break
except DeadLockError as e:
except DeadLockError:
with lock:
cycles += 1
if cycles == 2:
flag = True
queue.put(True)
raise e

def function_3():
nonlocal flag
Expand All @@ -154,14 +149,12 @@ def function_3():
with lock_2:
if flag:
break
except DeadLockError as e:
except DeadLockError:
with lock:
cycles += 1
if cycles == 2:
flag = True
queue.put(True)
raise e


thread_1 = Thread(target=function_1)
thread_2 = Thread(target=function_2)
Expand Down

0 comments on commit f625f02

Please sign in to comment.