From f38f253de0bc379b896c7f9b3a7f5e154fb83323 Mon Sep 17 00:00:00 2001 From: RGBCube <78925721+RGBCube@users.noreply.github.com> Date: Tue, 21 Jun 2022 18:28:11 +0300 Subject: [PATCH] Cleanup workflows - Added Bandit - Added unimport, isort, flynt - Added PyRight - Enabled preview mode on Bandit --- .github/workflows/autoblack.yml | 30 --------------------- .github/workflows/bandit.yml | 26 ++++++++++++++++++ .github/workflows/lint.yml | 47 +++++++++++++++++++++++++++++++++ .github/workflows/pylint.yml | 33 ++++++++++++----------- .github/workflows/pyright.yml | 28 ++++++++++++++++++++ pyproject.toml | 46 +++++++++++++++++++++++++++++++- 6 files changed, 164 insertions(+), 46 deletions(-) delete mode 100644 .github/workflows/autoblack.yml create mode 100644 .github/workflows/bandit.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/pyright.yml diff --git a/.github/workflows/autoblack.yml b/.github/workflows/autoblack.yml deleted file mode 100644 index 6b00ae9..0000000 --- a/.github/workflows/autoblack.yml +++ /dev/null @@ -1,30 +0,0 @@ -# GitHub Action that uses Black to reformat the Python code in an incoming pull request. -# If all Python code in the pull request is compliant with Black then this Action does nothing. -# Othewrwise, Black is run and its changes are committed back to the incoming pull request. -# https://github.com/cclauss/autoblack - -name: autoblack -on: [pull_request] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.7 - uses: actions/setup-python@v1 - with: - python-version: 3.7 - - name: Install Black - run: pip install black - - name: Run black --check . - run: black --check . - - name: If needed, commit black changes to the pull request - if: failure() - run: | - black . - git config --global user.name 'autoblack' - git config --global user.email 'cclauss@users.noreply.github.com' - git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY - git checkout $GITHUB_HEAD_REF - git commit -am "fixup: Format Python code with Black" - git push diff --git a/.github/workflows/bandit.yml b/.github/workflows/bandit.yml new file mode 100644 index 0000000..d8a0277 --- /dev/null +++ b/.github/workflows/bandit.yml @@ -0,0 +1,26 @@ +name: Bandit + +on: [ pull_request, push ] + +jobs: + build: + if: github.event.pull_request.user.type != 'Bot' + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.8', '3.9', '3.10' ] + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Bandit + run: pip install -U pip bandit + + - name: Run Bandit + run: bandit --recursive ./ diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c2c5235 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,47 @@ +name: Lint + +on: [ pull_request, push ] + +jobs: + build: + if: github.event.pull_request.user.type != 'Bot' + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.8', '3.9', '3.10' ] + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Unimport, Isort, Black, and Flynt + run: pip install -U pip unimport isort black flynt + + - name: Run Unimport + continue-on-error: true + run: unimport ./ --ignore-init --gitignore -r + + - name: Run Isort + run: isort ./ + + - name: Run Black + run: black ./ + + - name: Run Flynt + run: flynt ./ -tc + + - name: Setup Git + run: git config user.name "Automated Linter" + + - name: Push To GitHub + continue-on-error: true + run: | + git pull + git add ./ + git commit --reuse-message=HEAD + git push diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 383e65c..848a02a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -1,23 +1,26 @@ -name: Pylint +name: PyLint -on: [push] +on: [ pull_request, push ] jobs: build: + if: github.event.pull_request.user.type != 'Bot' runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: [ '3.8', '3.9', '3.10' ] + steps: - - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v3 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install pylint - - name: Analysing the code with pylint - run: | - pylint $(git ls-files '*.py') + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install PyLint + run: pip install -U pip pylint + + - name: Run PyLint + run: pylint $(git ls-files '*.py') diff --git a/.github/workflows/pyright.yml b/.github/workflows/pyright.yml new file mode 100644 index 0000000..920383b --- /dev/null +++ b/.github/workflows/pyright.yml @@ -0,0 +1,28 @@ +name: PyRight + +on: [ pull_request, push ] + +jobs: + build: + if: github.event.pull_request.user.type != 'Bot' + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ '3.8', '3.9', '3.10' ] + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + + - name: Install PyRight & Dependencies + run: | + pip install -U pip pyright + pip install -Ur requirements.txt + + - name: Run PyRight + run: pyright ./ diff --git a/pyproject.toml b/pyproject.toml index 06168bb..dc4a088 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,3 +1,47 @@ [tool.black] line-length = 125 -skip-string-normalization = true \ No newline at end of file +skip-string-normalization = true +preview = true # better formatting basically + +[tool.isort] +line_length = 125 +combine_as_imports = true +combine_star = true + +[tool.pyright] +typeCheckingMode = "basic" +strictListInference = true +strictDictionaryInference = true +strictSetInference = true + +# explicity enabling is better than making it strict and disabling stuff +reportMissingModuleSource = "error" +reportAssertAlwaysTrue = "error" +reportInvalidStringEscapeSequence = "error" +reportInvalidTypeVarUse = "error" +reportSelfClsParameterName = "error" +reportUnsupportedDunderAll = "error" +reportUnusedExpression = "error" +reportWildcardImportFromLibrary = "error" +reportConstantRedefinition = "error" +reportDuplicateImport = "error" +reportImportCycles = "error" +reportIncompatibleVariableOverride = "error" +reportIncompleteStub = "error" +reportInconsistentConstructor = "error" +reportInvalidStubStatement = "error" +reportMatchNotExhaustive = "error" +reportMissingParameterType = "error" +reportTypeCommentUsage = "error" +reportUnnecessaryCast = "error" +reportUnnecessaryComparison = "error" +reportUnnecessaryIsInstance = "error" +reportUnusedClass = "error" +reportUnusedVariable = "error" +reportUntypedBaseClass = "error" +reportUntypedClassDecorator = "error" +reportUntypedFunctionDecorator = "error" +reportUntypedNamedTuple = "error" +reportCallInDefaultInitializer = "error" +reportPropertyTypeMismatch = "error" +reportUnnecessaryTypeIgnoreComment = "error" \ No newline at end of file