Skip to content

Commit 12cbcff

Browse files
Merge pull request #2702 from pybamm-team/pre-commit
2 parents a48b28f + 32c2648 commit 12cbcff

File tree

8 files changed

+36
-72
lines changed

8 files changed

+36
-72
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ Please add a line in the relevant section of [CHANGELOG.md](https://github.com/p
1414

1515
# Key checklist:
1616

17-
- [ ] No style issues: `$ pre-commit run`
18-
- [ ] All tests pass: `$ python run-tests.py --unit`
19-
- [ ] The documentation builds: `$ cd docs` and then `$ make clean; make html`
17+
- [ ] No style issues: `$ pre-commit run` (see [CONTRIBUTING.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) for how to set this up to run automatically when committing locally, in just two lines of code)
18+
- [ ] All tests pass: `$ python run-tests.py --all`
19+
- [ ] The documentation builds: `$ python run-tests.py --doctest`
2020

21-
You can run all three at once, using `$ python run-tests.py --quick`.
21+
You can run unit and doctests together at once, using `$ python run-tests.py --quick`.
2222

2323
## Further checks:
2424

.pre-commit-config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ ci:
33
autofix_commit_msg: "style: pre-commit fixes"
44

55
repos:
6-
- repo: https://github.com/pre-commit/mirrors-prettier
7-
rev: v3.0.0-alpha.4
8-
hooks:
9-
- id: prettier
10-
exclude: assets/js/webapp\.js
11-
126
- repo: https://github.com/psf/black
137
rev: 23.1.0
148
hooks:

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Finally, if you really, really, _really_ love developing PyBaMM, have a look at
6161

6262
## Coding style guidelines
6363

64-
PyBaMM follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-0008/) for coding style. These are very common guidelines, and community tools have been developed to check how well projects implement them. We recommend using pre-commit hooks to check your code before committing it. See [installing and using pre-commit](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) section for more details.
64+
PyBaMM follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-0008/) for coding style. These are very common guidelines, and community tools have been developed to check how well projects implement them. We recommend using pre-commit hooks to check your code before committing it. See [installing and using pre-commit](#installing-and-using-pre-commit) section for more details.
6565

6666
### Ruff
6767

@@ -307,7 +307,7 @@ PyBaMM is documented in several ways.
307307

308308
First and foremost, every method and every class should have a [docstring](https://www.python.org/dev/peps/pep-0257/) that describes in plain terms what it does, and what the expected input and output is.
309309

310-
These docstrings can be fairly simple, but can also make use of [reStructuredText](http://docutils.sourceforge.net/docs/user/rst/quickref.html), a markup language designed specifically for writing [technical documentation](https://en.wikipedia.org/wiki/ReStructuredText). For example, you can link to other classes and methods by writing ``:class:`pybamm.Model` `` and ``:meth:`run()` ``.
310+
These docstrings can be fairly simple, but can also make use of [reStructuredText](http://docutils.sourceforge.net/docs/user/rst/quickref.html), a markup language designed specifically for writing [technical documentation](https://en.wikipedia.org/wiki/ReStructuredText). For example, you can link to other classes and methods by writing `` :class:`pybamm.Model` `` and `` :meth:`run()` ``.
311311

312312
In addition, we write a (very) small bit of documentation in separate reStructuredText files in the `docs` directory. Most of what these files do is simply import docstrings from the source code. But they also do things like add tables and indexes. If you've added a new class to a module, search the `docs` directory for that module's `.rst` file and add your class (in alphabetical order) to its index. If you've added a whole new module, copy-paste another module's file and add a link to your new file in the appropriate `index.rst` file.
313313

docs/source/user_guide/installation/GNU-linux.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,6 @@ not being used when I run my Python script.
197197
i.e. ``pip install -e .``. This sets the installed location of the
198198
source files to your current directory.
199199

200-
**Problem:** When running ``python run-tests.py --quick``, gives error
201-
``FileNotFoundError: [Errno 2] No such file or directory: 'flake8': 'flake8``.
202-
203-
**Solution:** make sure you have included the ``[dev,docs]`` flags when
204-
you pip installed PyBaMM, i.e. ``pip install -e .[dev,docs]``
205-
206200
**Problem:** Errors when solving model
207201
``ValueError: Integrator name ida does not exsist``, or
208202
``ValueError: Integrator name cvode does not exsist``.

docs/source/user_guide/installation/install-from-source.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Using Tox (recommended)
130130
131131
132132
This creates a virtual environment ``.tox/dev`` (or ``windows-dev``) inside the ``PyBaMM/`` directory.
133-
It comes ready with PyBaMM and some useful development tools like `flake8 <https://flake8.pycqa.org/en/latest/>`_ and `black <https://black.readthedocs.io/en/stable/>`_.
133+
It comes ready with PyBaMM and some useful development tools like `pre-commit <https://pre-commit.com/>`_ and `black <https://black.readthedocs.io/en/stable/>`_.
134134

135135
You can now activate the environment with
136136

@@ -228,7 +228,6 @@ Doctests, examples, style and coverage
228228
--------------------------------------
229229

230230
- ``tox -e examples``: Run the example scripts in ``examples/scripts``.
231-
- ``tox -e flake8``: Check for PEP8 compliance.
232231
- ``tox -e doctests``: Run doctests.
233232
- ``tox -e coverage``: Measure current test coverage.
234233

run-tests.py

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,6 @@ def run_code_tests(executable=False, folder: str = "unit", interpreter="python")
5858
sys.exit(ret)
5959

6060

61-
def run_flake8():
62-
"""
63-
Runs flake8 in a subprocess, exits if it doesn't finish.
64-
"""
65-
print("Running flake8 ... ")
66-
sys.stdout.flush()
67-
p = subprocess.Popen(["flake8"], stderr=subprocess.PIPE)
68-
try:
69-
ret = p.wait()
70-
except KeyboardInterrupt:
71-
try:
72-
p.terminate()
73-
except OSError:
74-
pass
75-
p.wait()
76-
print("")
77-
sys.exit(1)
78-
if ret == 0:
79-
print("ok")
80-
else:
81-
print("FAILED")
82-
sys.exit(ret)
83-
84-
8561
def run_doc_tests():
8662
"""
8763
Checks if the documentation can be built, runs any doctests (currently not
@@ -328,17 +304,14 @@ def export_notebook(ipath, opath):
328304
help="Run unit tests using the `python` interpreter.",
329305
)
330306
parser.add_argument(
331-
"--nosub",
307+
"--all",
332308
action="store_true",
333-
help="Run unit tests without starting a subprocess.",
309+
help="Run all tests (unit and integration) using the `python` interpreter.",
334310
)
335-
# Daily tests vs unit tests
336311
parser.add_argument(
337-
"--folder",
338-
nargs=1,
339-
default=["unit"],
340-
choices=["unit", "integration", "all"],
341-
help="Which folder to run the tests from.",
312+
"--nosub",
313+
action="store_true",
314+
help="Run unit tests without starting a subprocess.",
342315
)
343316
# Notebook tests
344317
parser.add_argument(
@@ -352,9 +325,11 @@ def export_notebook(ipath, opath):
352325
metavar=("in", "out"),
353326
help="Export a Jupyter notebook to a Python file for manual testing.",
354327
)
355-
# Doctests
328+
# Flake8 (deprecated)
356329
parser.add_argument(
357-
"--flake8", action="store_true", help="Run flake8 to check for style issues"
330+
"--flake8",
331+
action="store_true",
332+
help="Run flake8 to check for style issues (deprecated, use pre-commit)",
358333
)
359334
# Doctests
360335
parser.add_argument(
@@ -366,7 +341,7 @@ def export_notebook(ipath, opath):
366341
parser.add_argument(
367342
"--quick",
368343
action="store_true",
369-
help="Run quick checks (unit tests, flake8, docs)",
344+
help="Run quick checks (code tests, docs)",
370345
)
371346
# Non-standard Python interpreter name for subprocesses
372347
parser.add_argument(
@@ -383,23 +358,23 @@ def export_notebook(ipath, opath):
383358
# Run tests
384359
has_run = False
385360
# Unit vs integration
386-
folder = args.folder[0]
387361
interpreter = args.interpreter
388362
# Unit tests
389363
if args.integration:
390364
has_run = True
391-
folder = args.folder[1]
392-
run_code_tests(True, folder, interpreter)
365+
run_code_tests(True, "integration", interpreter)
393366
if args.unit:
394367
has_run = True
395-
run_code_tests(True, folder, interpreter)
368+
run_code_tests(True, "unit", interpreter)
369+
if args.all:
370+
has_run = True
371+
run_code_tests(True, "all", interpreter)
396372
if args.nosub:
397373
has_run = True
398-
run_code_tests(folder=folder, interpreter=interpreter)
374+
run_code_tests(folder="unit", interpreter=interpreter)
399375
# Flake8
400376
if args.flake8:
401-
has_run = True
402-
run_flake8()
377+
raise NotImplementedError("flake8 is no longer used. Use pre-commit instead.")
403378
# Doctests
404379
if args.doctest:
405380
has_run = True
@@ -414,8 +389,7 @@ def export_notebook(ipath, opath):
414389
# Combined test sets
415390
if args.quick:
416391
has_run = True
417-
run_flake8()
418-
run_code_tests(folder, interpreter=interpreter)
392+
run_code_tests("all", interpreter=interpreter)
419393
run_doc_tests()
420394
# Help
421395
if not has_run:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def compile_KLU():
216216
"myst-parser",
217217
], # For doc generation
218218
"dev": [
219-
"flake8>=3", # For code style checking
219+
"pre-commit", # For code style checking
220220
"black", # For code style auto-formatting
221221
],
222222
},

tox.ini

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ setenv =
1212
deps =
1313
dev-!windows-!mac: cmake
1414
dev: black
15-
dev,doctests: sphinx>=1.5
16-
dev,doctests: pydata-sphinx-theme
17-
dev,doctests: sphinx_design
18-
dev,doctests: sphinx-copybutton
19-
dev,doctests: myst-parser
15+
doctests: sphinx>=1.5
16+
doctests: pydata-sphinx-theme
17+
doctests: sphinx_design
18+
doctests: sphinx-copybutton
19+
doctests: myst-parser
2020
!windows-!mac: scikits.odes
2121

2222
commands =
2323
tests-!windows-!mac: sh -c "pybamm_install_jax" # install jax, jaxlib for ubuntu
24-
tests: python run-tests.py --unit --folder all
24+
tests: python run-tests.py --all
2525
unit: python run-tests.py --unit
26-
integration: python run-tests.py --unit --folder integration
26+
integration: python run-tests.py --integration
2727
examples: python run-tests.py --examples
2828
dev-!windows-!mac: sh -c "echo export LD_LIBRARY_PATH={env:LD_LIBRARY_PATH} >> {envbindir}/activate"
2929
doctests: python run-tests.py --doctest
@@ -62,6 +62,9 @@ deps =
6262
sphinx>=1.5
6363
pydata-sphinx-theme
6464
sphinx-autobuild
65+
sphinx_design
66+
sphinx-copybutton
67+
myst-parser
6568
changedir = docs
6669
commands = sphinx-autobuild --open-browser -qT . {envtmpdir}/html
6770

0 commit comments

Comments
 (0)