Skip to content

Commit

Permalink
Modern packaging + ruff + numpy 2 compat (#187)
Browse files Browse the repository at this point in the history
* Modern packaging + ruff (NPY201)

* move to src folder + ruff

* Better pyproject + add tests for 3.12

* Fix install Windows

* fix ruff for some docstring

* Disable docstring formatting

* disable py312

* ruff fixes

* re-enable macos

* disable macos

* fix missing line code block rst

* add tests folder to coverage

* remove test folder from coverage

* add libomp for macos-latest

* 2nd attempt

* re-enable lspopt

* add setuptools dep

* fix numpy deprecation

* Merge branch 'master' into modern_packaging
* Including manual conflict resolution on [test_]staging.py

---------

Co-authored-by: Remington Mallett <[email protected]>
  • Loading branch information
raphaelvallat and remrama authored Dec 28, 2024
1 parent 6e6a067 commit 4dcd72d
Show file tree
Hide file tree
Showing 55 changed files with 307 additions and 277 deletions.
14 changes: 0 additions & 14 deletions .coveragerc

This file was deleted.

10 changes: 0 additions & 10 deletions .github/workflows/black.yml

This file was deleted.

24 changes: 13 additions & 11 deletions .github/workflows/python_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,47 @@ name: Python tests

on:
push:
branches: [master, develop]
branches: [master]
pull_request:
branches: [master, develop]
branches: [master]

jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest, windows-latest] # macos-latest
python-version: ["3.9", "3.10", "3.11"]
platform: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]

runs-on: ${{ matrix.platform }}

env:
FORCE_COLOR: true

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install libomp (macOS)
if: ${{ matrix.platform == 'macos-latest' }}
run: brew install libomp

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
pip install .
pip install ".[test]"
- name: Test with pytest
run: |
pytest --cov --cov-report=xml --cov-config=setup.cfg --verbose
pytest --cov --cov-report=xml --verbose
- name: Upload coverage report
if: ${{ matrix.platform == 'ubuntu-latest' && matrix.python-version == 3.9 }}
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: a58a0c62-fb11-4429-977b-65bec01ecb44
file: ./coverage.xml
13 changes: 13 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Linting"
uses: astral-sh/ruff-action@v1
- name: "Formatting"
uses: astral-sh/ruff-action@v1
with:
args: "format --check"
19 changes: 2 additions & 17 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
# Add README, LICENSE and requirements :
# Add README and LICENSE :
include README.rst
include LICENSE
include requirements.txt

# Add trained classifiers
# v0.4.0
include yasa/classifiers/clf_eeg_lgb_0.4.0.joblib
include yasa/classifiers/clf_eeg+eog_lgb_0.4.0.joblib
include yasa/classifiers/clf_eeg+eog+emg_lgb_0.4.0.joblib
include yasa/classifiers/clf_eeg+eog+emg+demo_lgb_0.4.0.joblib

# v0.5.0
include yasa/classifiers/clf_eeg_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+demo_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+eog_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+eog+demo_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+emg_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+emg+demo_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+eog+emg_lgb_0.5.0.joblib
include yasa/classifiers/clf_eeg+eog+emg+demo_lgb_0.5.0.joblib
recursive-include yasa/classifiers/ *.joblib
13 changes: 13 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
.. image:: https://pepy.tech/badge/yasa
:target: https://pepy.tech/badge/yasa

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

----------------

.. figure:: /docs/pictures/yasa_logo.png
Expand Down Expand Up @@ -48,6 +52,15 @@ Alternatively, YASA can be installed with conda:
conda config --set channel_priority strict
conda install yasa
To build and install from source, clone this repository or download the source archive and decompress the files

.. code-block:: shell
cd yasa
pip install ".[test]" # install the package
pip install --editable ".[test]" # or editable install
pytest # test the package
**What are the prerequisites for using YASA?**

To use YASA, all you need is:
Expand Down
2 changes: 0 additions & 2 deletions codecov.yml

This file was deleted.

4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import os
import sys
import time
import yasa

import sphinx_bootstrap_theme

import yasa

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ Code guidelines

Before starting new code, we highly recommend opening an issue on `GitHub <https://github.com/raphaelvallat/yasa>`_ to discuss potential changes.

* Please use standard `pep8 <https://pypi.python.org/pypi/pep8>`_ and `flake8 <http://flake8.pycqa.org/>`_ Python style guidelines. To test that your code complies with those, you can run:
* Please use standard `pep8 <https://pypi.python.org/pypi/pep8>`_ and `flake8 <http://flake8.pycqa.org/>`_ Python style guidelines. YASA uses `ruff <https://github.com/astral-sh/ruff>`_ for code formatting. Before submitting a PR, please make sure to run the following command in the root folder of YASA:

