Skip to content

Commit

Permalink
Merge pull request #33 from NHPatterson/fix-json-pad-issue
Browse files Browse the repository at this point in the history
fix serialization of numpy to json with encoder
  • Loading branch information
NHPatterson committed Feb 10, 2023
2 parents 499988e + 73d2e05 commit c714621
Show file tree
Hide file tree
Showing 52 changed files with 44 additions and 75 deletions.
40 changes: 11 additions & 29 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ jobs:
name: ${{ matrix.platform }} py${{ matrix.python-version }}
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.8", "3.9"]
python-version: [3.8, 3.9, "3.10"]

steps:
- uses: actions/checkout@v2
Expand All @@ -31,37 +32,18 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

# these libraries, along with pytest-xvfb (added in the `deps` in tox.ini),
# enable testing on Qt on linux
- name: Install Linux libraries
if: runner.os == 'Linux'
run: |
sudo apt-get install -y libdbus-1-3 libxkbcommon-x11-0 libxcb-icccm4 \
libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 \
libxcb-xinerama0 libxcb-xinput0 libxcb-xfixes0
# 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
if (Test-Path -Path "C:\Windows\system32\opengl32.dll" -PathType Leaf) {Exit 0} else {Exit 1}
# 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
# these libraries enable testing on Qt on linux
- uses: tlambert03/setup-qt-libs@v1

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools tox tox-gh-actions
# this runs the platform-specific tests declared in tox.ini
- name: Test with tox
run: tox
env:
PLATFORM: ${{ matrix.platform }}

- name: Coverage
uses: codecov/codecov-action@v2
pip install pytest pytest-cookies tox napari-plugin-engine
pip install .
- name: Test
uses: GabrielBB/xvfb-action@v1
with:
run: python -m pytest -s -v --color=yes


deploy:
Expand Down
16 changes: 0 additions & 16 deletions napari_imsmicrolink/_tests/test_imsmicrolink.py

This file was deleted.

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


[tool.setuptools_scm]
write_to = "src/napari_imsmicrolink/_version.py"
11 changes: 8 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[metadata]
name = napari-imsmicrolink
version = 0.1.8
author = Nathan Heath Patterson
author_email = heath.patterson@vanderbilt.edu
license = MIT
Expand All @@ -15,7 +14,6 @@ classifiers =
Topic :: Software Development :: Testing
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Expand All @@ -29,7 +27,9 @@ project_urls =

[options]
packages = find:
python_requires = >=3.7
python_requires = >=3.8
package_dir =
=src
# add your package requirements here
install_requires =
numpy
Expand All @@ -45,7 +45,12 @@ install_requires =
opencv-python
czifile
imagecodecs
napari[all]
setup_requires =
setuptools-scm

[options.packages.find]
where = src

[options.entry_points]
napari.manifest =
Expand Down
5 changes: 0 additions & 5 deletions setup.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from napari_imsmicrolink.utils.color import COLOR_HEXES
from napari_imsmicrolink.utils.image import centered_transform, grayscale
from napari_imsmicrolink.utils.coords import pmap_coords_to_h5

from napari_imsmicrolink.utils.json import NpEncoder

class IMSMicroLink(QWidget):
def __init__(self, napari_viewer: napari.Viewer):
Expand Down Expand Up @@ -833,7 +833,7 @@ def _write_data(
pmeta_out_fp = Path(output_dir) / f"{project_name}-IMSML-meta.json"

with open(pmeta_out_fp, "w") as json_out:
json.dump(project_metadata, json_out, indent=1)
json.dump(project_metadata, json_out, indent=1, cls=NpEncoder)

if output_filetype == ".h5":
if split_by_file_roi:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 12 additions & 0 deletions src/napari_imsmicrolink/utils/json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json
import numpy as np

class NpEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.integer):
return int(obj)
if isinstance(obj, np.floating):
return float(obj)
if isinstance(obj, np.ndarray):
return obj.tolist()
return super(NpEncoder, self).default(obj)
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 4 additions & 20 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,10 @@ PLATFORM =
windows-latest: windows

[testenv]
platform =
macos: darwin
linux: linux
windows: win32
passenv =
CI
GITHUB_ACTIONS
DISPLAY XAUTHORITY
NUMPY_EXPERIMENTAL_ARRAY_FUNCTION
PYVISTA_OFF_SCREEN
deps =
pytest # https://docs.pytest.org/en/latest/contents.html
pytest-cov # https://pytest-cov.readthedocs.io/en/latest/
pytest-xvfb ; sys_platform == 'linux'
# you can remove these if you don't use them
napari
pytest-qt
qtpy
pyqt5
commands = pytest -v --color=yes --cov=napari_imsmicrolink --cov-report=xml
deps = pytest
pytest-cookies
tox
commands = pytest -v {posargs:tests}

[flake8]
max-line-length = 88
Expand Down

0 comments on commit c714621

Please sign in to comment.