diff --git a/.flake8 b/.flake8 deleted file mode 100644 index b37ae0f2..00000000 --- a/.flake8 +++ /dev/null @@ -1,5 +0,0 @@ -[flake8] -max-line-length = 119 -ignore = E261, W503 -exclude = Snakefile, *.smk -builtins = snakemake # for using the snakemake injection in scripts diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..01a342f2 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,17 @@ +# See https://pre-commit.com for more information +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + # See https://pre-commit.com/hooks + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-added-large-files +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.2 + hooks: + # Run the linter. + - id: ruff + args: [--fix] + # Run the formatter. + - id: ruff-format diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000..822dffca --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,36 @@ +line-length = 88 +preview = true # required to activate many pycodestyle errors and warnings as of 2024-03-13 +builtins = ["snakemake"] + +[format] +quote-style = "double" +indent-style = "space" +docstring-code-format = false +line-ending = "auto" + +[lint] +select = [ + # pycodestyle errors + "E", + # pycodestyle warnings + "W", + # Pyflakes + "F", + # pyupgrade + "UP", + # flake8-bugbear + "B", + # flake8-simplify + "SIM", + # isort + "I", +] +ignore = [ + # here and below, rules are redundant with formatter, see + # https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules + "E501", + "W191", + "E111", + "E114", + "E117", +] diff --git a/CHANGELOG.md b/CHANGELOG.md index 10981e98..785f5725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Added (workflow) +* **ADD** Ruff as our default linter and formatter (#285). * **ADD** DAG rule that generates a visualisation of Snakemake's directed acyclic graph (#208). * **ADD** IPython debugger to all conda environments to ease debugging (#254). * **ADD** a default Snakemake profile to run on local machines in addition to the existing profile for Euler (#211). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7037fc1..ccecdb51 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,7 +11,10 @@ If you have found a bug in Euro-Calliope or you want to propose a new feature, p We welcome changes that you provide as [a pull request](https://github.com/calliope-project/euro-calliope/pulls). -If you consider doing that, you need to know our branching model -- that is, which branches exist and what meaning they have. +If you consider doing that, you need to know two things: our code guidelines and our branching model. +Our code guidelines are implemented through automatic linting (code analysis) and formatting. For both, we employ the tool [Ruff](https://docs.astral.sh/ruff/). It is open-source and available as a [plug-in to many IDEs](https://docs.astral.sh/ruff/integrations/). All you need is to install the plug-in for your IDE and then you should see linting problems and you will be able to format the code automatically based on our guidelines. If you want more, you can use a [Git pre-commit-hook](https://pre-commit.com) but that step is optional. + +Next, let's talk about our branching model -- that is, which branches exist and what meaning they have. Do not worry, it is easy. Our branching model is a simplified version of _git-flow_. We are giving you a summary here that is likely sufficient for you. If you want more information, read the [blog entry](https://nvie.com/posts/a-successful-git-branching-model/) introducing git-flow.