Skip to content

Commit

Permalink
Dev deps (#330)
Browse files Browse the repository at this point in the history
* Replace black with ruff format and format doc string code

* Fix some formatting deltas and exclude some rules that apply more broadly than before.

* Remove hard coded black from workflow

* Add some more package bounds. Add test for oldest package version.
* Locally verified 1.24, wouldn't be too hard to update to support older if desired

* Actually add github action for testing oldest

* Bad default glob

* Uv really means it when they say oldest.

* Try using uv pip interface without venv

* Another round. Worked locally

* Another minimum

* Remove final black reference

* Try updating broken link

* Update pytest instructions
  • Loading branch information
ntjohnson1 authored Nov 11, 2024
1 parent 2c77248 commit 6a71510
Show file tree
Hide file tree
Showing 19 changed files with 491 additions and 424 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/oldest-support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This should mirror regression tests. Ideally we find a way in the future to fold the two together

name: Test Oldest Dependencies

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
UV_SYSTEM_PYTHON: 1

jobs:
test-oldest:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

# Use uv since it has easy lowest resolution
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "**/pyproject.toml"

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9' # Find a way to globally define our minimum python once

- name: Install dependencies with minimum versions
run: |
uv sync --resolution lowest-direct --extra dev
- name: Run tests
run: |
uv run --resolution lowest-direct pytest ./tests
3 changes: 0 additions & 3 deletions .github/workflows/regression-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
run: |
python -m pip install --upgrade coverage coveralls sphinx_rtd_theme
pip install ".[dev]"
- name: Check auto-formatters
run: |
black --check .
- name: Run tests
run: |
coverage run --source pyttb -m pytest tests/
Expand Down
10 changes: 3 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.284
rev: v0.7.2
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
language_version: python
- id: ruff-format
- repo: https://github.com/kynan/nbstripout
rev: 0.6.1
rev: 0.8.0
hooks:
- id: nbstripout
args: [
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
# v1.3.3 (2022-07-11)
- Fixed indexing bug in `tensor.mttkrp` (Issue #35, PR #36)
- Updated LICENSE to compliant format (Issue #33 , PR #34)
- Now using [coveralls.io](https://coveralls.io/github/sandialabs/pyttb) for coverage reporting
- Now using [coveralls.io](https://coveralls.io/github/sandialabs/pyttb?branch=main) for coverage reporting
- Now using [readthedocs.io](https://pyttb.readthedocs.io/en/latest/) for documentation

# v1.3.2 (2022-07-06)
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ current or filing a new [issue](https://github.com/sandialabs/pyttb/issues).
1. Run autoformatters and linting from root of project (they will change your code)
```commandline
ruff check . --fix
black .
ruff format
```
1. Ruff's `--fix` won't necessarily address everything and may point out issues that need manual attention
1. [We](./.pre-commit-config.yaml) optionally support [pre-commit hooks](https://pre-commit.com/) for this
Expand All @@ -52,15 +52,15 @@ current or filing a new [issue](https://github.com/sandialabs/pyttb/issues).
1. Run tests (at desired fidelity)
1. Just doctests (enabled by default)
```commandline
pytest
pytest .
```
1. Functional tests
```commandline
pytest .
pytest tests
```
1. With coverage
```commandline
pytest . --cov=pyttb --cov-report=term-missing
pytest tests --cov=pyttb --cov-report=term-missing
```
1. (Optionally) Building documentation and tutorials
Expand Down
36 changes: 21 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ readme = "README.md"
requires-python = ">=3.9"

dependencies = [
"numpy",
"numpy_groupies",
"scipy",
"matplotlib",
"numpy<3.0,>=1.24",
"numpy_groupies>0.11",
"scipy>1.9",
"matplotlib>3.7",
]

classifiers = [
Expand All @@ -32,18 +32,19 @@ documentation = "https://pyttb.readthedocs.io"

[project.optional-dependencies]
dev = [
"black[jupyter]",
"mypy",
"nbstripout",
"pytest",
"pytest-cov",
"ruff==0.0.284",
"pre-commit",
"mypy>=1.10,<1.14.0",
# Also in pre-commit
"nbstripout>=0.8,<0.9",
"pytest>8.0",
"pytest-cov>5.0",
# Also in pre-commit
"ruff>=0.7,<0.8",
"pre-commit>=4.0,<5.0",
]
doc = [
"sphinx >= 4.0",
"sphinx_rtd_theme",
"myst-nb",
"sphinx_rtd_theme>2.0",
"myst-nb>1.0",
]
profiling = [
"gprof2dot",
Expand All @@ -65,7 +66,7 @@ version = {attr = "pyttb.__version__"}
requires = ["setuptools>=61.0", "numpy", "numpy_groupies", "scipy", "wheel"]
build-backend = "setuptools.build_meta"

[tool.ruff]
[tool.ruff.lint]
select = ["E", "F", "PL", "W", "I", "N", "NPY", "RUF", "B"]
ignore = [
# Ignored in conversion to ruff since not previously enforced
Expand All @@ -83,13 +84,18 @@ ignore = [
# There is ongoing discussion about logging/warning etc
"B028",
]
[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
# See see https://github.com/astral-sh/ruff/issues/3172 for details on this becoming simpler

# Everything but I, F (to catch import mess and potential logic errors)
"tests/**.py" = ["E", "PL", "W", "N", "NPY", "RUF", "B"]
# Ignore everything for now
"docs/**.py" = ["E", "F", "PL", "W", "I", "N", "NPY", "RUF", "B"]
"docs/**.ipynb" = ["E", "F", "PL", "W", "I", "N", "NPY", "RUF", "B"]
"profiling/**.ipynb" = ["E", "F", "PL", "W", "I", "N", "NPY", "RUF", "B"]

[tool.ruff.format]
docstring-code-format = true

[tool.mypy]
warn_unused_configs = true
Expand Down
4 changes: 2 additions & 2 deletions pyttb/cp_apr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ def tt_cp_apr_pqnr( # noqa: PLR0912,PLR0913,PLR0915


@overload
def tt_calcpi_prowsubprob( # noqa: PLR0913
def tt_calcpi_prowsubprob(
Data: ttb.sptensor,
Model: ttb.ktensor,
rank: int,
Expand All @@ -1150,7 +1150,7 @@ def tt_calcpi_prowsubprob( # noqa: PLR0913


@overload
def tt_calcpi_prowsubprob( # noqa: PLR0913
def tt_calcpi_prowsubprob(
Data: ttb.tensor,
Model: ttb.ktensor,
rank: int,
Expand Down
6 changes: 3 additions & 3 deletions pyttb/gcp/fg_est.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


@overload
def estimate( # noqa: PLR0913
def estimate(
model: ttb.ktensor,
data_subs: np.ndarray,
data_vals: np.ndarray,
Expand All @@ -30,7 +30,7 @@ def estimate( # noqa: PLR0913


@overload
def estimate( # noqa: PLR0913
def estimate(
model: ttb.ktensor,
data_subs: np.ndarray,
data_vals: np.ndarray,
Expand All @@ -43,7 +43,7 @@ def estimate( # noqa: PLR0913


@overload
def estimate( # noqa: PLR0913
def estimate(
model: ttb.ktensor,
data_subs: np.ndarray,
data_vals: np.ndarray,
Expand Down
2 changes: 1 addition & 1 deletion pyttb/hosvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def hosvd( # noqa: PLR0912,PLR0913,PLR0915
Example
-------
>>> data = np.array([[29, 39.], [63., 85.]])
>>> data = np.array([[29, 39.0], [63.0, 85.0]])
>>> tol = 1e-4
>>> disable_printing = -1
>>> tensorInstance = ttb.tensor(data)
Expand Down
14 changes: 7 additions & 7 deletions pyttb/khatrirao.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ def khatrirao(*matrices: np.ndarray, reverse: bool = False) -> np.ndarray:
Examples
--------
>>> A = np.random.normal(size=(5,2))
>>> B = np.random.normal(size=(5,2))
>>> _ = khatrirao(A,B) #<-- Khatri-Rao of A and B
>>> _ = khatrirao(B,A,reverse=True) #<-- same thing as above
>>> _ = khatrirao(A,A,B) #<-- passing multiple items
>>> _ = khatrirao(B,A,A,reverse = True) #<-- same as above
>>> _ = khatrirao(*[A,A,B]) #<-- passing a list via unpacking items
>>> A = np.random.normal(size=(5, 2))
>>> B = np.random.normal(size=(5, 2))
>>> _ = khatrirao(A, B) # <-- Khatri-Rao of A and B
>>> _ = khatrirao(B, A, reverse=True) # <-- same thing as above
>>> _ = khatrirao(A, A, B) # <-- passing multiple items
>>> _ = khatrirao(B, A, A, reverse=True) # <-- same as above
>>> _ = khatrirao(*[A, A, B]) # <-- passing a list via unpacking items
"""
# Determine if list of matrices of multiple matrix arguments
if len(matrices) == 1 and isinstance(matrices[0], list):
Expand Down
Loading

0 comments on commit 6a71510

Please sign in to comment.