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

Use and apply black formatting #860

Open
wants to merge 63 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
85dd777
use black, isort, pyproject.toml, pre-commit; rm versioneer
rly Apr 6, 2023
d0551f1
bug fix
rly Apr 6, 2023
1a823ea
Add importlib_resources to reqs for py<3.8
rly Apr 6, 2023
4ba292a
test importlib-resources/metadata reqs
rly Apr 6, 2023
8e8736d
Debuggin
rly Apr 6, 2023
e18b647
More debugging
rly Apr 6, 2023
7f9fde0
Debugging x3
rly Apr 6, 2023
3d9650f
Fix import issue on py37
rly Apr 6, 2023
eda3b60
Restore .codespellrc
rly Apr 6, 2023
64dbe81
Fix codespell action
rly Apr 6, 2023
3389392
Fix broken doc link
rly Apr 6, 2023
a3697ae
Fix RTD
rly Apr 6, 2023
78e16bd
Add changelog
rly Apr 6, 2023
49839e0
Merge branch 'dev' into infrastructure
rly Apr 7, 2023
f5f127f
Run all tests temporarily
rly Apr 7, 2023
350bd24
Merge branch 'infrastructure' of github.com:hdmf-dev/hdmf into infras…
rly Apr 7, 2023
cafb1a7
Restore .github/workflows/run_all_tests.yml
rly Apr 7, 2023
b790946
Merge branch 'infrastructure' of github.com:hdmf-dev/hdmf into infras…
rly Apr 7, 2023
438c182
Merge branch 'dev' into infrastructure
rly Apr 7, 2023
e2c6af7
Merge branch 'dev' into infrastructure
rly May 10, 2023
f2a88a3
Re-run pre-commit hooks
rly May 10, 2023
f5f1784
Update reqs
rly May 10, 2023
6af2436
Use codespell action v2
rly May 10, 2023
7368a8d
Discard changes to docs/gallery/multicontainerinterface.py
rly May 10, 2023
997f0e2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
05f4e10
Discard changes to docs/gallery/multicontainerinterface.py
rly May 10, 2023
9811873
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2023
4e118ba
Exclude black, isort from docs/gallery
rly May 10, 2023
de7a32e
Merge branch 'infrastructure' of github.com:hdmf-dev/hdmf into infras…
rly May 10, 2023
b40e311
Fix black exclude
rly May 10, 2023
f16fdf8
Add Matthew to authors
rly May 10, 2023
04f53ba
Replace flake8 and isort with ruff
rly May 10, 2023
57f8685
Remove test.py
rly May 10, 2023
7c3c283
Revert changes to gallery docs
rly May 10, 2023
0e2ee9c
Update due credit
rly May 10, 2023
2e441fe
Fix gallery tests
rly May 10, 2023
e076bb6
Temporarily run all tests
rly May 10, 2023
c1ecf8b
Revert temp running all tests
rly May 10, 2023
7a1a1a2
Update changelog
rly May 10, 2023
61a7c45
Remove outdated makefile
rly May 10, 2023
d1f960e
Remove unused gitattributes
rly May 10, 2023
70aef7e
Update badge image URLs
rly May 10, 2023
2b4f2f2
Update docs/CONTRIBUTING.rst
rly May 10, 2023
dd3580d
Adjust formatting for resources.py
rly May 10, 2023
5f92b87
Adjust black formatting
rly May 10, 2023
f8238f3
Adjust black formatting
rly May 10, 2023
7c516e3
Replace special ascii apostrophe
rly May 10, 2023
0bff088
Configure black to not exclude src/hdmf/build
rly May 10, 2023
deb8403
Adjustments to black on docval pt 1
rly May 10, 2023
b751675
Adjust black line breaks, fix black exclude
rly May 10, 2023
a8ab471
Style adjustment
rly May 10, 2023
4f09ff4
Remove unnecessary noqa
rly May 10, 2023
1d79998
Adjust style
rly May 10, 2023
0c600a5
Adjust style
rly May 10, 2023
08376c4
Adjust style
rly May 10, 2023
618023f
Revert black changes for now
rly May 11, 2023
888ce99
Use black
rly May 11, 2023
6f0081f
Apply black and manual adjustments
rly May 11, 2023
4680195
Merge branch 'dev' into black
rly May 11, 2023
a7a684e
Merge branch 'dev' into black
rly May 12, 2023
d0655cc
Update CHANGELOG.md
rly May 12, 2023
82267ed
Merge branch 'dev' into black
bendichter Jun 16, 2023
f85165d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jun 16, 2023
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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ repos:
args: [--pytest-test-first]
exclude: ^tests/unit/helpers/
- id: check-docstring-first
# - repo: https://github.com/psf/black
# rev: 23.3.0
# hooks:
# - id: black
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.272
hooks:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HDMF Changelog

