Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit #19

Merged
merged 2 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 0 additions & 124 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,129 +1,5 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
124 changes: 124 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
repos:
# Prevent commits to the main branch.
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: no-commit-to-branch
name: ensure we are not committing to branch `main`
args:
- --branch=main

# Make sure all imports are absolute in Python files.
- repo: https://github.com/MarcoGorelli/absolufy-imports
rev: v0.3.1
hooks:
- id: absolufy-imports
name: format Python imports using absolufy-imports

# Sort Python imports using `isort`.
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: sort Python imports using isort
args:
- --force-grid-wrap=0
- --line-length=100
- --multi-line=3
- --overwrite-in-place
- --profile=black
- --trailing-comma
- --use-parentheses

# Remove unused `# noqa` comments
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa

# Remove all unused imports for Python files.
- repo: https://github.com/hadialqattan/pycln
rev: v2.1.5
hooks:
- id: pycln
name: remove unused Python imports using pycln

# Python formatting
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
name: format Python code using black
args:
- --line-length=100
- --verbose

# Lint Python files using `ruff`.
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.275
hooks:
- id: ruff
name: lint Python using ruff
args:
- --diff
- --line-length=100
- --respect-gitignore
- --verbose

# Markdown formatting
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.16
hooks:
- id: mdformat
name: format Markdown using mdformat
args:
- --wrap=100
additional_dependencies:
- mdformat-myst==0.1.5
- mdformat_tables==0.4.1
- mdformat-frontmatter==2.0.1

# YAML formatting
- repo: https://github.com/lyz-code/yamlfix
rev: 1.11.0
hooks:
- id: yamlfix
name: format YAML using yamlfix
args:
- ./

# TOML formatting
- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.0
hooks:
- id: taplo
name: format TOML using taplo
args:
- format
- --config=.taplo.toml

# Check docstrings are formatted correctly
- repo: https://github.com/jsh9/pydoclint
rev: 0.0.13
hooks:
- id: pydoclint
args:
- --config=pyproject.toml

# Run `flake8` on Python files.
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
name: inspect Python code using flake8
args:
- --verbose
additional_dependencies:
- flake8-annotations==3.0.1
- flake8-builtins==2.1.0
- flake8-debugger==4.1.2
- flake8-docstrings==1.7.0
- flake8-eradicate==1.5.0
- flake8-markdown==0.4.0
- flake8-print==5.0.0
- flake8-pyproject==1.2.3
17 changes: 17 additions & 0 deletions .taplo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[formatting]
align_comments = false
align_entries = false
allowed_blank_lines = 2
array_auto_collapse = true
array_auto_expand = true
array_trailing_comma = true
column_width = 88
compact_arrays = true
compact_entries = false
compact_inline_tables = true
crlf = false
indent_entries = false
indent_string = " "
indent_tables = false
reorder_keys = true
trailing_newline = true
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ cd arviz_dashboard
pip install --editable .[dev,examples]
```

Once the package has been installed, we need to install the `pre-commit` hooks used for maintaining
code hygiene. Run the following commands to set up the required `pre-commit` hooks for development.

```bash
pre-commit install
```

When you commit your changes to your branch, `pre-commit` will install the tools defined in the
config file, and check give feedback about required changes in order for the push to pass linting
and formatting tests.

If you add a new hook to the `.pre-commit-config.yaml` file, run the following command in order to
check if you hook is working against all the files.

```bash
pre-commit run --all-files
```

### Contributor installation test

TBD
Expand Down
78 changes: 39 additions & 39 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,58 +29,58 @@ readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">3.9"

[project.optional-dependencies]
dev = [
# Automation
"pre-commit",

# Python code formatting
"absolufy-imports", # use only absolute imports, no `from .module import method`
"black", # code formatting
"isort", # sort imports

# Python code linting
"flake8",
"flake8-builtins", # ensure python builtins are not used as variables
"flake8-debugger", # remove ipdb or pdb statements
"flake8-eradicate", # remove unused code
"flake8-docstrings", # ensure docstrings exist
"Flake8-pyproject", # allow configs for flake8 in the pyproject.toml file
"pycln", # remove unused import statements
"ruff", # lint python code

# Python code testing
"pytest",
"pytest-cov",

# Python type checking
"pyre-check",

# Python docstring style checking
"pydocstyle",

# Markdown code formatting
"mdformat",
"mdformat-myst",
]
dev = ["pre-commit"]
examples = ["pymc"]

[project.urls]
"Bug Tracker" = "https://github.com/arviz-devs/arviz_dashboard/issues"
"Documentation" = "https://github.com/arviz-devs/arviz_dashboard"
"Homepage" = "https://github.com/arviz-devs/arviz_dashboard"
"Source Code" = "https://github.com/arviz-devs/arviz_dashboard"
"Repository" = "https://github.com/arviz-devs/arviz_dashboard"

[tool.hatch.version]
path = "src/arviz_dashboard/__init__.py"

[tool.flake8]
ignore = ["D100"]
max-line-length = 100
per-file-ignores = ["__init__.py:D104"]

[tool.isort]
force_grid_wrap = 0
include_trailing_comma = true
line_length = 100
multi_line_output = 3
profile = "black"
use_parentheses = true

[tool.black]
line-length = 100

[tool.ruff]
line-length = 100
per-file-ignores = {"__init__.py" = ["F401"]}

[tool.pycln]
all = true
disable_all_dunder_policy = true
expand_stars = true
extend_exclude = "__init__.py"
path = "src/arviz_dashboard"
verbose = true

[tool.yamlfix]
explicit_start = false
line_length = 100
section_whitelines = 1
sequence_style = "block_style"
whitelines = 1

[tool.flake8]
ignore = [
"ANN002", # missing type annotations for *args
"ANN003", # missing type annotations for *kwargs
"D100", # missing docstring in public module
"D104", # missing docstring in public package
"D107", # missing docstring in __init__ methods of classes
]
max-line-length = 100
per-file-ignores = ["__init__.py:F401"]

[tool.pydoclint]
style = "numpy"