Skip to content
Open
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
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
default_install_hook_types: [pre-commit, commit-msg]
default_stages: [pre-commit]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
args: ['--maxkb=5120']
- id: check-ast
- id: end-of-file-fixer
- id: mixed-line-ending
args: ['--fix=lf']
- id: no-commit-to-branch
- id: trailing-whitespace
exclude: '\.(md|rst)$'
- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0
hooks:
- id: gitleaks
- repo: https://github.com/pycqa/isort
rev: 7.0.0
hooks:
- id: isort
args: ['--profile=black']
- repo: https://github.com/psf/black
rev: 25.9.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we are using black version 22.3.0, but probably we can do update with this change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your confirmation. Indeed, IIRC, 22.3.0 is to keep maintain the compatibility of python3.8, as we dropped its support, so I hope we can upgrade some toolchains to align tool's bug fix or style rules.

E.g. 22.3.0 will format multiple string line but has an issue like

# original 
test = (
    "foo"
    "bar"
)

# 22.3.0
test = ("foo" "bar")

# 25.9.0
test = ("foobar")

We can consider which version to use, not necessarily the latest version I put here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can upgrade to the latest version

hooks:
- id: black
- repo: local
hooks:
- id: pylint
name: pylint
entry: static-checks/check-lint
language: python
additional_dependencies:
- pylint==4.0.0
pass_filenames: false
Comment on lines +31 to +37
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Document submodule path requirement and verify Python environment usage.

The entry: static-checks/check-lint assumes the avocado-static-checks submodule is located at static-checks/ relative to the consuming repository's root. This requirement should be documented so users know where to place the submodule.

Additionally, the check-lint script uses python3 -m pylint (line 4 of check-lint), which invokes the system Python. However, pre-commit creates a virtualenv and installs pylint==4.0.0 in that environment via additional_dependencies. There's a potential mismatch where the script might not use the pylint from the virtualenv.

Consider one of the following approaches:

  1. Modify check-lint to use the current Python environment:
    Change line 4 from TOOL_CMD="python3 -m $TOOL_NAME" to TOOL_CMD="python -m $TOOL_NAME" (without the 3) so it uses the active Python from pre-commit's virtualenv.

  2. Document the expected setup:
    Add a README or comment explaining that consuming repos must:

    • Place the submodule at static-checks/
    • Ensure the config file path is correct relative to the submodule
  3. Verify the environment behavior:

Run this script to check how pre-commit sets up the environment:


🏁 Script executed:

#!/bin/bash
# Verify pre-commit Python environment setup
echo "Checking pre-commit hook configuration..."

# Check if check-lint script exists
if [ -f "check-lint" ]; then
  echo "✓ Found check-lint script"
  
  # Check the python command used
  if grep -q "python3 -m" check-lint; then
    echo "⚠ Script uses 'python3 -m pylint' which may not use pre-commit's virtualenv"
    echo "  Consider changing to 'python -m pylint' to use the virtualenv Python"
  fi
else
  echo "✗ check-lint not found in root"
  echo "  This is expected if it's in a submodule at static-checks/"
fi

# Verify the pre-commit config structure
if [ -f ".pre-commit-config.yaml" ]; then
  echo "✓ Found .pre-commit-config.yaml"
  
  # Check for the pylint hook configuration
  if grep -A 5 "id: pylint" .pre-commit-config.yaml | grep -q "language: python"; then
    echo "✓ Pylint hook uses language: python (creates virtualenv)"
  fi
  
  if grep -A 5 "id: pylint" .pre-commit-config.yaml | grep -q "static-checks/check-lint"; then
    echo "⚠ Entry path assumes submodule at static-checks/"
  fi
fi

Length of output: 352



---

🏁 Script executed:

