Skip to content

[MSD-612][feat] Meteor: MILLING <> FIB-VIEW FM posture switching (TESCAN/TFS) #4068

[MSD-612][feat] Meteor: MILLING <> FIB-VIEW FM posture switching (TESCAN/TFS)

[MSD-612][feat] Meteor: MILLING <> FIB-VIEW FM posture switching (TESCAN/TFS) #4068

# This workflow will check for exceptions to raise properly and do not generate syntax errors.
# Also old code style using parenthesis in class definitions will be checked
# This workflow runs py_compile on all modified Python files to catch syntax errors.
name: Syntax checking
on:
[push, pull_request]
jobs:
mixup_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Check exceptions
# Not related to tests, but to QA in general: Exceptions usually take only 1 argument
# So a comma is probably a sign of syntax error and should be replaced by a %
run: |
grep -IrE --colour 'raise .+".*%.*",' --include=*.py ./src/odemis ./scripts/ ./plugins/ || exit 0
if [[ $? -eq 0 ]]; then
echo "Found the above syntax errors in exceptions, this is a sign that a comma should be replaced by a %."
exit 1
fi
- name: Check old style classes
if: ${{ !cancelled() }}
# Only use parenthesis in class definition if there is inheritance (code-style)
run: |
grep -IrE --colour "class .+\(\).*:" --include=*.py ./src/odemis || exit 0
if [[ $? -eq 0 ]]; then
echo "The above syntax errors were found, only use parenthesis in class definition if there is inheritance (code-style)."
exit 1
fi
- name: Check test cases are runnable
if: ${{ !cancelled() }}
run: |
# Check that all test cases are runnable (i.e., have a proper __main__ guard)
# Discover all *_test.py under any */test/ folder from repo root.
mapfile -d '' -t testfiles < <(find . -type f -path '*/test/*_test.py' \
-not -path './.git/*' -print0)
if [[ ${#testfiles[@]} -eq 0 ]]; then
echo "No test files found under */test/*_test.py"
exit 0
fi
exit_code=0
for f in "${testfiles[@]}"; do
# Match the canonical main guard to reduce false positives
if ! grep -qE "^[[:space:]]*if[[:space:]]+__name__[[:space:]]*==[[:space:]]*[\"']__main__[\"'][[:space:]]*:" "$f"; then
echo "::warning title=Non-runnable test:: $f lacks an '__main__' guard"
exit_code=1
fi
done
exit "$exit_code"
syntax_check:
runs-on: ubuntu-latest
strategy:
matrix:
python_version: [ "3.8", "3.10", "3.12" ]
steps:
- name: Checkout branch
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v47
- name: Setup Python environment
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python_version }}
- name: Run py_compile on changed files
run: |
for changed_file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $changed_file == *.py && -f "$changed_file" ]];
then
python -m py_compile "$changed_file"
fi
done