Skip to content
Closed
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
122 changes: 50 additions & 72 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: check
name: "🛠️ check"
on:
workflow_dispatch:
push:
Expand All @@ -14,65 +14,59 @@ concurrency:

jobs:
test:
name: test ${{ matrix.py }} - ${{ matrix.os }}
name: "🧪 Test ${{ matrix.py }} - ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
py:
- "pypy3.10" # ahead to start it earlier because takes longer
- "3.14t"
- "3.14"
- "3.13"
- "3.12"
- "3.11"
- "3.10"
- "3.9"
- "pypy3.11"
os:
- ubuntu-latest
- windows-latest
- macos-latest
- ubuntu-24.04
- windows-2025
- macos-15
exclude:
- { os: windows-2025, py: pypy3.11 }

steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add .local/bin to Windows PATH
if: runner.os == 'Windows'
shell: bash
run: echo "$USERPROFILE/.local/bin" >> $GITHUB_PATH
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Install Python
- name: "🔄 Install the latest version of uv"
uses: astral-sh/setup-uv@v7
- name: "🧪 Install tox"
run: uv tool install --python-preference only-managed --python 3.14 tox --with tox-uv
- name: "🐍 Install Python"
run: uv python install --python-preference only-managed ${{ matrix.py }}
- name: Setup test suite
- name: "⚙️ Setup test suite"
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.py }}
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Run test suite
if: ${{ !startsWith(matrix.py, 'pypy')}}
run: tox run --skip-pkg-install -e ${{ matrix.py }}
env:
PYTEST_ADDOPTS: "-vv --durations=20"
DIFF_AGAINST: HEAD
UV_PYTHON_PREFERENCE: only-managed
- name: Run test suite without coverage
if: ${{ startsWith(matrix.py, 'pypy')}}
run: tox run --skip-pkg-install -e ${{ matrix.py }} --
- name: "✅ Run test suite"
run: |
if [[ "${{ matrix.py }}" == pypy* ]]; then
tox run --skip-pkg-install -e ${{ matrix.py }} --
else
tox run --skip-pkg-install -e ${{ matrix.py }}
fi
shell: bash
env:
PYTEST_ADDOPTS: "-vv --durations=20"
UV_PYTHON_PREFERENCE: only-managed
- name: Rename coverage report file
DIFF_AGAINST: HEAD
- name: "📝 Rename coverage report file"
if: ${{ !startsWith(matrix.py, 'pypy')}}
run: |
import os; import sys
os.rename(f".tox/.coverage.${{ matrix.py }}", f".tox/.coverage.${{ matrix.py }}-{sys.platform}")
shell: python
- name: Upload coverage data
- name: "📦 Upload coverage data"
if: ${{ !startsWith(matrix.py, 'pypy')}}
uses: actions/upload-artifact@v4
with:
Expand All @@ -82,84 +76,68 @@ jobs:
retention-days: 3

coverage:
name: Combine coverage
runs-on: ubuntu-latest
name: "📊 Combine coverage"
runs-on: ubuntu-24.04
needs: test
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add .local/bin to Windows PATH
if: runner.os == 'Windows'
shell: bash
run: echo "$USERPROFILE/.local/bin" >> $GITHUB_PATH
- name: Install hatch
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Build package to generate version
run: uv build --python 3.13 --python-preference only-managed --wheel . --out-dir dist
- name: Setup coverage tool
- name: "🔄 Install the latest version of uv"
uses: astral-sh/setup-uv@v7
- name: "🧪 Install tox"
run: uv tool install --python-preference only-managed --python 3.14 tox --with tox-uv
- name: "📦 Build package to generate version"
run: uv build --python 3.14 --python-preference only-managed --wheel . --out-dir dist
- name: "⚙️ Setup coverage tool"
run: tox -e coverage --notest
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Download coverage data
- name: "⬇️ Download coverage data"
uses: actions/download-artifact@v5
with:
path: .tox
pattern: .coverage.*
merge-multiple: true
- name: Combine and report coverage
- name: "📊 Combine and report coverage"
run: tox -e coverage --skip-pkg-install
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Upload HTML report
- name: "📤 Upload HTML report"
uses: actions/upload-artifact@v4
with:
name: html-report
path: .tox/htmlcov

