diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..9dc163c4 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,15 @@ +exclude: '.git' +default_stages: [commit] + +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: end-of-file-fixer + - id: trailing-whitespace + - id: check-added-large-files + + - repo: https://github.com/psf/black + rev: 24.4.2 + hooks: + - id: black diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0de3761e..c2dc9f49 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,12 +27,26 @@ By contributing to RAMP, e.g. through opening a pull request or submitting a pat To contribute changes: - Fork the project on GitHub +- Follow the "Setup" steps below - Create a feature branch (e.g. named "add-this-new-feature") to work on in your fork - Add your name to the [AUTHORS](AUTHORS) file - Commit your changes to the feature branch - Push the branch to GitHub - On GitHub, create a new pull request from the feature branch +### Setup + +1. Create a virtual environment and install the dev dependencies with + + pip install -r dev_requirements.txt + +2. Install the pre-commit hooks with + + pre-commit install + + This will mainly make sure you can't commit if your code is not linted with black. + The pre-commit hook will check if your code is linted and if it is not it will simply lint it for you, you then only need to stage the changes made by the linter and commit again, as simple as that :) + ### Pull requests Before submitting a pull request, check whether you have: @@ -54,7 +68,7 @@ Please try to write clear commit messages. One-line messages are fine for small ## Testing -Testing is used by RAMP developers to make sure their new feature/bug fix is not breaking existing code. As RAMP is stochastic some tests are only qualitative, other unit tests are ran by GitHub Actions. +Testing is used by RAMP developers to make sure their new feature/bug fix is not breaking existing code. As RAMP is stochastic some tests are only qualitative, other unit tests are ran by GitHub Actions. Before running the tests locally, you need to install the testing dependencies @@ -73,7 +87,7 @@ To run the qualitative test, you'll have to run from the root level of this repository. If you already ran this script, you will be asked if you want to overwrite the results files (if you decide not to, the results are not going to be regenerated from your latest code version). You should compare the results of your code and those saved from the latest stable version thanks to the image which is displayed after the script ran. - + Ideally, the difference between reference and new results should be minimal and just due to the stochastic nature of the code. If more pronounced, it should be fully explainable based on the changes made to the code and aligned to the expectations of the developers (i.e. it should reflect a change in the output *wanted* and precisely *sought* with the commit in question). ### Unit tests @@ -82,4 +96,4 @@ Run `pytest tests/` form the root of the repository to run the unit tests. ## Attribution -The layout and content of this document is partially based on [calliope](https://github.com/calliope-project/calliope/blob/master/CONTRIBUTING.md)'s equivalent document. \ No newline at end of file +The layout and content of this document is partially based on [calliope](https://github.com/calliope-project/calliope/blob/master/CONTRIBUTING.md)'s equivalent document. diff --git a/dev_requirements.txt b/dev_requirements.txt new file mode 100644 index 00000000..d39a2e2b --- /dev/null +++ b/dev_requirements.txt @@ -0,0 +1,3 @@ +pre-commit +black==24.4.2 +-r tests/requirements.txt diff --git a/setup.py b/setup.py index f833a97a..d8dfc540 100644 --- a/setup.py +++ b/setup.py @@ -23,6 +23,7 @@ "openpyxl >= 3.0.6", "tqdm", "plotly", + "multiprocess", ], # classifiers=[ # "Programming Language :: Python :: 3.7",