Skip to content

Commit

Permalink
refactor: full scikit-learn compatibility + general refactor (#241)
Browse files Browse the repository at this point in the history
- Use `scikit-learn` ≥1.4 metadata routing for full API compatibility
- Switch from `setup.py` to `pyproject.toml`
- Switch to `poetry` for dependency management
- Use `tox` for documentation building, unit tests and linting
- Add pre-commit hooks
- Add coverage checks via `coveralls`
- Drop support for Python <3.11
- Support Python 3.11 and 3.12
- Add issue and pull request templates
- Add license information to `.py` files
- Update repository documentation
- Use `cliff` for `CHANGELOG.md` generation
- Update Sphinx documenation
- Switch to `numpy` docstring format (via `napoleon`)
- Move library code from `lib/` to `sequentia/`
- Move unit tests from `lib/test` to `tests/`
- Add `sequentia.enums` module for configuration values.
- Add `sequentia.version` sub-package for versioning information.
- Add `sequentia._internal` sub-package for internal logic.
- Remove `sequentia.pipeline` module.
- Make topologies internal
- Remove `pydantic` validation classes for model inputs
- Remove `pydantic` validation for `numpy` arrays
- Use key-word only arguments more widely (e.g. for `lengths`)
- Use `pydantic.validate_call` for validating constructors and other functions
- Use type hinting
- Use `ABCMeta` metaclass for base classes (e.g. `ClassifierMixin`/`RegressorMixin` and `BaseHMM`)
- Use `abc` decorators for abstract methods
- Avoid unnecessarily redefining methods on subclasses for only documentation purposes
- Add `predict_log_proba` to classifiers
- Move majority of validation logic to `sequentia._internal._validation` module
- Prefix all HMM parameter setter functions with `set_state`
- Rename `set_transitions` to set_state_transition_probs`
- Rename `set_state_emissions` to `set_state_emission_probs`
- Rename `set_state_covariances` to `set_state_covars`
- Use static methods to define default HMM parameters
- Handle KNN querying for single training sequences and single query sequences
- Update `IndependentFunctionTransformer` to match `FunctionTransformer` from `scikit-learn` ≥1.4 API
- Use `Helpers` fixture class for accessing helper methods in unit tests
  • Loading branch information
eonu authored Apr 1, 2024
1 parent f31918e commit 2786899
Show file tree
Hide file tree
Showing 167 changed files with 8,205 additions and 6,596 deletions.
102 changes: 59 additions & 43 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,62 @@
version: 2
version: "2.1"

workflows:
version: 2
test:
jobs:
- python_3.8
- python_3.9
- python_3.10

template: &template
docker:
- image: ubuntu:bionic
steps:
- checkout
- run:
name: Set up miniconda
command: |
apt update
apt install -y wget
cd $HOME
wget "https://repo.anaconda.com/miniconda/Miniconda3-4.7.10-Linux-x86_64.sh" -O miniconda.sh
printf '%s' "8a324adcc9eaf1c09e22a992bb6234d91a94146840ee6b11c114ecadafc68121 miniconda.sh" | sha256sum -c
bash miniconda.sh -b -p $HOME/miniconda
- run:
name: Set up environment, dependencies and run tests
command: |
export PATH="$HOME/miniconda/bin:$PATH"
conda create -n sequentia python=$PYTHON_VERSION -y
source activate sequentia
pip install ".[dev]"
pytest lib/test --disable-pytest-warnings
orbs:
python: circleci/python@2.1.1
coveralls: coveralls/coveralls@2.2.1

jobs:
python_3.8:
<<: *template
environment:
PYTHON_VERSION: "3.8"
python_3.9:
<<: *template
environment:
PYTHON_VERSION: "3.9"
python_3.10:
<<: *template
environment:
PYTHON_VERSION: "3.10"
linting:
executor:
name: python/default
tag: "3.11"
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
args: --only base
- run:
name: Linting
command: |
poetry run tox -e lint
tests:
parameters:
version:
type: string
executor:
name: python/default
tag: <<parameters.version>>
steps:
- checkout
- python/install-packages:
pkg-manager: poetry
args: --only base
# - run:
# name: Docstring tests
# command: |
# poetry run tox -e tests.doctest
- run:
name: Unit tests
command: |
poetry run -- tox -e tests -- --cov
- coveralls/upload:
flag_name: <<parameters.version>>
parallel: true
coverage:
executor:
name: python/default
steps:
- coveralls/upload:
carryforward: 3.11, 3.12
parallel_finished: true

workflows:
checks:
jobs:
- linting
- tests:
matrix:
parameters:
version: ["3.11", "3.12"]
- coverage:
requires:
- tests
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @eonu
68 changes: 68 additions & 0 deletions .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Report unexpected behaviour
description: If you came across something unexpected, let us know here!
labels: [bug, pending]

body:
- type: checkboxes
id: exists
attributes:
label: Has this already been reported?
description: If you haven't already, please look other existing issues to see if this bug has already been reported.
options:
- label: This is a new bug!
required: true

- type: textarea
id: expected-behaviour
attributes:
label: Expected behaviour
description: |
Please describe the behaviour that you expected to see.
If appropriate, provide any links to official Sequentia documentation that indicate this is the behaviour that is expected.
validations:
required: true

- type: textarea
id: observed-behaviour
attributes:
label: Observed behaviour
description: |
Please describe the unexpected behaviour that you observed.
Make sure to provide as much information as possible, so that we can investigate as thoroughly as we can.
validations:
required: true

- type: textarea
id: example
attributes:
label: Code to reproduce
description: >
Please provide a snippet of code that shows how to reproduce the bug,
making sure that it is [minimal and reproducible](https://stackoverflow.com/help/minimal-reproducible-example).
placeholder: |
import sequentia
...
render: Python

- type: textarea
id: version
attributes:
label: Version details
description: |
To help us get to the root of the problem as fast as possible, please run the following command to display version information about:
- Python
- Sequentia
- Operating system
```bash
python -c "import sequentia; print(sequentia.version.version_info())"
```
render: Text
validations:
required: true
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Got a question?
url: "https://github.com/eonu/sequentia/discussions/new?category=questions"
about: Start a discussion on GitHub discussions where Sequentia developers and users can respond.
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/feature.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Request a new feature or improvement
description: If you have a suggestion for something that might improve Sequentia, let us know here!
labels: [feature, pending]

body:
- type: checkboxes
id: exists
attributes:
label: Does this suggestion already exist?
description: If you haven't already, please look through the documentation and other existing issues to see if this feature is already implemented.
options:
- label: This is a new feature!
required: true

- type: textarea
id: feature-description
attributes:
label: Feature description
description: Please describe the new feature or improvement that you would like.
validations:
required: true
13 changes: 13 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Description

<!-- If your pull request fixes an existing issue (e.g. #xxx), mention "Fixes #xxx" here. -->

<!-- Please describe the purpose of the pull request. -->
<!-- Provide thorough details about what you changed and why. -->

## Checklist

- [ ] I have added new tests (if necessary).
- [ ] I have ensured that tests and coverage are passing on CI.
- [ ] I have updated any relevant documentation (if necessary).
- [ ] I have used a descriptive pull request title.
25 changes: 25 additions & 0 deletions .github/workflows/create-github-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Create GitHub release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: "Get previous tag"
id: latest-tag
uses: "WyriHaximus/github-action-get-previous-tag@v1"
- uses: ncipollo/release-action@v1
with:
tag: ${{ steps.latest-tag.outputs.tag }}
generateReleaseNotes: true
token: ${{ secrets.GITHUB_TOKEN }}
19 changes: 19 additions & 0 deletions .github/workflows/create-pypi-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Create PyPI release

on:
push:
branches:
- master

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Build and publish to PyPI
uses: JRubics/poetry-publish@v1.17
with:
python_version: "3.11.3"
poetry_version: "==1.7.1"
pypi_token: ${{ secrets.PYPI_TOKEN }}
60 changes: 60 additions & 0 deletions .github/workflows/create-release-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Create release PR

on:
workflow_dispatch:
inputs:
version:
description: Version
required: true

jobs:
create-pull-request:
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v4
with:
ref: dev
fetch-depth: 0
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.11.3
- name: Install Poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.7.1
- name: Install base dependencies
run: poetry install --sync --only base
- name: Bump version
run: |
poetry run -q invoke release.build -- -v ${{ github.event.inputs.version }}
- name: Update changelog
uses: orhun/git-cliff-action@v2
id: cliff-changelog
with:
config: cliff.toml
args: --tag ${{ github.event.inputs.version }}
env:
OUTPUT: CHANGELOG.md
- name: Get changelog entry
uses: orhun/git-cliff-action@v2
id: cliff-entry
with:
config: cliff.toml
args: --unreleased --strip header
env:
OUTPUT: ENTRY.md
- name: Create pull request
uses: peter-evans/create-pull-request@v5.0.2
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "release: v${{ github.event.inputs.version }}"
title: "release: v${{ github.event.inputs.version }}"
body: "${{ steps.cliff-entry.outputs.content }}"
branch: release/${{ github.event.inputs.version }}
- uses: rickstaa/action-create-tag@v1
with:
tag: v${{ github.event.inputs.version }}
github_token: ${{ secrets.GITHUB_TOKEN }}
43 changes: 43 additions & 0 deletions .github/workflows/semantic-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Enforce semantic PR title

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
pull-requests: read

jobs:
main:
name: validate
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
with:
subjectPattern: ^(?![A-Z]).+$
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern. Please ensure that the subject
doesn't start with an uppercase character.
types: |
build
chore
ci
docs
feat
fix
perf
refactor
release
revert
style
tests
scopes: |
deps
git
pkg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ehthumbs.db
Thumbs.db

# Byte-compiled / optimized / DLL files
__pycache__/
__pycache__
*.py[cod]
*$py.class

Expand Down Expand Up @@ -73,6 +73,7 @@ docs/_build
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
Pipfile.lock
poetry.lock

# Environments
.env
Expand All @@ -87,3 +88,9 @@ venv.bak/
.spyderproject
.spyproject
.vscode

# Ruff
.ruff_cache

# Changelog entry
ENTRY.md
Loading

0 comments on commit 2786899

Please sign in to comment.