From 96dbd5fbfc9fb968d62932d937e7614b9301c518 Mon Sep 17 00:00:00 2001 From: Lukas Heumos Date: Tue, 25 Mar 2025 10:29:39 +0100 Subject: [PATCH] Modernize setup Signed-off-by: Lukas Heumos --- .flake8 | 60 ---------------------------------- .github/workflows/release.yaml | 2 +- .github/workflows/test.yaml | 4 +-- .pre-commit-config.yaml | 21 ++++-------- .readthedocs.yaml | 19 +++++------ README.md | 11 ++++--- docs/_static/.gitkeep | 0 docs/_templates/.gitkeep | 0 docs/api.md | 1 - docs/conf.py.rej | 44 ------------------------- docs/preprocessing.rst | 8 ----- pyproject.toml | 34 ++++--------------- tests/conftest.py | 3 +- tests/pl/test_render_labels.py | 4 --- tests/pl/test_utils.py | 3 -- 15 files changed, 33 insertions(+), 181 deletions(-) delete mode 100644 .flake8 delete mode 100644 docs/_static/.gitkeep delete mode 100644 docs/_templates/.gitkeep delete mode 100644 docs/conf.py.rej delete mode 100644 docs/preprocessing.rst diff --git a/.flake8 b/.flake8 deleted file mode 100644 index a30ef821..00000000 --- a/.flake8 +++ /dev/null @@ -1,60 +0,0 @@ -# Can't yet be moved to the pyproject.toml due to https://github.com/PyCQA/flake8/issues/234 -[flake8] -max-line-length = 120 -ignore = - # line break before a binary operator -> black does not adhere to PEP8 - W503 - # line break occured after a binary operator -> black does not adhere to PEP8 - W504 - # line too long -> we accept long comment lines; black gets rid of long code lines - E501 - # whitespace before : -> black does not adhere to PEP8 - E203 - # line break before binary operator -> black does not adhere to PEP8 - W503 - # missing whitespace after ,', ';', or ':' -> black does not adhere to PEP8 - E231 - # continuation line over-indented for hanging indent -> black does not adhere to PEP8 - E126 - # too many leading '#' for block comment -> this is fine for indicating sections - E262 - # Do not assign a lambda expression, use a def -> lambda expression assignments are convenient - E731 - # allow I, O, l as variable names -> I is the identity matrix - E741 - # Missing docstring in public package - D104 - # Missing docstring in public module - D100 - # Missing docstring in __init__ - D107 - # Errors from function calls in argument defaults. These are fine when the result is immutable. - B008 - # Missing docstring in magic method - D105 - # format string does contain unindexed parameters - P101 - # first line should end with a period [Bug: doesn't work with single-line docstrings] - D400 - # First line should be in imperative mood; try rephrasing - D401 -exclude = .git,__pycache__,build,docs/_build,dist -per-file-ignores = - tests/*: D - */__init__.py: F401 - src/spatialdata_io/_constants/_enum.py: RST, D -rst-roles = - class, - func, - ref, - attr, - cite:p, - cite:t, -rst-directives = - envvar, - exception, - seealso, -rst-substitutions = - version, -extend-ignore = - RST307, diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ebc1e49e..9bd6c545 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,7 +11,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Set up Python 3.12 - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.12" cache: pip diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6cd3250e..d460deff 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,9 +26,9 @@ jobs: PYTHON: ${{ matrix.python }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v3 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 552a4f7c..53f55fa9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,26 +8,19 @@ minimum_pre_commit_version: 2.16.0 ci: skip: [] repos: - - repo: https://github.com/psf/black - rev: 25.1.0 - hooks: - - id: black - - repo: https://github.com/pre-commit/mirrors-prettier - rev: v4.0.0-alpha.8 + - repo: https://github.com/rbubley/mirrors-prettier + rev: v3.5.1 hooks: - id: prettier - - repo: https://github.com/asottile/blacken-docs - rev: 1.19.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.2 hooks: - - id: blacken-docs + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy rev: v1.15.0 hooks: - id: mypy additional_dependencies: [numpy, types-requests] exclude: tests/|docs/ - - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.11.0 - hooks: - - id: ruff - args: [--fix, --exit-non-zero-on-fix] diff --git a/.readthedocs.yaml b/.readthedocs.yaml index dbec2a8f..dd21449c 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,16 +1,15 @@ -# https://docs.readthedocs.io/en/stable/config-file/v2.html version: 2 build: - os: ubuntu-20.04 + os: ubuntu-24.04 tools: - python: "3.10" + python: "3.12" + commands: + - asdf plugin add uv + - asdf install uv latest + - asdf global uv latest + - uv venv + - uv pip install .[docs,pre] + - .venv/bin/python -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html sphinx: configuration: docs/conf.py fail_on_warning: false -python: - install: - - method: pip - path: . - extra_requirements: - - docs - - pre diff --git a/README.md b/README.md index d356b79c..08242353 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,10 @@ The `spatialdata-plot` package extends `spatialdata` with a declarative plotting API that enables to quickly visualize `spatialdata` objects and their respective elements (i.e. `images`, `labels`, `points` and `shapes`). -SpatialData’s plotting capabilities allow to quickly visualise all contained modalities. The user can specify which elements should be rendered (images, labels, points, shapes) and specify certain parameters for each layer, such as for example the intent to color shapes by a gene’s expression profile or which color to use for which image channel. When the plot is then eventually displayed, all transformations, alignments and coordinate systems are internally processed to form the final visualisation. In concordance with the general SpatialData philosophy, all modalities of the major spatial technologies are supported out of the box. +SpatialData’s plotting capabilities allow to quickly visualise all contained modalities. +The user can specify which elements should be rendered (images, labels, points, shapes) and specify certain parameters for each layer, such as for example the intent to color shapes by a gene’s expression profile or which color to use for which image channel. +When the plot is then eventually displayed, all transformations, alignments and coordinate systems are internally processed to form the final visualisation. +In concordance with the general SpatialData philosophy, all modalities of the major spatial technologies are supported out of the box. @@ -36,15 +39,13 @@ Python installed, we recommend installing [Mambaforge](https://github.com/conda- There are several alternative options to install spatialdata-plot: - -1. Install the latest development version: +2. Install the latest development version: ```bash pip install git+https://github.com/scverse/spatialdata-plot.git@main diff --git a/docs/_static/.gitkeep b/docs/_static/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/_templates/.gitkeep b/docs/_templates/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/docs/api.md b/docs/api.md index 11987c51..6ad7c002 100644 --- a/docs/api.md +++ b/docs/api.md @@ -4,7 +4,6 @@ :maxdepth: 1 :caption: API -preprocessing.rst plotting.rst ``` diff --git a/docs/conf.py.rej b/docs/conf.py.rej deleted file mode 100644 index 97caeb8a..00000000 --- a/docs/conf.py.rej +++ /dev/null @@ -1,44 +0,0 @@ -diff a/docs/conf.py b/docs/conf.py (rejected hunks) -@@ -57,6 +57,7 @@ extensions = [ - "sphinx_autodoc_typehints", - "sphinx.ext.mathjax", - "IPython.sphinxext.ipython_console_highlighting", -+ "sphinxext.opengraph", - *[p.stem for p in (HERE / "extensions").glob("*.py")], - ] - -@@ -108,12 +109,15 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "**.ipynb_checkpoints"] - # - html_theme = "sphinx_book_theme" - html_static_path = ["_static"] -+html_css_files = ["css/custom.css"] -+ - html_title = project_name - - html_theme_options = { - "repository_url": repository_url, - "use_repository_button": True, - "path_to_docs": "docs/", -+ "navigation_with_keys": False, - } - - pygments_style = "default" -@@ -123,18 +127,3 @@ nitpick_ignore = [ - # you can add an exception to this list. - # ("py:class", "igraph.Graph"), - ] -- -- --def setup(app): -- """App setup hook.""" -- app.add_config_value( -- "recommonmark_config", -- { -- "auto_toc_tree_section": "Contents", -- "enable_auto_toc_tree": True, -- "enable_math": True, -- "enable_inline_math": False, -- "enable_eval_rst": True, -- }, -- True, -- ) diff --git a/docs/preprocessing.rst b/docs/preprocessing.rst deleted file mode 100644 index 64283b22..00000000 --- a/docs/preprocessing.rst +++ /dev/null @@ -1,8 +0,0 @@ -.. highlight:: shell - -====================== -Preprocessing (`.pp`) -====================== - -.. automodule:: spatialdata_plot.pp.basic - :members: diff --git a/pyproject.toml b/pyproject.toml index 45bbd798..d491c024 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,27 +73,6 @@ filterwarnings = [ # "ignore:.*U.*mode is deprecated:DeprecationWarning", ] -[tool.black] -line-length = 120 -target-version = ['py310'] -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs - | \.git - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - )/ -) -''' - [tool.jupytext] formats = "ipynb,md" @@ -110,6 +89,7 @@ version-file = "_version.py" allow-direct-references = true [tool.ruff] +line-length = 120 exclude = [ ".git", ".tox", @@ -119,7 +99,8 @@ exclude = [ "dist", "setup.py", ] -lint.ignore = [ +[tool.ruff.lint] +ignore = [ # Do not assign a lambda expression, use a def -> lambda expression assignments are convenient "E731", # allow I, O, l as variable names -> I is the identity matrix, i, j, k, l is reasonable indexing notation @@ -137,8 +118,7 @@ lint.ignore = [ # Missing docstring in magic method "D105", ] -line-length = 120 -lint.select = [ +select = [ "D", # flake8-docstrings "I", # isort "E", # pycodestyle @@ -157,8 +137,8 @@ lint.select = [ "RET", # flake8-raise "PGH", # pygrep-hooks ] -lint.unfixable = ["B", "UP", "C4", "BLE", "T20", "RET"] -target-version = "py310" +unfixable = ["B", "UP", "C4", "BLE", "T20", "RET"] + [tool.ruff.lint.per-file-ignores] "tests/*" = ["D", "PT", "B024"] "*/__init__.py" = ["F401", "D104", "D107", "E402"] @@ -166,6 +146,7 @@ target-version = "py310" # "src/spatialdata/transformations/transformations.py" = ["D101","D102", "D106", "B024", "T201", "RET504"] "tests/conftest.py"= ["E402", "RET504"] "src/spatialdata_plot/pl/utils.py"= ["PGH003"] + [tool.ruff.lint.pydocstyle] convention = "numpy" @@ -189,4 +170,3 @@ push = false "{version}", "{pep440_version}", ] - diff --git a/tests/conftest.py b/tests/conftest.py index 73ea410b..1c085297 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -214,8 +214,7 @@ def empty_table() -> SpatialData: @pytest.fixture( # params=["labels"] - params=["full", "empty"] - + ["images", "labels", "points", "table_single_annotation", "table_multiple_annotations"] + params=["full", "empty"] + ["images", "labels", "points", "table_single_annotation", "table_multiple_annotations"] # + ["empty_" + x for x in ["table"]] # TODO: empty table not supported yet ) def sdata(request) -> SpatialData: diff --git a/tests/pl/test_render_labels.py b/tests/pl/test_render_labels.py index d938ae33..a3f592b0 100644 --- a/tests/pl/test_render_labels.py +++ b/tests/pl/test_render_labels.py @@ -98,9 +98,7 @@ def test_plot_can_color_labels_by_categorical_variable(self, sdata_blobs: Spatia ], ) def test_plot_can_color_labels_by_categorical_variable_in_other_table(self, sdata_blobs: SpatialData, label: str): - def _make_tablemodel_with_categorical_labels(sdata_blobs, label): - adata = sdata_blobs.tables["table"].copy() max_col = adata.to_df().idxmax(axis=1) max_col = max_col.str.replace("channel_", "ch").str.replace("_sum", "") @@ -163,7 +161,6 @@ def test_plot_label_colorbar_uses_alpha_of_less_transparent_infill( self, sdata_blobs: SpatialData, ): - sdata_blobs.pl.render_labels( "blobs_labels", color="channel_0_sum", fill_alpha=0.1, outline_alpha=0.7, contour_px=15 ).pl.show() @@ -172,7 +169,6 @@ def test_plot_label_colorbar_uses_alpha_of_less_transparent_outline( self, sdata_blobs: SpatialData, ): - sdata_blobs.pl.render_labels("blobs_labels", color="channel_0_sum", fill_alpha=0.7, outline_alpha=0.1).pl.show() def test_can_plot_with_one_element_color_table(self, sdata_blobs: SpatialData): diff --git a/tests/pl/test_utils.py b/tests/pl/test_utils.py index 0ad75710..d8ecb000 100644 --- a/tests/pl/test_utils.py +++ b/tests/pl/test_utils.py @@ -86,7 +86,6 @@ def test_plot_can_set_zero_in_cmap_to_transparent(self, sdata_blobs: SpatialData ], ) def test_is_color_like(color_result: tuple[ColorLike, bool]): - color, result = color_result assert spatialdata_plot.pl.utils._is_color_like(color) == result @@ -121,7 +120,6 @@ def test_utils_sanitise_na_color(input_output): ], ) def test_utils_sanitise_na_color_accepts_valid_inputs(input_output): - func_input, expected_output = input_output assert _sanitise_na_color(func_input) == expected_output @@ -141,7 +139,6 @@ def test_utils_sanitise_na_color_fails_when_input_isnt_a_color(): ], ) def test_utils_get_subplots_produces_correct_axs_layout(input_output): - num_images, ncols, len_axs, axs_visible = input_output _, axs = _get_subplots(num_images=num_images, ncols=ncols)