diff --git a/.cruft.json b/.cruft.json index 09ddcda..2e42fa5 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,7 +1,7 @@ { "template": "https://github.com/scverse/cookiecutter-scverse", - "commit": "87a407a65408d75a949c0b54b19fd287475a56f8", - "checkout": null, + "commit": "d383d94fadff9e4e6fdb59d77c68cb900d7cedec", + "checkout": "v0.6.0", "context": { "cookiecutter": { "project_name": "pytometry", @@ -10,19 +10,33 @@ "author_full_name": "Maren Büttner", "author_email": "maren.buettner@tum.de", "github_user": "scverse", - "project_repo": "https://github.com/scverse/pytometry", + "github_repo": "pytometry", "license": "Apache License Version 2.0", + "ide_integration": true, "_copy_without_render": [ ".github/workflows/build.yaml", ".github/workflows/test.yaml", "docs/_templates/autosummary/**.rst" ], + "_exclude_on_template_update": [ + "CHANGELOG.md", + "LICENSE", + "README.md", + "docs/api.md", + "docs/index.md", + "docs/notebooks/example.ipynb", + "docs/references.bib", + "docs/references.md", + "src/**", + "tests/**" + ], "_render_devdocs": false, "_jinja2_env_vars": { "lstrip_blocks": true, "trim_blocks": true }, - "_template": "https://github.com/scverse/cookiecutter-scverse" + "_template": "https://github.com/scverse/cookiecutter-scverse", + "_commit": "d383d94fadff9e4e6fdb59d77c68cb900d7cedec" } }, "directory": null diff --git a/.editorconfig b/.editorconfig index 050f911..66678e3 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,10 +8,7 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{yml,yaml}] -indent_size = 2 - -[.cruft.json] +[{*.{yml,yaml,toml},.cruft.json}] indent_size = 2 [Makefile] diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index a5a20e6..3ca1ccb 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -23,67 +23,72 @@ body: - type: textarea id: versions attributes: - label: Version information + label: Versions description: | - Please paste below the output of + Which version of packages. + + Please install `session-info2`, run the following command in a notebook, + click the “Copy as Markdown” button, then paste the results into the text box below. + + ```python + In[1]: import session_info2; session_info2.session_info(dependencies=True) + ``` + + Alternatively, run this in a console: ```python - import session_info - session_info.show(html=False, dependencies=True) + >>> import session_info2; print(session_info2.session_info(dependencies=True)._repr_mimebundle_()["text/markdown"]) ``` + render: python placeholder: | - ----- - anndata 0.8.0rc2.dev27+ge524389 - session_info 1.0.0 - ----- - asttokens NA - awkward 1.8.0 - backcall 0.2.0 - cython_runtime NA - dateutil 2.8.2 - debugpy 1.6.0 - decorator 5.1.1 - entrypoints 0.4 - executing 0.8.3 - h5py 3.7.0 - ipykernel 6.15.0 - jedi 0.18.1 - mpl_toolkits NA - natsort 8.1.0 - numpy 1.22.4 - packaging 21.3 - pandas 1.4.2 - parso 0.8.3 - pexpect 4.8.0 - pickleshare 0.7.5 - pkg_resources NA - prompt_toolkit 3.0.29 - psutil 5.9.1 - ptyprocess 0.7.0 - pure_eval 0.2.2 - pydev_ipython NA - pydevconsole NA - pydevd 2.8.0 - pydevd_file_utils NA - pydevd_plugins NA - pydevd_tracing NA - pygments 2.12.0 - pytz 2022.1 - scipy 1.8.1 - setuptools 62.5.0 - setuptools_scm NA - six 1.16.0 - stack_data 0.3.0 - tornado 6.1 - traitlets 5.3.0 - wcwidth 0.2.5 - zmq 23.1.0 - ----- - IPython 8.4.0 - jupyter_client 7.3.4 - jupyter_core 4.10.0 - ----- - Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:58:50) [GCC 10.3.0] - Linux-5.18.6-arch1-1-x86_64-with-glibc2.35 - ----- - Session information updated at 2022-07-07 17:55 + anndata 0.11.3 + ---- ---- + charset-normalizer 3.4.1 + coverage 7.7.0 + psutil 7.0.0 + dask 2024.7.1 + jaraco.context 5.3.0 + numcodecs 0.15.1 + jaraco.functools 4.0.1 + Jinja2 3.1.6 + sphinxcontrib-jsmath 1.0.1 + sphinxcontrib-htmlhelp 2.1.0 + toolz 1.0.0 + session-info2 0.1.2 + PyYAML 6.0.2 + llvmlite 0.44.0 + scipy 1.15.2 + pandas 2.2.3 + sphinxcontrib-devhelp 2.0.0 + h5py 3.13.0 + tblib 3.0.0 + setuptools-scm 8.2.0 + more-itertools 10.3.0 + msgpack 1.1.0 + sparse 0.15.5 + wrapt 1.17.2 + jaraco.collections 5.1.0 + numba 0.61.0 + pyarrow 19.0.1 + pytz 2025.1 + MarkupSafe 3.0.2 + crc32c 2.7.1 + sphinxcontrib-qthelp 2.0.0 + sphinxcontrib-serializinghtml 2.0.0 + zarr 2.18.4 + asciitree 0.3.3 + six 1.17.0 + sphinxcontrib-applehelp 2.0.0 + numpy 2.1.3 + cloudpickle 3.1.1 + sphinxcontrib-bibtex 2.6.3 + natsort 8.4.0 + jaraco.text 3.12.1 + setuptools 76.1.0 + Deprecated 1.2.18 + packaging 24.2 + python-dateutil 2.9.0.post0 + ---- ---- + Python 3.13.2 | packaged by conda-forge | (main, Feb 17 2025, 14:10:22) [GCC 13.3.0] + OS Linux-6.11.0-109019-tuxedo-x86_64-with-glibc2.39 + Updated 2025-03-18 15:47 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6937ecb..04a29d8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,20 +10,24 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +defaults: + run: + # to fail on error in multiline statements (-e), in pipes (-o pipefail), and on unset variables (-u). + shell: bash -euo pipefail {0} + jobs: package: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - - name: Set up Python 3.13 - uses: actions/setup-python@v6 with: - python-version: "3.13" - cache: "pip" - cache-dependency-path: "**/pyproject.toml" - - name: Install build dependencies - run: python -m pip install --upgrade pip wheel twine build + filter: blob:none + fetch-depth: 0 + - name: Install uv + uses: astral-sh/setup-uv@v6 + with: + cache-dependency-glob: pyproject.toml - name: Build package - run: python -m build + run: uv build - name: Check package - run: twine check --strict dist/*.whl + run: uvx twine check --strict dist/*.whl diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5ed7927..dcebb24 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -4,6 +4,11 @@ on: release: types: [published] +defaults: + run: + # to fail on error in multiline statements (-e), in pipes (-o pipefail), and on unset variables (-u). + shell: bash -euo pipefail {0} + # Use "trusted publishing", see https://docs.pypi.org/trusted-publishers/ jobs: release: @@ -19,11 +24,11 @@ jobs: with: filter: blob:none fetch-depth: 0 - - uses: actions/setup-python@v6 + - name: Install uv + uses: astral-sh/setup-uv@v6 with: - python-version: "3.x" - cache: "pip" - - run: pip install build - - run: python -m build + cache-dependency-glob: pyproject.toml + - name: Build package + run: uv build - name: Publish package distributions to PyPI uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index ef5bf7d..0bd76e8 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,56 +12,92 @@ concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +defaults: + run: + # to fail on error in multiline statements (-e), in pipes (-o pipefail), and on unset variables (-u). + shell: bash -euo pipefail {0} + jobs: + # Get the test environment from hatch as defined in pyproject.toml. + # This ensures that the pyproject.toml is the single point of truth for test definitions and the same tests are + # run locally and on continuous integration. + # Check [[tool.hatch.envs.hatch-test.matrix]] in pyproject.toml and https://hatch.pypa.io/latest/environment/ for + # more details. + get-environments: + runs-on: ubuntu-latest + outputs: + envs: ${{ steps.get-envs.outputs.envs }} + steps: + - uses: actions/checkout@v4 + with: + filter: blob:none + fetch-depth: 0 + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Get test environments + id: get-envs + run: | + ENVS_JSON=$(uvx hatch env show --json | jq -c 'to_entries + | map( + select(.key | startswith("hatch-test")) + | { + name: .key, + label: (if (.key | contains("pre")) then .key + " (PRE-RELEASE DEPENDENCIES)" else .key end), + python: .value.python + } + )') + echo "envs=${ENVS_JSON}" | tee $GITHUB_OUTPUT + + # Run tests through hatch. Spawns a separate runner for each environment defined in the hatch matrix obtained above. test: - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash -e {0} # -e to fail on error + needs: get-environments strategy: fail-fast: false matrix: - include: - - os: ubuntu-latest - python: "3.11" - - os: ubuntu-latest - python: "3.13" - - os: ubuntu-latest - python: "3.13" - pip-flags: "--pre" - name: PRE-RELEASE DEPENDENCIES + os: [ubuntu-latest] + env: ${{ fromJSON(needs.get-environments.outputs.envs) }} - name: ${{ matrix.name }} Python ${{ matrix.python }} - - env: - OS: ${{ matrix.os }} - PYTHON: ${{ matrix.python }} + name: ${{ matrix.env.label }} + runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v5 - - name: Set up Python ${{ matrix.python }} - uses: actions/setup-python@v6 + - uses: actions/checkout@v4 with: - python-version: ${{ matrix.python }} - cache: "pip" - cache-dependency-path: "**/pyproject.toml" - - - name: Install test dependencies - run: | - python -m pip install --upgrade pip wheel - - name: Install dependencies - run: | - pip install ${{ matrix.pip-flags }} ".[dev,test]" - - name: Test + filter: blob:none + fetch-depth: 0 + - name: Install uv + uses: astral-sh/setup-uv@v5 + with: + python-version: ${{ matrix.env.python }} + cache-dependency-glob: pyproject.toml + - name: create hatch environment + run: uvx hatch env create ${{ matrix.env.name }} + - name: run tests using hatch env: MPLBACKEND: agg PLATFORM: ${{ matrix.os }} DISPLAY: :42 + run: uvx hatch run ${{ matrix.env.name }}:run-cov -v --color=yes -n auto + - name: generate coverage report run: | - coverage run -m pytest -v --color=yes - - name: Report coverage - run: | - coverage report + # See https://coverage.readthedocs.io/en/latest/config.html#run-patch + test -f .coverage || uvx hatch run ${{ matrix.env.name }}:cov-combine + uvx hatch run ${{ matrix.env.name }}:cov-report # report visibly + uvx hatch run ${{ matrix.env.name }}:coverage xml # create report for upload - name: Upload coverage uses: codecov/codecov-action@v5 + + # Check that all tests defined above pass. This makes it easy to set a single "required" test in branch + # protection instead of having to update it frequently. See https://github.com/re-actors/alls-green#why. + check: + name: Tests pass in all hatch environments + if: always() + needs: + - get-environments + - test + runs-on: ubuntu-latest + steps: + - uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} diff --git a/.gitignore b/.gitignore index 2a0ef5e..5a0b129 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,15 @@ buck-out/ # Compiled files .venv/ __pycache__/ +.*cache/ + +# Distribution / packaging +/dist/ + +# Tests and coverage +/data/ +/node_modules/ +/.coverage* .mypy_cache/ .ruff_cache/ @@ -26,7 +35,7 @@ __pycache__/ # IDEs /.idea/ -/.vscode/ +.vscode/ # Data files from tutorials /docs/notebooks/*.fcs diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a6c979..b9de3fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,12 +6,17 @@ default_stages: - pre-push minimum_pre_commit_version: 2.16.0 repos: - - repo: https://github.com/rbubley/mirrors-prettier - rev: v3.6.2 + - repo: https://github.com/biomejs/pre-commit + rev: v2.2.4 hooks: - - id: prettier + - id: biome-format + exclude: ^\.cruft\.json$ # inconsistent indentation with cruft - file never to be modified manually. + - repo: https://github.com/tox-dev/pyproject-fmt + rev: v2.6.0 + hooks: + - id: pyproject-fmt - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.14.2 + rev: v0.13.2 hooks: - id: ruff-check types_or: [python, pyi, jupyter] @@ -31,8 +36,3 @@ repos: # Check that there are no merge conflicts (could be generated by template sync) - id: check-merge-conflict args: [--assume-in-merge] - - repo: https://github.com/kynan/nbstripout - rev: "0.8.1" - hooks: - - id: nbstripout - files: 'docs/notebooks/.*\.ipynb$' diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 03e7881..c3f3f96 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -3,14 +3,13 @@ version: 2 build: os: ubuntu-24.04 tools: - python: "3.13" -sphinx: - configuration: docs/conf.py - # disable this for more lenient docs builds - fail_on_warning: true -python: - install: - - method: pip - path: . - extra_requirements: - - doc + python: "3.12" + jobs: + create_environment: + - asdf plugin add uv + - asdf install uv latest + - asdf global uv latest + build: + html: + - uvx hatch run docs:build + - mv docs/_build $READTHEDOCS_OUTPUT diff --git a/biome.jsonc b/biome.jsonc new file mode 100644 index 0000000..9f8f220 --- /dev/null +++ b/biome.jsonc @@ -0,0 +1,17 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.2.0/schema.json", + "vcs": { "enabled": true, "clientKind": "git", "useIgnoreFile": true }, + "formatter": { "useEditorconfig": true }, + "overrides": [ + { + "includes": ["./.vscode/*.json", "**/*.jsonc"], + "json": { + "formatter": { "trailingCommas": "all" }, + "parser": { + "allowComments": true, + "allowTrailingCommas": true, + }, + }, + }, + ], +} diff --git a/docs/_templates/autosummary/class.rst b/docs/_templates/autosummary/class.rst index e4665df..7b4a0cf 100644 --- a/docs/_templates/autosummary/class.rst +++ b/docs/_templates/autosummary/class.rst @@ -9,11 +9,11 @@ {% block attributes %} {% if attributes %} Attributes table -~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~ .. autosummary:: {% for item in attributes %} - ~{{ fullname }}.{{ item }} + ~{{ name }}.{{ item }} {%- endfor %} {% endif %} {% endblock %} @@ -26,7 +26,7 @@ Methods table .. autosummary:: {% for item in methods %} {%- if item != '__init__' %} - ~{{ fullname }}.{{ item }} + ~{{ name }}.{{ item }} {%- endif -%} {%- endfor %} {% endif %} @@ -35,7 +35,7 @@ Methods table {% block attributes_documentation %} {% if attributes %} Attributes -~~~~~~~~~~~ +~~~~~~~~~~ {% for item in attributes %} diff --git a/docs/conf.py b/docs/conf.py index beb0fb9..d8cbbc2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -37,7 +37,7 @@ html_context = { "display_github": True, # Integrate GitHub "github_user": "scverse", - "github_repo": "https://github.com/scverse/pytometry", + "github_repo": project_name, "github_version": "main", "conf_py_path": "/docs/", } @@ -55,6 +55,7 @@ "sphinx.ext.napoleon", "sphinxcontrib.bibtex", "sphinx_autodoc_typehints", + "sphinx_tabs.tabs", "sphinx.ext.mathjax", "IPython.sphinxext.ipython_console_highlighting", "sphinxext.opengraph", @@ -81,7 +82,6 @@ myst_url_schemes = ("http", "https", "mailto") nb_output_stderr = "remove" nb_execution_mode = "off" -nb_execution_timeout = 600 nb_merge_streams = True typehints_defaults = "braces" @@ -94,6 +94,7 @@ intersphinx_mapping = { "python": ("https://docs.python.org/3", None), "anndata": ("https://anndata.readthedocs.io/en/stable/", None), + "scanpy": ("https://scanpy.readthedocs.io/en/stable/", None), "numpy": ("https://numpy.org/doc/stable/", None), "matplotlib": ("https://matplotlib.org/stable", None), "pandas": ("https://pandas.pydata.org/pandas-docs/stable/", None), diff --git a/docs/contributing.md b/docs/contributing.md index 19a6864..699d942 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -1,22 +1,138 @@ # Contributing guide -Scanpy provides extensive [developer documentation][scanpy developer guide], most of which applies to this project, too. -This document will not reproduce the entire content from there. Instead, it aims at summarizing the most important -information to get you started on contributing. +This document aims at summarizing the most important information for getting you started on contributing to this project. +We assume that you are already familiar with git and with making pull requests on GitHub. -We assume that you are already familiar with git and with making pull requests on GitHub. If not, please refer -to the [scanpy developer guide][]. +For more extensive tutorials, that also cover the absolute basics, +please refer to other resources such as the [pyopensci tutorials][], +the [scientific Python tutorials][], or the [scanpy developer guide][]. + +[pyopensci tutorials]: https://www.pyopensci.org/learn.html +[scientific Python tutorials]: https://learn.scientific-python.org/development/tutorials/ +[scanpy developer guide]: https://scanpy.readthedocs.io/en/latest/dev/index.html + +:::{tip} The *hatch* project manager + +We highly recommend to familiarize yourself with [`hatch`][hatch]. +Hatch is a Python project manager that + +- manages virtual environments, separately for development, testing and building the documentation. + Separating the environments is useful to avoid dependency conflicts. +- allows to run tests locally in different environments (e.g. different python versions) +- allows to run tasks defined in `pyproject.toml`, e.g. to build documentation. + +While the project is setup with `hatch` in mind, +it is still possible to use different tools to manage dependencies, such as `uv` or `pip`. + +::: + +[hatch]: https://hatch.pypa.io/latest/ ## Installing dev dependencies -In addition to the packages needed to _use_ this package, you need additional python packages to _run tests_ and _build -the documentation_. It's easy to install them using `pip`: +In addition to the packages needed to _use_ this package, +you need additional python packages to [run tests](#writing-tests) and [build the documentation](#docs-building). + +:::::{tabs} +::::{group-tab} Hatch + +On the command line, you typically interact with hatch through its command line interface (CLI). +Running one of the following commands will automatically resolve the environments for testing and +building the documentation in the background: + +```bash +hatch test # defined in the table [tool.hatch.envs.hatch-test] in pyproject.toml +hatch run docs:build # defined in the table [tool.hatch.envs.docs] +``` + +When using an IDE such as VS Code, +you’ll have to point the editor at the paths to the virtual environments manually. +The environment you typically want to use as your main development environment is the `hatch-test` +environment with the latest Python version. + +To get a list of all environments for your projects, run ```bash -cd pytometry +hatch env show -i +``` + +This will list “Standalone” environments and a table of “Matrix” environments like the following: + +``` ++------------+---------+--------------------------+----------+---------------------------------+-------------+ +| Name | Type | Envs | Features | Dependencies | Scripts | ++------------+---------+--------------------------+----------+---------------------------------+-------------+ +| hatch-test | virtual | hatch-test.py3.10-stable | dev | coverage-enable-subprocess==1.0 | cov-combine | +| | | hatch-test.py3.13-stable | test | coverage[toml]~=7.4 | cov-report | +| | | hatch-test.py3.13-pre | | pytest-mock~=3.12 | run | +| | | | | pytest-randomly~=3.15 | run-cov | +| | | | | pytest-rerunfailures~=14.0 | | +| | | | | pytest-xdist[psutil]~=3.5 | | +| | | | | pytest~=8.1 | | ++------------+---------+--------------------------+----------+---------------------------------+-------------+ +``` + +From the `Envs` column, select the environment name you want to use for development. +In this example, it would be `hatch-test.py3.13-stable`. + +Next, create the environment with + +```bash +hatch env create hatch-test.py3.13-stable +``` + +Then, obtain the path to the environment using + +```bash +hatch env find hatch-test.py3.13-stable +``` + +In case you are using VScode, now open the command palette (Ctrl+Shift+P) and search for `Python: Select Interpreter`. +Choose `Enter Interpreter Path` and paste the path to the virtual environment from above. + +In this future, this may become easier through a hatch vscode extension. + +:::: + +::::{group-tab} uv + +A popular choice for managing virtual environments is [uv][]. +The main disadvantage compared to hatch is that it supports only a single environment per project at a time, +which requires you to mix the dependencies for running tests and building docs. +This can have undesired side-effects, +such as requiring to install a lower version of a library your project depends on, +only because an outdated sphinx plugin pins an older version. + +To initalize a virtual environment in the `.venv` directory of your project, simply run + +```bash +uv sync --all-extras +``` + +The `.venv` directory is typically automatically discovered by IDEs such as VS Code. + +:::: + +::::{group-tab} Pip + +Pip is nowadays mostly superseded by environment manager such as [hatch][]. +However, for the sake of completeness, and since it’s ubiquitously available, +we describe how you can manage environments manually using `pip`: + +```bash +python3 -m venv .venv +source .venv/bin/activate pip install -e ".[dev,test,doc]" ``` +The `.venv` directory is typically automatically discovered by IDEs such as VS Code. + +:::: +::::: + +[hatch environments]: https://hatch.pypa.io/latest/tutorials/environment/basic-usage/ +[uv]: https://docs.astral.sh/uv/ + ## Code-style This package uses [pre-commit][] to enforce consistent code-styles. @@ -28,10 +144,11 @@ To enable pre-commit locally, simply run pre-commit install ``` -in the root of the repository. Pre-commit will automatically download all dependencies when it is run for the first time. +in the root of the repository. +Pre-commit will automatically download all dependencies when it is run for the first time. -Alternatively, you can rely on the [pre-commit.ci][] service enabled on GitHub. If you didn't run `pre-commit` before -pushing changes to GitHub it will automatically commit fixes to your pull request, or show an error message. +Alternatively, you can rely on the [pre-commit.ci][] service enabled on GitHub. +If you didn’t run `pre-commit` before pushing changes to GitHub it will automatically commit fixes to your pull request, or show an error message. If pre-commit.ci added a commit on a branch you still have been working on locally, simply use @@ -42,71 +159,121 @@ git pull --rebase to integrate the changes into yours. While the [pre-commit.ci][] is useful, we strongly encourage installing and running pre-commit locally first to understand its usage. -Finally, most editors have an _autoformat on save_ feature. Consider enabling this option for [ruff][ruff-editors] -and [prettier][prettier-editors]. +Finally, most editors have an _autoformat on save_ feature. +Consider enabling this option for [ruff][ruff-editors] and [biome][biome-editors]. +[pre-commit]: https://pre-commit.com/ +[pre-commit.ci]: https://pre-commit.ci/ [ruff-editors]: https://docs.astral.sh/ruff/integrations/ -[prettier-editors]: https://prettier.io/docs/en/editors.html +[biome-editors]: https://biomejs.dev/guides/integrate-in-editor/ + +(writing-tests)= ## Writing tests -```{note} -Remember to first install the package with `pip install -e '.[dev,test]'` +This package uses [pytest][] for automated testing. +Please write {doc}`scanpy:dev/testing` for every function added to the package. + +Most IDEs integrate with pytest and provide a GUI to run tests. +Just point yours to one of the environments returned by + +```bash +hatch env create hatch-test # create test environments for all supported versions +hatch env find hatch-test # list all possible test environment paths +``` + +Alternatively, you can run all tests from the command line by executing + +:::::{tabs} +::::{group-tab} Hatch + +```bash +hatch test # test with the highest supported Python version +# or +hatch test --all # test with all supported Python versions +``` + +:::: + +::::{group-tab} uv + +```bash +uv run pytest ``` -This package uses the [pytest][] for automated testing. Please [write tests][scanpy-test-docs] for every function added -to the package. +:::: -Most IDEs integrate with pytest and provide a GUI to run tests. Alternatively, you can run all tests from the -command line by executing +::::{group-tab} Pip ```bash +source .venv/bin/activate pytest ``` +:::: +::::: + in the root of the repository. +[pytest]: https://docs.pytest.org/ + ### Continuous integration -Continuous integration will automatically run the tests on all pull requests and test +Continuous integration via GitHub actions will automatically run the tests on all pull requests and test against the minimum and maximum supported Python version. -Additionally, there's a CI job that tests against pre-releases of all dependencies -(if there are any). The purpose of this check is to detect incompatibilities -of new package versions early on and gives you time to fix the issue or reach -out to the developers of the dependency before the package is released to a wider audience. +Additionally, there’s a CI job that tests against pre-releases of all dependencies (if there are any). +The purpose of this check is to detect incompatibilities of new package versions early on and +gives you time to fix the issue or reach out to the developers of the dependency before the package +is released to a wider audience. -[scanpy-test-docs]: https://scanpy.readthedocs.io/en/latest/dev/testing.html#writing-tests +The CI job is defined in `.github/workflows/test.yaml`, +however the single point of truth for CI jobs is the Hatch test matrix defined in `pyproject.toml`. +This means that local testing via hatch and remote testing on CI tests against the same python versions and uses the same environments. ## Publishing a release ### Updating the version number -Before making a release, you need to update the version number in the `pyproject.toml` file. Please adhere to [Semantic Versioning][semver], in brief +Before making a release, you need to update the version number in the `pyproject.toml` file. +Please adhere to [Semantic Versioning][semver], in brief > Given a version number MAJOR.MINOR.PATCH, increment the: > -> 1. MAJOR version when you make incompatible API changes, -> 2. MINOR version when you add functionality in a backwards compatible manner, and -> 3. PATCH version when you make backwards compatible bug fixes. +> 1. MAJOR version when you make incompatible API changes, +> 2. MINOR version when you add functionality in a backwards compatible manner, and +> 3. PATCH version when you make backwards compatible bug fixes. > > Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. Once you are done, commit and push your changes and navigate to the "Releases" page of this project on GitHub. -Specify `vX.X.X` as a tag name and create a release. For more information, see [managing GitHub releases][]. This will automatically create a git tag and trigger a Github workflow that creates a release on PyPI. +Specify `vX.X.X` as a tag name and create a release. +For more information, see [managing GitHub releases][]. +This will automatically create a git tag and trigger a Github workflow that creates a release on [PyPI][]. + +[semver]: https://semver.org/ +[managing GitHub releases]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository +[pypi]: https://pypi.org/ ## Writing documentation -Please write documentation for new or changed features and use-cases. This project uses [sphinx][] with the following features: +Please write documentation for new or changed features and use-cases. +This project uses [sphinx][] with the following features: -- the [myst][] extension allows to write documentation in markdown/Markedly Structured Text +- The [myst][] extension allows to write documentation in markdown/Markedly Structured Text - [Numpy-style docstrings][numpydoc] (through the [napoloen][numpydoc-napoleon] extension). - Jupyter notebooks as tutorials through [myst-nb][] (See [Tutorials with myst-nb](#tutorials-with-myst-nb-and-jupyter-notebooks)) -- [Sphinx autodoc typehints][], to automatically reference annotated input and output types +- [sphinx-autodoc-typehints][], to automatically reference annotated input and output types - Citations (like {cite:p}`Virshup_2023`) can be included with [sphinxcontrib-bibtex](https://sphinxcontrib-bibtex.readthedocs.io/) -See the [scanpy developer docs](https://scanpy.readthedocs.io/en/latest/dev/documentation.html) for more information -on how to write documentation. +See scanpy’s {doc}`scanpy:dev/documentation` for more information on how to write your own. + +[sphinx]: https://www.sphinx-doc.org/en/master/ +[myst]: https://myst-parser.readthedocs.io/en/latest/intro.html +[myst-nb]: https://myst-nb.readthedocs.io/en/latest/ +[numpydoc-napoleon]: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html +[numpydoc]: https://numpydoc.readthedocs.io/en/latest/format.html +[sphinx-autodoc-typehints]: https://github.com/tox-dev/sphinx-autodoc-typehints ### Tutorials with myst-nb and jupyter notebooks @@ -114,47 +281,50 @@ The documentation is set-up to render jupyter notebooks stored in the `docs/note Currently, only notebooks in `.ipynb` format are supported that will be included with both their input and output cells. It is your responsibility to update and re-run the notebook whenever necessary. -If you are interested in automatically running notebooks as part of the continuous integration, please check -out [this feature request](https://github.com/scverse/cookiecutter-scverse/issues/40) in the `cookiecutter-scverse` -repository. +If you are interested in automatically running notebooks as part of the continuous integration, +please check out [this feature request][issue-render-notebooks] in the `cookiecutter-scverse` repository. + +[issue-render-notebooks]: https://github.com/scverse/cookiecutter-scverse/issues/40 #### Hints -- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. Only - if you do so can sphinx automatically create a link to the external documentation. -- If building the documentation fails because of a missing link that is outside your control, you can add an entry to - the `nitpick_ignore` list in `docs/conf.py` +- If you refer to objects from other packages, please add an entry to `intersphinx_mapping` in `docs/conf.py`. + Only if you do so can sphinx automatically create a link to the external documentation. +- If building the documentation fails because of a missing link that is outside your control, + you can add an entry to the `nitpick_ignore` list in `docs/conf.py` + +(docs-building)= -#### Building the docs locally +### Building the docs locally + +:::::{tabs} +::::{group-tab} Hatch + +```bash +hatch run docs:build +hatch run docs:open +``` + +:::: + +::::{group-tab} uv ```bash cd docs -make html -open _build/html/index.html +uv run sphinx-build -M html . _build -W +(xdg-)open _build/html/index.html ``` - +:::: -[scanpy developer guide]: https://scanpy.readthedocs.io/en/latest/dev/index.html -[cookiecutter-scverse-instance]: https://cookiecutter-scverse-instance.readthedocs.io/en/latest/template_usage.html -[github quickstart guide]: https://docs.github.com/en/get-started/quickstart/create-a-repo?tool=webui -[codecov]: https://about.codecov.io/sign-up/ -[codecov docs]: https://docs.codecov.com/docs -[codecov bot]: https://docs.codecov.com/docs/team-bot -[codecov app]: https://github.com/apps/codecov -[pre-commit.ci]: https://pre-commit.ci/ -[readthedocs.org]: https://readthedocs.org/ -[myst-nb]: https://myst-nb.readthedocs.io/en/latest/ -[jupytext]: https://jupytext.readthedocs.io/en/latest/ -[pre-commit]: https://pre-commit.com/ -[anndata]: https://github.com/scverse/anndata -[mudata]: https://github.com/scverse/mudata -[pytest]: https://docs.pytest.org/ -[semver]: https://semver.org/ -[sphinx]: https://www.sphinx-doc.org/en/master/ -[myst]: https://myst-parser.readthedocs.io/en/latest/intro.html -[numpydoc-napoleon]: https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html -[numpydoc]: https://numpydoc.readthedocs.io/en/latest/format.html -[sphinx autodoc typehints]: https://github.com/tox-dev/sphinx-autodoc-typehints -[pypi]: https://pypi.org/ -[managing GitHub releases]: https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository +::::{group-tab} Pip + +```bash +source .venv/bin/activate +cd docs +sphinx-build -M html . _build -W +(xdg-)open _build/html/index.html +``` + +:::: +::::: diff --git a/pyproject.toml b/pyproject.toml index 4001228..4def2ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,147 +1,158 @@ [build-system] build-backend = "hatchling.build" -requires = ["hatchling", "hatch-vcs"] +requires = [ "hatchling" ] [project] name = "pytometry" -dynamic = ["version"] +version = "0.1.6" description = "Flow & mass cytometry analytics in scverse" readme = "README.md" -requires-python = ">=3.11" -license = {file = "LICENSE"} +license = { file = "LICENSE" } +maintainers = [ + { name = "Maren Büttner", email = "maren.buettner@tum.de" }, + { name = "Quentin Blampey" }, +] authors = [ - {name = "Maren Büttner"}, + { name = "Maren Büttner" }, ] -maintainers = [ - {name = "Maren Büttner", email = "maren.buettner@tum.de"}, - {name = "Quentin Blampey"}, +requires-python = ">=3.11" +classifiers = [ + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", ] -urls.Documentation = "https://pytometry.readthedocs.io/" -urls.Source = "https://github.com/scverse/pytometry" -urls.Home-page = "https://github.com/scverse/pytometry" dependencies = [ - "numpy>=2.0.0", - "numba>=0.57", - "pandas", - "anndata", - "scanpy", - "scipy", - "seaborn", - "matplotlib", - "readfcs>=1.1.0", - "flowutils", - "consensusclustering>=0.2.4", - "minisom", + "consensusclustering>=0.2.4", + "flowutils", + "minisom", + "numba>=0.57", + "numpy>=2", + "readfcs>=1.1", + "scanpy", ] - -[project.optional-dependencies] -dev = [ - "pre-commit", +optional-dependencies.dev = [ + "pre-commit", + "twine>=4.0.2", ] -doc = [ - "docutils>=0.8,!=0.18.*,!=0.19.*", - "sphinx>=4", - "sphinx-book-theme>=1.0.0", - "myst-nb>=1.1.0", - "sphinxcontrib-bibtex>=1.0.0", - "sphinx-autodoc-typehints", - "sphinxext-opengraph", - # For notebooks - "ipykernel", - "ipython", - "sphinx-copybutton", - "pandas", +optional-dependencies.doc = [ + "docutils>=0.8,!=0.18.*,!=0.19.*", + "ipykernel", + "ipython", + "myst-nb>=1.1", + "pandas", + # Until pybtex >0.24.0 releases: https://bitbucket.org/pybtex-devs/pybtex/issues/169/ + "setuptools", + "sphinx>=8.1", + "sphinx-autodoc-typehints", + "sphinx-book-theme>=1", + "sphinx-copybutton", + "sphinx-tabs", + "sphinxcontrib-bibtex>=1", + "sphinxext-opengraph", ] -test = [ - "pytest", - "coverage", - "nbproject", - "nbproject_test", +optional-dependencies.test = [ + "coverage>=7.10", + "pytest", + "pytest-cov", # For VS Code’s coverage functionality ] +# https://docs.pypi.org/project_metadata/#project-urls +urls.Documentation = "https://pytometry.readthedocs.io/" +urls.Homepage = "https://github.com/scverse/pytometry" +urls.Source = "https://github.com/scverse/pytometry" -[tool.hatch.version] -source = "vcs" +[tool.hatch.envs.default] +installer = "uv" +features = [ "dev" ] -[tool.coverage.run] -source = ["pytometry"] -omit = [ - "**/test_*.py", -] +[tool.hatch.envs.docs] +features = [ "doc" ] +scripts.build = "sphinx-build -M html docs docs/_build -W {args}" +scripts.open = "python -m webbrowser -t docs/_build/html/index.html" +scripts.clean = "git clean -fdX -- {args:docs}" -[tool.pytest.ini_options] -testpaths = ["tests"] -xfail_strict = true -addopts = [ - "--import-mode=importlib", # allow using test files with same name +# Test the lowest and highest supported Python versions with normal deps +[[tool.hatch.envs.hatch-test.matrix]] +deps = [ "stable" ] +python = [ "3.11", "3.13" ] + +# Test the newest supported Python version also with pre-release deps +[[tool.hatch.envs.hatch-test.matrix]] +deps = [ "pre" ] +python = [ "3.13" ] + +[tool.hatch.envs.hatch-test] +features = [ "dev", "test" ] + +[tool.hatch.envs.hatch-test.overrides] +# If the matrix variable `deps` is set to "pre", +# set the environment variable `UV_PRERELEASE` to "allow". +matrix.deps.env-vars = [ + { key = "UV_PRERELEASE", value = "allow", if = [ "pre" ] }, ] [tool.ruff] line-length = 120 -src = ["src"] -extend-include = ["*.ipynb"] +src = [ "src" ] +extend-include = [ "*.ipynb" ] -[tool.ruff.format] -docstring-code-format = true +format.docstring-code-format = true -[tool.ruff.lint] -select = [ - "F", # Errors detected by Pyflakes - "E", # Error detected by Pycodestyle - "W", # Warning detected by Pycodestyle - "I", # isort - "D", # pydocstyle - "B", # flake8-bugbear - "TID", # flake8-tidy-imports - "C4", # flake8-comprehensions - "BLE", # flake8-blind-except - "UP", # pyupgrade - "RUF022", # Reorder __all__ with isort-style rules - "RUF100", # Report unused noqa directives +lint.select = [ + "B", # flake8-bugbear + "BLE", # flake8-blind-except + "C4", # flake8-comprehensions + "D", # pydocstyle + "E", # Error detected by Pycodestyle + "F", # Errors detected by Pyflakes + "I", # isort + "RUF100", # Report unused noqa directives + "TID", # flake8-tidy-imports + "UP", # pyupgrade + "W", # Warning detected by Pycodestyle ] -ignore = [ - # line too long -> we accept long comment lines; formatter gets rid of long code lines - "E501", - # 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", - # __magic__ methods are often self-explanatory, allow missing docstrings - "D105", - # 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", - ## Disable one in each pair of mutually incompatible rules - # We don’t want a blank line before a class docstring - "D203", - # We want docstrings to start immediately after the opening triple quote - "D213", +lint.ignore = [ + "B008", # Errors from function calls in argument defaults. These are fine when the result is immutable. + "D100", # Missing docstring in public module + "D104", # Missing docstring in public package + "D105", # __magic__ methods are often self-explanatory, allow missing docstrings + "D107", # Missing docstring in __init__ + # Disable one in each pair of mutually incompatible rules + "D203", # We don’t want a blank line before a class docstring + "D213", # <> We want docstrings to start immediately after the opening triple quote + "D400", # first line should end with a period [Bug: doesn’t work with single-line docstrings] + "D401", # First line should be in imperative mood; try rephrasing + "E501", # line too long -> we accept long comment lines; formatter gets rid of long code lines + "E731", # Do not assign a lambda expression, use a def -> lambda expression assignments are convenient + "E741", # allow I, O, l as variable names -> I is the identity matrix ] +lint.per-file-ignores."*/__init__.py" = [ "F401" ] +lint.per-file-ignores."docs/*" = [ "I" ] +lint.per-file-ignores."tests/*" = [ "D" ] +lint.pydocstyle.convention = "numpy" -[tool.ruff.lint.pydocstyle] -convention = "numpy" +[tool.pytest.ini_options] +testpaths = [ "tests" ] +xfail_strict = true +addopts = [ + "--import-mode=importlib", # allow using test files with same name +] -[tool.ruff.lint.per-file-ignores] -"docs/*" = ["I"] -"tests/*" = ["D"] -"*/__init__.py" = ["F401"] +[tool.coverage.run] +source = [ "pytometry" ] +patch = [ "subprocess" ] +omit = [ + "**/test_*.py", +] [tool.cruft] skip = [ - "tests", - "src/**/__init__.py", - "src/**/basic.py", - "docs/api.md", - "docs/changelog.md", - "docs/references.bib", - "docs/references.md", - "docs/notebooks/example.ipynb", + "tests", + "src/**/__init__.py", + "src/**/basic.py", + "docs/api.md", + "docs/changelog.md", + "docs/references.bib", + "docs/references.md", + "docs/notebooks/example.ipynb", ] diff --git a/src/pytometry/pp/_process_data.py b/src/pytometry/pp/_process_data.py index 278400f..a024809 100644 --- a/src/pytometry/pp/_process_data.py +++ b/src/pytometry/pp/_process_data.py @@ -160,11 +160,11 @@ def compensate( 'with neither `adata.var.index` nor `adata.var["channel"].' ) # match columns of spill mat such that they exactly correspond to adata.var.index - ref_names = ref_col[np.in1d(ref_col, idx_in)] - query_names = compens.columns[np.in1d(compens.columns, idx_in)] + ref_names = ref_col[np.isin(ref_col, idx_in)] + query_names = compens.columns[np.isin(compens.columns, idx_in)] idx_sort = [np.where(query_names == x)[0][0] for x in ref_names] - query_idx = np.in1d(compens.columns, query_names) - ref_idx = np.in1d(ref_col, ref_names) + query_idx = np.isin(compens.columns, query_names) + ref_idx = np.isin(ref_col, ref_names) # subset compensation matrix to the columns to run the compensation on compens = compens.iloc[query_idx, query_idx] diff --git a/tests/test_notebooks.py b/tests/test_notebooks.py deleted file mode 100644 index 43b10ce..0000000 --- a/tests/test_notebooks.py +++ /dev/null @@ -1,16 +0,0 @@ -from pathlib import Path - -import nbproject_test as test -from nbproject._logger import logger - - -def test_notebooks(): - # assuming this is in the tests folder - docs_folder = Path(__file__).parents[1] / "docs/" - - for check_folder in docs_folder.glob("./**"): - # these are the notebook testpaths - if not str(check_folder).endswith(("guides", "tutorials")): - continue - logger.debug(f"\n{check_folder}") - test.execute_notebooks(check_folder, write=True)