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

Pre-commit hooks for notebook formatting & reproducibility #22

Merged
merged 10 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion .azp/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ jobs:
- template: jobs/execute_notebooks.yml
parameters:
build_master: true

9 changes: 9 additions & 0 deletions .azp/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ schedules:
variables:
- template: variables/image.yml

resources:
repositories:
- repository: asottile
type: github
endpoint: github
name: asottile/azure-pipeline-templates
ref: refs/tags/v2.1.0

jobs:
- template: job--pre-commit.yml@asottile
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are running a job that is define by a .yml file in asottile/azure-pipeline-templates. What if this repo changes the file, or goes stale? We just copy the file in to our templates directory and remove the resources block to keep control.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tagged to a release so this file should not be expected to change. I would prefer to let it use the external template for simplicity. ref: refs/tags/v2.1.0

- template: jobs/execute_notebooks.yml
parameters:
build_master: true
69 changes: 69 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: 'v3.4.0'
hooks:
- id: end-of-file-fixer
exclude: 'setup.cfg'
- id: trailing-whitespace
exclude: 'setup.cfg'
- id: debug-statements
- repo: https://github.com/asottile/pyupgrade
rev: 'v2.10.0'
hooks:
- id: pyupgrade
args:
- --py36-plus
- repo: https://github.com/pycqa/isort
rev: '5.7.0'
hooks:
- id: isort
- repo: https://github.com/google/yapf
rev: 'a53e340c2ff24b36c98945c6f0374c6e21899afe'
hooks:
- id: yapf
args:
- --in-place
- --recursive
- repo: https://gitlab.com/pycqa/flake8
rev: '3.8.4'
hooks:
- id: flake8
args:
- --max-line-length=100
- repo: https://github.com/nbQA-dev/nbQA
rev: 0.5.7
hooks:
- id: nbqa-pyupgrade
args:
- --nbqa-mutate
- --py36-plus
- id: nbqa-isort
args:
- --nbqa-mutate
# This can replace the local hook definition below when https://github.com/nbQA-dev/nbQA/pull/547 is released
#- id: nbqa-yapf
# args:
# - --nbqa-mutate
- repo: https://github.com/kynan/nbstripout
rev: 0.3.9
hooks:
- id: nbstripout
args:
# Strip metadata but keep counts and outputs
- --keep-count
- --keep-output
- repo: https://github.com/bdice/nb-strip-paths
rev: b1203bb13ac55f2ba381530c17f7e56ff497f508
hooks:
- id: nb-strip-paths
- repo: local
hooks:
- id: nbqa-yapf
name: nbqa-yapf
description: "Run 'yapf' on a Jupyter Notebook"
entry: nbqa yapf --in-place --nbqa-mutate
language: python
language_version: python3
require_serial: true
types: [jupyter]
additional_dependencies: [nbqa, yapf]
69 changes: 7 additions & 62 deletions 00-Introducing-HOOMD-blue/01-The-Simulation-Object.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.430972Z",
"iopub.status.busy": "2021-02-16T17:05:52.430338Z",
"iopub.status.idle": "2021-02-16T17:05:52.550516Z",
"shell.execute_reply": "2021-02-16T17:05:52.551176Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"import hoomd"
Expand All @@ -64,14 +57,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.603506Z",
"iopub.status.busy": "2021-02-16T17:05:52.602473Z",
"iopub.status.idle": "2021-02-16T17:05:52.604758Z",
"shell.execute_reply": "2021-02-16T17:05:52.605707Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"cpu = hoomd.device.CPU()"
Expand All @@ -88,12 +74,6 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.958741Z",
"iopub.status.busy": "2021-02-16T17:05:52.957512Z",
"iopub.status.idle": "2021-02-16T17:05:52.960040Z",
"shell.execute_reply": "2021-02-16T17:05:52.961060Z"
},
"tags": [
"raises-exception"
]
Expand Down Expand Up @@ -124,14 +104,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.966625Z",
"iopub.status.busy": "2021-02-16T17:05:52.965442Z",
"iopub.status.idle": "2021-02-16T17:05:52.967926Z",
"shell.execute_reply": "2021-02-16T17:05:52.968934Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"sim = hoomd.Simulation(device=cpu)"
Expand All @@ -147,14 +120,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.973837Z",
"iopub.status.busy": "2021-02-16T17:05:52.972863Z",
"iopub.status.idle": "2021-02-16T17:05:52.975052Z",
"shell.execute_reply": "2021-02-16T17:05:52.975445Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -178,14 +144,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.980093Z",
"iopub.status.busy": "2021-02-16T17:05:52.979618Z",
"iopub.status.idle": "2021-02-16T17:05:52.982367Z",
"shell.execute_reply": "2021-02-16T17:05:52.982747Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -202,14 +161,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.986433Z",
"iopub.status.busy": "2021-02-16T17:05:52.985959Z",
"iopub.status.idle": "2021-02-16T17:05:52.989070Z",
"shell.execute_reply": "2021-02-16T17:05:52.988593Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand All @@ -226,14 +178,7 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:52.993018Z",
"iopub.status.busy": "2021-02-16T17:05:52.992482Z",
"iopub.status.idle": "2021-02-16T17:05:52.994942Z",
"shell.execute_reply": "2021-02-16T17:05:52.995376Z"
}
},
"metadata": {},
"outputs": [
{
"name": "stdout",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:53.976985Z",
"iopub.status.busy": "2021-02-16T17:05:53.976367Z",
"iopub.status.idle": "2021-02-16T17:05:54.098654Z",
"shell.execute_reply": "2021-02-16T17:05:54.099258Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"import hoomd\n",
"import math"
"import math\n",
"\n",
"import hoomd"
]
},
{
Expand All @@ -64,14 +58,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:54.103395Z",
"iopub.status.busy": "2021-02-16T17:05:54.102667Z",
"iopub.status.idle": "2021-02-16T17:05:54.104316Z",
"shell.execute_reply": "2021-02-16T17:05:54.104922Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"mc = hoomd.hpmc.integrate.ConvexPolyhedron(seed=1)"
Expand All @@ -88,22 +75,17 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:54.108771Z",
"iopub.status.busy": "2021-02-16T17:05:54.108163Z",
"iopub.status.idle": "2021-02-16T17:05:54.109905Z",
"shell.execute_reply": "2021-02-16T17:05:54.110393Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"mc.shape['octahedron'] = dict(vertices=[(-0.5, 0, 0),\n",
" (0.5, 0, 0),\n",
" (0, -0.5, 0),\n",
" (0, 0.5, 0),\n",
" (0, 0, -0.5),\n",
" (0, 0, 0.5)])"
"mc.shape['octahedron'] = dict(vertices=[\n",
" (-0.5, 0, 0),\n",
" (0.5, 0, 0),\n",
" (0, -0.5, 0),\n",
" (0, 0.5, 0),\n",
" (0, 0, -0.5),\n",
" (0, 0, 0.5),\n",
"])"
]
},
{
Expand All @@ -127,14 +109,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:54.114079Z",
"iopub.status.busy": "2021-02-16T17:05:54.113272Z",
"iopub.status.idle": "2021-02-16T17:05:54.115409Z",
"shell.execute_reply": "2021-02-16T17:05:54.116046Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"mc.nselect = 2\n",
Expand All @@ -160,14 +135,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:54.166614Z",
"iopub.status.busy": "2021-02-16T17:05:54.165448Z",
"iopub.status.idle": "2021-02-16T17:05:54.167845Z",
"shell.execute_reply": "2021-02-16T17:05:54.168807Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"cpu = hoomd.device.CPU()\n",
Expand All @@ -184,14 +152,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"execution": {
"iopub.execute_input": "2021-02-16T17:05:54.173991Z",
"iopub.status.busy": "2021-02-16T17:05:54.172735Z",
"iopub.status.idle": "2021-02-16T17:05:54.175316Z",
"shell.execute_reply": "2021-02-16T17:05:54.176337Z"
}
},
"metadata": {},
"outputs": [],
"source": [
"sim.operations.integrator = mc"
Expand Down
Loading