Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into ibl_exporter
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahpearl committed Oct 19, 2024
2 parents bf4e72a + a606364 commit 29e5b61
Show file tree
Hide file tree
Showing 609 changed files with 51,017 additions and 26,108 deletions.
4 changes: 2 additions & 2 deletions .github/actions/build-test-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ runs:
python -m pip install -U pip # Official recommended way
source ${{ github.workspace }}/test_env/bin/activate
pip install tabulate # This produces summaries at the end
pip install -e .[test,extractors,streaming_extractors,full]
pip install -e .[test,extractors,streaming_extractors,test_extractors,full]
shell: bash
- name: Force installation of latest dev from key-packages when running dev (not release)
run: |
source ${{ github.workspace }}/test_env/bin/activate
spikeinterface_is_dev_version=$(python -c "import importlib.metadata; version = importlib.metadata.version('spikeinterface'); print(version.endswith('dev0'))")
spikeinterface_is_dev_version=$(python -c "import spikeinterface; print(spikeinterface.DEV_MODE)")
if [ $spikeinterface_is_dev_version = "True" ]; then
echo "Running spikeinterface dev version"
pip install --no-cache-dir git+https://github.com/NeuralEnsemble/python-neo
Expand Down
19 changes: 14 additions & 5 deletions .github/actions/install-wine/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@ name: Install packages
description: This action installs the package and its dependencies for testing

inputs:
python-version:
description: 'Python version to set up'
required: false
os:
description: 'Operating system to set up'
required: false
required: true

runs:
using: "composite"
steps:
- name: Install wine (needed for Plexon2)
- name: Install wine on Linux
if: runner.os == 'Linux'
run: |
sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
sudo dpkg --add-architecture i386
sudo apt-get update -qq
sudo apt-get install -yqq --allow-downgrades libc6:i386 libgcc-s1:i386 libstdc++6:i386 wine
shell: bash
- name: Install wine on macOS
if: runner.os == 'macOS'
run: |
brew install --cask xquartz
brew install --cask wine-stable
shell: bash

- name: Skip installation on Windows
if: ${{ inputs.os == 'Windows' }}
run: echo "Skipping Wine installation on Windows. Not necessary."
shell: bash
23 changes: 0 additions & 23 deletions .github/actions/show-test-environment/action.yml

This file was deleted.

57 changes: 0 additions & 57 deletions .github/import_test.py

This file was deleted.

9 changes: 7 additions & 2 deletions .github/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#!/bin/bash

MARKER=$1
NOVIRTUALENV=$2

# Check if the second argument is provided and if it is equal to --no-virtual-env
if [ -z "$NOVIRTUALENV" ] || [ "$NOVIRTUALENV" != "--no-virtual-env" ]; then
source $GITHUB_WORKSPACE/test_env/bin/activate
fi

source $GITHUB_WORKSPACE/test_env/bin/activate
pytest -m "$MARKER" -vv -ra --durations=0 --durations-min=0.001 | tee report.txt; test ${PIPESTATUS[0]} -eq 0 || exit 1
echo "# Timing profile of ${MARKER}" >> $GITHUB_STEP_SUMMARY
python $GITHUB_WORKSPACE/.github/build_job_summary.py report.txt >> $GITHUB_STEP_SUMMARY
python $GITHUB_WORKSPACE/.github/scripts/build_job_summary.py report.txt >> $GITHUB_STEP_SUMMARY
rm report.txt
2 changes: 2 additions & 0 deletions .github/scripts/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This folder contains test scripts for running in the CI, that are not run as part of the usual
CI because they are too long / heavy. These are run on cron-jobs once per week.
File renamed without changes.
30 changes: 30 additions & 0 deletions .github/scripts/check_kilosort4_releases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import re
from pathlib import Path
import requests
import json
from packaging.version import parse
import spikeinterface

def get_pypi_versions(package_name):
"""
Make an API call to pypi to retrieve all
available versions of the kilosort package.
"""
url = f"https://pypi.org/pypi/{package_name}/json"
response = requests.get(url)
response.raise_for_status()
data = response.json()
versions = list(sorted(data["releases"].keys()))
# Filter out versions that are less than 4.0.16
versions = [ver for ver in versions if parse(ver) >= parse("4.0.16")]
return versions


