Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from poetry to uv #23

Merged
merged 6 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions .github/workflows/python-publish-ezmsg-sigproc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# This workflow will upload a Python Package using Twine when a release is created
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Upload Python Package - ezmsg-sigproc

Expand All @@ -22,20 +16,15 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build

- name: Build ezmsg-sigproc
run: python -m build .
- name: Publish ezmsg-sigproc
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
password: ${{ secrets.PYPI_API_TOKEN_SIGPROC }}
packages_dir: dist

- name: Install uv
uses: astral-sh/setup-uv@v2

- name: Build Package
run: uv build

- name: Publish Package
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN_SIGPROC }}
run: uvx twine upload dist/*
46 changes: 18 additions & 28 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
strategy:
matrix:
python-version: [3.8, 3.9, "3.10"]
python-version: [3.9, "3.10", "3.11", "3.12"]
os:
- "ubuntu-latest"
- "windows-latest"
Expand All @@ -21,31 +21,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v2
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip and install pipx
run: |
python -m pip install --upgrade pip pipx flake8

- name: Install Poetry via pipx
run: |
pipx install poetry
echo "$HOME/.local/bin/" >> $GITHUB_PATH

- name: Install dependencies with Poetry
run: |
poetry install --with test

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Test ezmsg-sigproc
run: |
poetry run python -m pytest -v tests
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install the project
run: uv sync --all-extras --dev

# - name: Lint
# run:
# uv tool run ruff check --output-format=github src

- name: Run tests
run: uv run pytest tests
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,5 @@ cython_debug/

# JetBrains
.idea/

src/ezmsg/sigproc/__version__.py
476 changes: 0 additions & 476 deletions poetry.lock

This file was deleted.

64 changes: 39 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,35 +1,49 @@
[tool.poetry]
[project]
name = "ezmsg-sigproc"
version = "1.2.5"
description = "Timeseries signal processing implementations in ezmsg"
authors = [
"Milsap, Griffin <[email protected]>",
"Peranich, Preston <[email protected]>",
"Boulay, Chadwick <[email protected]>"
{ name = "Griffin Milsap", email = "[email protected]" },
{ name = "Preston Peranich", email = "[email protected]" },
{ name = "Chadwick Boulay", email = "[email protected]" }
]
license = "MIT"
readme = "README.md"
packages = [{ include = "ezmsg", from = "src" }]
requires-python = ">=3.9"
dynamic = ["version"]
dependencies = [
"ezmsg>=3.5.0",
"numpy>=2.0.2",
"pywavelets>=1.6.0",
"scipy>=1.13.1",
]

[tool.poetry.dependencies]
python = "^3.9"
numpy = "^1.19.5"
scipy = "^1.6.3"
pywavelets = "^1.6.0"
ezmsg = "^3.5.0"
[project.optional-dependencies]
test = [
"flake8>=7.1.1",
"frozendict>=2.4.4",
"pytest-asyncio>=0.24.0",
"pytest-cov>=5.0.0",
"pytest>=8.3.3",
]

[tool.poetry.group.test.dependencies]
pytest = "^7.0.0"
pytest-cov = "*"
pytest-asyncio = "*"
flake8 = "*"
frozendict = "^2.4.4"
[build-system]
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[tool.pytest.ini_options]
addopts = ["--import-mode=importlib"]
pythonpath = ["src", "tests"]
testpaths = "tests"
[tool.hatch.version]
source = "vcs"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
[tool.hatch.build.hooks.vcs]
version-file = "src/ezmsg/sigproc/__version__.py"

[tool.hatch.build.targets.wheel]
packages = ["src/ezmsg"]

[tool.uv]
dev-dependencies = [
"ruff>=0.6.7",
]

[tool.pytest.ini_options]
norecursedirs = "tests/helpers"
addopts = "-p no:warnings"
5 changes: 1 addition & 4 deletions src/ezmsg/sigproc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import importlib.metadata


__version__ = importlib.metadata.version("ezmsg-sigproc")
from .__version__ import __version__ as __version__
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), 'helpers'))
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions tests/test_affine_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def test_affine_generator():

gen = affine_transform(weights=csv_path, axis="ch", right_multiply=False)
ax_arr_out = gen.send(axis_arr_in)
assert np.array_equal(ax_arr_out.data, expected_out)
assert np.allclose(ax_arr_out.data, expected_out)

# Try again as str, not Path
gen = affine_transform(weights=str(csv_path), axis="ch", right_multiply=False)
ax_arr_out = gen.send(axis_arr_in)
assert np.array_equal(ax_arr_out.data, expected_out)
assert np.allclose(ax_arr_out.data, expected_out)

# Try again as direct ndarray
gen = affine_transform(weights=weights, axis="ch", right_multiply=False)
ax_arr_out = gen.send(axis_arr_in)
assert np.array_equal(ax_arr_out.data, expected_out)
assert np.allclose(ax_arr_out.data, expected_out)

# One more time, but we pre-transpose the weights and do not override right_multiply
gen = affine_transform(weights=weights.T, axis="ch", right_multiply=True)
ax_arr_out = gen.send(axis_arr_in)
assert np.array_equal(ax_arr_out.data, expected_out)
assert np.allclose(ax_arr_out.data, expected_out)


def test_affine_passthrough():
Expand Down
10 changes: 5 additions & 5 deletions tests/test_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ def test_spectrum_vs_sps_fft(complex: bool):
assert np.allclose(test_spec, sp_res)


class TestSpectrumSettings(ez.Settings):
class SpectrumSettingsTest(ez.Settings):
synth_settings: EEGSynthSettings
window_settings: WindowSettings
spectrum_settings: SpectrumSettings
log_settings: MessageLoggerSettings
term_settings: TerminateOnTotalSettings = field(default_factory=TerminateOnTotalSettings)


class TestSpectrumIntegration(ez.Collection):
SETTINGS = TestSpectrumSettings
class SpectrumIntegrationTest(ez.Collection):
SETTINGS = SpectrumSettingsTest

SOURCE = EEGSynth()
WIN = Window()
Expand Down Expand Up @@ -221,7 +221,7 @@ def test_spectrum_system(
test_filename = get_test_fn(test_name)
ez.logger.info(test_filename)

settings = TestSpectrumSettings(
settings = SpectrumSettingsTest(
synth_settings=EEGSynthSettings(
fs=fs,
n_time=n_time,
Expand All @@ -246,7 +246,7 @@ def test_spectrum_system(
total=target_messages,
)
)
system = TestSpectrumIntegration(settings)
system = SpectrumIntegrationTest(settings)
ez.run(SYSTEM=system)

messages: typing.List[AxisArray] = [_ for _ in message_log(test_filename)]
Expand Down
12 changes: 6 additions & 6 deletions tests/test_synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def test_aclock_agen(dispatch_rate: typing.Optional[float]):
t_elapsed = time.time() - t_start
assert all([_ == ez.Flag() for _ in result])
if dispatch_rate:
assert (run_time - 1 / dispatch_rate) < t_elapsed < (run_time + 0.1)
assert (run_time - 1.1 / dispatch_rate) < t_elapsed < (run_time + 0.1)
else:
assert t_elapsed < (n_target * 1e-4) # 100 usec per iteration is pretty generous

Expand Down Expand Up @@ -308,14 +308,14 @@ def f_test(t): return amp * np.sin(2 * np.pi * freq * t + phase)
# TODO: test SinGenerator in a system.


class TestEEGSynthSettings(ez.Settings):
class EEGSynthSettingsTest(ez.Settings):
synth_settings: EEGSynthSettings
log_settings: MessageLoggerSettings
term_settings: TerminateOnTotalSettings = field(default_factory=TerminateOnTotalSettings)


class TestEEGSynthIntegration(ez.Collection):
SETTINGS = TestEEGSynthSettings
class EEGSynthIntegrationTest(ez.Collection):
SETTINGS = EEGSynthSettingsTest

SOURCE = EEGSynth()
SINK = MessageLogger()
Expand Down Expand Up @@ -345,7 +345,7 @@ def test_eegsynth_system(
test_filename = get_test_fn(test_name)
ez.logger.info(test_filename)

settings = TestEEGSynthSettings(
settings = EEGSynthSettingsTest(
synth_settings=EEGSynthSettings(
fs=fs,
n_time=n_time,
Expand All @@ -360,7 +360,7 @@ def test_eegsynth_system(
)
)

system = TestEEGSynthIntegration(settings)
system = EEGSynthIntegrationTest(settings)
ez.run(SYSTEM=system)

messages: typing.List[AxisArray] = [_ for _ in message_log(test_filename)]
Expand Down
Loading