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

Add pre-commit setup #356

Merged
merged 10 commits into from
Apr 24, 2023
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-json
exclude: "^asv.conf.json$"
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.10.0
hooks:
- id: rst-directive-colons
- id: rst-inline-touching-normal

- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black

- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
types: [file, python]

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v2.7.1
hooks:
- id: prettier
exclude: "^asv.conf.json$"
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ easier to validate it.

## Pull requests

### Linting your code

Before commiting anything, install the pre-commit hooks:

```shell
python3 -m pip install -r requirements-extra.txt
pre-commit install
```

This will ensure that your contribution passes our linting checks.

### PRs should be linked to a GitHub issue

Before opening a pull request to this repository, first please make sure there is a GitHub issue
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include webpack.config.js
include NEWS.rst
include .flake8
include src/memray/py.typed
include .pre-commit-config.yaml

recursive-include src/vendor *
recursive-include src/memray *.py
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ python3 -m pip install -e . -r requirements-test.txt -r requirements-extra.txt

This will install Memray in the virtual environment in development mode (the `-e` of the last `pip install` command).

If you plan to contribute back, you should install the pre-commit hooks:

```shell
pre-commit install
```

This will ensure that your contribution passes our linting checks.

# Documentation

You can find the latest documentation available [here](https://bloomberg.github.io/memray/).
Expand Down
1 change: 1 addition & 0 deletions requirements-extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ mypy
bump2version
towncrier
check-manifest
pre-commit
-r requirements-docs.txt
6 changes: 3 additions & 3 deletions src/memray/_memray_test_utils.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ cdef class PymallocMemoryAllocator:
self.ptr = PyObject_Malloc(size)
else:
raise RuntimeError("Invlid pymalloc domain")

return self.ptr != NULL

@cython.profile(True)
Expand All @@ -175,7 +175,7 @@ cdef class PymallocMemoryAllocator:
self.ptr = PyObject_Calloc(1, size)
else:
raise RuntimeError("Invlid pymalloc domain")

return self.ptr != NULL

@cython.profile(True)
Expand All @@ -188,7 +188,7 @@ cdef class PymallocMemoryAllocator:
self.ptr = PyObject_Realloc(self.ptr, size)
else:
raise RuntimeError("Invlid pymalloc domain")

return self.ptr != NULL

cdef do_not_optimize_ptr(void* ptr):
Expand Down