Skip to content

Commit

Permalink
Restore custom isort section sorting (#299)
Browse files Browse the repository at this point in the history
* Add classifiers

* Combine optional dependencies

* Fix target version sorting

* Bump pre-commit

* Remove isort section

* Add custom isort section sorting

* Update `pre-commit`

* Run `ruff` on all code

* Fix `pyproject.toml`
  • Loading branch information
paddyroddy authored Apr 21, 2023
1 parent 69fc3a8 commit 666821e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.257
rev: v0.0.262
hooks:
- id: ruff
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.4.2
rev: v1.5.1
hooks:
- id: remove-tabs
exclude: Makefile|docs/Makefile|\.bat$
Expand All @@ -23,7 +23,7 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/pappasam/toml-sort
Expand Down
4 changes: 2 additions & 2 deletions btrack/btypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def to_dict(self) -> Dict[str, Any]:
def from_dict(properties: Dict[str, Any]) -> PyTrackObject:
"""Build an object from a dictionary."""
obj = PyTrackObject()
fields = {k: kt for k, kt in PyTrackObject._fields_}
fields = dict(PyTrackObject._fields_)
attr = [k for k in fields if k in properties]
for key in attr:
new_data = properties[key]
Expand Down Expand Up @@ -362,7 +362,7 @@ def __init__(
children: Optional[List[int]] = None,
fate: constants.Fates = constants.Fates.UNDEFINED,
):
assert all([isinstance(o, PyTrackObject) for o in data])
assert all(isinstance(o, PyTrackObject) for o in data)

self.ID = ID
self._data = data
Expand Down
2 changes: 1 addition & 1 deletion btrack/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def filtered_objects(
)
)
properties = {k: grp["properties"][k][:] for k in p_keys}
assert all([len(p) == len(txyz) for p in properties.values()])
assert all(len(p) == len(txyz) for p in properties.values())

# note that this doesn't do much error checking at the moment
# TODO(arl): this should now reference the `properties`
Expand Down
2 changes: 1 addition & 1 deletion btrack/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def objects_from_dict(objects_dict: dict) -> List[btypes.PyTrackObject]:
objects = []
n_objects = int(objects_dict["t"].shape[0])

assert all([v.shape[0] == n_objects for k, v in objects_dict.items()])
assert all(v.shape[0] == n_objects for k, v in objects_dict.items())

for i in range(n_objects):
data = {k: v[i] for k, v in objects_dict.items()}
Expand Down
4 changes: 3 additions & 1 deletion btrack/napari/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

if TYPE_CHECKING:
import numpy.typing as npt

from magicgui.widgets import Container

from btrack.config import TrackerConfig
from btrack.napari.config import TrackerConfigs

import logging

import qtpy.QtWidgets

import magicgui.widgets
import napari
import qtpy.QtWidgets

import btrack
import btrack.napari.config
Expand Down
3 changes: 2 additions & 1 deletion btrack/napari/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import os
from typing import Callable, List, Optional, Sequence, Union

from napari.types import LayerDataTuple
from napari_plugin_engine import napari_hook_implementation

from napari.types import LayerDataTuple

from btrack.io import HDF5FileHandler
from btrack.utils import tracks_to_napari

Expand Down
4 changes: 2 additions & 2 deletions btrack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def crop_volume(objects, volume=constants.VOLUME):

def within(o):
return all(
[getattr(o, a) >= v[0] and getattr(o, a) <= v[1] for a, v in axes]
getattr(o, a) >= v[0] and getattr(o, a) <= v[1] for a, v in axes
)

return [o for o in objects if within(o)]
Expand All @@ -103,7 +103,7 @@ def _cat_tracks_as_dict(
tracks: list[btypes.Tracklet], properties: List[str]
) -> dict:
"""Concatenate all tracks as dictionary."""
assert all([isinstance(t, btypes.Tracklet) for t in tracks])
assert all(isinstance(t, btypes.Tracklet) for t in tracks)

data: dict = {}

