We welcome contributions to ethopy, a Python package for behavioral training! Whether you're interested in adding new analysis methods, improving documentation, or fixing bugs, your help is appreciated. Here's how you can contribute:
- Reporting bugs or usability issues
- Improving documentation and examples
- Adding new behavioral analysis features
- Enhancing existing modules
- Implementing new visualization methods
- Adding support for new data formats
- Optimizing performance
We use GitHub to host code, track issues and feature requests, and accept pull requests. Here's our development workflow:
- Fork the repo and create your branch from
main. - Set up your development environment:
# Create a virtual environment python -m venv venv source venv/bin/activate # or `venv\Scripts\activate` on Windows # Install development dependencies pip install -e ".[dev]"
- Write your code and add tests:
- Add unit tests for new features
- Use the mocking pattern described in the Testing section below
- Ensure code quality:
- Run tests:
pytest -vv - Check code style:
ruff check . - Fix formatting issues:
ruff format . - Type checking:
mypy src/ethopy# TODO a lot of errors
- Run tests:
- Update documentation:
- Add docstrings (Google format)
- Update API documentation if needed
- Include examples in docstrings if necessary
- Submit your pull request
- Ensure your PR includes:
- A clear description of the changes
- Any updates to documentation
- New or updated tests
- Example usage if applicable
- Link any related issues in the PR description
- The PR will be reviewed by maintainers who may request changes
- Once approved, your PR will be merged
We follow scientific Python coding standards to maintain consistency:
- Code Style:
- Follow PEP 8 guidelines
- Use Google docstring format
- Maximum line length: 88 characters
- Use type hints for function signatures
- Use snake_case for functions/variables, CamelCase for classes
- Use double quotes for strings
Ethopy has specific testing requirements due to its database connections:
-
Database Mocking:
- Tests must run without an actual database connection
- Use the established mocking pattern for database and threading
-
Testing Pattern:
- Use the
patch_importsfixture pattern from existing tests - Import modules inside test functions, not at module level
- Example:
import pytest import sys from unittest.mock import patch, MagicMock @pytest.fixture(scope="module") def patch_imports(): """Patch imports to prevent database connections.""" mocks = {'datajoint': MagicMock(), 'datajoint.config': MagicMock()} with patch.dict(sys.modules, mocks), patch('pathlib.Path.home'), patch('threading.Thread'): yield @pytest.mark.usefixtures("patch_imports") class TestYourModule: # Tests go here...
- Use the
-
Running Tests:
pytest -vv- For a single test:
pytest tests/test_behavior.py::TestBehavior::test_update_history -v
- For a single test:
-
Troubleshooting:
- If tests hang, it usually means threading or database connection issues
- Ensure all threads are mocked and database connections are properly patched
- See existing test files for reference implementations
-
CI Environment:
- GitHub Actions will run all tests with database mocking
- Always ensure your tests pass in a CI environment with no database
Report bugs and feature requests using GitHub's Issue Tracker. When reporting bugs:
- Use a clear and descriptive title
- Describe the exact steps to reproduce the bug
- Include example code and data if possible
- Describe the expected behavior
- Include system information:
- ethopy version
- Python version
- Operating system
- Relevant package versions (numpy, pandas, etc.)
By contributing to ethopy, you agree that your contributions will be licensed under the same license as the project. Please contact the maintainers if you have any questions about licensing.