From 0459f08eebdbb911c8a714d91709a4cca9447ef4 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 11 Apr 2021 03:21:48 +0200 Subject: [PATCH] GitHub Action to lint Python code (#151) * GitHub Action to lint Python code * Fix typo --- .github/workflows/lint_python.yml | 20 +++++++++++++ .../c-or-cpp/Insert-and-delete-beginning.c | 2 +- sorting/python/bubble-sort.py | 28 +++++++++++-------- 3 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/lint_python.yml diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml new file mode 100644 index 00000000..ec21ecb2 --- /dev/null +++ b/.github/workflows/lint_python.yml @@ -0,0 +1,20 @@ +name: lint_python +on: [pull_request, push] +jobs: + lint_python: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v2 + - run: pip install bandit black codespell flake8 isort mypy pytest pyupgrade safety + - run: bandit --recursive --skip B101 . # B101 is assert statements + - run: black --check . || true + - run: codespell --ignore-words-list="ans,nnumber" --quiet-level=2 # --skip="" + - run: flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + - run: isort --check-only --profile black . + - run: pip install -r requirements.txt || true + - run: mypy --ignore-missing-imports . + - run: pytest . || true + - run: pytest --doctest-modules . + - run: shopt -s globstar && pyupgrade --py36-plus **/*.py + - run: safety check diff --git a/linked-lists/c-or-cpp/Insert-and-delete-beginning.c b/linked-lists/c-or-cpp/Insert-and-delete-beginning.c index 22d0d163..4e5941ed 100644 --- a/linked-lists/c-or-cpp/Insert-and-delete-beginning.c +++ b/linked-lists/c-or-cpp/Insert-and-delete-beginning.c @@ -34,7 +34,7 @@ void insertBeg(int data){ link->data = data ; //Point the link's pointer to the current head link->next = head ; - //Update the Head to the node we want to insert at the begining + //Update the Head to the node we want to insert at the beginning head = link ; } diff --git a/sorting/python/bubble-sort.py b/sorting/python/bubble-sort.py index 0dcf8c74..3e0be520 100644 --- a/sorting/python/bubble-sort.py +++ b/sorting/python/bubble-sort.py @@ -1,15 +1,21 @@ -def bubbleSort(arr): - n = len(arr) +arr = [23, 34, 25, 12, 54, 11, 90] - for i in range(n-1): - for j in range(0, n-i-1): - if arr[j] > arr[j+1] : - arr[j], arr[j+1] = arr[j+1], arr[j] -arr = [23, 34, 25, 12, 54, 11, 90] +def bubbleSort(arr): + """ + >>> bubbleSort(arr) + [11, 12, 23, 25, 34, 54, 90] + """ + n = len(arr) + for i in range(n-1): + for j in range(0, n-i-1): + if arr[j] > arr[j+1]: + arr[j], arr[j+1] = arr[j+1], arr[j] + return arr -bubbleSort(arr) -print ("Sorted array is:") -for i in range(len(arr)): - print (arr[i]) \ No newline at end of file +bubbleSort(arr) + +print("Sorted array is:") +for i in range(len(arr)): + print(arr[i])