Skip to content

Commit c698adb

Browse files
authored
Merge pull request #17 from pymor/precommit
Pre-commit setup and formatting/linting fixups
2 parents 5b5add1 + e869c08 commit c698adb

File tree

20 files changed

+498
-278
lines changed

20 files changed

+498
-278
lines changed

.ci/make_env_file.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import os
44
from os.path import expanduser
55
from shlex import quote
6+
67
home = expanduser("~")
78

8-
prefixes = os.environ.get('ENV_PREFIXES', 'TRAVIS CI encrypt TOKEN TESTS').split(' ')
9-
blacklist = ['TRAVIS_COMMIT_MESSAGE']
10-
env_file = os.environ.get('ENV_FILE', os.path.join(home, 'env'))
11-
with open(env_file, 'wt') as env:
12-
for k,v in os.environ.items():
9+
prefixes = os.environ.get("ENV_PREFIXES", "TRAVIS CI encrypt TOKEN TESTS").split(" ")
10+
blacklist = ["TRAVIS_COMMIT_MESSAGE"]
11+
env_file = os.environ.get("ENV_FILE", os.path.join(home, "env"))
12+
with open(env_file, "wt") as env:
13+
for k, v in os.environ.items():
1314
for pref in prefixes:
1415
if k.startswith(pref) and k not in blacklist:
15-
env.write('{}={}\n'.format(k,quote(v)))
16+
env.write("{}={}\n".format(k, quote(v)))

.clang-format

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
AlignAfterOpenBracket: true
2+
AlignConsecutiveAssignments: false
3+
AlignEscapedNewlines: Right
4+
AlignOperands: true
5+
AlignTrailingComments: false
6+
AllowAllParametersOfDeclarationOnNextLine: true
7+
AllowShortBlocksOnASingleLine: false
8+
AllowShortCaseLabelsOnASingleLine: false
9+
AllowShortFunctionsOnASingleLine: Empty
10+
AllowShortIfStatementsOnASingleLine: false
11+
AllowShortLoopsOnASingleLine: false
12+
AlwaysBreakAfterDefinitionReturnType: None
13+
AlwaysBreakAfterReturnType: None
14+
AlwaysBreakBeforeMultilineStrings: false
15+
AlwaysBreakTemplateDeclarations: true
16+
BasedOnStyle: Mozilla
17+
BinPackArguments: false
18+
BinPackParameters: false
19+
BreakBeforeBinaryOperators: NonAssignment
20+
BraceWrapping:
21+
SplitEmptyFunction: false
22+
SplitEmptyRecord: false
23+
BreakBeforeTernaryOperators: true
24+
BreakConstructorInitializers: BeforeComma
25+
ColumnLimit: 120
26+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
27+
ConstructorInitializerIndentWidth: 2
28+
ContinuationIndentWidth: 4
29+
Cpp11BracedListStyle: true
30+
DerivePointerAlignment: false
31+
ExperimentalAutoDetectBinPacking: false
32+
FixNamespaceComments: true
33+
IndentCaseLabels: true
34+
IndentPPDirectives: AfterHash
35+
IndentWidth: 2
36+
IndentWrappedFunctionNames: false
37+
KeepEmptyLinesAtTheStartOfBlocks: true
38+
Language: Cpp
39+
MaxEmptyLinesToKeep: 2
40+
NamespaceIndentation: None
41+
PenaltyBreakComment: 60
42+
PenaltyBreakFirstLessLess: 120
43+
PenaltyBreakString: 1000
44+
PenaltyExcessCharacter: 1000000
45+
PenaltyReturnTypeOnItsOwnLine: 60
46+
PointerAlignment: Left
47+
SortIncludes: false
48+
SpaceAfterCStyleCast: false
49+
SpaceAfterTemplateKeyword: true
50+
SpaceBeforeAssignmentOperators: true
51+
SpaceBeforeParens: ControlStatements
52+
SpaceInEmptyParentheses: false
53+
SpacesBeforeTrailingComments: 1
54+
SpacesInAngles: false
55+
SpacesInCStyleCastParentheses: false
56+
SpacesInParentheses: false
57+
SpacesInSquareBrackets: false
58+
Standard: Cpp11
59+
TabWidth: 2
60+
UseTab: Never

.github/workflows/autosquash_check.yml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
1-
# homepage: https://github.com/gaurav-nelson/github-action-markdown-link-check
2-
name: Check Markdown links
3-
41
on: [pull_request]
52

