From 0fb03fd7511bba2107f162eb0ba637eefece53a0 Mon Sep 17 00:00:00 2001 From: Jayaram Kancherla Date: Wed, 18 Dec 2024 10:34:15 -0800 Subject: [PATCH] chore: remove Python 3.8 support (#16) --- .github/workflows/pypi-publish.yml | 8 ++++---- .github/workflows/pypi-test.yml | 6 +++--- .pre-commit-config.yaml | 29 +++++++++++++++-------------- CHANGELOG.md | 6 +++++- docs/conf.py | 11 +++++++---- docs/requirements.txt | 1 + pyproject.toml | 4 ++++ setup.cfg | 5 +++-- src/mopsy/adders.py | 16 ++++------------ src/mopsy/mops.py | 7 +------ src/mopsy/nops.py | 4 +--- src/mopsy/sops.py | 4 +--- 12 files changed, 49 insertions(+), 52 deletions(-) diff --git a/.github/workflows/pypi-publish.yml b/.github/workflows/pypi-publish.yml index 7b591a2..030cd10 100644 --- a/.github/workflows/pypi-publish.yml +++ b/.github/workflows/pypi-publish.yml @@ -13,11 +13,11 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 + - uses: actions/checkout@v4 + - name: Set up Python 3.11 + uses: actions/setup-python@v5 with: - python-version: 3.9 + python-version: 3.11 - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/pypi-test.yml b/.github/workflows/pypi-test.yml index 9dc019a..22f6c4a 100644 --- a/.github/workflows/pypi-test.yml +++ b/.github/workflows/pypi-test.yml @@ -15,13 +15,13 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ '3.8', '3.9', '3.10', '3.11', '3.12' ] + python-version: [ '3.9', '3.10', '3.11', '3.12', '3.13' ] name: Python ${{ matrix.python-version }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: 'pip' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3c9601c..d736753 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ exclude: '^docs/conf.py' repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: trailing-whitespace - id: check-added-large-files @@ -17,26 +17,27 @@ repos: - id: mixed-line-ending args: ['--fix=auto'] # replace 'auto' with 'lf' to enforce Linux/Mac line endings or 'crlf' for Windows -- repo: https://github.com/PyCQA/docformatter - rev: v1.7.5 - hooks: - - id: docformatter - additional_dependencies: [tomli] - args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120] - # --config, ./pyproject.toml +# - repo: https://github.com/PyCQA/docformatter +# rev: master +# hooks: +# - id: docformatter +# additional_dependencies: [tomli] +# args: [--in-place, --wrap-descriptions=120, --wrap-summaries=120] +# # --config, ./pyproject.toml -- repo: https://github.com/psf/black - rev: 24.8.0 - hooks: - - id: black - language_version: python3 +# - repo: https://github.com/psf/black +# rev: 24.8.0 +# hooks: +# - id: black +# language_version: python3 - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.6.8 + rev: v0.8.2 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format ## If like to embrace black styles even in the docs: # - repo: https://github.com/asottile/blacken-docs diff --git a/CHANGELOG.md b/CHANGELOG.md index cc76e9b..82cf780 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,15 @@ # Changelog +## Version 0.3.0 + +- chore: Remove Python 3.8 (EOL) +- precommit: Replace docformatter with ruff's formatter + ## Version 0.2.8 - Set dependency for `scipy`. Seems like the hstack and vstack functions have been updated in 1.13.0+. - ## Version 0.2.0 - 0.2.7 - Support multi apply diff --git a/docs/conf.py b/docs/conf.py index 7cf736a..3d9ec4a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -72,6 +72,7 @@ "sphinx.ext.ifconfig", "sphinx.ext.mathjax", "sphinx.ext.napoleon", + "sphinx_autodoc_typehints", ] # Add any paths that contain templates here, relative to this directory. @@ -170,10 +171,12 @@ def setup(app): todo_emit_warnings = True autodoc_default_options = { - 'special-members': True, - 'undoc-members': False, - 'exclude-members': '__weakref__, __dict__, __str__, __module__, __init__' - } + # 'members': 'var1, var2', + # 'member-order': 'bysource', + "special-members": True, + "undoc-members": True, + "exclude-members": "__weakref__, __dict__, __str__, __module__", +} autosummary_generate = True autosummary_imported_members = True diff --git a/docs/requirements.txt b/docs/requirements.txt index 0aec8ef..e1619a4 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -5,3 +5,4 @@ furo # sphinx_rtd_theme recommonmark sphinx>=3.2.1 +sphinx-autodoc-typehints diff --git a/pyproject.toml b/pyproject.toml index a7cea75..00aa968 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,10 @@ extend-ignore = ["F821"] [tool.ruff.pydocstyle] convention = "google" +[tool.ruff.format] +docstring-code-format = true +docstring-code-line-length = 20 + [tool.ruff.per-file-ignores] "__init__.py" = ["E402", "F401"] diff --git a/setup.cfg b/setup.cfg index 800d649..5ecd7c5 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,7 +41,7 @@ package_dir = =src # Require a min/specific Python version (comma-separated conditions) -python_requires = >=3.8 +python_requires = >=3.9 # Add here dependencies of your project (line-separated), e.g. requests>=2.2,<3.0. # Version specifiers like >=2.2,<3.0 avoid problems due to API changes in @@ -50,7 +50,8 @@ python_requires = >=3.8 install_requires = importlib-metadata; python_version<"3.8" numpy - scipy<1.13.0 + scipy<1.13.0; python_version<="3.9" + scipy; python_version>"3.9" [options.packages.find] diff --git a/src/mopsy/adders.py b/src/mopsy/adders.py index fbdb260..789c92a 100644 --- a/src/mopsy/adders.py +++ b/src/mopsy/adders.py @@ -11,9 +11,7 @@ __license__ = "MIT" -def append_row( - mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarray] -) -> sp.sparse.spmatrix: +def append_row(mat: sp.sparse.spmatrix, row: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix: """A generic append function for sparse matrices. Args: @@ -32,9 +30,7 @@ def append_row( return sparse_append(mat=mat, row_or_column=row, axis=0) -def append_col( - mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarray] -) -> sp.sparse.spmatrix: +def append_col(mat: sp.sparse.spmatrix, col: Union[sp.sparse.spmatrix, np.ndarray]) -> sp.sparse.spmatrix: """A generic append function for sparse matrices. Args: @@ -89,16 +85,12 @@ def sparse_append( new_mat = None if axis == 0: if mat.shape[0] != row_or_column.shape[0]: - raise TypeError( - "Matrix and new row do not have the same shape along the first dimension." - ) + raise TypeError("Matrix and new row do not have the same shape along the first dimension.") new_mat = sp.sparse.vstack([mat, row_or_column]) else: if mat.shape[1] != row_or_column.shape[0]: - raise TypeError( - "Matrix and new row do not have the same shape along the second dimension." - ) + raise TypeError("Matrix and new row do not have the same shape along the second dimension.") new_mat = sp.sparse.hstack([mat, row_or_column]) diff --git a/src/mopsy/mops.py b/src/mopsy/mops.py index 474284e..ca6fed8 100644 --- a/src/mopsy/mops.py +++ b/src/mopsy/mops.py @@ -39,12 +39,7 @@ def groupby_indices(self, group: Sequence) -> dict: A dictionary with each group name as the key and the values containing the list of indices that map to it. """ - return { - k: [x[0] for x in v] - for k, v in groupby( - sorted(enumerate(group), key=lambda x: x[1]), lambda x: x[1] - ) - } + return {k: [x[0] for x in v] for k, v in groupby(sorted(enumerate(group), key=lambda x: x[1]), lambda x: x[1])} def _apply(self, func: Callable[[list], Any], axis: Union[int, bool]): if self.non_zero: diff --git a/src/mopsy/nops.py b/src/mopsy/nops.py index b7a3d63..e4ff325 100644 --- a/src/mopsy/nops.py +++ b/src/mopsy/nops.py @@ -15,9 +15,7 @@ class Nops(Mops): def __init__(self, mat: np.ndarray, non_zero: bool = False) -> None: super().__init__(mat, non_zero=non_zero) - def iter( - self, group: Sequence[str] = None, axis: Union[int, bool] = 0 - ) -> Iterator[Tuple]: + def iter(self, group: Sequence[str] = None, axis: Union[int, bool] = 0) -> Iterator[Tuple]: """Iterator over groups and an axis. Args: diff --git a/src/mopsy/sops.py b/src/mopsy/sops.py index e5f84fc..9eb69ca 100644 --- a/src/mopsy/sops.py +++ b/src/mopsy/sops.py @@ -58,9 +58,7 @@ def iter(self, group: list = None, axis: Union[int, bool] = 0) -> Iterator[Tuple else: yield (k, Sops(mat[:, v], self.non_zero)) - def _apply( - self, func: Callable[[list], Any], axis: Union[int, bool] = 0 - ) -> np.ndarray: + def _apply(self, func: Callable[[list], Any], axis: Union[int, bool] = 0) -> np.ndarray: mat = self.matrix.tocsc() if axis == 0 else self.matrix.tocsr() if self.non_zero: # reduction along an axis