```shell
#!/bin/bash
# Verify submodule status and actual entry path
echo "=== Checking .gitmodules ==="
if [ -f ".gitmodules" ]; then
  cat .gitmodules
else
  echo "No .gitmodules found - no submodules detected"
fi

echo -e "\n=== Checking for static-checks directory ==="
if [ -d "static-checks" ]; then
  echo "✓ static-checks/ directory exists"
  if [ -f "static-checks/check-lint" ]; then
    echo "✓ static-checks/check-lint exists"
  else
    echo "✗ static-checks/check-lint NOT found"
  fi
  if [ -L "static-checks" ]; then
    echo "  (static-checks is a symlink)"
  fi
else
  echo "✗ static-checks/ directory NOT found"
fi

echo -e "\n=== Actual entry path in .pre-commit-config.yaml ==="
grep -A 2 "id: pylint" .pre-commit-config.yaml | grep "entry:"

echo -e "\n=== Inspecting check-lint script ==="
head -15 check-lint

Length of output: 674


Fix broken pylint hook entry and ensure venv Python is used

  • In .pre-commit-config.yaml, change
    entry: static-checks/check-lint
    to the actual script path (e.g. entry: ./check-lint) so pre-commit can locate the hook.
  • In check-lint, replace
    TOOL_CMD="python3 -m $TOOL_NAME"
    with
    TOOL_CMD="python -m $TOOL_NAME"
    to invoke pylint from the virtualenv’s Python rather than the system interpreter.
🤖 Prompt for AI Agents
In .pre-commit-config.yaml around lines 31-37, the hook entry points to a
non-existent script; update the entry value to the actual script path (for
example change entry: static-checks/check-lint to entry: ./check-lint) so
pre-commit can locate and execute the hook; additionally, in the check-lint
script replace the TOOL_CMD invocation that uses python3 (TOOL_CMD="python3 -m
$TOOL_NAME") with the venv-aware python (TOOL_CMD="python -m $TOOL_NAME") so the
virtualenv's interpreter runs pylint instead of the system Python.

- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
hooks:
- id: codespell
args: ['-I=spell.ignore']
exclude: 'static-checks/.*'
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.23.0
hooks:
- id: commitlint
additional_dependencies: ['@commitlint/config-conventional']
stages: [commit-msg]
10 changes: 3 additions & 7 deletions check-lint
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ if [ -f "$CONFIG_FILE" ]; then
fi
done < "$CONFIG_FILE"
else
# If the configuration file does not exist, print a message and use default config for all files
echo "Configuration file '$CONFIG_FILE' not found. Running $TOOL_NAME with default config on all files..."
if ! $TOOL_CMD --rcfile="$DEFAULT_CONFIG_PATH" $ALL_FILES; then
overall_exit_status=1 # Set to 1 if there were any issues
fi

exit $overall_exit_status
# If the configuration file does not exist, print a message and exit
echo "Configuration file '$CONFIG_FILE' not found. Skipping pylint."
exit 0
fi

# Calculate remaining files that weren't checked with a custom config
Expand Down
43 changes: 43 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { UserConfig } from '@commitlint/types'

const config: UserConfig = {
extends: ['@commitlint/config-conventional'],
rules: {
// Body
'body-leading-blank': [2, 'always'],
'body-empty': [0, 'never'],
'body-min-length': [0, 'always', 1],
'body-case': [0, 'always', 'lower-case'],

// Footer
'footer-leading-blank': [2, 'always'],
'footer-empty': [0, 'never'],
'footer-max-length': [0, 'always', 72],

// Header
'header-case': [0, 'always', 'lower-case'],
'header-full-stop': [2, 'never', '.'],
'header-max-length': [2, 'always', 72],
'header-min-length': [2, 'always', 1],

// Scope / Subject
'scope-case': [0, 'always', 'lower-case'],
'scope-empty': [0, 'always'],
'subject-case': [0, 'always', 'lower-case'],
'subject-empty': [0, 'never'],
'subject-full-stop': [2, 'never', '.'],

// Type
'type-case': [0, 'always', 'lower-case'],
'type-empty': [0, 'always'],
'type-enum': [0, 'always', []],

// Signed-off-by
'signed-off-by': [2, 'always', 'Signed-off-by:'],
},
helpUrl:
'https://avocado-framework.readthedocs.io/en/latest/guides/contributor/chapters/styleguides.html#commit-style-guide',
}

export default config