-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic linting and formatting checks (#68)
* Added configurations for basic linting and formatting checks * simplify the used ruff ruleset for now * Add GitHub Workflow to perform linting and show results
- Loading branch information
Showing
7 changed files
with
167 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
name: Lint Code | ||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
# Cancel running jobs for the same workflow and branch. | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | ||
jobs: | ||
lint-python: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: x # any version | ||
check-latest: true | ||
- name: Install tox | ||
run: python -m pip install tox | ||
- name: Test | ||
run: tox -ve linting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,39 @@ | ||
--- | ||
name: tek-repo-lint | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
branches: [master] | ||
pull_request: | ||
branches: [ "main" ] | ||
branches: [master] | ||
workflow_dispatch: | ||
|
||
# select correct state for repository | ||
env: | ||
# state: private | ||
state: public | ||
|
||
jobs: | ||
public-or-private-repo: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
repostate: ${{ steps.repo-state.outputs.repostate }} | ||
steps: | ||
|
||
- name: Repo state | ||
id: repo-state | ||
run: echo "repostate=${{env.state}}" >> $GITHUB_OUTPUT | ||
- name: Repo public? | ||
if: "${{ env.state == 'public' }}" | ||
run: echo "Workflow has repo set as public. If this is incorrect, uncomment line 11." | ||
- name: Repo private? | ||
if: "${{ env.state == 'private' }}" | ||
run: echo "Workflow has repo set as private. If this is incorrect, uncomment line 12." | ||
|
||
check-for-codeowners-file: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for CODEOWNERS | ||
id: codeowners_file | ||
uses: initialstate/file-check-action@v1 | ||
with: | ||
file: ".github/CODEOWNERS" | ||
|
||
- name: CODEOWNERS file Output Test | ||
run: echo ${{ steps.codeowners_file.outputs.file_exists }} | ||
|
||
- name: CODEOWNERS file exists with content | ||
if: steps.codeowners_file.outputs.file_exists == 'true' | ||
run: echo CODEOWNERS file exists! | ||
|
||
- name: CODEOWNERS file does not exist | ||
if: steps.codeowners_file.outputs.file_exists == 'false' | ||
run: echo CODEOWNERS file does not exist! | ||
|
||
check-for-readme-file: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for README.md | ||
id: readme_file | ||
uses: initialstate/file-check-action@v1 | ||
with: | ||
file: "README" | ||
|
||
- name: README file Output Test | ||
run: echo ${{ steps.readme_file.outputs.file_exists }} | ||
|
||
- name: README file exists with content | ||
if: steps.readme_file.outputs.file_exists == 'true' | ||
run: echo README file exists! | ||
|
||
- name: README file does not exist | ||
if: steps.readme_file.outputs.file_exists == 'false' | ||
run: echo README file does not exist! | ||
|
||
check-for-license: | ||
needs: public-or-private-repo | ||
if: needs.public-or-private-repo.outputs.repostate == 'public' | ||
check-for-file: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
filename: | ||
- .github/CODEOWNERS | ||
- README.@(md|rst) | ||
- LICENSE.@(md|rst) | ||
- .github/workflows/codeql.yml | ||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for LICENSE.md | ||
id: license_file | ||
uses: initialstate/file-check-action@v1 | ||
- uses: actions/checkout@v4 | ||
- name: Ensure ${{ matrix.filename }} exists | ||
uses: andstor/file-existence-action@v3 | ||
with: | ||
file: "LICENSE" | ||
|
||
- name: LICENSE file Output Test | ||
run: echo ${{ steps.license_file.outputs.file_exists }} | ||
|
||
- name: LICENSE file exists with content | ||
if: steps.license_file.outputs.file_exists == 'true' | ||
run: echo LICENSE file exists! | ||
|
||
- name: LICENSE file does not exist | ||
if: steps.license_file.outputs.file_exists == 'false' | ||
run: echo LICENSE file does not exist! | ||
|
||
check-for-dependabot-file: | ||
files: ${{ matrix.filename }} | ||
ignore_case: false | ||
follow_symbolic_links: false | ||
fail: true # Set the step to fail if the file doesn't exist | ||
# Check that all jobs passed | ||
check-repo-lint-passed: | ||
if: ${{ !cancelled() }} | ||
needs: [check-for-file] | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for dependabot.yml | ||
id: dependabot_file | ||
uses: initialstate/file-check-action@v1 | ||
- name: Decide whether the needed jobs succeeded or failed | ||
uses: re-actors/alls-green@release/v1 | ||
with: | ||
file: ".github/dependabot.yml" | ||
|
||
- name: dependabot.yml file Output Test | ||
run: echo ${{ steps.dependabot_file.outputs.file_exists }} | ||
|
||
- name: dependabot file exists with content | ||
if: steps.dependabot_file.outputs.file_exists == 'true' | ||
run: echo dependabot file exists! | ||
|
||
- name: dependabot file does not exist | ||
if: steps.dependabot_file.outputs.file_exists == 'false' | ||
run: echo dependabot file does not exist! | ||
|
||
check-for-codeql-file: | ||
runs-on: ubuntu-latest | ||
steps: | ||
|
||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for codeql-analysis.yml | ||
id: codeql-analysis_file | ||
uses: initialstate/file-check-action@v1 | ||
with: | ||
file: ".github/workflows/codeql-analysis.yml" | ||
|
||
- name: codeql-analysis.yml file Output Test | ||
run: echo ${{ steps.codeql-analysis_file.outputs.file_exists }} | ||
|
||
- name: codeql-analysis file exists with content | ||
if: steps.codeql-analysis_file.outputs.file_exists == 'true' | ||
run: echo codeql-analysis file exists! | ||
|
||
- name: codeql-analysis file does not exist | ||
if: steps.codeql-analysis_file.outputs.file_exists == 'false' | ||
run: echo codeql-analysis file does not exist! | ||
jobs: ${{ toJSON(needs) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Ignore IDE config folders | ||
.idea/ | ||
.vscode/ | ||
|
||
# Ignore caches and binaries | ||
.ruff_cache/ | ||
__pycache__/ | ||
*.py[cod] | ||
.tox/ | ||
|
||
# Ignore virtual environments | ||
*env*/ | ||
*venv*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
default_install_hook_types: [pre-commit] | ||
default_stages: [pre-commit] | ||
repos: | ||
- repo: https://github.com/pre-commit/pre-commit-hooks | ||
rev: v4.6.0 | ||
hooks: | ||
- id: check-yaml | ||
args: [--unsafe] | ||
- id: check-toml | ||
- id: check-json | ||
- id: check-xml | ||
- id: requirements-txt-fixer | ||
# - id: trailing-whitespace # TODO: enable | ||
# - id: end-of-file-fixer # TODO: enable | ||
- id: check-case-conflict | ||
- id: check-merge-conflict | ||
- id: forbid-submodules | ||
# TODO: enable these hooks | ||
# - repo: https://github.com/Lucas-C/pre-commit-hooks | ||
# rev: v1.5.5 | ||
# hooks: | ||
# - id: remove-tabs | ||
# - id: forbid-tabs | ||
- repo: https://github.com/python-jsonschema/check-jsonschema | ||
rev: 0.29.0 | ||
hooks: | ||
- id: check-github-workflows | ||
args: [--verbose] | ||
- repo: https://github.com/pappasam/toml-sort | ||
rev: v0.23.1 | ||
hooks: | ||
- id: toml-sort-fix | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.5.4 | ||
hooks: | ||
- id: ruff | ||
# args: [--fix, --exit-non-zero-on-fix] | ||
- id: ruff-format | ||
args: [--check, --diff] | ||
- repo: https://github.com/PyCQA/docformatter | ||
rev: v1.7.5 | ||
hooks: | ||
- id: docformatter | ||
additional_dependencies: [tomli] | ||
args: [--check, --diff] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
[tool.docformatter] | ||
close-quotes-on-newline = true | ||
in-place = true | ||
recursive = true | ||
wrap-descriptions = 100 | ||
wrap-summaries = 0 | ||
|
||
[tool.ruff] | ||
line-length = 100 | ||
target-version = "py38" # always generate Python 3.8 compatible code | ||
|
||
[tool.ruff.lint] | ||
fixable = ["ALL"] | ||
flake8-quotes = {docstring-quotes = "double"} | ||
ignore = [ | ||
"T201" # `print` found | ||
] | ||
pydocstyle = {convention = "google"} | ||
# https://beta.ruff.rs/docs/rules/ | ||
select = [ | ||
# "ALL" # TODO: enable ALL | ||
"E", | ||
"F", | ||
"I", | ||
"N", | ||
"PLE", | ||
"Q", | ||
"RUF" | ||
] | ||
|
||
[tool.ruff.lint.isort] | ||
force-sort-within-sections = false | ||
lines-between-types = 1 | ||
order-by-type = false | ||
|
||
[tool.tomlsort] | ||
all = true | ||
in_place = true | ||
spaces_before_inline_comment = 2 | ||
|
||
[tool.tox] | ||
legacy_tox_ini = """ | ||
[tox] | ||
requires = tox>4 | ||
no_package = True | ||
envlist = linting | ||
skip_missing_interpreters = True | ||
[testenv:linting] | ||
deps = | ||
pre-commit | ||
commands = | ||
pre-commit run --all-files | ||
""" |