Skip to content

Commit

Permalink
Standardise package structure
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorTatarnikov committed Nov 28, 2023
1 parent 9614ce8 commit f0640d3
Show file tree
Hide file tree
Showing 41 changed files with 328 additions and 253 deletions.
117 changes: 61 additions & 56 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
@@ -1,90 +1,95 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: tests

on:
push:
branches:
- main
- npe2
tags:
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
pull_request:
branches:
- main
- npe2
workflow_dispatch:

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

manifest:
name: Check Manifest
runs-on: ubuntu-latest
steps:
- uses: neuroinformatics-unit/actions/check_manifest@v2

test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
needs: [linting, manifest]
name: ${{ matrix.os }} py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10']
# 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: macos-latest
python-version: "3.10"
- os: windows-latest
python-version: "3.10"

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

# these libraries enable testing on Qt on linux
- uses: tlambert03/setup-qt-libs@v1
- uses: pyvista/setup-headless-display-action@v2
with:
qt: true

# strategy borrowed from vispy for installing opengl libs on windows
- name: Install Windows OpenGL
if: runner.os == 'Windows'
run: |
git clone --depth 1 https://github.com/pyvista/gl-ci-helpers.git
powershell gl-ci-helpers/appveyor/install_opengl.ps1
# cache atlases needed by the tests
- name: Cache Atlases
id: atlas-cache
uses: actions/cache@v3
with:
path: | # ensure we don't cache any interrupted atlas download and extraction!
~/.brainglobe/*
!~/.brainglobe/atlas.tar.gz
key: ${{ runner.os }}-cached-atlases
enableCrossOsArchive: false # ~ and $HOME evaluate to different places across OSs!

# note: if you need dependencies from conda, considering using
# setup-miniconda: https://github.com/conda-incubator/setup-miniconda
# and
# tox-conda: https://github.com/tox-dev/tox-conda
- name: Install dependencies
- if: ${{ steps.atlas-cache.outputs.cache-hit == 'true' }}
name: List files in brainglobe data folder # good to be able to sanity check that user data is as expected
run: |
python -m pip install --upgrade pip
python -m pip install setuptools tox tox-gh-actions
ls -af ~/.brainglobe/
# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
uses: aganders3/headless-gui@v1
# Run tests
- uses: neuroinformatics-unit/actions/test@v2
with:
run: python -m tox
env:
PLATFORM: ${{ matrix.platform }}

- name: Coverage
uses: codecov/codecov-action@v3
python-version: ${{ matrix.python-version }}

deploy:
# this will run when you have tagged a commit, starting with "v*"
# and requires that you have put your twine API key in your
# github secrets (see readme for details)
build_sdist_wheels:
name: Build source distribution
needs: [test]
if: github.event_name == 'push' && github.ref_type == 'tag'
runs-on: ubuntu-latest
if: contains(github.ref, 'tags')
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools setuptools_scm wheel twine build
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
run: |
git tag
python -m build .
twine upload dist/*
- uses: neuroinformatics-unit/actions/build_sdist_wheels@v2


upload_all:
name: Publish build distributions
needs: [build_sdist_wheels]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: artifact
path: dist
- uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.TWINE_API_KEY }}
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,3 @@ venv/

# written by setuptools_scm
**/_version.py

# Other test files
Logs/
34 changes: 20 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Configuring https://pre-commit.ci/
ci:
autoupdate_schedule: monthly

exclude: 'conf.py'
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
Expand All @@ -16,17 +13,26 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.292
rev: v0.1.6
hooks:
- id: ruff
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 23.11.0
hooks:
- id: black
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.5.1
# hooks:
# - id: mypy
# additional_dependencies:
# - types-setuptools
# - types-requests
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- 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]
- repo: https://github.com/tlambert03/napari-plugin-checks
rev: v0.3.0
hooks:
- id: napari-plugin-checks
10 changes: 10 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
include LICENSE
include README.md
include .napari-hub/DESCRIPTION.md
include .napari-hub/config.yml
include brainglobe_registration/napari.yaml
include brainglobe_registration/resources/brainglobe.png
exclude .pre-commit-config.yaml

