From ad47e2361c251242b1fcff039002585b2391e406 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:37:02 +0100 Subject: [PATCH 1/8] update style workflows --- .github/workflows/code-style.yaml | 49 ------------------------------- .pre-commit-config.yaml | 19 +++++------- 2 files changed, 7 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/code-style.yaml diff --git a/.github/workflows/code-style.yaml b/.github/workflows/code-style.yaml deleted file mode 100644 index 34f12fae..00000000 --- a/.github/workflows/code-style.yaml +++ /dev/null @@ -1,49 +0,0 @@ -name: style -concurrency: - group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} - cancel-in-progress: true -on: # yamllint disable-line rule:truthy - pull_request: - push: - branches: [main] - workflow_dispatch: - -jobs: - style: - timeout-minutes: 10 - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Setup Python 3.9 - uses: actions/setup-python@v5 - with: - python-version: '3.9' - architecture: 'x64' - - name: Install dependencies - run: | - python -m pip install --progress-bar off --upgrade pip setuptools - python -m pip install --progress-bar off .[style] - - name: Run isort - uses: isort/isort-action@master - - name: Run black - uses: psf/black@stable - with: - options: "--check --verbose" - - name: Run Ruff - run: ruff check pycrostates - - name: Run codespell - uses: codespell-project/actions-codespell@master - with: - check_filenames: true - check_hidden: true - skip: ./.git,./build,./.github,*.bib,./.mypy_cache,./.pytest_cache - ignore_words_file: ./.codespellignore - - name: Run pydocstyle - run: pydocstyle . - - name: Run bibclean - run: bibclean-check docs/references.bib - - name: Run toml-sort - run: toml-sort pyproject.toml --check - - name: Run yamllint - run: yamllint . -c .yamllint.yaml --strict diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46e20331..76cda31b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,3 @@ -ci: - skip: [codespell, pydocstyle, yamllint] - repos: - repo: https://github.com/pycqa/isort rev: 5.13.2 @@ -8,25 +5,23 @@ repos: - id: isort files: pycrostates - - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.0 - hooks: - - id: black - args: [--quiet] - files: pycrostates - - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.8 hooks: - id: ruff - args: [--fix, --exit-non-zero-on-fix] + name: ruff linter + args: [--fix] + files: pycrostates + - id: ruff-format + name: ruff formatter files: pycrostates - repo: https://github.com/codespell-project/codespell rev: v2.2.6 hooks: - id: codespell - args: [--check-filenames, --ignore-words=.codespellignore, --skip=*.bib] + args: [--write-changes] + additional_dependencies: [tomli] - repo: https://github.com/pycqa/pydocstyle rev: 6.3.0 From 542dc96671553e477bc97366cf779e98727c164b Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:37:06 +0100 Subject: [PATCH 2/8] fix type-hint --- pycrostates/utils/_logs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pycrostates/utils/_logs.py b/pycrostates/utils/_logs.py index 6b74f670..42f401aa 100644 --- a/pycrostates/utils/_logs.py +++ b/pycrostates/utils/_logs.py @@ -158,7 +158,7 @@ class _use_log_level: %(verbose)s """ - def __init__(self, verbose: Union[bool, str, int, None] = None): + def __init__(self, verbose: Optional[Union[bool, str, int]] = None): self._old_level = logger.level self._level = verbose From 22f0e57ca9e1201551b7ef0e0422d0420da45d40 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:38:58 +0100 Subject: [PATCH 3/8] update dependencies and configuration --- pyproject.toml | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 142b5fc5..8b11f8dc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -75,20 +75,24 @@ docs = [ 'sphinx_gallery', 'sphinxcontrib-bibtex', ] +stubs = [ + 'isort', + 'mypy', + 'ruff>=0.1.8', +] style = [ 'bibclean', - 'black', - 'codespell', + 'codespell[toml]>=2.2.4', 'isort', 'pydocstyle[toml]', - 'ruff', + 'ruff>=0.1.8', 'toml-sort', 'yamllint', ] test = [ 'pymatreader', - 'pytest', 'pytest-cov', + 'pytest>=6.0', ] [project.scripts] @@ -100,21 +104,11 @@ homepage = 'https://pycrostates.readthedocs.io/en/master/' source = 'https://github.com/vferat/pycrostates' tracker = 'https://github.com/vferat/pycrostates/issues' -[tool.black] -extend-exclude = ''' -( - __pycache__ - | \.github/ - | docs/ - | paper/ - | pycrostates/html_templates/repr - | setup.py - | tutorials/ -) -''' -include = '\.pyi?$' -line-length = 88 -target-version = ['py39'] +[tool.codespell] +check-filenames = true +check-hidden = true +ignore-words = '.codespellignore' +skip = 'build,.git,.mypy_cache,.pytest_cache' [tool.coverage.report] exclude_lines = [ @@ -166,8 +160,14 @@ extend-exclude = [ 'setup.py', ] line-length = 88 +select = ["E", "F", "W"] +target-version = 'py39' + +[tool.ruff.format] +docstring-code-format = true [tool.ruff.per-file-ignores] +'*.pyi' = ['E501'] '__init__.py' = ['F401'] [tool.setuptools] From 68ca7d7504ecd270c3248857e3f2d34cf3b4e0ed Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:40:37 +0100 Subject: [PATCH 4/8] add workflows to generate stubs --- .github/workflows/publish.yaml | 6 ++- .github/workflows/stubs.yaml | 41 +++++++++++++++++++++ tools/stubgen.py | 67 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/stubs.yaml create mode 100644 tools/stubgen.py diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index b534e5fa..6fcb3b14 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -20,7 +20,11 @@ jobs: - name: Install dependencies run: | python -m pip install --progress-bar off --upgrade pip setuptools - python -m pip install --progress-bar off .[build] + python -m pip install --progress-bar off -e .[build,stubs] + - name: Display system information + run: pycrostates-sys_info --developer + - name: Generate stub files + run: python tools/stubgen.py - name: Build and publish env: TWINE_USERNAME: __token__ diff --git a/.github/workflows/stubs.yaml b/.github/workflows/stubs.yaml new file mode 100644 index 00000000..90545bf2 --- /dev/null +++ b/.github/workflows/stubs.yaml @@ -0,0 +1,41 @@ +name: stubs +concurrency: + group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.ref }} + cancel-in-progress: true +on: # yamllint disable-line rule:truthy + schedule: + - cron: '0 3 * * *' + workflow_dispatch: + +jobs: + generate: + timeout-minutes: 10 + runs-on: ubuntu-latest + defaults: + run: + shell: bash + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: 3.9 + architecture: 'x64' + - name: Install package + run: | + python -m pip install --progress-bar off --upgrade pip setuptools + python -m pip install --progress-bar off -e .[stubs] + - name: Display system information + run: pycrostates-sys_info --developer + - name: Generate stub files + run: python tools/stubgen.py + - name: Push stub files + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -m "deploy stub files [ci skip]" + git push + fi diff --git a/tools/stubgen.py b/tools/stubgen.py new file mode 100644 index 00000000..6b90cc00 --- /dev/null +++ b/tools/stubgen.py @@ -0,0 +1,67 @@ +import ast +import subprocess +import sys +from importlib import import_module +from pathlib import Path + +import isort +from mypy import stubgen + +import pycrostates + +directory = Path(pycrostates.__file__).parent +# remove existing stub files +for file in directory.rglob("*.pyi"): + file.unlink() +# generate stub files, including private members and docstrings +files = [ + str(file.as_posix()) + for file in directory.rglob("*.py") + if file.parent.name not in ("commands", "tests") + and file.name not in ("conftest.py", "_tests.py", "_version.py") +] +stubgen.main( + [ + "--no-analysis", + "--no-import", + "--include-private", + "--include-docstrings", + "--output", + str(directory.parent), + *files, + ] +) +stubs = list(directory.rglob("*.pyi")) +config = str((directory.parent / "pyproject.toml")) +config_isort = isort.settings.Config(config) + +# expand docstrings and inject into stub files +for stub in stubs: + module_path = str(stub.relative_to(directory).with_suffix("").as_posix()) + module = import_module(f"{directory.name}.{module_path.replace('/', '.')}") + module_ast = ast.parse(stub.read_text(encoding="utf-8")) + objects = [ + node + for node in module_ast.body + if isinstance(node, (ast.ClassDef, ast.FunctionDef)) + ] + for node in objects: + docstring = getattr(module, node.name).__doc__ + if not docstring and isinstance(node, ast.FunctionDef): + continue + elif docstring: + node.body[0].value.value = docstring + for method in node.body: + if not isinstance(method, ast.FunctionDef): + continue + docstring = getattr(getattr(module, node.name), method.name).__doc__ + if docstring: + method.body[0].value.value = docstring + unparsed = ast.unparse(module_ast) + stub.write_text(unparsed, encoding="utf-8") + # sort imports + isort.file(stub, config=config_isort) + +# run ruff to improve stub style +exec = subprocess.run(["ruff", "format", str(directory), "--config", config]) +sys.exit(exec.returncode) From ec52adbb01f787013a657cdbf95b4b211014fc7e Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:42:36 +0100 Subject: [PATCH 5/8] improve _docs.py --- pycrostates/utils/_docs.py | 91 +++++++++++--------------------------- 1 file changed, 26 insertions(+), 65 deletions(-) diff --git a/pycrostates/utils/_docs.py b/pycrostates/utils/_docs.py index 7e080d96..3aa9432a 100644 --- a/pycrostates/utils/_docs.py +++ b/pycrostates/utils/_docs.py @@ -23,16 +23,15 @@ ) for key in keys: - entry = docdict_mne[key] + entry: str = docdict_mne[key] if ".. versionchanged::" in entry: entry = entry.replace(".. versionchanged::", ".. versionchanged:: MNE ") if ".. versionadded::" in entry: entry = entry.replace(".. versionadded::", ".. versionadded:: MNE ") docdict[key] = entry +del key -docdict[ - "verbose" -] = """ +docdict["verbose"] = """ verbose : int | str | bool | None Sets the verbosity level. The verbosity increases gradually between ``"CRITICAL"``, ``"ERROR"``, ``"WARNING"``, ``"INFO"`` and ``"DEBUG"``. If None is provided, the @@ -40,27 +39,19 @@ ``"WARNING"`` for False and to ``"INFO"`` for True.""" # ---- Clusters ---- -docdict[ - "n_clusters" -] = """ +docdict["n_clusters"] = """ n_clusters : int The number of clusters, i.e. the number of microstates. """ -docdict[ - "cluster_centers" -] = """ +docdict["cluster_centers"] = """ cluster_centers : array (n_clusters, n_channels) Fitted clusters, i.e. the microstates maps.""" -docdict[ - "cluster_names" -] = """ +docdict["cluster_names"] = """ cluster_names : list | None Name of the clusters.""" # ---- Metrics ----- -docdict[ - "cluster" -] = """ +docdict["cluster"] = """ cluster : :ref:`cluster` Fitted clustering algorithm from which to compute score. For more details about current clustering implementations, check the :ref:`Clustering` section of the @@ -68,42 +59,28 @@ """ # ------ I/O ------- -docdict[ - "fname_fiff" -] = """ +docdict["fname_fiff"] = """ fname : str | Path Path to the ``.fif`` file where the clustering solution is saved.""" # -- Segmentation -- -docdict[ - "cluster_centers_seg" -] = """ +docdict["cluster_centers_seg"] = """ cluster_centers : array (n_clusters, n_channels) Clusters, i.e. the microstates maps used to compute the segmentation.""" -docdict[ - "labels_raw" -] = """ +docdict["labels_raw"] = """ labels : array of shape ``(n_samples,)`` Microstates labels attributed to each sample, i.e. the segmentation.""" -docdict[ - "labels_epo" -] = """ +docdict["labels_epo"] = """ labels : array of shape ``(n_epochs, n_samples)`` Microstates labels attributed to each sample, i.e. the segmentation.""" -docdict[ - "labels_transition" -] = """ +docdict["labels_transition"] = """ labels : array of shape ``(n_samples,)`` or ``(n_epochs, n_samples)`` Microstates labels attributed to each sample, i.e. the segmentation.""" # TODO: predict_parameters docstring is missing. -docdict[ - "predict_parameters" -] = """ +docdict["predict_parameters"] = """ predict_parameters : dict | None The prediction parameters.""" -docdict[ - "stat_transition" -] = """ +docdict["stat_transition"] = """ stat : str Aggregate statistic to compute transitions. Can be: @@ -112,9 +89,7 @@ the first axis is always equal to ``1``. * ``percent``: normalize count such as the probabilities along the first axis is always equal to ``100``.""" -docdict[ - "stat_expected_transitions" -] = """ +docdict["stat_expected_transitions"] = """ stat : str Aggregate statistic to compute transitions. Can be: @@ -122,48 +97,34 @@ the first axis is always equal to ``1``. * ``percent``: normalize count such as the probabilities along the first axis is always equal to ``100``.""" -docdict[ - "ignore_repetitions" -] = """ +docdict["ignore_repetitions"] = """ ignore_repetitions : bool If ``True``, ignores state repetitions. For example, the input sequence ``AAABBCCD`` will be transformed into ``ABCD`` before any calculation. This is equivalent to setting the duration of all states to 1 sample.""" -docdict[ - "transition_matrix" -] = """ +docdict["transition_matrix"] = """ T : array of shape ``(n_cluster, n_cluster)`` Array of transition probability values from one label to another. First axis indicates state ``"from"``. Second axis indicates state ``"to"``.""" # ------ Viz ------- -docdict[ - "cmap" -] = """ +docdict["cmap"] = """ cmap : str | colormap | None The colormap to use. If None, ``viridis`` is used.""" -docdict[ - "block" -] = """ +docdict["block"] = """ block : bool Whether to halt program execution until the figure is closed.""" -docdict[ - "axes_topo" -] = """ +docdict["axes_topo"] = """ axes : Axes | None Either ``None`` to create a new figure or axes (or an array of axes) on which the topographic map should be plotted. If the number of microstates maps to plot is ``≥ 1``, an array of axes of size ``n_clusters`` should be provided.""" -docdict[ - "axes_seg" -] = """ +docdict["axes_seg"] = """ axes : Axes | None Either ``None`` to create a new figure or axes on which the segmentation is plotted.""" -docdict[ - "axes_cbar" -] = """ +docdict["axes_cbar"] = """ cbar_axes : Axes | None Axes on which to draw the colorbar, otherwise the colormap takes space from the main axes.""" @@ -218,16 +179,16 @@ def fill_doc(f: Callable) -> Callable: def _indentcount_lines(lines: list[str]) -> int: """Minimum indent for all lines in line list. - >>> lines = [' one', ' two', ' three'] + >>> lines = [" one", " two", " three"] >>> indentcount_lines(lines) 1 >>> lines = [] >>> indentcount_lines(lines) 0 - >>> lines = [' one'] + >>> lines = [" one"] >>> indentcount_lines(lines) 1 - >>> indentcount_lines([' ']) + >>> indentcount_lines([" "]) 0 """ indent = sys.maxsize @@ -270,7 +231,7 @@ def copy_doc(source: Callable) -> Callable: >>> class B(A): ... @copy_doc(A.m1) ... def m1(): - ... ''' this gets appended''' + ... '''this gets appended''' ... pass >>> print(B.m1.__doc__) Docstring for m1 this gets appended From dc4cf92e0b61af58d699996e9c1b4f3e16aefc1d Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 13:56:07 +0100 Subject: [PATCH 6/8] improve type-hints and ignore html templates --- pycrostates/__init__.py | 2 +- pycrostates/cluster/__init__.py | 2 +- pycrostates/cluster/utils/__init__.py | 2 +- pycrostates/datasets/__init__.py | 2 +- pycrostates/io/__init__.py | 2 +- pycrostates/metrics/__init__.py | 2 +- pycrostates/preprocessing/__init__.py | 2 +- pycrostates/segmentation/__init__.py | 2 +- pycrostates/utils/__init__.py | 2 +- pycrostates/utils/_imports.py | 4 ++-- pycrostates/viz/__init__.py | 2 +- tools/stubgen.py | 12 +++++++++--- 12 files changed, 21 insertions(+), 15 deletions(-) diff --git a/pycrostates/__init__.py b/pycrostates/__init__.py index 999f2576..950b6a86 100644 --- a/pycrostates/__init__.py +++ b/pycrostates/__init__.py @@ -5,7 +5,7 @@ from .utils._logs import set_log_level from .utils.sys_info import sys_info # noqa: F401 -__all__ = ( +__all__: tuple[str, ...] = ( "cluster", "datasets", "metrics", diff --git a/pycrostates/cluster/__init__.py b/pycrostates/cluster/__init__.py index bd97d04f..4d6c6ca3 100644 --- a/pycrostates/cluster/__init__.py +++ b/pycrostates/cluster/__init__.py @@ -18,7 +18,7 @@ from .aahc import AAHCluster # noqa: F401 from .kmeans import ModKMeans # noqa: F401 -__all__ = ( +__all__: tuple[str, ...] = ( "ModKMeans", "AAHCluster", ) diff --git a/pycrostates/cluster/utils/__init__.py b/pycrostates/cluster/utils/__init__.py index d224258a..235bf2e1 100644 --- a/pycrostates/cluster/utils/__init__.py +++ b/pycrostates/cluster/utils/__init__.py @@ -2,4 +2,4 @@ from .utils import optimize_order # noqa: F401 -__all__ = ("optimize_order",) +__all__: tuple[str, ...] = ("optimize_order",) diff --git a/pycrostates/datasets/__init__.py b/pycrostates/datasets/__init__.py index 77d82eea..77397cab 100644 --- a/pycrostates/datasets/__init__.py +++ b/pycrostates/datasets/__init__.py @@ -7,4 +7,4 @@ from . import lemon -__all__ = ("lemon",) +__all__: tuple[str, ...] = ("lemon",) diff --git a/pycrostates/io/__init__.py b/pycrostates/io/__init__.py index 6bff703e..01096d4c 100644 --- a/pycrostates/io/__init__.py +++ b/pycrostates/io/__init__.py @@ -4,4 +4,4 @@ from .meas_info import ChInfo from .reader import read_cluster -__all__ = ("ChData", "ChInfo", "read_cluster") +__all__: tuple[str, ...] = ("ChData", "ChInfo", "read_cluster") diff --git a/pycrostates/metrics/__init__.py b/pycrostates/metrics/__init__.py index 926e35ec..073f9075 100644 --- a/pycrostates/metrics/__init__.py +++ b/pycrostates/metrics/__init__.py @@ -7,7 +7,7 @@ from .dunn import dunn_score from .silhouette import silhouette_score -__all__ = ( +__all__: tuple[str, ...] = ( "calinski_harabasz_score", "davies_bouldin_score", "dunn_score", diff --git a/pycrostates/preprocessing/__init__.py b/pycrostates/preprocessing/__init__.py index 88aea68e..6d29671d 100644 --- a/pycrostates/preprocessing/__init__.py +++ b/pycrostates/preprocessing/__init__.py @@ -7,4 +7,4 @@ from .resample import resample from .spatial_filter import apply_spatial_filter -__all__ = ("apply_spatial_filter", "extract_gfp_peaks", "resample") +__all__: tuple[str, ...] = ("apply_spatial_filter", "extract_gfp_peaks", "resample") diff --git a/pycrostates/segmentation/__init__.py b/pycrostates/segmentation/__init__.py index 85714ecc..17b0c492 100644 --- a/pycrostates/segmentation/__init__.py +++ b/pycrostates/segmentation/__init__.py @@ -4,7 +4,7 @@ compute_transition_matrix, ) -__all__ = ( +__all__: tuple[str, ...] = ( "compute_expected_transition_matrix", "compute_transition_matrix", "EpochsSegmentation", diff --git a/pycrostates/utils/__init__.py b/pycrostates/utils/__init__.py index 9ab02015..8877fae1 100644 --- a/pycrostates/utils/__init__.py +++ b/pycrostates/utils/__init__.py @@ -3,4 +3,4 @@ from ._config import get_config from .utils import _compare_infos, _corr_vectors, _distance_matrix # noqa: F401 -__all__ = ("get_config",) +__all__: tuple[str, ...] = ("get_config",) diff --git a/pycrostates/utils/_imports.py b/pycrostates/utils/_imports.py index a60ce880..33fabb9e 100644 --- a/pycrostates/utils/_imports.py +++ b/pycrostates/utils/_imports.py @@ -9,7 +9,7 @@ # A mapping from import name to package name (on PyPI) when the package name # is different. {python: PyPI} -INSTALL_MAPPING = {} +_INSTALL_MAPPING: dict[str, str] = {} def import_optional_dependency(name: str, extra: str = "", raise_error: bool = True): @@ -38,7 +38,7 @@ def import_optional_dependency(name: str, extra: str = "", raise_error: bool = T The imported module when found. None is returned when the package is not found and raise_error is False. """ - package_name = INSTALL_MAPPING.get(name) + package_name = _INSTALL_MAPPING.get(name) install_name = package_name if package_name is not None else name try: diff --git a/pycrostates/viz/__init__.py b/pycrostates/viz/__init__.py index 5396d3ca..17c6fe4e 100644 --- a/pycrostates/viz/__init__.py +++ b/pycrostates/viz/__init__.py @@ -4,7 +4,7 @@ from .cluster_centers import plot_cluster_centers from .segmentation import plot_epoch_segmentation, plot_raw_segmentation -__all__ = ( +__all__: tuple[str, ...] = ( "plot_cluster_centers", "plot_raw_segmentation", "plot_epoch_segmentation", diff --git a/tools/stubgen.py b/tools/stubgen.py index 6b90cc00..8a677666 100644 --- a/tools/stubgen.py +++ b/tools/stubgen.py @@ -17,7 +17,7 @@ files = [ str(file.as_posix()) for file in directory.rglob("*.py") - if file.parent.name not in ("commands", "tests") + if file.parent.name not in ("commands", "html_templates", "tests") and file.name not in ("conftest.py", "_tests.py", "_version.py") ] stubgen.main( @@ -50,13 +50,19 @@ if not docstring and isinstance(node, ast.FunctionDef): continue elif docstring: - node.body[0].value.value = docstring + try: + node.body[0].value.value = docstring + except AttributeError: + continue for method in node.body: if not isinstance(method, ast.FunctionDef): continue docstring = getattr(getattr(module, node.name), method.name).__doc__ if docstring: - method.body[0].value.value = docstring + try: + method.body[0].value.value = docstring + except AttributeError: + continue unparsed = ast.unparse(module_ast) stub.write_text(unparsed, encoding="utf-8") # sort imports From 04357d64957467a56ec4af139dbc4547013c26f4 Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 14:05:28 +0100 Subject: [PATCH 7/8] fix stubs --- pyproject.toml | 2 +- tools/stubgen.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8b11f8dc..d18811e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ tracker = 'https://github.com/vferat/pycrostates/issues' check-filenames = true check-hidden = true ignore-words = '.codespellignore' -skip = 'build,.git,.mypy_cache,.pytest_cache' +skip = 'build,.git,.mypy_cache,.pytest_cache,paper/paper.bib' [tool.coverage.report] exclude_lines = [ diff --git a/tools/stubgen.py b/tools/stubgen.py index 8a677666..a5d3bf09 100644 --- a/tools/stubgen.py +++ b/tools/stubgen.py @@ -64,6 +64,11 @@ except AttributeError: continue unparsed = ast.unparse(module_ast) + # remove unused imports conflicting with arguments, kwargs, method names, ... + unparsed = unparsed.replace(", verbose as verbose", "") + unparsed = unparsed.replace( + "from ..viz import plot_cluster_centers as plot_cluster_centers", "" + ) stub.write_text(unparsed, encoding="utf-8") # sort imports isort.file(stub, config=config_isort) From badab9029a6e6e9c581b40e097dba88fa12fc6df Mon Sep 17 00:00:00 2001 From: Mathieu Scheltienne Date: Wed, 20 Dec 2023 14:06:48 +0100 Subject: [PATCH 8/8] fix codespell --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d18811e2..55584f50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ tracker = 'https://github.com/vferat/pycrostates/issues' check-filenames = true check-hidden = true ignore-words = '.codespellignore' -skip = 'build,.git,.mypy_cache,.pytest_cache,paper/paper.bib' +skip = 'build,.git,.mypy_cache,.pytest_cache,paper/*' [tool.coverage.report] exclude_lines = [