generated from retaildevcrews/gh-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from retaildevcrews/nunos/python-linters-and-f…
…ormatters setting up linters and black formatter
- Loading branch information
Showing
7 changed files
with
902 additions
and
1 deletion.
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
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,4 @@ | ||
[flake8] | ||
max-line-length = 110 | ||
# ignore space before `:` since black adds space | ||
extend-ignore = E203 |
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,24 @@ | ||
# Python Development | ||
|
||
To ensure a level of code quality and best practices, this repo includes Python linters and formatter configuration. | ||
Before commiting changes to the code in this repo, make sure you execute the following steps: | ||
|
||
```bash | ||
# navigate to root of repo | ||
cd /workspaces/botify | ||
|
||
# install all required tools (only required once) | ||
poetry install | ||
|
||
# format code - this is a pre-requisite for the linting step | ||
make -f python.mk format | ||
|
||
# run linters | ||
make -f python.mk lint | ||
``` | ||
|
||
## Evaluating and fixing linter errors | ||
|
||
There are 5 steps to the linting process and in most cases, when one of the steps fails it won't progress any further. This means that after you fix all the errors, you should run the linters again because the additional steps will likely catch additional problems. | ||
|
||
In some cases, you need to override a certain rule because it may be too impractical to fix. Depending on the linter that is generating the error there are different ways of doing this through config files or code annotations. This should only be used in special cases where the cost of fixing largely surpasses the benefit (e.g: test classes). |
Large diffs are not rendered by default.
Oops, something went wrong.
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,92 @@ | ||
[tool.poetry] | ||
name = "Botify" | ||
authors = [] | ||
description = "Generative AI chatbot that leverages Azure Cloud Services, Microsoft Open-Source, and other Open-Source technologies to create a question/answer bot." | ||
version = "1.0.0" | ||
package-mode = false | ||
|
||
[tool.poetry.dependencies] | ||
python = "^3.10" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
pytest = "*" | ||
black = {extras = ["jupyter"], version = "*"} | ||
isort = "*" | ||
mypy = "*" | ||
flake8 = "*" | ||
pylint = "*" | ||
pytest-cov = "*" | ||
|
||
[tool.black] | ||
line_length = 110 | ||
|
||
[tool.isort] | ||
# vertical hanging indent | ||
multi_line_output = 3 | ||
|
||
# Includes a trailing comma on multi line imports that include parentheses | ||
include_trailing_comma = true | ||
|
||
line_length = 110 | ||
|
||
[tool.mypy] | ||
# no optional errors, since the list of optional errors may change | ||
strict = true | ||
|
||
# visually nicer output in error messages | ||
pretty = true | ||
|
||
# suppresses error messages about imports that cannot be resolved. | ||
ignore_missing_imports = true | ||
|
||
# warns about casting an expression to its inferred type. | ||
warn_redundant_casts = true | ||
|
||
# shows a warning when encountering any code inferred to be unreachable or redundant. | ||
warn_unreachable = true | ||
|
||
# allows variables to be redefined with an arbitrary type. | ||
allow_redefinition = true | ||
|
||
# disallows defining functions without type annotations or with incomplete type annotations. | ||
disallow_untyped_defs = true | ||
|
||
# this flag tells mypy that top-level packages will be based in either the current directory, or a member of the MYPYPATH. | ||
explicit_package_bases = true | ||
|
||
[tool.pylint.'MAIN'] | ||
# Discover python modules and packages in the file system subtree. | ||
recursive = true | ||
|
||
# [tool.pylint.'MESSAGES CONTROL'] | ||
disable = "C0103" | ||
|
||
[tool.pylint.'BASIC'] | ||
# Include a hint for the correct naming format with invalid-name. | ||
include-naming-hint = true | ||
|
||
# Regular expression matching correct variable names. | ||
variable-rgx = "^[a-z][a-z0-9]*(([_a-z0-9]+)*)?$" | ||
|
||
# Regular expression matching correct argument names. | ||
argument-rgx = "^[a-z][a-z0-9]*(([_a-z0-9]+)*)?$" | ||
|
||
# Defaults to ('i', 'j', 'k', 'ex', 'Run', '_') | ||
good-names = "" | ||
|
||
[tool.pylint.'FORMAT'] | ||
max-line-length = 110 | ||
|
||
[tool.pylint.'DESIGN'] | ||
# Maximum number of arguments for method | ||
max-args=10 | ||
|
||
# Maximum number of attributes for a class (see R0902). | ||
max-attributes=20 | ||
|
||
[tool.coverage.run] | ||
omit = [".*", "*/site-packages/*", "tests/*"] | ||
|
||
[tool.coverage.report] | ||
omit = ["tests/*"] | ||
fail_under = 70 |
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,16 @@ | ||
# Makefile for Poetry-managed Python projects | ||
|
||
REPO_ROOT_PATH = $(shell git rev-parse --show-toplevel 2> /dev/null) | ||
|
||
.PHONY: format lint | ||
|
||
format: | ||
poetry run black --config "$(REPO_ROOT_PATH)/pyproject.toml" . | ||
poetry run isort --config-root $(REPO_ROOT_PATH) --resolve-all-configs . | ||
|
||
lint: | ||
poetry run black --config "$(REPO_ROOT_PATH)/pyproject.toml" . --check | ||
poetry run flake8 --config $(REPO_ROOT_PATH)/.flake8 . | ||
poetry run isort --config-root $(REPO_ROOT_PATH) --resolve-all-configs --check-only --diff . | ||
poetry run pylint --rcfile $(REPO_ROOT_PATH)/pyproject.toml . | ||
poetry run mypy --config-file $(REPO_ROOT_PATH)/pyproject.toml . |