Skip to content

Commit

Permalink
changes formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Jul 4, 2024
1 parent 780d291 commit a19aecb
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 36 deletions.
8 changes: 7 additions & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 20 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
10 changes: 0 additions & 10 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pytest-cov = "*"
coverage = "*"
pytest = "*"
coveralls = "*"
yapf = "*"
pre-commit = "*"
mkdocs = "*"
mkdocs-material = "*"
Expand All @@ -56,6 +55,7 @@ pytest-asyncio = "*"
google-apps-meet = "*"
google-auth-httplib2 = "*"
google-auth-oauthlib = "*"
black = "*"

[packages]
django = "*"
Expand Down
31 changes: 22 additions & 9 deletions scripts/hooks/postinstall/install_vscode_formatter.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down

0 comments on commit a19aecb

Please sign in to comment.