recursive-include brainglobe_registration/parameters *.txt
recursive-include brainglobe_registration/resources *.tif
recursive-exclude imgs *.png
recursive-exclude * __pycache__
recursive-exclude * *.py[co]
recursive-exclude docs *
recursive-exclude tests *
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from typing import List

import itk
import numpy as np
from bg_atlasapi import BrainGlobeAtlas
from typing import List


def get_atlas_by_name(atlas_name: str) -> BrainGlobeAtlas:
Expand All @@ -27,7 +28,7 @@ def run_registration(
atlas_image,
moving_image,
annotation_image,
parameter_lists: List[tuple[str, dict]] = None,
parameter_lists: List[tuple[str, dict]],
) -> tuple[np.ndarray, itk.ParameterObject, np.ndarray]:
"""
Run the registration process on the given images.
Expand Down Expand Up @@ -92,7 +93,7 @@ def run_registration(
)


def setup_parameter_object(parameter_lists: List[tuple[str, dict]] = None):
def setup_parameter_object(parameter_lists: List[tuple[str, dict]]):
"""
Set up the parameter object for the registration process.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,37 @@
from pathlib import Path

import numpy as np

from brainglobe_registration.elastix.register import run_registration
from brainglobe_registration.widgets.select_images_view import SelectImagesView
from brainglobe_registration.widgets.adjust_moving_image_view import (
AdjustMovingImageView,
)
from brainglobe_registration.widgets.parameter_list_view import (
RegistrationParameterListView,
)
from brainglobe_registration.widgets.transform_select_view import (
TransformSelectView,
)
from brainglobe_registration.utils.utils import (
adjust_napari_image_layer,
open_parameter_file,
find_layer_index,
get_image_layer_names,
)

from bg_atlasapi import BrainGlobeAtlas
from bg_atlasapi.list_atlases import get_downloaded_atlases
from napari.viewer import Viewer
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QGroupBox,
QPushButton,
QTabWidget,
QVBoxLayout,
QWidget,
QTabWidget,
QPushButton,
)
from skimage.segmentation import find_boundaries

from brainglobe_registration.elastix.register import run_registration
from brainglobe_registration.utils.brainglobe_logo import header_widget
from brainglobe_registration.utils.utils import (
adjust_napari_image_layer,
find_layer_index,
get_image_layer_names,
open_parameter_file,
)
from brainglobe_registration.widgets.adjust_moving_image_view import (
AdjustMovingImageView,
)
from brainglobe_registration.widgets.parameter_list_view import (
RegistrationParameterListView,
)
from brainglobe_registration.widgets.select_images_view import SelectImagesView
from brainglobe_registration.widgets.transform_select_view import (
TransformSelectView,
)


class RegistrationWidget(QWidget):
Expand All @@ -54,7 +52,11 @@ def __init__(self, napari_viewer: Viewer):
self._atlas: BrainGlobeAtlas = None
self._moving_image = None

self.transform_params = {"rigid": {}, "affine": {}, "bspline": {}}
self.transform_params: dict[str, dict] = {
"rigid": {},
"affine": {},
"bspline": {},
}
self.transform_selections = []

for transform_type in self.transform_params:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""
Can this be imorted from brainrender-napari? We can also move this to a bgutils maybe?
"""


from importlib.resources import files

from qtpy.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QWidget, QVBoxLayout
from qtpy.QtWidgets import QGroupBox, QHBoxLayout, QLabel, QVBoxLayout, QWidget

brainglobe_logo = files("brainglobe_registration").joinpath(
"resources/brainglobe.png"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import napari
from pytransform3d.rotations import active_matrix_from_angle
import numpy as np
from pathlib import Path
from typing import List

import napari
import numpy as np
from pytransform3d.rotations import active_matrix_from_angle


def adjust_napari_image_layer(
image_layer: napari.layers.Image, x: int, y: int, rotate: float
Expand Down
File renamed without changes.
Loading

0 comments on commit f0640d3

Please sign in to comment.