mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-25 11:05:49 +03:00
20de685a4b
Some checks failed
Tests / check-lockfile (push) Has been cancelled
Build docker images / build (push) Has been cancelled
Deploy the documentation / Calculate variables for GitHub Pages deployment (push) Has been cancelled
/ Check locked dependencies have sdists (push) Has been cancelled
Build release artifacts / Build sdist (push) Has been cancelled
Build release artifacts / Calculate list of debian distros (push) Has been cancelled
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (aarch64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Has been cancelled
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, macos-12) (push) Has been cancelled
Build release artifacts / Build wheels on ${{ matrix.os }} for ${{ matrix.arch }} (x86_64, ${{ startsWith(github.ref, 'refs/pull/') }}, ubuntu-20.04) (push) Has been cancelled
Tests / changes (push) Has been cancelled
Tests / lint-crlf (push) Has been cancelled
Tests / lint-newsfile (push) Has been cancelled
Deploy the documentation / GitHub Pages (push) Has been cancelled
Build release artifacts / Build .deb packages (push) Has been cancelled
Build release artifacts / Attach assets to release (push) Has been cancelled
Tests / check-sampleconfig (push) Has been cancelled
Tests / check-schema-delta (push) Has been cancelled
Tests / lint (push) Has been cancelled
Tests / Typechecking (push) Has been cancelled
Tests / lint-pydantic (push) Has been cancelled
Tests / lint-clippy (push) Has been cancelled
Tests / lint-clippy-nightly (push) Has been cancelled
Tests / lint-rustfmt (push) Has been cancelled
Tests / lint-readme (push) Has been cancelled
Tests / linting-done (push) Has been cancelled
Tests / calculate-test-jobs (push) Has been cancelled
Tests / trial (push) Has been cancelled
Tests / trial-olddeps (push) Has been cancelled
Tests / trial-pypy (all, pypy-3.8) (push) Has been cancelled
Tests / sytest (push) Has been cancelled
Tests / export-data (push) Has been cancelled
Tests / portdb (11, 3.8) (push) Has been cancelled
Tests / complement (monolith, SQLite) (push) Has been cancelled
Tests / complement (workers, Postgres) (push) Has been cancelled
Tests / cargo-test (push) Has been cancelled
Tests / cargo-bench (push) Has been cancelled
Tests / tests-done (push) Has been cancelled
Tests / portdb (15, 3.11) (push) Has been cancelled
Tests / complement (monolith, Postgres) (push) Has been cancelled
143 lines
4 KiB
Bash
Executable file
143 lines
4 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
#
|
|
# Runs linting scripts over the local Synapse checkout
|
|
# black - opinionated code formatter
|
|
# ruff - lints and finds mistakes
|
|
|
|
set -e
|
|
|
|
usage() {
|
|
echo
|
|
echo "Usage: $0 [-h] [-d] [paths...]"
|
|
echo
|
|
echo "-d"
|
|
echo " Lint files that have changed since the last git commit."
|
|
echo
|
|
echo " If paths are provided and this option is set, both provided paths and those"
|
|
echo " that have changed since the last commit will be linted."
|
|
echo
|
|
echo " If no paths are provided and this option is not set, all files will be linted."
|
|
echo
|
|
echo " Note that paths with a file extension that is not '.py' will be excluded."
|
|
echo "-h"
|
|
echo " Display this help text."
|
|
}
|
|
|
|
USING_DIFF=0
|
|
files=()
|
|
|
|
while getopts ":dh" opt; do
|
|
case $opt in
|
|
d)
|
|
USING_DIFF=1
|
|
;;
|
|
h)
|
|
usage
|
|
exit
|
|
;;
|
|
\?)
|
|
echo "ERROR: Invalid option: -$OPTARG" >&2
|
|
usage
|
|
exit
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Strip any options from the command line arguments now that
|
|
# we've finished processing them
|
|
shift "$((OPTIND-1))"
|
|
|
|
if [ $USING_DIFF -eq 1 ]; then
|
|
# Check both staged and non-staged changes
|
|
for path in $(git diff HEAD --name-only); do
|
|
filename=$(basename "$path")
|
|
file_extension="${filename##*.}"
|
|
|
|
# If an extension is present, and it's something other than 'py',
|
|
# then ignore this file
|
|
if [[ -n ${file_extension+x} && $file_extension != "py" ]]; then
|
|
continue
|
|
fi
|
|
|
|
# Append this path to our list of files to lint
|
|
files+=("$path")
|
|
done
|
|
fi
|
|
|
|
# Append any remaining arguments as files to lint
|
|
files+=("$@")
|
|
|
|
if [[ $USING_DIFF -eq 1 ]]; then
|
|
# If we were asked to lint changed files, and no paths were found as a result...
|
|
if [ ${#files[@]} -eq 0 ]; then
|
|
# Then print and exit
|
|
echo "No files found to lint."
|
|
exit 0
|
|
fi
|
|
else
|
|
# If we were not asked to lint changed files, and no paths were found as a result,
|
|
# then lint everything!
|
|
if [[ -z ${files+x} ]]; then
|
|
# CI runs each linter on the entire checkout, e.g. `black .`. So don't
|
|
# rely on this list to *find* lint targets if that misses a file; instead;
|
|
# use it to exclude files from linters when this can't be done by config.
|
|
#
|
|
# To check which files the linters examine, use:
|
|
# black --verbose . 2>&1 | \grep -v ignored
|
|
# isort --show-files .
|
|
# flake8 --verbose . # This isn't a great option
|
|
# mypy has explicit config in mypy.ini; there is also mypy --verbose
|
|
files=(
|
|
"synapse" "docker" "tests"
|
|
"scripts-dev"
|
|
"contrib" "synmark" "stubs" ".ci"
|
|
)
|
|
fi
|
|
fi
|
|
|
|
echo "Linting these paths: ${files[*]}"
|
|
echo
|
|
|
|
# Print out the commands being run
|
|
set -x
|
|
|
|
# Ensure the sort order of imports.
|
|
isort "${files[@]}"
|
|
|
|
# Ensure Python code conforms to an opinionated style.
|
|
python3 -m black "${files[@]}"
|
|
|
|
# Ensure the sample configuration file conforms to style checks.
|
|
./scripts-dev/config-lint.sh
|
|
|
|
# Catch any common programming mistakes in Python code.
|
|
# --quiet suppresses the update check.
|
|
ruff check --quiet --fix "${files[@]}"
|
|
|
|
# Catch any common programming mistakes in Rust code.
|
|
#
|
|
# --bins, --examples, --lib, --tests combined explicitly disable checking
|
|
# the benchmarks, which can fail due to `#![feature]` macros not being
|
|
# allowed on the stable rust toolchain (rustc error E0554).
|
|
#
|
|
# --allow-staged and --allow-dirty suppress clippy raising errors
|
|
# for uncommitted files. Only needed when using --fix.
|
|
#
|
|
# -D warnings disables the "warnings" lint.
|
|
#
|
|
# Using --fix has a tendency to cause subsequent runs of clippy to recompile
|
|
# rust code, which can slow down this script. Thus we run clippy without --fix
|
|
# first which is quick, and then re-run it with --fix if an error was found.
|
|
if ! cargo-clippy --bins --examples --lib --tests -- -D warnings > /dev/null 2>&1; then
|
|
cargo-clippy \
|
|
--bins --examples --lib --tests --allow-staged --allow-dirty --fix -- -D warnings
|
|
fi
|
|
|
|
# Ensure the formatting of Rust code.
|
|
cargo-fmt
|
|
|
|
# Ensure all Pydantic models use strict types.
|
|
./scripts-dev/check_pydantic_models.py lint
|
|
|
|
# Ensure type hints are correct.
|
|
mypy
|