3+
name: Checks
4+
65
jobs:
7-
markdown-link-check:
6+
git:
7+
name: Block Autosquash Commits
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Block Autosquash Commits
11+
uses: xt0rted/block-autosquash-commits-action@v2
12+
with:
13+
repo-token: ${{ secrets.GITHUB_TOKEN }}
14+
source:
815
runs-on: ubuntu-latest
916
steps:
1017
- uses: actions/checkout@v2
1118
- name: markdown-link-check
1219
uses: gaurav-nelson/[email protected]
13-
1420
with:
1521
use-verbose-mode: 'yes'
1622
check-modified-files-only: 'yes'
1723
base-branch: 'main'
24+
- uses: pre-commit/[email protected]

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/lib/CMakeLists.txt.user
22
build
33
CMakeLists.txt.user
4+
.idea

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v3.2.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: check-yaml
9+
- id: check-added-large-files
10+
- id: debug-statements
11+
- repo: https://github.com/psf/black
12+
rev: 21.11b0
13+
hooks:
14+
- id: black
15+
- repo: https://github.com/pycqa/flake8
16+
rev: 3.9.2
17+
hooks:
18+
- id: flake8
19+
exclude: "^(versioneer.py|src/pymor_dealii/version.py)"
20+
- repo: https://github.com/pre-commit/mirrors-clang-format
21+
rev: 'v13.0.0'
22+
hooks:
23+
- id: clang-format
24+
exclude: "^lib/pybind11"

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Requirements
2+
============
3+
4+
`deal.II` with development headers
5+
6+
Usage
7+
=====
8+
9+
```
10+
git clone --recurse-submodules https://github.com/pymor/pymor-deal.II
11+
cd pymor-deal.II
12+
python -m pip install pymor
13+
python -m pip install -e .
14+
python test/demo.py
15+
```
16+
17+
18+
Development notes
19+
=================
20+
21+
We have a `pre-commit` config that is also run/checked in CI.
22+
Python source is formatted with `black`.
23+
C++ source is formatted with `clang-format`.

lib/bindings.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
33
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
44

5-
65
#include <deal.II/lac/dynamic_sparsity_pattern.h>
76
#include <deal.II/lac/precondition.h>
87
#include <deal.II/lac/solver_cg.h>
@@ -145,7 +144,7 @@ void bind_sparse_matrix(pybind11::module& module) {
145144
.def("vmult", &Matrix::template vmult<Vector, Vector>)
146145
.def("Tvmult", &Matrix::template Tvmult<Vector, Vector>)
147146
.def("get_sparsity_pattern", &Matrix::get_sparsity_pattern, py::return_value_policy::reference)
148-
.def("add", (void (Matrix::*)(Number, const Matrix&)) & Matrix::template add<Number>)
147+
.def("add", (void(Matrix::*)(Number, const Matrix&)) & Matrix::template add<Number>)
149148
.def("copy_from", (Matrix & (Matrix::*)(const Matrix&)) & Matrix::template copy_from<Number>)
150149
.def("cg_solve", cg_solve);
151150
}

lib/rhs.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ inline void RightHandSide<dim>::vector_value(const Point<dim>& p, Vector<double>
9898
// If now the point <code>p</code> is in a circle (sphere) of radius 0.2
9999
// around one of these points, then set the force in x-direction to one,
100100
// otherwise to zero:
101-
if ((static_cast<Point<dim>>(p - point_1).square() < 0.2 * 0.2)
102-
|| (static_cast<Point<dim>>(p - point_2).norm_square() < 0.2 * 0.2))
101+
if ((static_cast<Point<dim>>(p - point_1).square() < 0.2 * 0.2) ||
102+
(static_cast<Point<dim>>(p - point_2).norm_square() < 0.2 * 0.2))
103103
values(0) = 1;
104104
else
105105
values(0) = 0;

lib/test_bindings.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright 2013-2018 pyMOR developers and contributors. All rights reserved.
33
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
44

5-
import pytest
65
import numpy as np
76
import pydealii_bindings as dealii
87

8+
99
def test_vector():
1010
v = dealii.Vector(10)
1111
u = dealii.Vector(10)
@@ -38,9 +38,10 @@ def test_vector():
3838
ddones[:] = np.ones((100,), np.double)
3939
npdd = np.array(ddones, copy=False)
4040
assert np.allclose(npdd, np.ones((100,), dtype=np.double))
41-
npdd += 1.
42-
ddones /= 2.
41+
npdd += 1.0
42+
ddones /= 2.0
4343
assert np.allclose(npdd, ddones)
4444

45+
4546
if __name__ == "__main__":
4647
test_vector()

0 commit comments

Comments
 (0)