if __name__ == "__main__":
# Get all KS4 versions from pipi and write to file.
package_name = "kilosort"
versions = get_pypi_versions(package_name)
with open(Path(os.path.realpath(__file__)).parent / "kilosort4-latest-version.json", "w") as f:
print(versions)
json.dump(versions, f)
129 changes: 129 additions & 0 deletions .github/scripts/determine_testing_environment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
from pathlib import Path
import argparse
import os


# We get the list of files change as an input
parser = argparse.ArgumentParser()
parser.add_argument("changed_files_in_the_pull_request", nargs="*", help="List of changed files")
args = parser.parse_args()

changed_files_in_the_pull_request = args.changed_files_in_the_pull_request
changed_files_in_the_pull_request_paths = [Path(file) for file in changed_files_in_the_pull_request]

# We assume nothing has been changed

core_changed = False
pyproject_toml_changed = False
neobaseextractor_changed = False
extractors_changed = False
plexon2_changed = False
preprocessing_changed = False
postprocessing_changed = False
qualitymetrics_changed = False
sorters_changed = False
sorters_external_changed = False
sorters_internal_changed = False
comparison_changed = False
curation_changed = False
widgets_changed = False
exporters_changed = False
sortingcomponents_changed = False
generation_changed = False
stream_extractors_changed = False
github_actions_changed = False


for changed_file in changed_files_in_the_pull_request_paths:

file_is_in_src = changed_file.parts[0] == "src"

if changed_file.name == "pyproject.toml":
pyproject_toml_changed = True
elif changed_file.name == "neobaseextractor.py":
neobaseextractor_changed = True
extractors_changed = True
elif changed_file.name == "plexon2.py":
plexon2_changed = True
elif changed_file.name == "nwbextractors.py":
extractors_changed = True # There are NWB tests that are not streaming
stream_extractors_changed = True
elif changed_file.name == "iblextractors.py":
stream_extractors_changed = True
elif "core" in changed_file.parts:
core_changed = True
elif "extractors" in changed_file.parts:
extractors_changed = True
elif "preprocessing" in changed_file.parts:
preprocessing_changed = True
elif "postprocessing" in changed_file.parts:
postprocessing_changed = True
elif "qualitymetrics" in changed_file.parts:
qualitymetrics_changed = True
elif "comparison" in changed_file.parts:
comparison_changed = True
elif "curation" in changed_file.parts:
curation_changed = True
elif "widgets" in changed_file.parts:
widgets_changed = True
elif "exporters" in changed_file.parts:
exporters_changed = True
elif "sortingcomponents" in changed_file.parts:
sortingcomponents_changed = True
elif "generation" in changed_file.parts:
generation_changed = True
elif "sorters" in changed_file.parts:
if "external" in changed_file.parts:
sorters_external_changed = True
elif "internal" in changed_file.parts:
sorters_internal_changed = True
else:
sorters_changed = True
elif ".github" in changed_file.parts:
if "workflows" in changed_file.parts:
github_actions_changed = True


run_everything = core_changed or pyproject_toml_changed or neobaseextractor_changed or github_actions_changed
run_generation_tests = run_everything or generation_changed
run_extractor_tests = run_everything or extractors_changed or plexon2_changed
run_preprocessing_tests = run_everything or preprocessing_changed
run_postprocessing_tests = run_everything or postprocessing_changed
run_qualitymetrics_tests = run_everything or qualitymetrics_changed
run_curation_tests = run_everything or curation_changed
run_sortingcomponents_tests = run_everything or sortingcomponents_changed

run_comparison_test = run_everything or run_generation_tests or comparison_changed
run_widgets_test = run_everything or run_qualitymetrics_tests or run_preprocessing_tests or widgets_changed
run_exporters_test = run_everything or run_widgets_test or exporters_changed

run_sorters_test = run_everything or sorters_changed
run_internal_sorters_test = run_everything or run_sortingcomponents_tests or sorters_internal_changed

run_streaming_extractors_test = stream_extractors_changed or github_actions_changed

install_plexon_dependencies = plexon2_changed


