Skip to content

Commit

Permalink
Run ruff. Also, pip install Python linters. (#762)
Browse files Browse the repository at this point in the history
Apparently Ubuntu has a "snap" for `ruff`, but it doesn't seem to be
working in 23.10.  So, just `pip install` both ruff and pyflakes if they
are not installed.

It gets a tiny bit complicated with pyflakes, because the Ubuntu package seems to call it `pyflakes3` and the pip package calls it `pyflakes`.  To avoid more complication, I took the risk of setting up an unnecessary virtualenv in one scenario.
  • Loading branch information
jtv committed Dec 5, 2023
1 parent fbc9268 commit e3aa3cb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ jobs:
name: Install
command: apt install -y lsb-release python3 cmake postgresql libpq-dev
postgresql-server-dev-all build-essential autoconf dh-autoreconf
autoconf-archive automake cppcheck clang
autoconf-archive automake cppcheck clang shellcheck
python3-virtualenv
- run:
name: Identify
command: lsb_release -a && c++ --version && clang++ --version
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ jobs:
- name: Build
run: |
gcc --version
sudo apt-get install -y postgresql
sudo apt-get install -y postgresql virtualenv
sudo service postgresql start
sudo su postgres -c "createuser --createdb $(whoami)"
createdb "$(whoami)"
# Using clang because currently the gcc build fails with an
# address sanitizer (asan) link error.
./configure --enable-maintainer-mode --enable-audit --disable-documentation --disable-static CXXFLAGS='-O1 -std=c++17' CXX=clang++
make -j4 check
make -j4 check || (cat test-suite.log && exit 1)
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
Expand Down
32 changes: 30 additions & 2 deletions tools/lint
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ count_includes() {
# It's OK for the grep to fail.
find "$SRCDIR/include/pqxx" -type f -print0 |
( xargs -0 grep -c "$PAT" || /bin/true ) |
sort
sort
}


Expand Down Expand Up @@ -142,10 +142,38 @@ cpplint() {


pylint() {
if which pyflakes3 >/dev/null
local venv

if ! which pyflakes -o ! which ruff >/dev/null
then
venv="$(mktemp -d)"
virtualenv "$venv"
# shellcheck disable=SC1091
. "$venv/bin/activate"
fi
if ! which pyflakes -a ! which pyflakes3 >/dev/null
then
pip install pyflakes
fi
if ! which ruff >/dev/null
then
pip install ruff
fi

if which pyflakes
then
pyflakes "$SRCDIR"/tools/*.py "$SRCDIR"/tools/splitconfig
else
pyflakes3 "$SRCDIR"/tools/*.py "$SRCDIR"/tools/splitconfig
fi

ruff "$SRCDIR"/tools/*.py "$SRCDIR"/tools/splitconfig

if test -n "$venv"
then
deactivate
rm -r "$venv"
fi
}


Expand Down

0 comments on commit e3aa3cb

Please sign in to comment.