From f1ba83cdbaba1c4e730d3a7f664c9be1f1075219 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 6 Dec 2022 10:20:38 +0000 Subject: [PATCH] Update packaging (#46) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update pre-commit config * update args for new brainreg version * lint * update manifest * Bump version: 0.0.5-rc0 → 0.0.5-rc1 * update testing * update packaging * update requirements * update manifest * move entry point to pyproject.toml * update hub preview version * update release for use with setuptools_scm * migrate from BG to neuroinformatics actions * add setuptools_scm to dev requirements * reduce number of tested version * update python versions tested * update release --- .flake8 | 4 + .github/workflows/plugin_preview.yml | 2 +- .github/workflows/test_and_deploy.yml | 101 ++++++++++++++++++-------- .pre-commit-config.yaml | 13 ++-- CITATION.CFF | 42 +++++------ MANIFEST.in | 2 + brainreg_napari/__init__.py | 1 - brainreg_napari/register.py | 3 + pyproject.toml | 76 ++++++++++++++++++- setup.cfg | 36 --------- setup.py | 66 ----------------- tox.ini | 16 ++-- 12 files changed, 187 insertions(+), 175 deletions(-) create mode 100644 .flake8 delete mode 100644 setup.py diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..f524e7f --- /dev/null +++ b/.flake8 @@ -0,0 +1,4 @@ +[flake8] +ignore = E203, E231, W503, E722 +max-line-length = 79 +exclude = __init__.py,build,.eggs diff --git a/.github/workflows/plugin_preview.yml b/.github/workflows/plugin_preview.yml index 4c70b9e..a0f4383 100644 --- a/.github/workflows/plugin_preview.yml +++ b/.github/workflows/plugin_preview.yml @@ -16,6 +16,6 @@ jobs: uses: actions/checkout@v2 - name: napari hub Preview Page Builder - uses: chanzuckerberg/napari-hub-preview-action@v0.1.5 + uses: chanzuckerberg/napari-hub-preview-action@v0.1 with: hub-ref: main diff --git a/.github/workflows/test_and_deploy.yml b/.github/workflows/test_and_deploy.yml index d2afd33..f83a6b0 100644 --- a/.github/workflows/test_and_deploy.yml +++ b/.github/workflows/test_and_deploy.yml @@ -1,59 +1,98 @@ name: tests -on: [push, pull_request] +on: + push: + branches: + - '*' + tags: + - '*' + pull_request: jobs: linting: runs-on: ubuntu-latest steps: - - uses: brainglobe/actions/lint@v1 + - uses: neuroinformatics-unit/actions/lint@v1.2.0 manifest: name: Check Manifest runs-on: ubuntu-latest steps: - - uses: brainglobe/actions/check_manifest@v1 + - uses: neuroinformatics-unit/actions/check_manifest@v1.2.0 test: - needs: [linting, manifest] + needs: [ linting, manifest ] name: ${{ matrix.os }} py${{ matrix.python-version }} runs-on: ${{ matrix.os }} strategy: matrix: - # Run all supported Python versions on linux and windows + # Run all supported Python versions on linux python-version: ["3.8", "3.9", "3.10"] - os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + # Test on Windows and macOS on only one OS to save time (and CI minutes) + include: + - os: macos-latest + python-version: "3.10" + - os: windows-latest + python-version: "3.10" steps: - # Setup pyqt libraries - - uses: tlambert03/setup-qt-libs@v1 - # Run tests - - uses: brainglobe/actions/test@v1 + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 with: 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) - needs: [test] - runs-on: ubuntu-latest - if: contains(github.ref, 'tags') - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: "3.x" + # 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 -U setuptools setuptools_scm wheel twine - - name: Build and publish + python -m pip install setuptools tox tox-gh-actions + + # this runs the platform-specific tests declared in tox.ini + - name: Test with tox + uses: GabrielBB/xvfb-action@v1 + with: + run: python -m tox env: - TWINE_USERNAME: __token__ - TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }} - run: | - git tag - python setup.py sdist bdist_wheel - twine upload dist/* + PLATFORM: ${{ matrix.platform }} + + - name: Coverage + uses: codecov/codecov-action@v2 + + 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@main + + + 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/gh-action-pypi-publish@v1.5.0 + with: + user: __token__ + password: ${{ secrets.TWINE_API_KEY }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index da63503..5f1f059 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: hooks: - id: isort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.1.0 + rev: v4.3.0 hooks: - id: check-docstring-first - id: check-executables-have-shebangs @@ -15,16 +15,19 @@ repos: args: [--fix=lf] - id: requirements-txt-fixer - id: trailing-whitespace - - repo: https://gitlab.com/pycqa/flake8 - rev: 3.9.2 + # bump2version produces whitespace in setup.cfg, so exclude to + # not inferfere with versioning + exclude: setup.cfg + - repo: https://github.com/pycqa/flake8 + rev: 5.0.4 hooks: - id: flake8 - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 22.10.0 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.931 + rev: v0.990 hooks: - id: mypy additional_dependencies: diff --git a/CITATION.CFF b/CITATION.CFF index f179705..bddbfee 100644 --- a/CITATION.CFF +++ b/CITATION.CFF @@ -9,19 +9,19 @@ authors: given-names: "M." - family-names: "Rousseau" given-names: "C." -- family-names: "Cossell" +- family-names: "Cossell" given-names: "L." -- family-names: "Tsitoura" +- family-names: "Tsitoura" given-names: " C." -- family-names: "Lenzi" +- family-names: "Lenzi" given-names: " S." -- family-names: "Obenhaus" +- family-names: "Obenhaus" given-names: "H." -- family-names: "Claudi" +- family-names: "Claudi" given-names: "F." -- family-names: "Branco" +- family-names: "Branco" given-names: "T." -- family-names: "Margrie" +- family-names: "Margrie" given-names: "T." url: https://github.com/brainglobe/brainreg-napari preferred-citation: @@ -40,19 +40,19 @@ preferred-citation: given-names: "M." - family-names: "Rousseau" given-names: "C." - - family-names: "Cossell" + - family-names: "Cossell" given-names: "L." - - family-names: "Tsitoura" + - family-names: "Tsitoura" given-names: " C." - - family-names: "Lenzi" + - family-names: "Lenzi" given-names: "S." - - family-names: "Obenhaus" + - family-names: "Obenhaus" given-names: "H." - - family-names: "Claudi" + - family-names: "Claudi" given-names: "F." - - family-names: "Branco" + - family-names: "Branco" given-names: "T." - - family-names: "Margrie" + - family-names: "Margrie" given-names: "T." references: - type: article @@ -70,13 +70,13 @@ references: given-names: "A." - family-names: "Jorge" given-names: "M." - - family-names: "Osten" + - family-names: "Osten" given-names: "P." - - family-names: "Ourselin" + - family-names: "Ourselin" given-names: "S." - - family-names: "Modat" + - family-names: "Modat" given-names: "M." - - family-names: "Margrie" + - family-names: "Margrie" given-names: "T." references: - type: article @@ -94,9 +94,9 @@ references: given-names: "L." - family-names: "Tyson" given-names: "A." - - family-names: "Branco" + - family-names: "Branco" given-names: "T." - - family-names: "Margrie" + - family-names: "Margrie" given-names: "T." - - family-names: "Portugues" + - family-names: "Portugues" given-names: "R." diff --git a/MANIFEST.in b/MANIFEST.in index 98bfaf4..92a1b01 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,10 +3,12 @@ include README.md include tox.ini include brainreg_napari/napari.yaml include .napari/config.yml +include CITATION.CFF recursive-exclude * __pycache__ recursive-exclude * *.py[co] recursive-exclude .napari * exclude .pre-commit-config.yaml +exclude .flake8 recursive-exclude examples * diff --git a/brainreg_napari/__init__.py b/brainreg_napari/__init__.py index 6b1072e..e69de29 100644 --- a/brainreg_napari/__init__.py +++ b/brainreg_napari/__init__.py @@ -1 +0,0 @@ -__version__ = "0.0.5-rc0" diff --git a/brainreg_napari/register.py b/brainreg_napari/register.py index 28111bf..2ab0e73 100644 --- a/brainreg_napari/register.py +++ b/brainreg_napari/register.py @@ -30,6 +30,8 @@ initialise_brainreg, ) +PRE_PROCESSING_ARGS = None + def add_registered_image_layers( viewer: napari.Viewer, *, registration_directory: pathlib.Path @@ -440,6 +442,7 @@ def run(): data_orientation, atlas.metadata["orientation"], niftyreg_args, + PRE_PROCESSING_ARGS, scaling, load_parallel, sort_input_file, diff --git a/pyproject.toml b/pyproject.toml index 9adde97..2880d4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,4 +1,77 @@ +[project] +name = "brainreg-napari" +authors = [{name = "Adam Tyson, Stephen Lenzi", email= "code@adamltyson.com"}] +description = "Multi-atlas whole-brain microscopy registration" +readme = "README.md" +requires-python = ">=3.8.0" +dynamic = ["version"] +classifiers = [ + "Development Status :: 4 - Beta", + "Framework :: napari", + "Topic :: Scientific/Engineering :: Image Recognition", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Operating System :: OS Independent", + ] + +license = {text = "BSD-3-Clause"} +dependencies = [ + "napari", + "napari-plugin-engine >= 0.1.4", + "magicgui", + "qtpy", + "brainglobe-napari-io", + "brainreg", + "brainreg-segment", + "pooch>1", # For sample data +] + +[project.optional-dependencies] +dev = [ + "black", + "pytest-cov", + "pytest", + "pytest-qt", + "napari", + "pyqt5", + "tox", + "gitpython", + "coverage>=5.0.3", + "bump2version", + "pre-commit", + "flake8", + "check-manifest", + "setuptools_scm", +] + +[project.urls] +homepage = "https://brainglobe.info" +bug_tracker = "https://github.com/brainglobe/brainreg-napari/issues" +documentation = "https://docs.brainglobe.info/brainreg-napari" +source_code = "https://github.com/brainglobe/brainreg-napari" +user_support = "https://forum.image.sc/tag/brainglobe" +twitter = "https://twitter.com/brain_globe" + +[project.entry-points."napari.manifest"] +brainreg-napari = "brainreg_napari:napari.yaml" + +[build-system] +requires = [ + "setuptools>=45", + "wheel", + "setuptools_scm[toml]>=6.2", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] + [tool.black] +target-version = ['py38', 'py39', 'py310'] skip-string-normalization = false line-length = 79 exclude = ''' @@ -8,10 +81,7 @@ exclude = ''' | \.git | \.hg | \.mypy_cache - | \.tox - | \.venv | _build - | buck-out | build | dist )/ diff --git a/setup.cfg b/setup.cfg index 591683e..edd8d70 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,38 +1,2 @@ -[bumpversion] -current_version = 0.0.5-rc0 -commit = True -tag = True -tag_name = {new_version} -parse = (?P\d+)\.(?P\d+)\.(?P\d+)(\-(?P[a-z]+)(?P\d+))? -serialize = - {major}.{minor}.{patch}-{release}{rc} - {major}.{minor}.{patch} - -[options.entry_points] -napari.manifest = - brainreg-napari = brainreg_napari:napari.yaml - [options.package_data] brainreg-napari = napari.yaml - -[bumpversion:part:release] -optional_value = prod -first_value = rc -values = - rc - prod - -[bumpversion:part:rc] - -[bumpversion:file:setup.py] -search = version="{current_version}" -replace = version="{new_version}" - -[bumpversion:file:brainreg_napari/__init__.py] -search = __version__ = "{current_version}" -replace = __version__ = "{new_version}" - -[flake8] -ignore = E203, E231, W503, E722 -max-line-length = 79 -exclude = __init__.py,build,.eggs diff --git a/setup.py b/setup.py deleted file mode 100644 index c98c7f3..0000000 --- a/setup.py +++ /dev/null @@ -1,66 +0,0 @@ -from os import path - -from setuptools import find_packages, setup - -this_directory = path.abspath(path.dirname(__file__)) -with open(path.join(this_directory, "README.md"), encoding="utf-8") as f: - long_description = f.read() - -requirements = [ - "napari", - "napari-plugin-engine >= 0.1.4", - "napari-ndtiffs", - "brainglobe-napari-io", - "brainreg", - "pooch>1", # For sample data -] - -setup( - name="brainreg-napari", - version="0.0.5-rc0", - author="Stephen Lenzi, Adam Tyson", - author_email="code@adamltyson.com", - license="BSD-3-Clause", - description="Multi-atlas whole-brain microscopy registration", - long_description=long_description, - long_description_content_type="text/markdown", - packages=find_packages(), - include_package_data=True, - python_requires=">=3.8", - install_requires=requirements, - extras_require={ - "dev": [ - "black", - "pytest-cov", - "pytest", - "gitpython", - "coverage>=5.0.3", - "bump2version", - "pre-commit", - "flake8", - "check-manifest", - ] - }, - url="https://brainglobe.info", - project_urls={ - "Source Code": "https://github.com/brainglobe/brainreg-napari", - "Bug Tracker": "https://github.com/brainglobe/brainreg-napari/issues", - "Documentation": "https://docs.brainglobe.info/", - "User Support": "https://forum.image.sc/tag/brainglobe", - "Twitter": "https://twitter.com/brain_globe", - }, - classifiers=[ - "Development Status :: 4 - Beta", - "Framework :: napari", - "Topic :: Scientific/Engineering :: Image Recognition", - "Intended Audience :: Developers", - "Intended Audience :: Science/Research", - "Programming Language :: Python", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Operating System :: POSIX :: Linux", - "Operating System :: Microsoft :: Windows :: Windows 10", - ], -) diff --git a/tox.ini b/tox.ini index 54197e4..86567cf 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,7 @@ # For more information about tox, see https://tox.readthedocs.io/en/latest/ [tox] -envlist = py{38,39,310}-{linux,windows} +envlist = py{38,39,310}-{linux,macos,windows} +isolated_build=true [gh-actions] python = @@ -11,6 +12,7 @@ python = [gh-actions:env] PLATFORM = ubuntu-latest: linux + macos-latest: macos windows-latest: windows [testenv] @@ -24,14 +26,6 @@ passenv = 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 - magicgui - pytest-qt - qtpy - pyqt5 +extras = + dev commands = pytest -v --color=yes --cov=brainreg_napari --cov-report=xml