environment_varaiables_to_add = {
"RUN_EXTRACTORS_TESTS": run_extractor_tests,
"RUN_PREPROCESSING_TESTS": run_preprocessing_tests,
"RUN_POSTPROCESSING_TESTS": run_postprocessing_tests,
"RUN_QUALITYMETRICS_TESTS": run_qualitymetrics_tests,
"RUN_CURATION_TESTS": run_curation_tests,
"RUN_SORTINGCOMPONENTS_TESTS": run_sortingcomponents_tests,
"RUN_GENERATION_TESTS": run_generation_tests,
"RUN_COMPARISON_TESTS": run_comparison_test,
"RUN_WIDGETS_TESTS": run_widgets_test,
"RUN_EXPORTERS_TESTS": run_exporters_test,
"RUN_SORTERS_TESTS": run_sorters_test,
"RUN_INTERNAL_SORTERS_TESTS": run_internal_sorters_test,
"INSTALL_PLEXON_DEPENDENCIES": install_plexon_dependencies,
"RUN_STREAMING_EXTRACTORS_TESTS": run_streaming_extractors_test,
}

# Write the conditions to the GITHUB_ENV file
env_file = os.getenv("GITHUB_ENV")
with open(env_file, "a") as f:
for key, value in environment_varaiables_to_add.items():
f.write(f"{key}={value}\n")
72 changes: 72 additions & 0 deletions .github/scripts/import_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import subprocess
import math

import_statement_list = [
"import spikeinterface",
"import spikeinterface.core",
"import spikeinterface.extractors",
"import spikeinterface.qualitymetrics",
"import spikeinterface.preprocessing",
"import spikeinterface.comparison",
"import spikeinterface.postprocessing",
"import spikeinterface.sortingcomponents",
"import spikeinterface.curation",
"import spikeinterface.exporters",
"import spikeinterface.widgets",
"import spikeinterface.full",
]

n_samples = 10
# Note that the symbols at the end are for centering the table
markdown_output = f"## \n\n| Imported Module ({n_samples=}) | Importing Time (seconds) | Standard Deviation (seconds) | Times List (seconds) |\n| :--: | :--------------: | :------------------: | :-------------: |\n"

exceptions = []

for import_statement in import_statement_list:
time_taken_list = []
for _ in range(n_samples):
script_to_execute = (
f"import timeit \n"
f"import_statement = '{import_statement}' \n"
f"time_taken = timeit.timeit(import_statement, number=1) \n"
f"print(time_taken) \n"
)

result = subprocess.run(["python", "-c", script_to_execute], capture_output=True, text=True)

if result.returncode != 0:
error_message = (
f"Error when running {import_statement} \n" f"Error in subprocess: {result.stderr.strip()}\n"
)
exceptions.append(error_message)
break

time_taken = float(result.stdout.strip())
time_taken_list.append(time_taken)

for time in time_taken_list:
import_time_threshold = 3.0 # Most of the times is sub-second but there outliers
if time >= import_time_threshold:
exceptions.append(
f"Importing {import_statement} took: {time:.2f} s. Should be <: {import_time_threshold} s."
)
break


if time_taken_list:
avg_time = sum(time_taken_list) / len(time_taken_list)
std_time = math.sqrt(sum((x - avg_time) ** 2 for x in time_taken_list) / len(time_taken_list))
times_list_str = ", ".join(f"{time:.2f}" for time in time_taken_list)
markdown_output += f"| `{import_statement}` | {avg_time:.2f} | {std_time:.2f} | {times_list_str} |\n"

import_time_threshold = 2.0
if avg_time > import_time_threshold:
exceptions.append(
f"Importing {import_statement} took: {avg_time:.2f} s in average. Should be <: {import_time_threshold} s."
)

if exceptions:
raise Exception("\n".join(exceptions))

# This is displayed to GITHUB_STEP_SUMMARY
print(markdown_output)
1 change: 1 addition & 0 deletions .github/scripts/kilosort4-latest-version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["4.0.10", "4.0.11", "4.0.12", "4.0.5", "4.0.6", "4.0.7", "4.0.8", "4.0.9"]
Loading

0 comments on commit 29e5b61

Please sign in to comment.