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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
python-version: "3.11"
- name: Install ruff
run: pip install --no-cache-dir ruff
run: pip install --no-cache-dir -r requirements-dev.txt
- name: Run ruff format check
run: ruff format --check .
- name: Run ruff lint check
Expand Down
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Optional git hooks for Python scenario files (same checks as CI — see scripts/lint).
# Setup: pip install -r requirements-dev.txt pre-commit && pre-commit install
# On Datadog laptops with global core.hooksPath, use ./scripts/lint instead of pre-commit install.
repos:
- repo: local
hooks:
- id: ruff
name: ruff (scripts/lint)
entry: scripts/lint
language: system
types: [python]
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ Checkout #profiling-library-pager to get notified of test failures.
Install go >= 1.25.1: `brew install go`, `choco install go`, etc.
Install docker.

### Python lint (scenario workloads)

CI and local checks use [Ruff](https://docs.astral.sh/ruff/). Install once:

```sh
pip install -r requirements-dev.txt
```

```sh
./scripts/lint # check (matches the ci.yml ruff job)
./scripts/format # auto-fix formatting and lint
```

Optional git hooks (skip on Datadog laptops that use global `core.hooksPath` — run `./scripts/lint` manually instead):

```sh
pip install pre-commit
pre-commit install
```

Ruff version is pinned only in `requirements-dev.txt`.

### Running Tests

```sh
Expand Down
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Python dev tools for repo-wide lint/format (ci.yml, scripts/lint, scripts/format, pre-commit).
ruff==0.15.5
1 change: 1 addition & 0 deletions scenarios/python_safe_point_bias_3.11/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Verifies that the Python profiler correctly attributes CPU time to `slow_method`
def empty_method() -> None:
pass


def slow_method() -> None:
while time() < end_time:
x = "h" + "e" + "l" + "l" + "o" + ","
Expand Down
9 changes: 9 additions & 0 deletions scripts/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh"
ruff_common_setup
ruff_resolve_targets "$@"

ruff check --fix "${RUFF_TARGETS[@]}"
ruff format "${RUFF_TARGETS[@]}"
10 changes: 10 additions & 0 deletions scripts/lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

# Matches the ruff job in .github/workflows/ci.yml (see also scripts/format).
source "$(dirname "${BASH_SOURCE[0]}")/ruff-common.sh"
ruff_common_setup
ruff_resolve_targets "$@"

ruff format --check "${RUFF_TARGETS[@]}"
ruff check "${RUFF_TARGETS[@]}"
17 changes: 17 additions & 0 deletions scripts/ruff-common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Shared setup for scripts/lint and scripts/format.
ruff_common_setup() {
RUFF_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$RUFF_ROOT"

if ! command -v ruff >/dev/null 2>&1; then
echo "ruff not found; install with: pip install -r $RUFF_ROOT/requirements-dev.txt" >&2
exit 1
fi
}

ruff_resolve_targets() {
RUFF_TARGETS=("$@")
if [ "${#RUFF_TARGETS[@]}" -eq 0 ]; then
RUFF_TARGETS=(".")
fi
}
Loading