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
41 changes: 27 additions & 14 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
name: Continuous Integration

# yamllint disable-line rule:truthy
on:
pull_request:
branches: [main]
Expand All @@ -14,12 +16,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Set up Python 3.11
uses: actions/setup-python@v6
with:
python-version: '3.12'
python-version: '3.11'

- name: Run pre-commit hooks
uses: pre-commit/action@v3.0.1
Expand All @@ -29,33 +31,44 @@ jobs:
needs: lint
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install test dependencies
run: pip install pytest
run: pip install -e ".[dev]"

- name: Run tests
run: python -m pytest
- name: Run tests with coverage
run: >-
python -m pytest tests/
--cov=timerun
--cov-branch
--cov-report=xml
--cov-report=term

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: python${{ matrix.python-version }}

build:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Set up Python 3.11
uses: actions/setup-python@v6
with:
python-version: '3.12'
python-version: '3.11'

- name: Install build dependencies
run: pip install build twine
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
uses: actions/checkout@v6

- name: Set up Python 3.12
uses: actions/setup-python@v5
- name: Set up Python 3.11
uses: actions/setup-python@v6
with:
python-version: '3.12'
python-version: '3.11'

- name: Install build dependencies
run: pip install build
Expand Down
39 changes: 14 additions & 25 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,24 @@ repos:
- id: check-yaml
- id: check-toml

- repo: https://github.com/adrienverge/yamllint
rev: v1.37.1
hooks:
- id: yamllint

- repo: https://github.com/pycqa/isort
rev: 6.0.1
hooks:
- id: isort

- repo: https://github.com/psf/black
rev: 25.1.0
hooks:
- id: black

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.17.1
- repo: https://github.com/HH-MWB/pyenforce
rev: v0.1.0
hooks:
- id: ruff-format
- id: ruff-check
- id: mypy

- repo: https://github.com/pylint-dev/pylint
rev: v3.3.8
hooks:
additional_dependencies:
- ".[mypy]" # Required to re-adds mypy as a dependency
- pytest
- id: pylint
additional_dependencies:
- ".[pylint]" # Required to re-adds Pylint as a dependency
- pytest
- id: bandit
- id: semgrep
- id: vulture

- repo: https://github.com/pycqa/bandit
rev: '1.8.6'
- repo: https://github.com/adrienverge/yamllint
rev: v1.37.1
hooks:
- id: bandit
args: ['-c', 'pyproject.toml']
- id: yamllint
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019-2025 HH-MWB
Copyright (c) 2019-2026 HH-MWB

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
75 changes: 65 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<p align="center"><strong>TimeRun</strong> - <em>Python library for elapsed time measurement.</em></p>

<p align="center">
<a href="https://github.com/HH-MWB/timerun/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/pypi/l/timerun.svg"></a>
<a href="https://pypi.org/project/timerun/"><img alt="PyPI Latest Release" src="https://img.shields.io/pypi/v/timerun.svg"></a>
<a href="https://pypi.org/project/timerun/"><img alt="Package Status" src="https://img.shields.io/pypi/status/timerun.svg"></a>
<a href="https://github.com/psf/black/"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<a href="https://pycqa.github.io/isort/"><img alt="Imports: isort" src="https://img.shields.io/badge/%20imports-isort-%231674b1"></a>
<a href="https://pypi.org/project/timerun/"><img alt="Version" src="https://img.shields.io/pypi/v/timerun.svg"></a>
<a href="https://pypi.org/project/timerun/"><img alt="Status" src="https://img.shields.io/pypi/status/timerun.svg"></a>
<a href="https://github.com/HH-MWB/timerun/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/pypi/l/timerun.svg"></a>
<a href="https://codecov.io/gh/HH-MWB/timerun"><img alt="Coverage" src="https://codecov.io/gh/HH-MWB/timerun/branch/main/graph/badge.svg"></a>
<a href="https://pepy.tech/project/timerun"><img alt="Total Downloads" src="https://static.pepy.tech/badge/timerun"></a>
</p>

TimeRun is a simple, yet elegant elapsed time measurement library for [Python](https://www.python.org). It is distributed as a single file module and has no dependencies other than the [Python Standard Library](https://docs.python.org/3/library/).
Expand Down Expand Up @@ -45,24 +45,79 @@ pip install git+https://github.com/HH-MWB/timerun.git
### Measure Code Block

```python
>>> import time
>>> from timerun import Timer
>>> with Timer() as timer:
... pass # put your code here
... time.sleep(0.1) # your code here
>>> print(timer.duration)
0:00:00.000000100
0:00:00.100000000
```

### Measure Function

```python
>>> import time
>>> from timerun import Timer
>>> timer = Timer()
>>> @timer
... def func():
... pass # put your code here
... time.sleep(0.1) # your code here
>>> func()
>>> print(timer.duration)
0:00:00.000000100
0:00:00.100000000
```

### Measure Async Function

```python
>>> import asyncio
>>> from timerun import Timer
>>> timer = Timer()
>>> @timer
... async def async_func():
... await asyncio.sleep(0.1) # your code here
>>> asyncio.run(async_func())
>>> print(timer.duration)
0:00:00.100000000
```

### Measure Async Code Block

```python
>>> import asyncio
>>> from timerun import Timer
>>> async def async_code():
... async with Timer() as timer:
... await asyncio.sleep(0.1) # your code here
... print(timer.duration)
>>> asyncio.run(async_code())
0:00:00.100000000
```

### Multiple Measurements

```python
>>> import time
>>> from timerun import Timer
>>> timer = Timer()
>>> with timer:
... time.sleep(0.1) # your code here
>>> with timer:
... time.sleep(0.1) # your code here
>>> print(timer.duration) # Last duration
0:00:00.100000000
>>> print(timer.durations) # All durations
(ElapsedTime(nanoseconds=100000000), ElapsedTime(nanoseconds=100000000))
```

### Advanced Options

```python
>>> from timerun import Timer
>>> # Exclude sleep time from measurements
>>> timer = Timer(count_sleep=False)
>>> # Limit storage to last 10 measurements
>>> timer = Timer(max_len=10)
```

## Contributing
Expand All @@ -71,4 +126,4 @@ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guid

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/HH-MWB/timerun/blob/master/LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/HH-MWB/timerun/blob/main/LICENSE) file for details.
19 changes: 2 additions & 17 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ classifiers = [
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Monitoring",
]
dynamic = ["version"]

[project.optional-dependencies]
dev = ["pytest", "pytest-cov"]
dev = ["pytest", "pytest-asyncio", "pytest-cov"]

[project.urls]
Homepage = "https://github.com/HH-MWB/timerun"
Expand All @@ -49,19 +50,3 @@ license-files = ["LICENSE"]

[tool.setuptools.dynamic]
version = { attr = "timerun.__version__" }

[tool.bandit]
skips = ["B101"] # Skip assert_used test

[tool.black]
line-length = 79
target-version = [
"py39",
"py310",
"py311",
"py312",
"py313",
]

[tool.isort]
profile = "black"
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test suite for timerun."""
Loading