diff --git a/.gitpod.yml b/.gitpod.yml index 678833cef..5dc45f0e9 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -33,4 +33,10 @@ vscode: - eamodio.gitlens - gruntfuggly.todo-tree - redhat.vscode-yaml - - bungcip.better-toml + - ms-python.black-formatter + - ms-python.isort + - janisdd.vscode-edit-csv + - tamasfe.even-better-toml + - ms-python.flake8 + - donjayamanne.githistory + - ms-python.debugpy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0572b595e..d891b018c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,19 +1,25 @@ repos: - - repo: https://github.com/google/yapf - rev: "v0.40.2" # Use the sha / tag you want to point at + - repo: https://github.com/psf/black + rev: "24.4.2" # Use the sha / tag you want to point at hooks: - - id: yapf - language: python - entry: yapf - args: [-i, -vv] - types: [python] - additional_dependencies: ['toml'] - # - repo: https://github.com/PyCQA/flake8 - # rev: 6.1.0 # pick the desired flake8 version - # hooks: - # - id: flake8 + - id: black + + # - repo: https://github.com/pycqa/isort + # rev: 5.13.2 + # hooks: + # - id: isort + + - repo: https://github.com/PyCQA/flake8 + rev: 7.1.0 + hooks: + - id: flake8 + additional_dependencies: + - flake8-bugbear + - flake8-docstrings + # exclude: ^src/blib2to3/ + - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 # docs https://pre-commit.com/hooks.html hooks: - id: trailing-whitespace @@ -23,10 +29,10 @@ repos: - id: check-yaml - id: debug-statements - id: check-merge-conflict - - id: double-quote-string-fixer - id: end-of-file-fixer - id: detect-private-key - id: check-toml + - repo: meta hooks: - id: check-hooks-apply diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 5dde15ceb..e69de29bb 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -1,10 +0,0 @@ - -# File configures YAPF to be used as a git hook with https://github.com/pre-commit/pre-commit - -- id: yapf - name: yapf - description: "A formatter for Python files." - entry: yapf - args: [-i, -vv] #inplace - language: python - types: [python] diff --git a/Pipfile b/Pipfile index 34a213c13..7c1be716f 100644 --- a/Pipfile +++ b/Pipfile @@ -39,7 +39,6 @@ pytest-cov = "*" coverage = "*" pytest = "*" coveralls = "*" -yapf = "*" pre-commit = "*" mkdocs = "*" mkdocs-material = "*" @@ -56,6 +55,7 @@ pytest-asyncio = "*" google-apps-meet = "*" google-auth-httplib2 = "*" google-auth-oauthlib = "*" +black = "*" [packages] django = "*" diff --git a/scripts/hooks/postinstall/install_vscode_formatter.py b/scripts/hooks/postinstall/install_vscode_formatter.py index 5f7b3929f..8c8a0c1d7 100644 --- a/scripts/hooks/postinstall/install_vscode_formatter.py +++ b/scripts/hooks/postinstall/install_vscode_formatter.py @@ -1,13 +1,13 @@ #!/bin/env python -import os import json +import os from pathlib import Path api_path = os.getcwd() -vscode_folder_path = Path(f'{api_path}/.vscode').resolve() -vscode_setting_path = Path(f'{api_path}/.vscode/settings.json').resolve() +vscode_folder_path = Path(f"{api_path}/.vscode").resolve() +vscode_setting_path = Path(f"{api_path}/.vscode/settings.json").resolve() if not os.path.isdir(vscode_folder_path): os.mkdir(vscode_folder_path) @@ -16,17 +16,30 @@ if os.path.isfile(vscode_setting_path): # import yaml - os.system(f'pipenv run python -m scripts.utils.fix_json {vscode_setting_path}') + os.system(f"pipenv run python -m scripts.utils.fix_json {vscode_setting_path}") - with open(vscode_setting_path, 'r') as vscode_setting_file: + with open(vscode_setting_path, "r") as vscode_setting_file: vscode_setting_json = json.load(vscode_setting_file) -vscode_setting_json['editor.formatOnSave'] = True -vscode_setting_json['python.formatting.provider'] = 'yapf' -bad_keys = [key for key in vscode_setting_json if key.startswith('//')] +if "python.formatting.provider" in vscode_setting_json: + del vscode_setting_json["python.formatting.provider"] + +vscode_setting_json["[python]"] = {} +vscode_setting_json["[python]"]["editor.formatOnSaveMode"] = "file" +vscode_setting_json["[python]"]["editor.formatOnSave"] = True +vscode_setting_json["[python]"]["editor.defaultFormatter"] = "ms-python.black-formatter" +vscode_setting_json["[python]"]["editor.codeActionsOnSave"] = {} +vscode_setting_json["[python]"]["editor.codeActionsOnSave"]["source.organizeImports"] = "explicit" +vscode_setting_json["isort.args"] = [ + "--profile", + "black", +] + + +bad_keys = [key for key in vscode_setting_json if key.startswith("//")] for key in bad_keys: del vscode_setting_json[key] -with open(vscode_setting_path, 'w') as vscode_setting_file: +with open(vscode_setting_path, "w") as vscode_setting_file: json.dump(vscode_setting_json, vscode_setting_file, indent=2) diff --git a/setup.cfg b/setup.cfg index 7019689c7..08e40e381 100644 --- a/setup.cfg +++ b/setup.cfg @@ -4,7 +4,8 @@ max-complexity = 20 select = F,D,C,N,B max-line-length = 120 -ignore = F403,D100,D101,D102,D103,D104,D105,D106,D107,D202,N818,S101 +; ignore = F403,D100,D101,D102,D103,D104,D105,D106,D107,D202,N818,S101 +ignore = F403,D,C,N818,S101 exclude = benchmarks/** benchmarks/*