Skip to content

Commit

Permalink
Add pre-commit hooks, Ruff formatting and linting (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sritchie authored Jan 25, 2024
1 parent a2b0afa commit a3807d0
Show file tree
Hide file tree
Showing 133 changed files with 6,103 additions and 3,580 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: pre-commit hooks

on:
pull_request:
push:
branches:
- main

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: 3.11.5

- uses: pre-commit/action@v3.0.0
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
args: [--unsafe]
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.11
hooks:
- id: ruff
# types_or: [ python, pyi, jupyter ]

- id: ruff-format
# types_or: [ python, pyi, jupyter ]
34 changes: 34 additions & 0 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Developer's Guide

This guide describes how to complete various tasks you'll encounter when working
on the Bayes3D codebase.

### Commit Hooks

We use [pre-commit](https://pre-commit.com/) to manage a series of git
pre-commit hooks for the project; for example, each time you commit code, the
hooks will make sure that your python is formatted properly. If your code isn't,
the hook will format it, so when you try to commit the second time you'll get
past the hook.

All hooks are defined in `.pre-commit-config.yaml`. To install these hooks,
install `pre-commit` if you don't yet have it. I prefer using
[pipx](https://github.com/pipxproject/pipx) so that `pre-commit` stays globally
available.

```bash
pipx install pre-commit
```

Then install the hooks with this command:

```bash
pre-commit install
```

Now they'll run on every commit. If you want to run them manually, run the
following command:

```bash
pre-commit run --all-files
```
2 changes: 1 addition & 1 deletion assets/sample_objs/bunny.obj
Original file line number Diff line number Diff line change
Expand Up @@ -7469,4 +7469,4 @@ f 2411 1493 2503
f 1493 1487 2503
f 1487 1318 2503
f 1318 1320 2503
f 1320 2443 2503
f 1320 2443 2503
2 changes: 1 addition & 1 deletion assets/sample_objs/cube.obj
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ f 15//15 23//23 17//17
f 3//3 14//14 16//16
f 3//3 16//16 6//6
f 4//4 18//18 22//22
f 4//4 22//22 11//11
f 4//4 22//22 11//11
2 changes: 1 addition & 1 deletion assets/sample_objs/diamond.obj
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ f 6 5 4
f 6 4 3
f 6 3 2
f 6 2 1
f 6 1 5
f 6 1 5
2 changes: 1 addition & 1 deletion assets/sample_objs/icosahedron.obj
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ f 12 11 6
f 10 9 5
f 8 3 9
f 10 8 9
f 2 8 10
f 2 8 10
2 changes: 1 addition & 1 deletion assets/sample_objs/occulder.obj
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ f 4//4 8//8 3//3
f 7//7 5//5 3//3
f 3//3 8//8 7//7
f 7//7 6//6 5//5
f 8//8 6//6 7//7
f 8//8 6//6 7//7
2 changes: 1 addition & 1 deletion assets/sample_objs/pyramid.obj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ f 3 4 2
f 5 2 1
f 4 5 1
f 3 5 4
f 5 3 2
f 5 3 2
2 changes: 1 addition & 1 deletion assets/sample_objs/sphere.obj
Original file line number Diff line number Diff line change
Expand Up @@ -806,4 +806,4 @@ f 17/17/17 159/159/159 158/158/158
f 13/13/13 157/157/157 159/159/159
f 14/14/14 160/160/160 161/161/161
f 15/15/15 161/161/161 162/162/162
f 13/13/13 162/162/162 160/160/160
f 13/13/13 162/162/162 160/160/160
20 changes: 4 additions & 16 deletions bayes3d/__init__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
"""
.. include:: ./documentation.md
"""
from .transforms_3d import *

from .camera import *
from .likelihood import *
from .renderer import *
from .rgbd import *
from .likelihood import *
from .camera import *
from .transforms_3d import *
from .viz import *
from . import utils
from . import distributions
from . import scene_graph
from . import colmap

try:
import genjax
from .genjax import *
except ImportError as e:
print("GenJAX not installed. Importing bayes3d without genjax dependencies.")
print(e)



RENDERER = None
41 changes: 20 additions & 21 deletions bayes3d/_mkl/gaussian_particle_system_v0.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../scripts/_mkl/notebooks/07a - Gaussian particle system v0.ipynb.

# %% auto 0
__all__ = ['normal_cdf', 'normal_pdf', 'normal_logpdf', 'inv', 'key', 'Array', 'Shape', 'Bool', 'Float', 'Int', 'Pose']
__all__ = [
"normal_cdf",
"normal_pdf",
"normal_logpdf",
"inv",
"key",
"Array",
"Shape",
"Bool",
"Float",
"Int",
"Pose",
]

# %% ../../scripts/_mkl/notebooks/07a - Gaussian particle system v0.ipynb 2
import bayes3d as b3d
import trimesh
import os
from bayes3d._mkl.utils import *
import matplotlib.pyplot as plt
import numpy as np
import jax
from jax import jit, vmap
import jax.numpy as jnp
from jax.scipy.spatial.transform import Rotation as Rot
from functools import partial
import genjax
from bayes3d.camera import Intrinsics, K_from_intrinsics, camera_rays_from_intrinsics
from bayes3d.transforms_3d import transform_from_pos_target_up, add_homogenous_ones, unproject_depth
import tensorflow_probability as tfp
from tensorflow_probability.substrates.jax.math import lambertw

import numpy as np

from bayes3d._mkl.utils import *

normal_cdf = jax.scipy.stats.norm.cdf
normal_pdf = jax.scipy.stats.norm.pdf
normal_cdf = jax.scipy.stats.norm.cdf
normal_pdf = jax.scipy.stats.norm.pdf
normal_logpdf = jax.scipy.stats.norm.logpdf
inv = jnp.linalg.inv

key = jax.random.PRNGKey(0)

# %% ../../scripts/_mkl/notebooks/07a - Gaussian particle system v0.ipynb 4
from typing import Any, NamedTuple
import numpy as np
from typing import NamedTuple

import jax
import jaxlib
import numpy as np

Array = np.ndarray | jax.Array
Shape = int | tuple[int, ...]
Expand Down
Loading

0 comments on commit a3807d0

Please sign in to comment.