Skip to content

Commit

Permalink
Merge branch 'master' into dev1
Browse files Browse the repository at this point in the history
* master: (23 commits)
  Rm deprecated
  Fixes
  Bump version
  Rm and demote less interesting exc
  Fix mpl issue
  Fix coverage
  Improve format
  Autoformat
  Test up to py312
  Autoformat
  Revise dependencies
  Use "upstream" pathos/dill for MP
  Fix MP
  Autoformat
  Comment, tiny
  Clean pyproject of flake8/autopep
  Sync ipynb
  Format via ruff in pre-commit
  Ruff isort
  amend
  ...
  • Loading branch information
patnr committed Oct 25, 2024
2 parents 26fd70b + c4b6ceb commit 05e6aa1
Show file tree
Hide file tree
Showing 123 changed files with 3,476 additions and 3,042 deletions.
55 changes: 27 additions & 28 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,38 @@ on:
- dev1
- "!gh-pages"
env:
IS_CI: 'true'
IS_CI: "true"

jobs:

bundled:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest']
python-version: ['3.9', '3.10', '3.11']
jobtype: ['test']
os: ["ubuntu-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"] # NB: also see versions for 'conda'
jobtype: ["test"]
include:
- os: 'ubuntu-latest'
python-version: '3.10'
jobtype: 'lint'
- os: 'ubuntu-latest'
python-version: '3.10'
jobtype: 'coverage'
- os: 'macos-latest'
python-version: '3.10'
jobtype: 'test'
- os: "ubuntu-latest"
python-version: "3.10"
jobtype: "lint"
- os: "ubuntu-latest"
python-version: "3.10"
jobtype: "coverage"
- os: "macos-latest"
python-version: "3.10"
jobtype: "test"
env:
JOBTYPE: ${{ matrix.jobtype }}

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

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'setup.py'
cache: "pip"
cache-dependency-path: "setup.py"

- name: Install dependencies
run: |
Expand Down Expand Up @@ -69,22 +68,22 @@ jobs:

conda:
defaults:
run:
shell: bash -el {0}
run:
shell: bash -el {0}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ['ubuntu-latest']
python-version: ['3.9', '3.10', '3.11']
os: ["ubuntu-latest"]
python-version: ["3.9", "3.12"]
include:
- os: 'macos-latest'
python-version: '3.10'
- os: 'windows-latest'
python-version: '3.9'
- os: "macos-latest"
python-version: "3.12"
- os: "windows-latest"
python-version: "3.12"

steps:
- uses: actions/checkout@v3
- uses: conda-incubator/setup-miniconda@v2
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
Expand Down
26 changes: 5 additions & 21 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,8 @@ repos:
- id: mixed-line-ending
args: ['--fix=no']

- repo: https://github.com/flakeheaven/flakeheaven
rev: 3.2.1
hooks:
- id: flakeheaven
additional_dependencies: [
flake8-docstrings,
flake8-bugbear,
flake8-comprehensions,
flake8-isort,
flake8-builtins,
pep8-naming,
]

- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
exclude: |
(?x)^(
examples/.*.py
)$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.0
hooks:
- id: ruff
- id: ruff-format
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ open the [Anaconda terminal](https://docs.conda.io/projects/conda/en/latest/user
and run the following commands:

```sh
conda create --yes --name dapper-env python=3.9
conda create --yes --name dapper-env python=3.12
conda activate dapper-env
python --version
```

Ensure the printed version is 3.9 or more.
Ensure the printed version is as desired.
*Keep using the same terminal for the commands below.*

### Install
Expand Down
1 change: 1 addition & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Configures pytest (beyond the ini file)."""

import matplotlib as mpl
import numpy
import pytest
Expand Down
2 changes: 1 addition & 1 deletion dapper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.. include:: ./README.md
"""

__version__ = "1.6.0"
__version__ = "1.7.0"

# A parsimonious list of imports used in the examples
from .dpr_config import rc
Expand Down
26 changes: 17 additions & 9 deletions dapper/da_methods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.. include:: ./README.md
"""

from pathlib import Path


Expand Down Expand Up @@ -82,7 +83,7 @@ def dataclass_with_defaults(cls):
def set_field(name, type_, val):
"""Set the inherited (i.e. default, i.e. has value) field."""
# Ensure annotations
cls.__annotations__ = getattr(cls, '__annotations__', {})
cls.__annotations__ = getattr(cls, "__annotations__", {})
# Set annotation
cls.__annotations__[name] = type_
# Set value
Expand All @@ -102,7 +103,7 @@ def set_field(name, type_, val):
# Define the new assimilate method (has bells and whistles)
def assimilate(self, HMM, xx, yy, desc=None, fail_gently=False, **stat_kwargs):
# Progressbar name
pb_name_hook = self.da_method if desc is None else desc # noqa
pb_name_hook = self.da_method if desc is None else desc # noqa

# Init stats
self.stats = dapper.stats.Stats(self, HMM, xx, yy, **stat_kwargs)
Expand All @@ -120,27 +121,30 @@ def assimilate(self, HMM, xx, yy, desc=None, fail_gently=False, **stat_kwargs):
# Don't use _print_cropped_traceback here -- It would
# crop out errors in the DAPPER infrastructure itself.
raise
self.stat("duration", time.time()-time0)
self.stat("duration", time.time() - time0)

# Overwrite the assimilate method with the new one
try:
_assimilate = cls.assimilate
except AttributeError as error:
raise AttributeError(
"Classes decorated by da_method()"
" must define a method called 'assimilate'.") from error
" must define a method called 'assimilate'."
) from error
cls.assimilate = functools.wraps(_assimilate)(assimilate)

# Shortcut for register_stat
def stat(self, name, value):
dapper.stats.register_stat(self.stats, name, value)

cls.stat = stat

# Make self.__class__.__name__ an attrib.
# Used by xpList.table_prep().
cls.da_method = cls.__name__

return cls

return dataclass_with_defaults


Expand All @@ -155,15 +159,17 @@ def crop_traceback(ERR):
msg = "Traceback (most recent call last):\n"
try:
# If in IPython, use its coloring functionality
__IPYTHON__ # type: ignore
__IPYTHON__ # type: ignore # noqa: B018
except (NameError, ImportError):
msg += "".join(traceback.format_tb(ERR.__traceback__))
else:
from IPython.core.debugger import Pdb

pdb_instance = Pdb()
pdb_instance.curframe = inspect.currentframe()

import dapper.da_methods

keep = False
for frame in traceback.walk_tb(ERR.__traceback__):
if keep:
Expand All @@ -175,10 +181,12 @@ def crop_traceback(ERR):
return msg

msg = crop_traceback(ERR) + "\nError message: " + str(ERR)
msg += ("\n\nResuming execution."
"\nIf instead you wish to raise the exceptions as usual,"
"\nwhich will halt the execution (and enable post-mortem debug),"
"\nthen use `fail_gently=False`")
msg += (
"\n\nResuming execution."
"\nIf instead you wish to raise the exceptions as usual,"
"\nwhich will halt the execution (and enable post-mortem debug),"
"\nthen use `fail_gently=False`"
)
print(msg, file=sys.stderr)


Expand Down
Loading

0 comments on commit 05e6aa1

Please sign in to comment.