Skip to content

Commit

Permalink
update to npe2 (#7)
Browse files Browse the repository at this point in the history
* update to npe2

* add test

* make extension handling consistent between napari.yaml and reader itself

* fix bug introduced in reader

* add deps
  • Loading branch information
alisterburt authored Jun 8, 2023
1 parent 1e488f3 commit ff25cd9
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 106 deletions.
80 changes: 71 additions & 9 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,88 @@

name: tests

on: push
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:
ubuntu-latest:
runs-on: ubuntu-latest
test:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ['3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
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

# 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
# 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
run: |
python -m pip install --upgrade pip
pip install setuptools tox tox-gh-actions
python -m pip install setuptools tox tox-gh-actions
# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
run: tox
uses: aganders3/headless-gui@v1
with:
run: python -m tox
env:
PLATFORM: ${{ matrix.platform }}

- name: Coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3

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)
needs: [test]
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/*
10 changes: 0 additions & 10 deletions napari_mrcfile_reader/__init__.py

This file was deleted.

58 changes: 58 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
[build-system]
requires = ["setuptools>=42.0.0", "wheel", "setuptools_scm"]
build-backend = "setuptools.build_meta"


[tool.setuptools_scm]
write_to = "src/napari_mrcfile_reader/_version.py"

[tool.black]
line-length = 79
target-version = ['py38', 'py39', 'py310']


[tool.ruff]
line-length = 79
select = [
"E", "F", "W", #flake8
"UP", # pyupgrade
"I", # isort
"BLE", # flake8-blind-exception
"B", # flake8-bugbear
"A", # flake8-builtins
"C4", # flake8-comprehensions
"ISC", # flake8-implicit-str-concat
"G", # flake8-logging-format
"PIE", # flake8-pie
"SIM", # flake8-simplify
]
ignore = [
"E501", # line too long. let black handle this
"UP006", "UP007", # type annotation. As using magicgui require runtime type annotation then we disable this.
"SIM117", # flake8-simplify - some of merged with statements are not looking great with black, reanble after drop python 3.9
]

exclude = [
".bzr",
".direnv",
".eggs",
".git",
".mypy_cache",
".pants.d",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"*vendored*",
"*_vendor*",
]

target-version = "py38"
fix = true
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

59 changes: 59 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[metadata]
name = napari-mrcfile-reader

description = Read MRC2014 files in napari using mrcfile.
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/alisterburt/napari-mrcfile-reader
author = Alister Burt
author_email = [email protected]
license = BSD-3-Clause
license_files = LICENSE
classifiers =
Development Status :: 2 - Pre-Alpha
Framework :: napari
Intended Audience :: Developers
License :: OSI Approved :: BSD License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Topic :: Scientific/Engineering :: Image Processing
project_urls =
Bug Tracker = https://github.com/alisterburt/napari-mrcfile-reader/issues
Documentation = https://github.com/alisterburt/napari-mrcfile-reader#README.md
Source Code = https://github.com/alisterburt/napari-mrcfile-reader
User Support = https://github.com/alisterburt/napari-mrcfile-reader/issues

[options]
packages = find:
install_requires =
numpy
mrcfile

python_requires = >=3.8
include_package_data = True
package_dir =
=src
setup_requires = setuptools_scm
# add your package requirements here

[options.packages.find]
where = src

[options.entry_points]
napari.manifest =
napari-mrcfile-reader = napari_mrcfile_reader:napari.yaml

[options.extras_require]
testing =
tox
pytest # https://docs.pytest.org/en/latest/contents.html
pytest-cov # https://pytest-cov.readthedocs.io/en/latest/


[options.package_data]
* = *.yaml
61 changes: 0 additions & 61 deletions setup.py

This file was deleted.

File renamed without changes.
11 changes: 11 additions & 0 deletions src/napari_mrcfile_reader/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

try:
from ._version import version as __version__
except ImportError:
__version__ = "unknown"

from ._reader import napari_get_reader

__all__ = (
"napari_get_reader",
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
"""
This module is an mrc file reader plugin for napari.
This module is an example of a barebones numpy reader plugin for napari.
It implements the ``napari_get_reader`` hook specification to create
a reader plugin.
see: https://napari.org/docs/plugins/hook_specifications.html
Replace code below accordingly. For complete documentation see:
https://napari.org/docs/plugins/for_plugin_developers.html
It implements the Reader specification, but your plugin may choose to
implement multiple readers or even other plugin contributions. see:
https://napari.org/stable/plugins/guides.html?#readers
"""
import numpy as np
from napari_plugin_engine import napari_hook_implementation
import mrcfile
import numpy as np


@napari_hook_implementation
def napari_get_reader(path):
"""A basic implementation of the napari_get_reader hook specification.
"""A basic implementation of a Reader contribution.
Parameters
----------
Expand All @@ -35,7 +30,15 @@ def napari_get_reader(path):
path = path[0]

# if we know we cannot read the file, we immediately return None.
extensions = ".mrc", ".mrcs", ".map"
extensions = (
'.mrc',
'.mrcs',
'.map',
'.st',
'.rec',
'.preali',
'.ali',
)
if not path.endswith(extensions):
return None

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import numpy as np
import mrcfile
import numpy as np

from napari_mrcfile_reader import napari_get_reader


# tmp_path is a pytest fixture
def test_reader(tmp_path):
# write a fake MRC file using mrcfile
"""An example of how you might test your plugin."""

# write some fake data using your supported file format
my_test_file = str(tmp_path / "myfile.mrc")
original_data = np.random.rand(20, 20).astype(np.float32)
mrcfile.new(my_test_file, original_data)
mrcfile.write(my_test_file, original_data)

# try to read it back in
reader = napari_get_reader(my_test_file)
Expand Down
19 changes: 19 additions & 0 deletions src/napari_mrcfile_reader/napari.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: napari-mrcfile-reader
display_name: napari-mrcfile-reader
contributions:
commands:
- id: napari-mrcfile-reader.get_reader
python_name: napari_mrcfile_reader._reader:napari_get_reader
title: Open data with napari-mrcfile-reader
readers:
- command: napari-mrcfile-reader.get_reader
accepts_directories: false
filename_patterns: [
'*.mrc',
'*.mrcs',
'*.map',
'*.st',
'*.rec',
'*.preali',
'*.ali',
]
Loading

0 comments on commit ff25cd9

Please sign in to comment.