Skip to content

Commit

Permalink
Merge pull request #76 from oemof/feature/pre-commit
Browse files Browse the repository at this point in the history
Add pre-commit
  • Loading branch information
jnnr committed Jan 9, 2023
2 parents 554dc88 + 3148f68 commit 9c41e03
Show file tree
Hide file tree
Showing 27 changed files with 296 additions and 262 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install .[aggregation] # install extra requirement to pass all tests
python -m pip install pytest coverage docutils check-manifest flake8 readme-renderer pygments isort
python -m pip install pytest coverage docutils check-manifest flake8 readme-renderer pygments isort black
- name: Test with pytest
run: |
Expand All @@ -54,5 +54,6 @@ jobs:
run: |
python setup.py check --strict --metadata --restructuredtext
check-manifest .
black --check .
flake8 src tests
isort --verbose --check-only --diff src tests
36 changes: 36 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
exclude: 'docs|node_modules|migrations|.git|.tox'
default_stages: [commit]
fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
files: (^|/)a/.+\.(py|html|sh|css|js)$

- repo: local
hooks:
- id: flake8
name: flake8
entry: flake8
language: python
types: [python]
args: ["src", "tests"]

- repo: local
hooks:
- id: isort
name: isort
entry: isort
language: python
types: [python]
args: ["--verbose", "src", "tests"]

- repo: local
hooks:
- id: black
name: black
entry: black
language: python
types: [python]
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ graft tests
include .coveragerc
include .cookiecutterrc
include .editorconfig
include .pre-commit-config.yaml
include punch_config.py
include punch_version.py
include pytest.ini
Expand Down
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,16 @@ https://oemof-tabular.readthedocs.io/
Development
===========

To run the all tests run::
Please activate pre-commit hooks in order to follow our coding styles:

::

pip install pre-commit
pre-commit install

To run the all tests run:

::

pytest

Expand Down
23 changes: 13 additions & 10 deletions punch_config.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
__config_version__ = 1

GLOBALS = {
'serializer': '{{major}}.{{minor}}.{{patch}}{{status if status}}',
"serializer": "{{major}}.{{minor}}.{{patch}}{{status if status}}",
}

FILES = [{ 'path': 'README.rst',
'serializer': '{{major}}.{{minor}}.{{patch}}'},
'docs/conf.py', 'setup.py',
'src/oemof/tabular/__init__.py']

VERSION = ['major', 'minor', 'patch',
{'name': 'status',
'type': 'value_list',
'allowed_values': ['', 'dev']}]
FILES = [
{"path": "README.rst", "serializer": "{{major}}.{{minor}}.{{patch}}"},
"docs/conf.py",
"setup.py",
"src/oemof/tabular/__init__.py",
]

VERSION = [
"major",
"minor",
"patch",
{"name": "status", "type": "value_list", "allowed_values": ["", "dev"]},
]
2 changes: 1 addition & 1 deletion punch_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
major = 0
minor = 0
patch = 2
status = 'dev'
status = "dev"
30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.black]
exclude = '''
/(
\
|
\.eggs
| \.git
| \.mypy_cache
| meta/migrations
| docs
| .venv
| venv
| .ipynb
| \.direnv
| \.hg
| \.mypy_cache
| \.nox
| \.tox
\.svn
| _build
| buck-out
| build
| dist
| docs
)/
'''
line-length=79

[tool.isort]
profile = "black"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ universal = 1
[flake8]
ignore = W391, W503, W504, E203
max-line-length = 79
exclude = */migrations/*
exclude = */migrations/*,./setup.py

[tool:pytest]
norecursedirs =
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def read(*names, **kwargs):
"toml",
],
extras_require={
'cli': ['click'],
'plots': ['plotly', 'matplotlib'],
'aggregation': ['tsam'],
'geometry': ['shapely', 'scipy', 'pyproj', 'geojson', 'pyshp'],
"cli": ["click"],
"plots": ["plotly", "matplotlib"],
"aggregation": ["tsam"],
"geometry": ["shapely", "scipy", "pyproj", "geojson", "pyshp"],
},
entry_points={"console_scripts": ["ota = oemof.tabular.cli:main"]},
)
7 changes: 2 additions & 5 deletions src/oemof/tabular/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ def update(d, u):
class Scenario(dict):
@classmethod
def from_path(cls, path):
scenarios[path] = cls(
building.read_build_config(path)
)
scenarios[path] = cls(building.read_build_config(path))
if "name" in scenarios[path]:
name = scenarios[path]["name"]
scenarios[name] = scenarios[path]
Expand All @@ -58,8 +56,7 @@ def __init__(self, *args, **kwargs):


def _test(ctx, package):
"""
"""
""" """
p = Package(package)
for r in p.resources:
try:
Expand Down
5 changes: 2 additions & 3 deletions src/oemof/tabular/config/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import json
import os
import pathlib
Expand All @@ -7,14 +6,14 @@

FOREIGN_KEYS_FILE = os.environ.get(
"OEMOF_TABULAR_FOREIGN_KEYS_FILE",
pathlib.Path(CONFIG_FOLDER, "foreign_keys.json")
pathlib.Path(CONFIG_FOLDER, "foreign_keys.json"),
)
with open(FOREIGN_KEYS_FILE, "r") as fk_file:
FOREIGN_KEYS = json.load(fk_file)

FOREIGN_KEY_DESCRIPTORS_FILE = os.environ.get(
"OEMOF_TABULAR_FOREIGN_KEY_DESCRIPTORS_FILE",
CONFIG_FOLDER / "foreign_key_descriptors.json"
CONFIG_FOLDER / "foreign_key_descriptors.json",
)
with open(FOREIGN_KEY_DESCRIPTORS_FILE, "r") as fk_descriptors_file:
FOREIGN_KEY_DESCRIPTORS = json.load(fk_descriptors_file)
6 changes: 3 additions & 3 deletions src/oemof/tabular/datapackage/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import os
import re

from datapackage import Package, Resource
import pandas as pd
from datapackage import Package, Resource

try:
import tsam.timeseriesaggregation as tsam
Expand All @@ -19,7 +19,7 @@


def temporal_skip(datapackage, n, path="/tmp", name=None, *args):
""" Creates a new datapackage by aggregating sequences inside the
"""Creates a new datapackage by aggregating sequences inside the
`sequence` folder of the specified datapackage by skipping `n` timesteps
Parameters
Expand Down Expand Up @@ -106,7 +106,7 @@ def temporal_skip(datapackage, n, path="/tmp", name=None, *args):


def temporal_clustering(datapackage, n, path="/tmp", how="daily"):
""" Creates a new datapackage by aggregating sequences inside the
"""Creates a new datapackage by aggregating sequences inside the
`sequence` folder of the specified datapackage by clustering `n` timesteps
Parameters
Expand Down

0 comments on commit 9c41e03

Please sign in to comment.