From 391826727e659c3310b490f242e564844f1374ca Mon Sep 17 00:00:00 2001 From: Juan Orduz Date: Mon, 5 Feb 2024 18:27:57 +0100 Subject: [PATCH] Improve CONTRIBUTING guidelines (#141) * improve local development description * add comment about pre-commit fix --- .pre-commit-config.yaml | 2 +- CONTRIBUTING.md | 58 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0962c42..11f3d58 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: mypy args: [--ignore-missing-imports] files: ^pymc_bart/ - additional_dependencies: [numpy<1.25.0, pandas-stubs] + additional_dependencies: [numpy<1.25.0, pandas-stubs==1.5.3.230304] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v3.2.0 hooks: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 399b154..bc20b83 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,6 +15,16 @@ Thanks for your interest in contributing code to pymc_bart! **If this is your first time contributing to a project on GitHub, please read through our step by step guide to contributing to pymc_bart** +### Local Development + +0. Create a virtual environment (optional, but strongly recommended) + +1. Install the library in editable mode + +```bash +pip install -e . +``` + ### Feature Branch 1. From the fork of the pymc_bart repository, create a new branch for your feature. @@ -42,8 +52,6 @@ git push origin feature_branch_name The repository has some code style checks in place. This will happen on every commit of a pull request. If you want to run the checks locally, you can do so by running the following command from the root of the repository: -0. Create a virtual environment (optional, but strongly recommended) - 1. Install pre-commit ```bash @@ -70,13 +78,57 @@ pre-commit run --all-files **Once you commit something the pre-commit hook will run all the checks**! +In particular, if the commited changed have linting errors, the commit will try to fix them. If successful,you need to add the changes again (for example, `git add -u`) and commit again. If not successful, you need to fix the errors manually and commit again. + You can skip this (for example when is WIP) by adding a flag (`-n` means no-verify) ```bash git commit -m"my message" -n ``` -**Remark:** One can, of course, install `ruff` in the Python environment to enable auto-format (for example in VS Code), but this is not strictly necessary. The specific versions of` ruff` and `mypy` must be only specified in `.pre-commit-config.yaml`. It should be the only source of truth! Hence, if you want to install them locally make sure you use the same versions (revisions `rev` in the config file) as in the config file. +### Pre-Commit Components + +One can, of course, install `ruff` in the Python environment to enable auto-format (for example in VS Code), but this is not strictly necessary. The specific versions of` ruff` and `mypy` must be only specified in [`.pre-commit-config.yaml`](.pre-commit-config.yaml). It should be the only source of truth! Hence, if you want to install them locally make sure you use the same versions (revisions `rev` in the config file) as in the config file. + +#### Ruff + +Once installed locally as + +``` +pip install ruff== +``` + +You can check the lint as + +```bash +ruff . --no-fix +``` + +You can allow `ruff` to fix the code by using the flag: + +```bash +ruff . --fix +``` + +#### MyPy + +We use `mypy` to check the type annotations. Once installed locally as + +```bash +pip install mypy== +``` + +You also need the `pandas-stubs` library with the version specified in the [`.pre-commit-config.yaml`](.pre-commit-config.yaml) file. + +```bash +pip install pandas-stubs== +``` + +Now, you can check the type annotations as + +```bash +mypy pymc_bart/. +``` ### Adding new features If you are interested in adding a new feature to pymc_bart,