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 for formatting, liniting and code checking. #302

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
6 changes: 3 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: PyPSA Mailing List
url: https://groups.google.com/forum/#!forum/pypsa
about: Please ask and answer general usage questions here.
- name: PyPSA Mailing List
url: https://groups.google.com/forum/#!forum/pypsa
about: Please ask and answer general usage questions here.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
branches:
- master
schedule:
- cron: "0 5 * * TUE"
- cron: "0 5 * * TUE"

jobs:
build:
Expand All @@ -35,18 +35,18 @@ jobs:
- uses: actions/checkout@v2

- name: Setup Miniconda
uses: conda-incubator/setup-miniconda@v2.1.1
uses: conda-incubator/setup-miniconda@v2.1.1
with: # checks out environment 'test' by default
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true
mamba-version: "*"
channels: conda-forge,defaults
channel-priority: true

- name: Install dependencies
- name: Install dependencies
run: |
echo -ne "url: ${CDSAPI_URL}\nkey: ${CDSAPI_TOKEN}\n" > ~/.cdsapirc
echo -e " - glpk\n - ipopt<3.13.3" >> envs/environment.yaml
echo -e "- glpk\n- ipopt<3.13.3" >> envs/environment.yaml
mamba env update -f envs/environment.yaml --name test

- name: Test snakemake workflow
run: |
conda list
Expand Down
67 changes: 67 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# SPDX-FileCopyrightText: : 2022 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: CC0-1.0

exclude: "^LICENSES"

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: mixed-line-ending
- id: check-added-large-files
args: ['--maxkb=2000']

# Sort package imports alphabetically
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]

# Find common spelling mistakes in comments and docstrings
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
hooks:
- id: codespell
args: ['--ignore-regex="\b[A-Z]+\b"'] # Ignore capital case words, e.g. country codes
types_or: [python, rst, markdown]
files: ^(scripts|doc)/

# Formatting with "black" coding style
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
# Format Python files
- id: black
# Format Jupyter Python notebooks
- id: black-jupyter

# Do YAML formatting (before the linter checks it for misses)
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.2.0
hooks:
- id: pretty-format-yaml
args: [--autofix, --indent, '2', --preserve-quotes]

# Use yamllint to check for valid YAML files and list syntax errors
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.26.3
hooks:
- id: yamllint
args: [--format, parsable, -c=.yamllint]

# Format Snakemake rule / workflow files
- repo: https://github.com/snakemake/snakefmt
rev: 0.4.4
hooks:
- id: snakefmt

# Check for FSFE REUSE compliance (licensing)
- repo: https://github.com/fsfe/reuse-tool
rev: v0.14.0
hooks:
- id: reuse
2 changes: 1 addition & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ version: 2
python:
version: 3.8
install:
- requirements: doc/requirements.txt
- requirements: doc/requirements.txt
system_packages: true
2 changes: 1 addition & 1 deletion .syncignore-receive
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ notebooks
doc
cutouts
data/bundle
*.nc
*.nc
39 changes: 39 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: : 2022 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: CC0-1.0

# Configuration is based on and overwrites 'default' configuration
extends: default

rules:
braces:
# Do not allow flow mappings using curly braces "{" and "}"
forbid: true
brackets:
max-spaces-inside: 0
max-spaces-inside-empty: 0
comments:
require-starting-space: true
min-spaces-from-content: 1
# Force correct indentation of comments
# yamllint disable-line rule:braces
comments-indentation: {}
# Do not require a specific document start marker
document-start: disable
document-end: disable
empty-lines:
max: 3
max-end: 0
indentation:
spaces: consistent
# Consistent indent-sequences clash with environment.yaml exported by conda
indent-sequences: whatever
# Disallow duplicate keys in listings
# yamllint disable-line rule:braces
key-duplicates: {}
line-length:
level: warning
max: 88
new-line-at-end-of-file: enable
truthy:
check-keys: false # Disable truthy check hits on keys like "on": ...
Loading