Skip to content

Commit

Permalink
Merge branch 'beta' into typescriptize-reports-files
Browse files Browse the repository at this point in the history
duvld committed Sep 19, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e88a4af + 80b0a76 commit 2999a30
Showing 5 changed files with 35 additions and 28 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/darker.yml
Original file line number Diff line number Diff line change
@@ -5,14 +5,25 @@ jobs:
darker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/setup-python@v5
- name: Install pip dependencies
run: python -m pip install flake8 flake8-quotes isort
- uses: akaihola/darker@master

- name: Set up Python
uses: actions/setup-python@v5
with:
options: '--check --isort -L "flake8 --max-line-length=88"'
revision: "origin/${{ github.event.pull_request.base.ref }}"
version: "~=2.1.1"
python-version: '3.10'

- name: Install pip dependencies
run: python -m pip install darker[isort] flake8 flake8-quotes isort --quiet

# use `--ignore=F821` to avoid raising false positive error in typing
# annotations with string, e.g. def my_method(my_model: 'ModelName')

# darker still exit with code 1 even with no errors on changes
- name: Run Darker with base commit
run: |
output=$(darker --check --isort -L "flake8 --max-line-length=88 --ignore=F821" kpi kobo hub -r ${{ github.event.pull_request.base.sha }})
[[ -n "$output" ]] && echo "$output" && exit 1 || exit 0
shell: /usr/bin/bash {0}
29 changes: 16 additions & 13 deletions format-python.sh
Original file line number Diff line number Diff line change
@@ -2,17 +2,20 @@

BASE_REVISION=$1

if [ -n "${UWSGI_USER}" ] && [ "${DEBIAN_FRONTEND}" == "noninteractive" ] && [ "${TMP_DIR}" == "/srv/tmp" ]; then
INSIDE_CONTAINER=1
else
INSIDE_CONTAINER=0
WHOAMI=$(whoami)
OWNER=$(ls -ld . | awk '{print $3}')
GOSU_USER=""

if [ "$WHOAMI" != "$OWNER" ]; then
GOSU_USER=$OWNER
fi

if [ -z "$BASE_REVISION" ]; then
BASE_REVISION="origin/beta"
echo "You must provide the base branch, e.g.: format-python.sh origin/beta"
exit
elif [ "$BASE_REVISION" == "-l" ] || [ "$BASE_REVISION" == "--last" ]; then
if [ "$INSIDE_CONTAINER" == "1" ]; then
BASE_REVISION=$(gosu "$UWSGI_USER" git log --oneline| head -n 1 | awk '{ print $1}')
if [ -n "$GOSU_USER" ]; then
BASE_REVISION=$(gosu "$GOSU_USER" git log --oneline| head -n 1 | awk '{ print $1}')
else
BASE_REVISION=$(git log --oneline| head -n 1 | awk '{ print $1}')
fi
@@ -27,16 +30,16 @@ fi
# - Unnecessary parentheses after class definition (--select UP039)
# - Indentation warning (--select W1)
# - No newline at end of file (--select W292)
if [ "$INSIDE_CONTAINER" == "1" ]; then
PYTHON_CHANGES=$(gosu "$UWSGI_USER" git diff --name-only "$BASE_REVISION" | grep '\.py')
if [ -n "$GOSU_USER" ]; then
PYTHON_CHANGES=$(gosu "$GOSU_USER" git diff --name-only "$BASE_REVISION" | grep '\.py')
else
PYTHON_CHANGES=$(git diff --name-only "$BASE_REVISION" | grep '\.py')
fi

if [ -n "$PYTHON_CHANGES" ]; then
echo "Using ruff..."
if [ "$INSIDE_CONTAINER" == "1" ]; then
gosu "$UWSGI_USER" git diff --name-only "$BASE_REVISION" | grep '\.py' | xargs ruff check --select Q --select I --select F401 --select UP026 --select UP034 --select UP039 --select W292 --fix
if [ -n "$GOSU_USER" ]; then
gosu "$GOSU_USER" git diff --name-only "$BASE_REVISION" | grep '\.py' | xargs ruff check --select Q --select I --select F401 --select UP026 --select UP034 --select UP039 --select W292 --fix
else
git diff --name-only "$BASE_REVISION" | grep '\.py' | xargs ruff check --select Q --select I --select F401 --select UP026 --select UP034 --select UP039 --select W292 --fix
fi
@@ -45,8 +48,8 @@ if [ -n "$PYTHON_CHANGES" ]; then
# --isort: Using isort
# --revision: Compare changes with revision $BASE_REVISION
echo "Using darker..."
if [ "$INSIDE_CONTAINER" == "1" ]; then
gosu "$UWSGI_USER" darker --isort --revision "$BASE_REVISION"
if [ -n "$GOSU_USER" ]; then
gosu "$GOSU_USER" darker --isort --revision "$BASE_REVISION"
else
darker --isort --revision "$BASE_REVISION"
fi
2 changes: 0 additions & 2 deletions kobo/apps/audit_log/serializers.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ class Meta:
fields = (
'app_label',
'model_name',
'object_id',
'user',
'user_uid',
'username',
@@ -32,7 +31,6 @@ class Meta:
read_only_fields = (
'app_label',
'model_name',
'object_id',
'user',
'user_uid',
'username',
2 changes: 0 additions & 2 deletions kobo/apps/audit_log/tests/api/v2/test_api_audit_log.py
Original file line number Diff line number Diff line change
@@ -106,7 +106,6 @@ def test_list_as_superuser(self):
{
'app_label': 'foo',
'model_name': 'bar',
'object_id': 1,
'user': 'http://testserver/api/v2/users/someuser/',
'user_uid': someuser.extra_details.uid,
'action': 'delete',
@@ -149,7 +148,6 @@ def test_filter_list(self):
{
'app_label': 'foo',
'model_name': 'bar',
'object_id': 1,
'user': 'http://testserver/api/v2/users/anotheruser/',
'user_uid': anotheruser.extra_details.uid,
'action': 'delete',
3 changes: 0 additions & 3 deletions kobo/apps/audit_log/views.py
Original file line number Diff line number Diff line change
@@ -36,7 +36,6 @@ class AuditLogViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
> {
> "app_label": "foo",
> "model_name": "bar",
> "object_id": 1,
> "user": "http://kf.kobo.local/users/kobo_user/",
> "action": "delete",
> "log_type": "asset-management",
@@ -111,7 +110,6 @@ class AllAccessLogViewSet(AuditLogViewSet):
> {
> "app_label": "kobo_auth",
> "model_name": "User",
> "object_id": 1,
> "user": "http://localhost/api/v2/users/admin/",
> "user_uid": "uBMZxx9tVfepvTRp3e9Twj",
> "username": "admin",
@@ -163,7 +161,6 @@ class AccessLogViewSet(AuditLogViewSet):
> {
> "app_label": "kobo_auth",
> "model_name": "User",
> "object_id": 1,
> "user": "http://localhost/api/v2/users/admin/",
> "user_uid": "uBMZxx9tVfepvTRp3e9Twj",
> "username": "admin",

0 comments on commit 2999a30

Please sign in to comment.