## HDMF 3.7.0 (Upcoming)

## Minor improvements
- Set code style guide to `black`. @rly [#860](https://github.com/hdmf-dev/hdmf/pull/860)

## HMDF 3.6.1 (May 18, 2023)

### Bug fixes
Expand Down
14 changes: 9 additions & 5 deletions docs/CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,25 @@ Style Guides
Python Code Style Guide
^^^^^^^^^^^^^^^^^^^^^^^

Before you create a Pull Request, make sure you are following the PEP8_ style guide. .
To check whether your code conforms to the HDMF style guide, simply run the ruff_ tool in the project's root
directory. ``ruff`` will also sort imports automatically and check against additional code style rules.
Before you create a Pull Request, make sure you are following the Black_ preview style guide, which follows PEP8.
We also break from the Black format by configuring it with a max line length of 120.
To check whether your code conforms to the Black_ preview style guide, simply run the ``black`` tool in the
project's root directory with the ``--check`` argument. You can also run the ``black`` tool without
the ``--check`` argument to have black automatically format the codebase to comply with the style guide.

We also use ``ruff`` to sort python imports automatically and double-check that the codebase
We also use the ruff_ tool to sort python imports automatically and double-check that the codebase
conforms to PEP8 standards, while using the codespell_ tool to check spelling.

``ruff`` and ``codespell`` are installed when you follow the developer installation instructions. See
The ``black``, ``ruff``, and ``codespell`` tools are installed when you follow the developer installation instructions. See
:ref:`install_developers`.

.. _Black: https://black.readthedocs.io/en/stable/
.. _ruff: https://beta.ruff.rs/docs/
.. _codespell: https://github.com/codespell-project/codespell

.. code::

$ black .
$ ruff check .
$ codespell

Expand Down
10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ exclude_lines = [

[tool.setuptools_scm]

# [tool.black]
# line-length = 120
# preview = true
# exclude = ".git|.mypy_cache|.tox|.venv|venv|.ipynb_checkpoints|_build/|dist/|__pypackages__|.ipynb"
# force-exclude = "src/hdmf/common/hdmf-common-schema|docs/gallery"
[tool.black]
line-length = 120
preview = true
exclude = ".git|.mypy_cache|.tox|.venv|venv|.ipynb_checkpoints|_build/|dist/|__pypackages__|.ipynb"
force-exclude = "src/hdmf/common/hdmf-common-schema|docs/gallery"

[tool.ruff]
select = ["E", "F", "T100", "T201", "T203"]
Expand Down
19 changes: 10 additions & 9 deletions src/hdmf/array.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from abc import abstractmethod, ABCMeta
from abc import ABCMeta, abstractmethod

import numpy as np


class Array:

def __init__(self, data):
self.__data = data
if hasattr(data, 'dtype'):
if hasattr(data, "dtype"):
self.dtype = data.dtype
else:
tmp = data
Expand Down Expand Up @@ -41,17 +40,20 @@ def __getitem__(self, arg):
idx.append(i)
return np.fromiter((self.__getidx__(x) for x in idx), dtype=self.dtype)
elif isinstance(arg, slice):
return np.fromiter((self.__getidx__(x) for x in self.__sliceiter(arg)), dtype=self.dtype)
return np.fromiter(
(self.__getidx__(x) for x in self.__sliceiter(arg)),
dtype=self.dtype,
)
elif isinstance(arg, tuple):
return (self.__getidx__(arg[0]), self.__getidx__(arg[1]))
else:
return self.__getidx__(arg)


class AbstractSortedArray(Array, metaclass=ABCMeta):
'''
"""
An abstract class for representing sorted array
'''
"""

@abstractmethod
def find_point(self, val):
Expand Down Expand Up @@ -160,11 +162,11 @@ def __ne__(self, other):


class SortedArray(AbstractSortedArray):
'''
"""
A class for wrapping sorted arrays. This class overrides
<,>,<=,>=,==, and != to leverage the sorted content for
efficiency.
'''
"""

def __init__(self, array):
super().__init__(array)
Expand All @@ -174,7 +176,6 @@ def find_point(self, val):


class LinSpace(SortedArray):

def __init__(self, start, stop, step):
self.start = start
self.stop = stop
Expand Down
4 changes: 2 additions & 2 deletions src/hdmf/backends/hdf5/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import h5_utils, h5tools
from .h5_utils import H5RegionSlicer, H5DataIO
from .h5tools import HDF5IO, H5SpecWriter, H5SpecReader
from .h5_utils import H5DataIO, H5RegionSlicer
from .h5tools import HDF5IO, H5SpecReader, H5SpecWriter
Loading