.. code-block:: bash
$ flake8
$ ruff format --line-length=100
* Use `NumPy style <https://numpydoc.readthedocs.io/en/latest/format.html>`_ for docstrings. Follow existing examples for simplest guidance.

Expand Down
13 changes: 13 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
.. image:: https://pepy.tech/badge/yasa
:target: https://pepy.tech/badge/yasa

.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
:target: https://github.com/astral-sh/ruff
:alt: Ruff

----------------

.. figure:: /pictures/yasa_logo.png
Expand Down Expand Up @@ -48,6 +52,15 @@ Alternatively, YASA can be installed with conda:
conda config --set channel_priority strict
conda install yasa
To build and install from source, clone this repository or download the source archive and decompress the files

.. code-block:: shell
cd yasa
pip install ".[test]" # install the package
pip install -e ".[test]" # or editable install
pytest # test the package
**What are the prerequisites for using YASA?**

To use YASA, all you need is:
Expand Down
6 changes: 6 additions & 0 deletions push_pypi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build and upload a new version of YASA

```bash
python -m build
twine upload dist/yasa-<VERSION>
```
134 changes: 131 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,132 @@
[tool.black]
[build-system]
requires = ["setuptools>=70.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "yasa"
description = "YASA: Analysis of polysomnography recordings."
readme = "README.rst"
license = {text = "BSD (3-clause)"}
authors = [
{name = "Raphael Vallat", email = "[email protected]"},
{name = "Remington Mallett", email = "[email protected]"},
]
maintainers = [
{name = "Raphael Vallat", email = "[email protected]"},
{name = "Remington Mallett", email = "[email protected]"},
]
classifiers = [
"Intended Audience :: Science/Research",
"Operating System :: MacOS",
"Operating System :: POSIX",
"Operating System :: Unix",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dynamic = ["version"]
requires-python = ">=3.9"
dependencies = [
"numpy>=1.18.1",
"scipy",
"pandas",
"matplotlib",
"seaborn",
"mne>=1.3",
"numba>=0.57.1",
"antropy",
"scikit-learn",
"tensorpac>=0.6.5",
"pyriemann>=0.2.7",
"sleepecg>=0.5.0",
"setuptools>=70",
"lspopt",
"ipywidgets",
"joblib",
"lightgbm",
]

[project.optional-dependencies]
test = [
"pytest>=6",
"pytest-cov",
# Ensure coverage is new enough for `source_pkgs`.
"coverage[toml]>=5.3",
"ruff"
]
docs = [
"sphinx>7.0.0",
"pydata_sphinx_theme",
"numpydoc",
"sphinx-copybutton",
"sphinx-design",
"sphinx-notfound-page",
]

[project.urls]
Homepage = "https://github.com/raphaelvallat/yasa/"
Downloads = "https://github.com/raphaelvallat/yasa/"

[tool.setuptools]
py-modules = ["yasa"]
include-package-data = true

[tool.setuptools.package-data]
yasa = [
"classifiers/*.joblib",
]

[tool.setuptools.packages.find]
namespaces = false
where = ["src"]

[tool.setuptools.dynamic]
version = {attr = "yasa.__version__"}

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "--showlocals --durations=10 --maxfail=2 --cov"
doctest_optionflags= ["NORMALIZE_WHITESPACE", "IGNORE_EXCEPTION_DETAIL"]
filterwarnings = [
"ignore::UserWarning",
"ignore::RuntimeWarning",
"ignore::FutureWarning",
]
markers = ["slow"]

[tool.coverage.run]
branch = true
omit = [
"*/tests/*",
]
source_pkgs = ["yasa"]

[tool.coverage.paths]
source = ["src"]

[tool.coverage.report]
show_missing = true
# sort = "Cover"

[tool.ruff]
line-length = 100
target-version = ['py311']
include = '\.pyi?$'
target-version = "py311"
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
lint.select = ["E4", "E7", "E9", "F", "I", "NPY201"]
exclude = [
"notebooks", # Skip jupyter notebook examples
"docs",
]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401", "F403"] # Ignore star and unused import violations for __init__.py files

[tool.ruff.lint.pydocstyle]
convention = "numpy"

[tool.ruff.format]
docstring-code-format = false
docstring-code-line-length = 90
4 changes: 0 additions & 4 deletions requirements-test.txt

This file was deleted.

16 changes: 0 additions & 16 deletions requirements.txt

This file was deleted.

Loading

0 comments on commit 4dcd72d

Please sign in to comment.