check:
name: ${{ matrix.tox_env }} - ${{ matrix.os }}
name: "🔎 ${{ matrix.tox_env }} - ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- ubuntu-24.04
- windows-2025
tox_env:
- dev
- type
- docs
- readme
- pkg_meta
exclude:
- { os: windows-latest, tox_env: readme }
- { os: windows-2025, tox_env: pkg_meta }
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Add .local/bin to Windows PATH
if: runner.os == 'Windows'
shell: bash
run: echo "$USERPROFILE/.local/bin" >> $GITHUB_PATH
- name: Install tox
run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
- name: Setup test suite
- name: "🔄 Install the latest version of uv"
uses: astral-sh/setup-uv@v7
- name: "🧪 Install tox"
run: uv tool install --python-preference only-managed --python 3.14 tox --with tox-uv
- name: "⚙️ Setup test suite"
run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.tox_env }}
env:
UV_PYTHON_PREFERENCE: only-managed
- name: Run test suite
- name: "✅ Run test suite"
run: tox run --skip-pkg-install -e ${{ matrix.tox_env }}
env:
UV_PYTHON_PREFERENCE: only-managed
30 changes: 12 additions & 18 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release to PyPI
name: 🚀Release to PyPI
on:
push:
tags: ["*"]
Expand All @@ -8,20 +8,16 @@ env:

jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build package
run: uv build --python 3.13 --python-preference only-managed --sdist --wheel . --out-dir dist
- name: Store the distribution packages
- name: "🔄 Install the latest version of uv"
uses: astral-sh/setup-uv@v7
- name: "📦 Build package"
run: uv build --python 3.14 --python-preference only-managed --sdist --wheel . --out-dir dist
- name: "📤 Store the distribution packages"
uses: actions/upload-artifact@v4
with:
name: ${{ env.dists-artifact-name }}
Expand All @@ -30,19 +26,17 @@ jobs:
release:
needs:
- build
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
environment:
name: release
name: "Release to PyPI"
url: https://pypi.org/project/filelock/${{ github.ref_name }}
permissions:
id-token: write
steps:
- name: Download all the dists
- name: "⬇️ Download all the dists"
uses: actions/download-artifact@v5
with:
name: ${{ env.dists-artifact-name }}
path: dist/
- name: Publish to PyPI
uses: pypa/[email protected]
with:
attestations: true
- name: "🚀 Publish to PyPI"
uses: pypa/[email protected]
19 changes: 9 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.33.2
rev: 0.34.0
hooks:
- id: check-github-workflows
args: ["--verbose"]
Expand All @@ -14,28 +14,27 @@ repos:
hooks:
- id: codespell
additional_dependencies: ["tomli>=2.2.1"]
- repo: https://github.com/tox-dev/tox-ini-fmt
rev: "1.6.0"
- repo: https://github.com/tox-dev/tox-toml-fmt
rev: "v1.1.0"
hooks:
- id: tox-ini-fmt
args: ["-p", "fix"]
- id: tox-toml-fmt
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.6.0"
rev: "v2.8.0"
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.12.8"
rev: "v0.14.0"
hooks:
- id: ruff-format
- id: ruff
- id: ruff-check
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.6.2" # Use the sha / tag you want to point at
hooks:
- id: prettier
additional_dependencies:
- prettier@3.4.2
- "@prettier/[email protected].1"
- prettier@3.6.2
- "@prettier/[email protected].2"
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
17 changes: 6 additions & 11 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
version: 2
build:
os: ubuntu-22.04
os: ubuntu-lts-latest
tools:
python: "3"
python:
install:
- method: pip
path: .
extra_requirements:
- docs
sphinx:
builder: html
configuration: docs/conf.py
fail_on_warning: true
commands:
- pip install uv
- uv venv
- uv pip install tox-uv
- .venv/bin/tox run -e docs --
28 changes: 28 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ The lock objects are recursive locks, which means that once acquired, they will
cite2()
# And released here.

It should also be noted that the lock is released during garbage collection.
Put another way, if you do not assign an acquired lock to a variable,
the lock will eventually be released (implicitly, not explicitly).
For this reason, using the lock in the way shown below is not something you should ever do,
always use the context manager (`with` form) instead.

This issue is illustrated with code below:

.. code-block:: python

import tempfile
from pathlib import Path

import filelock

# If you create a lock and acquire it but don't assign it,
# you will not actually hold the lock forever.
# Instead, the lock is released
# when the created variable is garbage collected.
FileLock(lock_path).acquire()
# At some point after the creation above,
# the lock is released again even though there is no explicit call to `release`.

# If you instead assign to a dummy variable,
# the lock will be hold
_ = FileLock(lock_path).acquire()
# Now the lock is being held
# (at least until `_` is reassigned and the lock is garbage collected)

Timeouts and non-blocking locks
-------------------------------
Expand Down
Loading