Skip to content

Commit

Permalink
Standardise package structure and add tests (#57)
Browse files Browse the repository at this point in the history
* Standardise tooling and package structure

* Add more assertions to the cellfinder xml reader test

* remove boilerplate comment

* Move cellfinder dir reader into workflows directory

* remove unused function

* restructure tests

* Add more assertions for writer test

* Expand cellfinder xml writer tests

* Test loading other files

* Add unit tests

* Add test for layer naming

* Move xml test data

* Add brainreg reader tests

* Add whole brain cell detection & registration tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

* Remove check for executables

* replace np.random.random with Generator

* Update GH workflow

* Update tests/tests/test_integration/test_cellfinder_reader.py

Co-authored-by: Alessandro Felder <[email protected]>

* update pre-commit

* update pre-commit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alessandro Felder <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2023
1 parent 3e910f4 commit 3ca66b2
Show file tree
Hide file tree
Showing 42 changed files with 2,425 additions and 407 deletions.
36 changes: 16 additions & 20 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Test (and Deploy on tag)
name: tests

on:
push:
branches:
- main
- '*'
tags:
- '*'
pull_request:

jobs:
linting:
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v2
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/lint@v2

manifest:
name: Check Manifest
Expand All @@ -21,43 +21,39 @@ jobs:
- uses: neuroinformatics-unit/actions/check_manifest@v2

test:
needs: [linting, manifest]
name: ${{ matrix.os }} py${{ matrix.python-version }}
needs: [linting,manifest]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Run across a mixture of Python versions and operating systems
# Run all supported Python versions on linux
python-version: ["3.9", "3.10", "3.11"]
os: [ubuntu-latest]
# Include one windows and macos run
include:
- os: ubuntu-latest
python-version: "3.11"
- os: macos-latest
python-version: "3.10"
- os: windows-latest
python-version: "3.9"
- os: ubuntu-latest
python-version: "3.8"
python-version: "3.10"

steps:
# these libraries enable testing on Qt on linux
- uses: tlambert03/setup-qt-libs@v1
# Run tests
- uses: neuroinformatics-unit/actions/test@v2
with:
python-version: ${{ matrix.python-version }}

build_sdist_wheel:
name: Build source distribution and wheel
build_sdist_wheels:
name: Build source distribution
needs: [test]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2


upload_all:
name: Publish build distributions
needs: [build_sdist_wheel]
if: github.event_name == 'push' && github.ref_type == 'tag'
needs: [build_sdist_wheels]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
Expand Down
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ nosetests.xml
coverage.xml
*,cover
.hypothesis/
.napari_cache

# Translations
*.mo
Expand All @@ -66,6 +65,11 @@ docs/_build/
# PyBuilder
target/

# Pycharm and VSCode
.idea/
venv/
.vscode/

# IPython Notebook
.ipynb_checkpoints

Expand All @@ -76,6 +80,4 @@ target/
.DS_Store

# written by setuptools_scm
*/_version.py

.idea/
**/_version.py
9 changes: 7 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ repos:
rev: v4.5.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-toml
- id: end-of-file-fixer
Expand All @@ -16,7 +15,7 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
rev: v0.1.7
hooks:
- id: ruff
- repo: https://github.com/psf/black
Expand All @@ -29,3 +28,9 @@ repos:
- id: mypy
additional_dependencies:
- types-setuptools
- repo: https://github.com/mgedmin/check-manifest
rev: "0.49"
hooks:
- id: check-manifest
args: [--no-build-isolation]
additional_dependencies: [setuptools-scm]
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
include LICENSE
include README.md
exclude tox.ini

exclude .pre-commit-config.yaml

exclude *.yml
exclude *.yaml
recursive-exclude tests *

recursive-exclude brainglobe_napari_io *.xml
include brainglobe_napari_io/napari.yaml
Expand Down
10 changes: 6 additions & 4 deletions brainglobe_napari_io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from importlib_metadata import version
from importlib.metadata import PackageNotFoundError, version

__version__ = version("brainglobe-napari-io")
__author__ = "Adam Tyson"
__license__ = "BSD-3-Clause"
try:
__version__ = version("brainglobe-napari-io")
except PackageNotFoundError:
# package is not installed
pass
7 changes: 0 additions & 7 deletions brainglobe_napari_io/cellfinder/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ def cells_df_as_np(
return cells


def cells_to_array(cells) -> Tuple[np.ndarray, np.ndarray]:
df = pd.DataFrame([c.to_dict() for c in cells])
points = cells_df_as_np(df[df["type"] == Cell.CELL])
rejected = cells_df_as_np(df[df["type"] == Cell.UNKNOWN])
return points, rejected


def get_cell_arrays(cells_file: os.PathLike) -> Tuple[np.ndarray, np.ndarray]:
df = cells_xml_to_df(str(cells_file))

Expand Down
8 changes: 4 additions & 4 deletions brainglobe_napari_io/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ contributions:
title: Brainreg Read Directory Atlas Space
python_name: brainglobe_napari_io.brainreg.reader_dir_atlas_space:brainreg_read_dir_atlas_space

- id: brainglobe-napari-io.cellfinder_read_dir
title: Cellfinder Read Directory
python_name: brainglobe_napari_io.cellfinder.reader_dir:cellfinder_read_dir
- id: brainglobe-napari-io.workflows_wholebrain_cell_read_dir
title: Workflows Whole Brain Cell Detection Read Directory
python_name: brainglobe_napari_io.workflows.wholebrain_cell_reader_dir:wholebrain_cell_read_dir

- id: brainglobe-napari-io.cellfinder_read_xml
title: Cellfinder Read XML
Expand All @@ -34,7 +34,7 @@ contributions:
- '*.tiff'
accepts_directories: true

- command: brainglobe-napari-io.cellfinder_read_dir
- command: brainglobe-napari-io.workflows_wholebrain_cell_read_dir
filename_patterns:
- '*.tif'
accepts_directories: true
Expand Down
Loading

0 comments on commit 3ca66b2

Please sign in to comment.