Expand Down
70 changes: 43 additions & 27 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: C++",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
Expand All @@ -29,36 +31,32 @@ dynamic = [
"version",
]
name = "btrack"
readme = "README.md"
requires-python = ">=3.8"
entry-points."napari.manifest".btrack = "btrack:napari.yaml"
license.file = "LICENSE.md"
optional-dependencies.docs = [
optional-dependencies = {docs = [
"numpydoc",
"pytz",
"sphinx_rtd_theme",
"sphinx",
"sphinx-automodapi",
"sphinx-panels",
"sphinx",
]
optional-dependencies.napari = [
"sphinx_rtd_theme",
], napari = [
"magicgui>=0.5.0",
"napari-plugin-engine>=0.1.4",
"napari>=0.4.16",
"qtpy",
]
optional-dependencies.pyqt = [
"btrack[napari]",
], pyqt = [
"PyQt5 >= 5.12.3, != 5.15.0",
]
optional-dependencies.pyside = [
"btrack[napari]",
], pyside = [
"PySide2 >= 5.13.2, != 5.15.0 ; python_version != '3.8'",
"PySide2 >= 5.14.2, != 5.15.0 ; python_version == '3.8'",
]
optional-dependencies.qt = [
"btrack[napari]",
], qt = [
"btrack[pyside]",
]
]}
readme = "README.md"
requires-python = ">=3.8"
entry-points."napari.manifest".btrack = "btrack:napari.yaml"
license.file = "LICENSE.md"
urls.bugtracker = "https://github.com/quantumjot/btrack/issues"
urls.documentation = "https://btrack.readthedocs.io"
urls.homepage = "https://github.com/quantumjot/btrack"
Expand All @@ -82,20 +80,22 @@ exclude = '''
)
'''
line-length = 79
target-version = ["py38", "py39", "py310"]
target-version = [
"py38",
"py39",
"py310",
]

[tool.coverage]
report = {skip_covered = true, sort = "cover"}
run = {branch = true, parallel = true, source = ["btrack"]}
run = {branch = true, parallel = true, source = [
"btrack",
]}
paths.source = [
"btrack",
".tox*/*/lib/python*/site-packages",
]

[tool.isort]
line_length = 79
profile = "black"

[tool.pytest.ini_options]
addopts = "--color=yes -ra -v"
testpaths = [
Expand Down Expand Up @@ -150,7 +150,21 @@ select = [
"YTT",
]
target-version = "py38"
isort.known-first-party = ["btrack"]
isort.known-first-party = [
"black",
]
isort.section-order = [
"future",
"standard-library",
"third-party",
"napari",
"first-party",
"local-folder",
]
isort.sections.napari = [
"magicgui",
"napari",
]
mccabe.max-complexity = 18
pep8-naming.classmethod-decorators = [
"classmethod",
Expand All @@ -167,11 +181,13 @@ local_scheme = "no-local-version"
write_to = "btrack/_version.py"

[tool.tomlsort]
sort_inline_arrays = false
sort_inline_tables = true
sort_table_keys = true
all = true
spaces_indent_inline_array = 4
trailing_comma_inline_array = true
overrides."project.classifiers".inline_arrays = false
overrides."tool.black.target-version".inline_arrays = false
overrides."tool.coverage.paths.source".inline_arrays = false
overrides."tool.ruff.isort.section-order".inline_arrays = false

[tool.tox]
legacy_tox_ini = """
Expand Down
3 changes: 2 additions & 1 deletion tests/napari/test_dock_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import json
from unittest.mock import patch

import napari
import numpy as np
import numpy.typing as npt
import pytest

import napari

import btrack
import btrack.napari
import btrack.napari.main
Expand Down
6 changes: 3 additions & 3 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ def test_segmentation_to_objects_type():
"""Test that btrack objects are returned."""
img, centroids = create_test_image()
objects = utils.segmentation_to_objects(img[np.newaxis, ...])
assert all([isinstance(o, btypes.PyTrackObject) for o in objects])
assert all(isinstance(o, btypes.PyTrackObject) for o in objects)


def test_segmentation_to_objects_type_generator():
"""Test generator as input."""
generator = _example_segmentation_generator()
objects = utils.segmentation_to_objects(generator)
assert all([isinstance(o, btypes.PyTrackObject) for o in objects])
assert all(isinstance(o, btypes.PyTrackObject) for o in objects)


@pytest.mark.parametrize("ndim", [2, 3])
Expand Down Expand Up @@ -231,7 +231,7 @@ def test_tracks_to_napari(ndim: int):
# keys that start with the property key, e.g. `nD` is replaced with `nD-0`
# and so forth
for key in tracks[0].properties:
assert any([k.startswith(key) for k in properties])
assert any(k.startswith(key) for k in properties)


@pytest.mark.parametrize("ndim", [1, 4])
Expand Down

0 comments on commit 666821e

Please sign in to comment.