Closed AlexTheWizardL closed 4 weeks ago
Decisions on the tools and rules:
Install Flake8 and the necessary plugins for linting:
pip install flake8 flake8-import-order flake8-docstrings flake8-bugbear
Motivation: These tools help enforce coding standards, detect errors, and improve code quality.
.flake8
Configuration FileCreate a .flake8
file in the root directory of your project with the following content:
[flake8]
max-line-length = 100
ignore = D100,D101,D102,D103,D104,D105,D107,D202,D203,D204,D205,D400,D401,D402,D403,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,E203,W503
import-order-style = google
docstring-convention = google
exclude = .git,__pycache__,.pytest_cache,*.egg-info
Motivation:
If using setup.py
, add development dependencies for easy setup:
from setuptools import setup, find_packages
setup(
name="cashctrl_api",
version="0.0.1",
description="Python client for the CashCtrl REST API",
url="https://github.com/macxred/cashctrl_api",
author="Lukas Elmiger",
python_requires=">=3.9",
install_requires=["requests", "pandas"],
packages=find_packages(exclude=("tests", "examples")),
extras_require={
"dev": [
"flake8",
"flake8-import-order",
"flake8-docstrings",
"flake8-bugbear"
]
}
)
Motivation: Ensures all developers have the necessary tools for linting and quality checks.
To check your code, run:
flake8
Motivation: Runs linting checks against your codebase to identify and fix style violations and potential errors.
Here is the commit that shows code aligned with provided linter rules: cashctrl_api#3887b60
By following these steps and implementing the suggested configurations, code will adhere to the Google Python Style Guide, promoting consistency, readability, and maintainability. This setup helps ensure that all contributors follow the same coding standards, making collaboration more efficient and the codebase more reliable.
This issue includes the following steps:
Here are some examples of open-source projects that use specific packages for linting, along with the rules they employ:
### 1. **Django** **Linter**: `flake8` **Rules**: - Django uses a custom `setup.cfg` configuration file for `flake8`. - Example configuration: ```ini [flake8] max-line-length = 119 exclude = .tox,build,dist ``` ### 2. **NumPy** **Linter**: `flake8` **Plugins**: `flake8-docstrings`, `flake8-bugbear` **Rules**: - Example configuration in `setup.cfg`: ```ini [flake8] max-line-length = 88 ignore = E203, E266, E501, W503, F403, F401 select = B,C,E,F,W,T4 docstring-convention = numpy ``` ### 3. **Pandas** **Linter**: `flake8` **Plugins**: `flake8-bugbear`, `flake8-comprehensions` **Rules**: - Example configuration in `setup.cfg`: ```ini [flake8] max-line-length = 88 ignore = E203, E501, W503 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist ``` ### 4. **Scikit-learn** **Linter**: `flake8` **Plugins**: `flake8-docstrings`, `flake8-import-order` **Rules**: - Example configuration in `setup.cfg`: ```ini [flake8] max-line-length = 88 ignore = E203, E266, E501, W503 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist select = B,C,E,F,W,T4 docstring-convention = numpy [flake8:import-order] application-import-names = sklearn ``` ### 5. **Requests** **Linter**: `flake8` **Rules**: - Example configuration in `setup.cfg`: ```ini [flake8] max-line-length = 120 exclude = docs/conf.py ``` ### Summary of Common Linter Configurations: 1. **max-line-length**: Varies from 88 to 120. 2. **ignore**: Commonly ignored rules include `E203`, `E266`, `E501`, `W503`. 3. **exclude**: Often excludes directories like `.git`, `__pycache__`, `build`, `dist`, and documentation configuration files. 4. **select**: Commonly selected rules include `B` (bugbear), `C` (complexity), `E` (errors), `F` (flake8-builtins), `W` (warnings), `T4` (type annotations). ### How to Configure Your Project You can create a `setup.cfg` or `.flake8` file at the root of your project and configure it similarly to the examples provided above. Adjust the rules and plugins based on your specific project needs and coding style preferences. Here's a template you can start with: ```ini [flake8] max-line-length = 88 ignore = E203, E266, E501, W503 exclude = .git,__pycache__,docs/source/conf.py,old,build,dist select = B,C,E,F,W,T4 docstring-convention = numpy [flake8:import-order] application-import-names = your_project_name ``` ### Running `flake8` To run `flake8` with your configuration, simply execute: ```bash flake8 ```Linter should be included for the cashctrl_api and cashctrl_ledger packages