Skip to content

Commit

Permalink
fixed several linting/testing issues
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Sep 16, 2023
1 parent d84fca1 commit ea5e180
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
21 changes: 2 additions & 19 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ name: lint

on:
push:
branches: [ develop, master ]
pull_request:
branches: [ develop ]

env:
FORCE_COLOR: 1

jobs:
lint:
tox:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.8', '3.10', '3.11']

steps:
- uses: actions/checkout@v4
Expand All @@ -26,21 +24,6 @@ jobs:
cache: 'pip'
- name: Python version
run: python --version
- name: Install dependencies
run: |
python -m pip install tox
- name: Test with pytest
run: tox -p all

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
cache: 'pip'

- name: Install dependencies
run: |
Expand Down
6 changes: 4 additions & 2 deletions portalocker/portalocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
__overlapped = pywintypes.OVERLAPPED()

def lock(file_: typing.Union[typing.IO, int], flags: LockFlags):
# Windows locking does not support locking through `fh.fileno()` so
# we cast it to make mypy and pyright happy
file_ = typing.cast(typing.IO, file_)

mode = 0
if flags & LockFlags.NON_BLOCKING:
mode |= win32con.LOCKFILE_FAIL_IMMEDIATELY

if flags & LockFlags.EXCLUSIVE:
mode |= win32con.LOCKFILE_EXCLUSIVE_LOCK

# Windows locking does not support locking through `fh.fileno()`
assert isinstance(file_, typing.IO)
# Save the old position so we can go back to that position but
# still lock from the beginning of the file
savepos = file_.tell()
Expand Down
6 changes: 4 additions & 2 deletions portalocker_tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def test_exlusive(tmpfile):

# Make sure we can't write the locked file
with pytest.raises(portalocker.LockException), open(
tmpfile, 'w+',
tmpfile,
'w+',
) as fh2:
portalocker.lock(fh2, portalocker.LOCK_EX | portalocker.LOCK_NB)
fh2.write('surprise and fear')
Expand All @@ -196,7 +197,8 @@ def test_shared(tmpfile):

# Make sure we can't write the locked file
with pytest.raises(portalocker.LockException), open(
tmpfile, 'w+',
tmpfile,
'w+',
) as fh2:
portalocker.lock(fh2, portalocker.LOCK_EX | portalocker.LOCK_NB)
fh2.write('surprise and fear')
Expand Down
12 changes: 8 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ commands = python -m pytest {posargs}
[testenv:mypy]
basepython = python3
deps = mypy
commands = mypy {toxinidir}/portalocker
commands =
mypy --install-types --non-interactive
mypy

[testenv:pyright]
changedir =
basepython = python3
deps = pyright
commands = pyright {toxinidir}/portalocker
deps =
pyright
-e{toxinidir}[tests,redis]
commands = pyright {toxinidir}/portalocker {toxinidir}/portalocker_tests

[testenv:flake8]
basepython = python3
Expand Down Expand Up @@ -69,7 +73,7 @@ commands =
sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html {posargs}

[testenv:ruff]
commands = ruff check .
commands = ruff check {toxinidir}/portalocker {toxinidir}/portalocker_tests
deps = ruff
skip_install = true

Expand Down

0 comments on commit ea5e180

Please sign in to comment.