From 577ea329ec992ca060d623f01a5ccf5b907e2182 Mon Sep 17 00:00:00 2001 From: Charles T Date: Wed, 6 Jan 2021 16:12:04 +0100 Subject: [PATCH] build: use PEP517/518 conventions (#100) see https://github.com/deepcharles/ruptures/pull/100#issuecomment-753632373 for a summary of this PR --- .circleci/config.yml | 61 ------------- .github/workflows/check-docs.yml | 11 +-- .github/workflows/check-linting.yml | 4 +- .github/workflows/publish-doc-to-remote.yml | 13 +-- .github/workflows/run-test-coverage.yml | 22 ++--- .github/workflows/run-test.yml | 13 +-- ...publish-to-pypi.yml => upload-to-pypi.yml} | 19 ++-- .gitignore | 5 +- CONTRIBUTING.md | 36 +++----- README.rst | 10 --- mkdocs.yml | 4 - pyproject.toml | 11 ++- ruptures/__init__.py | 16 ---- ruptures/datasets/__init__.py | 22 ----- ruptures/utils/__init__.py | 4 - setup.cfg | 64 ++++++++++++- setup.py | 90 +++---------------- src/ruptures/__init__.py | 8 ++ {ruptures => src/ruptures}/base.py | 0 {ruptures => src/ruptures}/costs/__init__.py | 0 .../ruptures}/costs/costautoregressive.py | 0 .../ruptures}/costs/costclinear.py | 0 .../ruptures}/costs/costcosine.py | 0 {ruptures => src/ruptures}/costs/costl1.py | 0 {ruptures => src/ruptures}/costs/costl2.py | 0 .../ruptures}/costs/costlinear.py | 0 {ruptures => src/ruptures}/costs/costml.py | 0 .../ruptures}/costs/costnormal.py | 0 {ruptures => src/ruptures}/costs/costrank.py | 0 {ruptures => src/ruptures}/costs/costrbf.py | 0 {ruptures => src/ruptures}/costs/factory.py | 0 src/ruptures/datasets/__init__.py | 5 ++ .../ruptures}/datasets/pw_constant.py | 0 .../ruptures}/datasets/pw_linear.py | 0 .../ruptures}/datasets/pw_normal.py | 0 .../ruptures}/datasets/pw_wavy.py | 0 .../ruptures}/detection/__init__.py | 0 .../detection/_detection/__init__.py | 0 .../ruptures}/detection/_detection/ekcpd.pxd | 0 .../ruptures}/detection/_detection/ekcpd.pyx | 0 .../detection/_detection/ekcpd_computation.c | 0 .../detection/_detection/ekcpd_computation.h | 0 .../_detection/ekcpd_pelt_computation.c | 0 .../_detection/ekcpd_pelt_computation.h | 0 .../ruptures}/detection/_detection/kernels.c | 0 .../ruptures}/detection/_detection/kernels.h | 0 .../ruptures}/detection/binseg.py | 0 .../ruptures}/detection/bottomup.py | 0 {ruptures => src/ruptures}/detection/dynp.py | 0 .../ruptures}/detection/kernelcpd.py | 21 +++-- {ruptures => src/ruptures}/detection/pelt.py | 0 .../ruptures}/detection/sanity_check.py | 0 .../ruptures}/detection/window.py | 0 {ruptures => src/ruptures}/exceptions.py | 0 .../ruptures}/metrics/__init__.py | 0 {ruptures => src/ruptures}/metrics/hamming.py | 0 .../ruptures}/metrics/hausdorff.py | 0 .../ruptures}/metrics/precisionrecall.py | 0 .../ruptures}/metrics/randindex.py | 0 .../ruptures}/metrics/sanity_check.py | 0 .../ruptures}/metrics/timeerror.py | 0 {ruptures => src/ruptures}/show/__init__.py | 0 {ruptures => src/ruptures}/show/display.py | 0 src/ruptures/utils/__init__.py | 6 ++ .../ruptures}/utils/_utils/__init__.py | 0 .../utils/_utils/convert_path_matrix.pxd | 0 .../utils/_utils/convert_path_matrix.pyx | 0 .../utils/_utils/convert_path_matrix_c.c | 0 .../utils/_utils/convert_path_matrix_c.h | 0 {ruptures => src/ruptures}/utils/bnode.py | 0 {ruptures => src/ruptures}/utils/drawbkps.py | 0 {ruptures => src/ruptures}/utils/utils.py | 0 .gitmodules => tests/__init__.py | 0 tests/test_costs.py | 5 +- 74 files changed, 162 insertions(+), 288 deletions(-) delete mode 100644 .circleci/config.yml rename .github/workflows/{publish-to-pypi.yml => upload-to-pypi.yml} (76%) delete mode 100644 README.rst delete mode 100644 ruptures/__init__.py delete mode 100644 ruptures/datasets/__init__.py delete mode 100644 ruptures/utils/__init__.py create mode 100644 src/ruptures/__init__.py rename {ruptures => src/ruptures}/base.py (100%) rename {ruptures => src/ruptures}/costs/__init__.py (100%) rename {ruptures => src/ruptures}/costs/costautoregressive.py (100%) rename {ruptures => src/ruptures}/costs/costclinear.py (100%) rename {ruptures => src/ruptures}/costs/costcosine.py (100%) rename {ruptures => src/ruptures}/costs/costl1.py (100%) rename {ruptures => src/ruptures}/costs/costl2.py (100%) rename {ruptures => src/ruptures}/costs/costlinear.py (100%) rename {ruptures => src/ruptures}/costs/costml.py (100%) rename {ruptures => src/ruptures}/costs/costnormal.py (100%) rename {ruptures => src/ruptures}/costs/costrank.py (100%) rename {ruptures => src/ruptures}/costs/costrbf.py (100%) rename {ruptures => src/ruptures}/costs/factory.py (100%) create mode 100644 src/ruptures/datasets/__init__.py rename {ruptures => src/ruptures}/datasets/pw_constant.py (100%) rename {ruptures => src/ruptures}/datasets/pw_linear.py (100%) rename {ruptures => src/ruptures}/datasets/pw_normal.py (100%) rename {ruptures => src/ruptures}/datasets/pw_wavy.py (100%) rename {ruptures => src/ruptures}/detection/__init__.py (100%) rename {ruptures => src/ruptures}/detection/_detection/__init__.py (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd.pxd (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd.pyx (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd_computation.c (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd_computation.h (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd_pelt_computation.c (100%) rename {ruptures => src/ruptures}/detection/_detection/ekcpd_pelt_computation.h (100%) rename {ruptures => src/ruptures}/detection/_detection/kernels.c (100%) rename {ruptures => src/ruptures}/detection/_detection/kernels.h (100%) rename {ruptures => src/ruptures}/detection/binseg.py (100%) rename {ruptures => src/ruptures}/detection/bottomup.py (100%) rename {ruptures => src/ruptures}/detection/dynp.py (100%) rename {ruptures => src/ruptures}/detection/kernelcpd.py (94%) rename {ruptures => src/ruptures}/detection/pelt.py (100%) rename {ruptures => src/ruptures}/detection/sanity_check.py (100%) rename {ruptures => src/ruptures}/detection/window.py (100%) rename {ruptures => src/ruptures}/exceptions.py (100%) rename {ruptures => src/ruptures}/metrics/__init__.py (100%) rename {ruptures => src/ruptures}/metrics/hamming.py (100%) rename {ruptures => src/ruptures}/metrics/hausdorff.py (100%) rename {ruptures => src/ruptures}/metrics/precisionrecall.py (100%) rename {ruptures => src/ruptures}/metrics/randindex.py (100%) rename {ruptures => src/ruptures}/metrics/sanity_check.py (100%) rename {ruptures => src/ruptures}/metrics/timeerror.py (100%) rename {ruptures => src/ruptures}/show/__init__.py (100%) rename {ruptures => src/ruptures}/show/display.py (100%) create mode 100644 src/ruptures/utils/__init__.py rename {ruptures => src/ruptures}/utils/_utils/__init__.py (100%) rename {ruptures => src/ruptures}/utils/_utils/convert_path_matrix.pxd (100%) rename {ruptures => src/ruptures}/utils/_utils/convert_path_matrix.pyx (100%) rename {ruptures => src/ruptures}/utils/_utils/convert_path_matrix_c.c (100%) rename {ruptures => src/ruptures}/utils/_utils/convert_path_matrix_c.h (100%) rename {ruptures => src/ruptures}/utils/bnode.py (100%) rename {ruptures => src/ruptures}/utils/drawbkps.py (100%) rename {ruptures => src/ruptures}/utils/utils.py (100%) rename .gitmodules => tests/__init__.py (100%) diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 61cd2c87..00000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,61 +0,0 @@ -# Python CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-python/ for more details -# -version: 2 -jobs: - build: - docker: - # specify the version you desire here - # use `-browsers` prefix for selenium tests, e.g. `3.6.1-browsers` - - image: circleci/python:3.6.1 - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 - - working_directory: ~/ruptures - - steps: - - checkout - - # Download and cache dependencies - - restore_cache: - keys: - - v1-dependencies-{{ checksum "requirements-dev.txt" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - - run: - name: install dependencies - command: | - python3 -m venv venv - . venv/bin/activate - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - python setup.py install - - - - save_cache: - paths: - - ./venv - key: v1-dependencies-{{ checksum "requirements-dev.txt" }} - - # run tests! - # this example uses Django's built-in test-runner - # other common Python testing frameworks include pytest and nose - # https://pytest.org - # https://nose.readthedocs.io - - run: - name: run tests - command: | - . venv/bin/activate - mkdir test-reports - py.test --junitxml=test-reports/junit.xml tests/ - - - store_test_results: - path: test-reports - - - store_artifacts: - path: test-reports diff --git a/.github/workflows/check-docs.yml b/.github/workflows/check-docs.yml index 10794545..cf700246 100644 --- a/.github/workflows/check-docs.yml +++ b/.github/workflows/check-docs.yml @@ -1,4 +1,4 @@ -name: "Pull Request Docs Check" +name: "Check docs" on: - pull_request @@ -7,19 +7,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up Python 3.x + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: - # Semantic version range syntax or exact version of a Python version python-version: '3.8' - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - name: Install ruptures and dependencies run: | python -m pip install --upgrade pip - if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi - python setup.py install + python -m pip install .[dev] - name: Run notebooks run: | jupyter nbconvert --inplace --to notebook --ExecutePreprocessor.kernel_name=python --execute $(find ./docs -name '*.ipynb') diff --git a/.github/workflows/check-linting.yml b/.github/workflows/check-linting.yml index 4f6c1be5..7b6a4db5 100644 --- a/.github/workflows/check-linting.yml +++ b/.github/workflows/check-linting.yml @@ -1,4 +1,4 @@ -name: check-linting +name: Check linting on: push: @@ -18,7 +18,7 @@ jobs: - name: Install pre-commit hooks run: | python -m pip install --upgrade pip - pip install pre-commit + python -m pip install pre-commit - name: Run pre-commit hooks run: | pre-commit run --all-files diff --git a/.github/workflows/publish-doc-to-remote.yml b/.github/workflows/publish-doc-to-remote.yml index ecd3e3d1..2877b818 100644 --- a/.github/workflows/publish-doc-to-remote.yml +++ b/.github/workflows/publish-doc-to-remote.yml @@ -1,5 +1,5 @@ -# Publish doc to website on new release (or manual trigger) -name: "docs" +# Publish docs to website on new release (or manual trigger) +name: "Publish docs online" on: release: @@ -14,23 +14,18 @@ jobs: - name: Set up Python 3.x uses: actions/setup-python@v2 with: - # Semantic version range syntax or exact version of a Python version python-version: '3.8' - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - name: Install ruptures and dependecies run: | python -m pip install --upgrade pip - if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi - python setup.py install + python -m pip install .[dev] - name: Run notebooks run: | jupyter nbconvert --inplace --to notebook --ExecutePreprocessor.kernel_name=python --execute $(find ./docs -name '*.ipynb') - name: Build documentation run: | mkdocs build - - name: Publish documentation to remote + - name: Publish documentation to remote repo uses: selenehyun/gh-push@master env: GITHUB_TOKEN: ${{ secrets.DOC_PUSHER_ACCESS_TOKEN }} diff --git a/.github/workflows/run-test-coverage.yml b/.github/workflows/run-test-coverage.yml index 6c24edf4..d7368cb5 100644 --- a/.github/workflows/run-test-coverage.yml +++ b/.github/workflows/run-test-coverage.yml @@ -1,7 +1,9 @@ -# This workflow will install Python dependencies, run tests, generate coverage report and upload it to codecov -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions +# This workflow will install Python dependencies, run tests, generate coverage +# report and upload it to codecov. +# For more information, see: +# https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: coverage +name: Run tests with coverage on: push: @@ -14,26 +16,20 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up Python 3.x + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: python-version: '3.8' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - pip install pytest-cov - name: Install ruptures run: | - python setup.py install + python -m pip install --upgrade pip + python -m pip install .[test] - name: Test with pytest run: | - pytest --cov-report=xml --cov=ruptures tests/ - + python -m pytest - name: Upload to Codecov run: | bash <(curl -s https://codecov.io/bash) - - uses: actions/upload-artifact@v2 with: path: coverage.xml diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 2373e3a3..c1b26723 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions -name: build +name: Run tests on: push: @@ -18,22 +18,17 @@ jobs: exclude: - os: windows-latest python-version: 3.9 - runs-on: ${{ matrix.os }} - steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements-dev.txt - name: Install ruptures run: | - python setup.py install + python -m pip install --upgrade pip + python -m pip install .[test] - name: Test with pytest run: | - pytest + python -m pytest \ No newline at end of file diff --git a/.github/workflows/publish-to-pypi.yml b/.github/workflows/upload-to-pypi.yml similarity index 76% rename from .github/workflows/publish-to-pypi.yml rename to .github/workflows/upload-to-pypi.yml index d77f4b8e..7848ffa8 100644 --- a/.github/workflows/publish-to-pypi.yml +++ b/.github/workflows/upload-to-pypi.yml @@ -1,4 +1,4 @@ -name: Publish to Pypi (sdist and wheels) +name: Upload package to Pypi on: workflow_dispatch: @@ -15,7 +15,7 @@ jobs: bitness: [32, 64] python: [36, 37, 38, 39] include: - # Run 32 and 64 bit version in parallel for Linux and Windows + # Run 32 and 64 bits version in parallel for Linux and Windows - os: windows-latest bitness: 64 platform_id: win_amd64 @@ -48,9 +48,7 @@ jobs: - name: Install cibuildwheel and dependencies run: | python -m pip install --upgrade pip - python -m pip install cibuildwheel - pip install -r requirements-dev.txt - pip install setuptools wheel twine + python -m pip install cibuildwheel twine - name: Build wheels env: @@ -59,7 +57,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python -m cibuildwheel --output-dir wheelhouse - twine upload wheelhouse/*.whl + python -m twine upload wheelhouse/*.whl - uses: actions/upload-artifact@v2 with: @@ -69,18 +67,13 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Set up Python 3.x + - name: Set up Python 3.8 uses: actions/setup-python@v2 with: - # Semantic version range syntax or exact version of a Python version python-version: '3.8' - # You can test your matrix by printing the current Python version - - name: Display Python version - run: python -c "import sys; print(sys.version)" - name: Install dependencies run: | python -m pip install --upgrade pip - pip install -r requirements-dev.txt pip install setuptools wheel twine - name: Build env: @@ -88,7 +81,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python setup.py sdist - twine upload dist/*.tar.gz + python -m twine upload dist/*.tar.gz - uses: actions/upload-artifact@v2 with: path: dist/*.tar.gz diff --git a/.gitignore b/.gitignore index 1b907e63..e16d60d8 100644 --- a/.gitignore +++ b/.gitignore @@ -82,7 +82,4 @@ docs/build/* .Trashes ehthumbs.db Thumbs.db -site/ -ruptures/utils/_utils/convert_path_matrix.c -ruptures/detection/_detection/continuous_linear_cpd.c -ruptures/detection/_detection/ekcpd.c +site/ \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 38dbab76..d76713fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,11 +5,6 @@ In all following steps, it is highly recommended to use a virtual environment. -### Install the requirements - -Several packages are needed to compile, format and test the code. -They are listed in `requirements-dev.txt` and can be installed with the following command. - ### Install the development version It is important that you contribute to the latest version of the code. @@ -20,33 +15,30 @@ git clone https://github.com/deepcharles/ruptures cd ruptures ``` -Then install the downloaded package. +Then install the downloaded package with `pip`. ``` -python -m pip install --verbose --no-build-isolation --editable . +python -m pip install --editable .[dev] ``` -#### With pip -``` -pip install -r requirements-dev.txt -``` +Note that `python -m` can be omitted most of the times, but within virtualenvs, it can prevent certain errors. +Also, in certain terminals (such as zsh), the square brackets must be escaped, e.g. replace `.[dev]` by `.\[dev\]`. -#### With conda -``` -conda --file requirements-dev.txt -``` - -Then run the following command to install the `pre-commit` hooks. -``` -pre-commit install -``` +In addition to `numpy`, `scipy` and `ruptures`, this command will install all packages needed to develop `ruptures`. +The exact list of librairies can be found in the [`setup.cfg` file](https://github.com/deepcharles/ruptures/blob/master/setup.cfg) (section `[options.extras_require]`). ### Pre-commit hooks We use `pre-commit` to run Git hooks before submitting the code to review. These hook scripts perform simple tasks before each commit (code formatting mostly). +To activate the hooks, simply run the following command in your terminal. + +``` +pre-commit install +``` + -Note that if you try to commit a non-compliant (i.e. badly formatted) file, `pre-commit` will modify this file and make the commit fail. +If you try to commit a non-compliant (i.e. badly formatted) file, `pre-commit` will modify this file and make the commit fail. However you need to stage the new changes **yourself** as `pre-commit` will not do that for you (this is by design; see [here](https://github.com/pre-commit/pre-commit/issues/806) or [here](https://github.com/pre-commit/pre-commit/issues/747)). Fortunately, `pre-commit` outputs useful messages. @@ -61,7 +53,7 @@ If you want to manually run all pre-commit hooks on a repository, run `pre-commi The following command executes the test suite. ``` -pytest +python -m pytest ``` ### Write docstrings diff --git a/README.rst b/README.rst deleted file mode 100644 index ada411d9..00000000 --- a/README.rst +++ /dev/null @@ -1,10 +0,0 @@ -ruptures: change point detection in Python -==================================================================================================== - -Short description ----------------------------------------------------------------------------------------------------- - -__ruptures__ is a Python library for offline change point detection. This package provides methods for the analysis and segmentation of non-stationary signals. Implemented algorithms include exact and approximate detection for various parametric and non-parametric models. __ruptures__ focuses on ease of use by providing a well-documented and consistent interface. In addition, thanks to its modular structure, different algorithms and models can be connected and extended within this package. - - -An extensive documentation is available `here `_ \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index a43fad32..fa8c6b0b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -89,10 +89,6 @@ nav: - Binseg: code-reference/detection/binseg-reference.md - BottomUp: code-reference/detection/bottomup-reference.md - Window: code-reference/detection/window-reference.md - # - GreedyAR: code-reference/detection/greedyar-reference.md - # - GreedyLinear: code-reference/detection/greedylinear-reference.md - # - Omp: code-reference/detection/omp-reference.md - # - OmpK: code-reference/detection/ompk-reference.md - Cost functions: - 'CostL1': code-reference/costs/costl1-reference.md - 'CostL2': code-reference/costs/costl2-reference.md diff --git a/pyproject.toml b/pyproject.toml index dd5279d1..cae4bb73 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] # Minimum requirements for the build system to execute. requires = [ - "setuptools", + "setuptools>=38.3.0", # version with most `setup.cfg` bugfixes "wheel", "Cython>=0.28.5", @@ -28,3 +28,12 @@ requires = [ "scipy>=0.19.1", ] +build-backend = "setuptools.build_meta" + +# pytest config +# For more information, see: +# https://docs.pytest.org/en/stable/customize.html#pyproject-toml +[tool.pytest.ini_options] +minversion = "6.0" +addopts = "--cov-report=xml --cov-report=term:skip-covered --cov=ruptures" +testpaths = ["tests"] \ No newline at end of file diff --git a/ruptures/__init__.py b/ruptures/__init__.py deleted file mode 100644 index 194dbeb3..00000000 --- a/ruptures/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -Offline change point detection for Python -==================================================================================================== -""" - -from .exceptions import NotEnoughPoints -from .datasets import pw_constant, pw_normal, pw_linear, pw_wavy -from .detection import ( - Binseg, - BottomUp, - Dynp, - KernelCPD, - Pelt, - Window, -) -from .show import display diff --git a/ruptures/datasets/__init__.py b/ruptures/datasets/__init__.py deleted file mode 100644 index 12dc76f8..00000000 --- a/ruptures/datasets/__init__.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -==================================================================================================== -Synthetic signals -==================================================================================================== - -:mod:`ruptures.datasets` is designed to simplify synthetic signal generation. - -.. toctree:: - :glob: - :maxdepth: 1 - - pw_constant - pw_normal - pw_linear - pw_wavy - -""" - -from .pw_constant import pw_constant -from .pw_normal import pw_normal -from .pw_linear import pw_linear -from .pw_wavy import pw_wavy diff --git a/ruptures/utils/__init__.py b/ruptures/utils/__init__.py deleted file mode 100644 index 5e10344d..00000000 --- a/ruptures/utils/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -"""Import utils functions.""" -from .utils import pairwise, unzip, admissible_filter, sanity_check -from .bnode import Bnode -from .drawbkps import draw_bkps diff --git a/setup.cfg b/setup.cfg index 8f696136..2eee20d7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,64 @@ +[metadata] +name = ruptures +version = attr: ruptures.__version__ +url = https://github.com/deepcharles/ruptures/ +license = BSD-2-Clause +license_files = LICENSE +author = Charles Truong, Laurent Oudre, Nicolas Vayatis +author_email = charles@doffy.net +maintainer = Charles Truong, Olivier Boulant +description = Change point detection for signals in Python. +long_description = file: README.md +long_description_content_type = text/markdown +project_urls = + Documentation = https://centre-borelli.github.io/ruptures-docs/ + Source = https://github.com/deepcharles/ruptures/ + Bug Tracker = https://github.com/deepcharles/ruptures/issues/ +keywords = + change point detection + signal segmentation + computer science + machine learning + kernel methods + time series +classifiers = + Programming Language :: Python :: 3 + Operating System :: OS Independent + Topic :: Scientific/Engineering :: Mathematics + Intended Audience :: Science/Research + License :: OSI Approved :: BSD License + +[options] +zip_safe = True +include_package_data = True +python_requires = >= 3.6 +install_requires = + numpy + scipy +packages = find: +package_dir = + =src + +[options.packages.find] +where = src + +[options.extras_require] +display = matplotlib +test = + pytest + pytest-cov +dev = + jupyter + matplotlib + mkdocs + mkdocs-macros-plugin + mkdocs-material + mkdocstrings + mknotebooks + pre-commit + pymdown-extensions + pytest + pytest-cov + [build_ext] -inplace=1 +inplace=1 \ No newline at end of file diff --git a/setup.py b/setup.py index 064a27aa..585421f1 100644 --- a/setup.py +++ b/setup.py @@ -1,94 +1,28 @@ -from setuptools import setup, find_packages, Extension -from setuptools.command.build_ext import build_ext -import numpy as np -from Cython.Build import cythonize - +from setuptools import Extension, find_packages, setup ext_modules = [ Extension( "ruptures.detection._detection.ekcpd", sources=[ - "ruptures/detection/_detection/ekcpd.pyx", - "ruptures/detection/_detection/ekcpd_computation.c", - "ruptures/detection/_detection/ekcpd_pelt_computation.c", - "ruptures/detection/_detection/kernels.c", + "src/ruptures/detection/_detection/ekcpd.pyx", + "src/ruptures/detection/_detection/ekcpd_computation.c", + "src/ruptures/detection/_detection/ekcpd_pelt_computation.c", + "src/ruptures/detection/_detection/kernels.c", ], ), Extension( "ruptures.utils._utils.convert_path_matrix", sources=[ - "ruptures/utils/_utils/convert_path_matrix.pyx", - "ruptures/utils/_utils/convert_path_matrix_c.c", + "src/ruptures/utils/_utils/convert_path_matrix.pyx", + "src/ruptures/utils/_utils/convert_path_matrix_c.c", ], ), ] -setup( - name="ruptures", - version="1.1.2", - packages=find_packages(exclude=["docs", "tests*", "images"]), - install_requires=["numpy", "scipy"], - extras_require={"display": ["matplotlib"]}, - setup_requires=["cython", "numpy"], - package_data={ - "ruptures.detection._detection": [ - "ekcpd.pxd", - "ekcpd.pyx", - "ekcpd_computation.h", - "ekcpd_pelt_computation.h", - "kernels.h", - ], - "ruptures.utils._utils": [ - "convert_path_matrix.pyx", - "convert_path_matrix.pxd", - "convert_path_matrix_c.h", - ], - }, - cmdclass={"build_ext": build_ext}, - python_requires=">=3", - url="https://centre-borelli.github.io/ruptures-docs/", - license="BSD License", - author="Charles Truong, Laurent Oudre, Nicolas Vayatis", - author_email="charles@doffy.net", - maintainer="Charles Truong, Olivier Boulant", - description="Change point detection for signals, in Python", - download_url="https://github.com/deepcharles/ruptures/archive/master.zip", - keywords=[ - "change point detection", - "signal segmentation", - "computer science", - "machine learning", - "kernel methods", - "time series", - ], - classifiers=[ - "Programming Language :: Python :: 3", - "Operating System :: OS Independent", - "Topic :: Scientific/Engineering :: Mathematics", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", - ], - long_description="""\ -Offline change point detection for Python. ------------------------------------------- - -**ruptures** is a Python library for offline change point detection. -This package provides methods for the analysis and segmentation of -non-stationary signals. -Implemented algorithms include exact and approximate detection for various -parametric and non-parametric models. -**ruptures** focuses on ease of use by providing a well-documented and -consistent interface. In addition, thanks to its modular structure, different -algorithms and models can be connected and extended within this package. - -An extensive documentation is available -`github.com/deepcharles/ruptures `_. +if __name__ == "__main__": + from Cython.Build import cythonize -This version requires Python 3 or later. -""", - ext_modules=cythonize( - ext_modules, - language_level="3", - ), -) + setup( + ext_modules=cythonize(ext_modules, language_level="3"), + ) diff --git a/src/ruptures/__init__.py b/src/ruptures/__init__.py new file mode 100644 index 00000000..c847c307 --- /dev/null +++ b/src/ruptures/__init__.py @@ -0,0 +1,8 @@ +"""Offline change point detection for Python.""" + +from .datasets import pw_constant, pw_linear, pw_normal, pw_wavy +from .detection import Binseg, BottomUp, Dynp, KernelCPD, Pelt, Window +from .exceptions import NotEnoughPoints +from .show import display + +__version__ = "1.1.2" diff --git a/ruptures/base.py b/src/ruptures/base.py similarity index 100% rename from ruptures/base.py rename to src/ruptures/base.py diff --git a/ruptures/costs/__init__.py b/src/ruptures/costs/__init__.py similarity index 100% rename from ruptures/costs/__init__.py rename to src/ruptures/costs/__init__.py diff --git a/ruptures/costs/costautoregressive.py b/src/ruptures/costs/costautoregressive.py similarity index 100% rename from ruptures/costs/costautoregressive.py rename to src/ruptures/costs/costautoregressive.py diff --git a/ruptures/costs/costclinear.py b/src/ruptures/costs/costclinear.py similarity index 100% rename from ruptures/costs/costclinear.py rename to src/ruptures/costs/costclinear.py diff --git a/ruptures/costs/costcosine.py b/src/ruptures/costs/costcosine.py similarity index 100% rename from ruptures/costs/costcosine.py rename to src/ruptures/costs/costcosine.py diff --git a/ruptures/costs/costl1.py b/src/ruptures/costs/costl1.py similarity index 100% rename from ruptures/costs/costl1.py rename to src/ruptures/costs/costl1.py diff --git a/ruptures/costs/costl2.py b/src/ruptures/costs/costl2.py similarity index 100% rename from ruptures/costs/costl2.py rename to src/ruptures/costs/costl2.py diff --git a/ruptures/costs/costlinear.py b/src/ruptures/costs/costlinear.py similarity index 100% rename from ruptures/costs/costlinear.py rename to src/ruptures/costs/costlinear.py diff --git a/ruptures/costs/costml.py b/src/ruptures/costs/costml.py similarity index 100% rename from ruptures/costs/costml.py rename to src/ruptures/costs/costml.py diff --git a/ruptures/costs/costnormal.py b/src/ruptures/costs/costnormal.py similarity index 100% rename from ruptures/costs/costnormal.py rename to src/ruptures/costs/costnormal.py diff --git a/ruptures/costs/costrank.py b/src/ruptures/costs/costrank.py similarity index 100% rename from ruptures/costs/costrank.py rename to src/ruptures/costs/costrank.py diff --git a/ruptures/costs/costrbf.py b/src/ruptures/costs/costrbf.py similarity index 100% rename from ruptures/costs/costrbf.py rename to src/ruptures/costs/costrbf.py diff --git a/ruptures/costs/factory.py b/src/ruptures/costs/factory.py similarity index 100% rename from ruptures/costs/factory.py rename to src/ruptures/costs/factory.py diff --git a/src/ruptures/datasets/__init__.py b/src/ruptures/datasets/__init__.py new file mode 100644 index 00000000..e353bc14 --- /dev/null +++ b/src/ruptures/datasets/__init__.py @@ -0,0 +1,5 @@ +"""Utility functions to load or generate data sets.""" +from .pw_constant import pw_constant +from .pw_linear import pw_linear +from .pw_normal import pw_normal +from .pw_wavy import pw_wavy diff --git a/ruptures/datasets/pw_constant.py b/src/ruptures/datasets/pw_constant.py similarity index 100% rename from ruptures/datasets/pw_constant.py rename to src/ruptures/datasets/pw_constant.py diff --git a/ruptures/datasets/pw_linear.py b/src/ruptures/datasets/pw_linear.py similarity index 100% rename from ruptures/datasets/pw_linear.py rename to src/ruptures/datasets/pw_linear.py diff --git a/ruptures/datasets/pw_normal.py b/src/ruptures/datasets/pw_normal.py similarity index 100% rename from ruptures/datasets/pw_normal.py rename to src/ruptures/datasets/pw_normal.py diff --git a/ruptures/datasets/pw_wavy.py b/src/ruptures/datasets/pw_wavy.py similarity index 100% rename from ruptures/datasets/pw_wavy.py rename to src/ruptures/datasets/pw_wavy.py diff --git a/ruptures/detection/__init__.py b/src/ruptures/detection/__init__.py similarity index 100% rename from ruptures/detection/__init__.py rename to src/ruptures/detection/__init__.py diff --git a/ruptures/detection/_detection/__init__.py b/src/ruptures/detection/_detection/__init__.py similarity index 100% rename from ruptures/detection/_detection/__init__.py rename to src/ruptures/detection/_detection/__init__.py diff --git a/ruptures/detection/_detection/ekcpd.pxd b/src/ruptures/detection/_detection/ekcpd.pxd similarity index 100% rename from ruptures/detection/_detection/ekcpd.pxd rename to src/ruptures/detection/_detection/ekcpd.pxd diff --git a/ruptures/detection/_detection/ekcpd.pyx b/src/ruptures/detection/_detection/ekcpd.pyx similarity index 100% rename from ruptures/detection/_detection/ekcpd.pyx rename to src/ruptures/detection/_detection/ekcpd.pyx diff --git a/ruptures/detection/_detection/ekcpd_computation.c b/src/ruptures/detection/_detection/ekcpd_computation.c similarity index 100% rename from ruptures/detection/_detection/ekcpd_computation.c rename to src/ruptures/detection/_detection/ekcpd_computation.c diff --git a/ruptures/detection/_detection/ekcpd_computation.h b/src/ruptures/detection/_detection/ekcpd_computation.h similarity index 100% rename from ruptures/detection/_detection/ekcpd_computation.h rename to src/ruptures/detection/_detection/ekcpd_computation.h diff --git a/ruptures/detection/_detection/ekcpd_pelt_computation.c b/src/ruptures/detection/_detection/ekcpd_pelt_computation.c similarity index 100% rename from ruptures/detection/_detection/ekcpd_pelt_computation.c rename to src/ruptures/detection/_detection/ekcpd_pelt_computation.c diff --git a/ruptures/detection/_detection/ekcpd_pelt_computation.h b/src/ruptures/detection/_detection/ekcpd_pelt_computation.h similarity index 100% rename from ruptures/detection/_detection/ekcpd_pelt_computation.h rename to src/ruptures/detection/_detection/ekcpd_pelt_computation.h diff --git a/ruptures/detection/_detection/kernels.c b/src/ruptures/detection/_detection/kernels.c similarity index 100% rename from ruptures/detection/_detection/kernels.c rename to src/ruptures/detection/_detection/kernels.c diff --git a/ruptures/detection/_detection/kernels.h b/src/ruptures/detection/_detection/kernels.h similarity index 100% rename from ruptures/detection/_detection/kernels.h rename to src/ruptures/detection/_detection/kernels.h diff --git a/ruptures/detection/binseg.py b/src/ruptures/detection/binseg.py similarity index 100% rename from ruptures/detection/binseg.py rename to src/ruptures/detection/binseg.py diff --git a/ruptures/detection/bottomup.py b/src/ruptures/detection/bottomup.py similarity index 100% rename from ruptures/detection/bottomup.py rename to src/ruptures/detection/bottomup.py diff --git a/ruptures/detection/dynp.py b/src/ruptures/detection/dynp.py similarity index 100% rename from ruptures/detection/dynp.py rename to src/ruptures/detection/dynp.py diff --git a/ruptures/detection/kernelcpd.py b/src/ruptures/detection/kernelcpd.py similarity index 94% rename from ruptures/detection/kernelcpd.py rename to src/ruptures/detection/kernelcpd.py index 073d92c2..68de3dcc 100644 --- a/ruptures/detection/kernelcpd.py +++ b/src/ruptures/detection/kernelcpd.py @@ -1,18 +1,23 @@ r"""Efficient kernel change point detection (dynamic programming)""" -from ruptures.utils import sanity_check -from ruptures.costs import cost_factory from ruptures.base import BaseCost, BaseEstimator +from ruptures.costs import cost_factory +from ruptures.utils import from_path_matrix_to_bkps_list, sanity_check -from ruptures.detection._detection.ekcpd import ( - ekcpd_L2, - ekcpd_Gaussian, - ekcpd_pelt_L2, - ekcpd_pelt_Gaussian, +# from ruptures.detection._detection.ekcpd import (ekcpd_cosine, ekcpd_Gaussian, +from ._detection.ekcpd import ( ekcpd_cosine, + ekcpd_Gaussian, + ekcpd_L2, ekcpd_pelt_cosine, + ekcpd_pelt_Gaussian, + ekcpd_pelt_L2, ) -from ruptures.utils._utils.convert_path_matrix import from_path_matrix_to_bkps_list + +# from ..utils._utils.convert_path_matrix import from_path_matrix_to_bkps_list + + +# from ruptures.utils._utils.convert_path_matrix import from_path_matrix_to_bkps_list class KernelCPD(BaseEstimator): diff --git a/ruptures/detection/pelt.py b/src/ruptures/detection/pelt.py similarity index 100% rename from ruptures/detection/pelt.py rename to src/ruptures/detection/pelt.py diff --git a/ruptures/detection/sanity_check.py b/src/ruptures/detection/sanity_check.py similarity index 100% rename from ruptures/detection/sanity_check.py rename to src/ruptures/detection/sanity_check.py diff --git a/ruptures/detection/window.py b/src/ruptures/detection/window.py similarity index 100% rename from ruptures/detection/window.py rename to src/ruptures/detection/window.py diff --git a/ruptures/exceptions.py b/src/ruptures/exceptions.py similarity index 100% rename from ruptures/exceptions.py rename to src/ruptures/exceptions.py diff --git a/ruptures/metrics/__init__.py b/src/ruptures/metrics/__init__.py similarity index 100% rename from ruptures/metrics/__init__.py rename to src/ruptures/metrics/__init__.py diff --git a/ruptures/metrics/hamming.py b/src/ruptures/metrics/hamming.py similarity index 100% rename from ruptures/metrics/hamming.py rename to src/ruptures/metrics/hamming.py diff --git a/ruptures/metrics/hausdorff.py b/src/ruptures/metrics/hausdorff.py similarity index 100% rename from ruptures/metrics/hausdorff.py rename to src/ruptures/metrics/hausdorff.py diff --git a/ruptures/metrics/precisionrecall.py b/src/ruptures/metrics/precisionrecall.py similarity index 100% rename from ruptures/metrics/precisionrecall.py rename to src/ruptures/metrics/precisionrecall.py diff --git a/ruptures/metrics/randindex.py b/src/ruptures/metrics/randindex.py similarity index 100% rename from ruptures/metrics/randindex.py rename to src/ruptures/metrics/randindex.py diff --git a/ruptures/metrics/sanity_check.py b/src/ruptures/metrics/sanity_check.py similarity index 100% rename from ruptures/metrics/sanity_check.py rename to src/ruptures/metrics/sanity_check.py diff --git a/ruptures/metrics/timeerror.py b/src/ruptures/metrics/timeerror.py similarity index 100% rename from ruptures/metrics/timeerror.py rename to src/ruptures/metrics/timeerror.py diff --git a/ruptures/show/__init__.py b/src/ruptures/show/__init__.py similarity index 100% rename from ruptures/show/__init__.py rename to src/ruptures/show/__init__.py diff --git a/ruptures/show/display.py b/src/ruptures/show/display.py similarity index 100% rename from ruptures/show/display.py rename to src/ruptures/show/display.py diff --git a/src/ruptures/utils/__init__.py b/src/ruptures/utils/__init__.py new file mode 100644 index 00000000..17dd0c66 --- /dev/null +++ b/src/ruptures/utils/__init__.py @@ -0,0 +1,6 @@ +"""Import utils functions.""" +from ruptures.utils._utils.convert_path_matrix import from_path_matrix_to_bkps_list + +from .bnode import Bnode +from .drawbkps import draw_bkps +from .utils import admissible_filter, pairwise, sanity_check, unzip diff --git a/ruptures/utils/_utils/__init__.py b/src/ruptures/utils/_utils/__init__.py similarity index 100% rename from ruptures/utils/_utils/__init__.py rename to src/ruptures/utils/_utils/__init__.py diff --git a/ruptures/utils/_utils/convert_path_matrix.pxd b/src/ruptures/utils/_utils/convert_path_matrix.pxd similarity index 100% rename from ruptures/utils/_utils/convert_path_matrix.pxd rename to src/ruptures/utils/_utils/convert_path_matrix.pxd diff --git a/ruptures/utils/_utils/convert_path_matrix.pyx b/src/ruptures/utils/_utils/convert_path_matrix.pyx similarity index 100% rename from ruptures/utils/_utils/convert_path_matrix.pyx rename to src/ruptures/utils/_utils/convert_path_matrix.pyx diff --git a/ruptures/utils/_utils/convert_path_matrix_c.c b/src/ruptures/utils/_utils/convert_path_matrix_c.c similarity index 100% rename from ruptures/utils/_utils/convert_path_matrix_c.c rename to src/ruptures/utils/_utils/convert_path_matrix_c.c diff --git a/ruptures/utils/_utils/convert_path_matrix_c.h b/src/ruptures/utils/_utils/convert_path_matrix_c.h similarity index 100% rename from ruptures/utils/_utils/convert_path_matrix_c.h rename to src/ruptures/utils/_utils/convert_path_matrix_c.h diff --git a/ruptures/utils/bnode.py b/src/ruptures/utils/bnode.py similarity index 100% rename from ruptures/utils/bnode.py rename to src/ruptures/utils/bnode.py diff --git a/ruptures/utils/drawbkps.py b/src/ruptures/utils/drawbkps.py similarity index 100% rename from ruptures/utils/drawbkps.py rename to src/ruptures/utils/drawbkps.py diff --git a/ruptures/utils/utils.py b/src/ruptures/utils/utils.py similarity index 100% rename from ruptures/utils/utils.py rename to src/ruptures/utils/utils.py diff --git a/.gitmodules b/tests/__init__.py similarity index 100% rename from .gitmodules rename to tests/__init__.py diff --git a/tests/test_costs.py b/tests/test_costs.py index b61d9606..bb5b80c3 100644 --- a/tests/test_costs.py +++ b/tests/test_costs.py @@ -1,14 +1,13 @@ import pytest - from ruptures.costs import ( CostAR, + CostCLinear, CostL1, CostL2, CostLinear, - CostCLinear, CostNormal, - CostRbf, CostRank, + CostRbf, cost_factory, ) from ruptures.datasets import pw_constant