Skip to content

Commit

Permalink
try fix ci using uv
Browse files Browse the repository at this point in the history
  • Loading branch information
d-chambers committed Oct 9, 2024
1 parent 86e69e6 commit 5a62234
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/test_conda_env.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: test
name: dbscan1d
channels:
- conda-forge
- defaults
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Lint the code using the defined pre-commits
name: LintCode
on: [push]

jobs:
lint_code:
runs-on: ubuntu-latest

# only run if CI isn't turned off
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci')

steps:
- uses: actions/checkout@v4

- name: install linting packages
run: pip install pre-commit --break-system-packages

- name: run all precommits
run: pre-commit run --all
41 changes: 0 additions & 41 deletions .github/workflows/on_master_commits.yml

This file was deleted.

19 changes: 10 additions & 9 deletions .github/workflows/release_published.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@ jobs:
runs-on: ubuntu-latest

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

- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: 'latest'
python-version: "3.11"
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml
- name: "get tags"
run: |
git fetch --tags --force # Retrieve annotated tags.
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python
run: uv python install 3.12

- name: install
shell: bash -l {0}
Expand Down
96 changes: 58 additions & 38 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
name: validate
on: [push]
# Run full test suite using conda env and all optional deps.
name: TestCode
on:
push:
branches:
- master
pull_request:
branches:
- master
paths:
- 'pyproject.toml'
- '**.py'
- '.github/workflows/*.yml'

jobs:
# Simply applies flake8 to code using pre-commit
lint_code:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1

- name: Setup conda
uses: s-weigand/setup-conda@v1
with:
python-version: "3.10"

- name: install linting packages
run: pip install pre-commit

- name: run all precommits
run: pre-commit run --all
# Cancel previous runs when this one starts.
concurrency:
group: TestCode-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true

jobs:
# Runs the tests on combinations of the supported python/os matrix.
test_code:

timeout-minutes: 25
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ['3.10', '3.11', "3.12"]

# only run if CI isn't turned off
if: github.event_name == 'push' || !contains(github.event.pull_request.labels.*.name, 'no_ci')

env:
# set conda environment file with dependencies
env_file: "test_conda_env.yml"

steps:
- uses: actions/checkout@v4
Expand All @@ -35,28 +43,40 @@ jobs:
run: |
git fetch --tags --force # Retrieve annotated tags.
- name: Setup conda
uses: conda-incubator/setup-miniconda@v2
with:
miniconda-version: 'latest'
python-version: ${{ matrix.python-version }}
activate-environment: test
environment-file: .github/test_conda_env.yml
condarc-file: .github/test_condarc.yml

- name: install
shell: bash -l {0}
- name: Install uv
uses: astral-sh/setup-uv@v3

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

- name: install dbscan1d
shell: bash -el {0}
run: |
pip install -e .
python -m pip install -e ".[dev]"
# Print out the package info for current environment
- name: print package info
shell: bash -l {0}
shell: bash -el {0}
run: |
conda info -a
conda list
uv pip list
# Runs test suite and calculates coverage
- name: run test suite
shell: bash -l {0}
run: |
pytest tests
shell: bash -el {0}
run: python -m pytest -s --cov dbscan1d --cov-append --cov-report=xml

# Upload coverage files
- uses: codecov/codecov-action@v4
with:
fail_ci_if_error: false
files: ./coverage.xml
flags: unittests
name: PR_tests
token: ${{ secrets.CODECOV_TOKEN }}


# This is a very useful step for debugging, it allows you to ssh into the CI
# machine (https://github.com/marketplace/actions/debugging-with-tmate).
#
#- name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
26 changes: 13 additions & 13 deletions tests/test_dbscan1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ def test_issue_7(self, issue_7_array):
# also test indices of core points
assert np.all(dbs_1.core_sample_indices_ == dbs_2.core_sample_indices_)


def test_sample_weights() -> None:
x = np.asarray([0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 1.1, 1.2])
labels = DBSCAN1D(eps=0.5, min_samples=3).fit_predict(x)
assert np.all(labels[:9] == 0)
assert np.all(labels[-2:] == -1)

weight = np.ones_like(x)
weight[-1] = 1.2
weight[-2] = 1.8
labels = DBSCAN1D(eps=0.5, min_samples=3).fit_predict(x, sample_weight=weight)
assert np.all(labels[:9] == 0)
assert np.all(labels[-2:] == 1)
def test_sample_weights(self) -> None:
"""Test case for sample weights ."""
x = np.asarray([0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 0.1, 0.2, 0.3, 1.1, 1.2])
labels = DBSCAN1D(eps=0.5, min_samples=3).fit_predict(x)
assert np.all(labels[:9] == 0)
assert np.all(labels[-2:] == -1)

weight = np.ones_like(x)
weight[-1] = 1.2
weight[-2] = 1.8
labels = DBSCAN1D(eps=0.5, min_samples=3).fit_predict(x, sample_weight=weight)
assert np.all(labels[:9] == 0)
assert np.all(labels[-2:] == 1)

0 comments on commit 5a62234

Please sign in to comment.