diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 17fae13..6c7531c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -2,13 +2,9 @@ name: Lint on: push: - branches: - - main - - dev + branches: [ main, dev ] pull_request: - branches: - - main - - dev + branches: [ main, dev ] jobs: lint: @@ -20,13 +16,15 @@ jobs: with: python-version: "3.12" - - name: Lint with black - uses: psf/black@stable + - name: Install Ruff + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Lint with Ruff + run: | + ruff check . --output-format=github - - name: Check for debugging print statements + - name: Check formatting with Ruff run: | - if grep -rq "print(" spectrum_utils; then - echo "Found the following print statements:" - grep -r "print(" spectrum_utils - exit 1 - fi + ruff format --check . diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 277a7e0..b5b1224 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,11 +1,8 @@ -# This workflows will upload a Python Package using Twine when a release is created. -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: PyPI +name: Publish to PyPI on: release: - types: [created] + types: [ created ] jobs: deploy: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 08be6b5..ab99248 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,17 +1,10 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions - -name: tests +name: Run tests on: push: - branches: - - main - - dev + branches: [ main, dev ] pull_request: - branches: - - main - - dev + branches: [ main, dev ] schedule: - cron: "0 0 1 1/1 *" # Run monthly. @@ -20,8 +13,8 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + os: [ ubuntu-latest, windows-latest, macos-latest ] + python-version: [ "3.10", "3.11", "3.12" ] steps: - uses: actions/checkout@v4 @@ -32,21 +25,15 @@ jobs: - name: Install dependencies run: | - python -m pip install --upgrade pip - pip install flake8 pytest pytest-cov wheel - pip install -e . - - name: Lint with flake8 - run: | - # Stop the build if there are Python syntax errors or undefined names. - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. - # The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + pip install uv + uv pip install pytest pytest-cov wheel --system + uv pip install -e . --system - name: Run unit and system tests run: | - pytest --cov=spectrum_utils tests/ + pytest --cov=spectrum_utils --verbose tests/ - name: Upload coverage to codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true + verbose: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd35db3..19cf96d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,12 @@ repos: - - repo: https://github.com/psf/black - rev: 22.8.0 # Replace by any tag/version: https://github.com/psf/black/tags - hooks: - - id: black - language_version: python3 # Should be a command that runs python3.6+ +- repo: https://github.com/astral-sh/ruff-pre-commit + # Ruff version. + rev: v0.4.1 + hooks: + # Run the linter. + - id: ruff + types_or: [ python, pyi, jupyter ] + args: [ --fix ] + # Run the formatter. + - id: ruff-format + types_or: [ python, pyi, jupyter ] diff --git a/.readthedocs.yml b/.readthedocs.yml index 2598a18..5a44aad 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,7 +1,7 @@ version: 2 python: - version: 3.8 + version: 3.10 install: - method: pip path: . diff --git a/README.md b/README.md index 473572a..8d57dfb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![conda](https://img.shields.io/conda/vn/bioconda/spectrum_utils?color=green)](http://bioconda.github.io/recipes/spectrum_utils/README.html) [![PyPI](https://img.shields.io/pypi/v/spectrum_utils?color=green)](https://pypi.org/project/spectrum_utils/) [![Build status](https://github.com/bittremieux/spectrum_utils/workflows/tests/badge.svg)](https://github.com/bittremieux/spectrum_utils/actions?query=workflow:tests) -[![docs](https://readthedocs.org/projects/spectrum_utils/badge/?version=latest)](https://spectrum_utils.readthedocs.io/en/latest/?badge=latest) +[![docs](https://readthedocs.org/projects/spectrum-utils/badge/?version=latest)](https://spectrum-utils.readthedocs.io/en/latest/?badge=latest) spectrum_utils is a Python package for efficient mass spectrometry data processing and visualization. @@ -18,7 +18,7 @@ spectrum_utils contains the following features: ## Installation -spectrum_utils requires Python version 3.8+ and can be installed with pip or conda. +spectrum_utils requires Python version 3.10+ and can be installed with pip or conda. Using pip: diff --git a/docs/src/conf.py b/docs/src/conf.py index d12acc2..58221cc 100644 --- a/docs/src/conf.py +++ b/docs/src/conf.py @@ -16,7 +16,6 @@ sys.path.insert(0, os.path.abspath(os.path.join("..", ".."))) -import pyteomics.usi import spectrum_utils diff --git a/docs/src/index.md b/docs/src/index.md index 2dcf694..39bcbd9 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -3,7 +3,7 @@ [![conda](https://img.shields.io/conda/vn/bioconda/spectrum_utils?color=green)](http://bioconda.github.io/recipes/spectrum_utils/README.html) [![PyPI](https://img.shields.io/pypi/v/spectrum_utils?color=green)](https://pypi.org/project/spectrum_utils/) [![Build status](https://github.com/bittremieux/spectrum_utils/workflows/tests/badge.svg)](https://github.com/bittremieux/spectrum_utils/actions?query=workflow:tests) -[![docs](https://readthedocs.org/projects/spectrum_utils/badge/?version=latest)](https://spectrum_utils.readthedocs.io/en/latest/?badge=latest) +[![docs](https://readthedocs.org/projects/spectrum_utils/badge/?version=latest)](https://spectrum-utils.readthedocs.io/en/latest/?badge=latest) ## About spectrum_utils diff --git a/environment.yml b/environment.yml index 98ee250..62599eb 100644 --- a/environment.yml +++ b/environment.yml @@ -13,4 +13,4 @@ dependencies: - pandas - platformdirs - pyteomics>=4.5 - - python>=3.8 + - python>=3.10 diff --git a/pyproject.toml b/pyproject.toml index 8c70c5b..0bbe56d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,28 +1,10 @@ [build-system] -requires = ['setuptools>=45', 'wheel', 'setuptools_scm[toml]>=6.0'] -build-backend = 'setuptools.build_meta' +requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.0"] +build-backend = "setuptools.build_meta" [tool.setuptools_scm] -[tool.black] +[tool.ruff] line-length = 79 -target-version = ['py312'] -include = '\.pyi?$' -exclude = ''' -( - /( - \.eggs # exclude a few common directories in the - | \.git # root of the project - | \.hg - | \.mypy_cache - | \.tox - | \.venv - | _build - | buck-out - | build - | dist - )/ - | foo.py # also separately exclude a file named foo.py in - # the root of the project -) -''' +target-version = "py310" +include = ["*.py"] diff --git a/setup.cfg b/setup.cfg index 6186d4a..284d7c8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,7 +22,7 @@ classifiers = [options] packages = find: include_package_data = True -python_requires = >=3.8 +python_requires = >=3.10 install_requires = fastobo lark>=1.0 @@ -34,9 +34,9 @@ install_requires = [options.extras_require] dev = - black pytest pytest-cov + ruff docs = myst-parser numpydoc>=1.1.0 diff --git a/spectrum_utils/proforma.py b/spectrum_utils/proforma.py index 7c54472..0cc0242 100644 --- a/spectrum_utils/proforma.py +++ b/spectrum_utils/proforma.py @@ -689,7 +689,9 @@ def parse(proforma: str) -> List[Proteoform]: @functools.lru_cache -def _import_cv(cv_id: str, cache: Optional[str]) -> Union[ +def _import_cv( + cv_id: str, cache: Optional[str] +) -> Union[ Tuple[Dict[str, Tuple[float, str]], Dict[str, Tuple[float, str]]], Dict[str, float], ]: @@ -869,8 +871,9 @@ def _parse_obo( ): term_mass = float( term_xref[ - term_xref.index('"') - + 1 : term_xref.rindex('"') + term_xref.index('"') + 1 : term_xref.rindex( + '"' + ) ] ) elif ( diff --git a/spectrum_utils/spectrum.py b/spectrum_utils/spectrum.py index d682fa4..f9c7059 100755 --- a/spectrum_utils/spectrum.py +++ b/spectrum_utils/spectrum.py @@ -129,7 +129,7 @@ def remove_precursor_peak( fragment_tol_mass: float, fragment_tol_mode: str, isotope: int = 0, - ) -> "MsmsSpectrumJit": + ) -> MsmsSpectrumJit: # TODO: This assumes [M+H]x charged ions. adduct_mass = 1.007825 neutral_mass = ( @@ -504,19 +504,19 @@ def remove_precursor_peak( """ Remove fragment peak(s) close to the precursor m/z. - Note: This peak manipulation will reset any ProForma annotations that - were applied previously. + Note: This peak manipulation will reset any ProForma annotations + that were applied previously. Parameters ---------- fragment_tol_mass : float - Fragment mass tolerance around the precursor mass to remove the - precursor peak. + Fragment mass tolerance around the precursor mass to remove + the precursor peak. fragment_tol_mode : {'Da', 'ppm'} Fragment mass tolerance unit. Either 'Da' or 'ppm'. isotope : int - The number of precursor isotopic peaks to be checked (the default - is 0 to check only the mono-isotopic peaks). + The number of precursor isotopic peaks to be checked (the + default is 0 to check only the mono-isotopic peaks). Returns -------