Contributing
Guide for contributing to PyneCore
Contributing to PyneCore
Introduction
Thank you for your interest in contributing to PyneCore! This document provides guidance for developers who want to contribute to this open-source project that brings TradingView Pine Script compatibility to Python.
PyneCore is designed with a focus on high performance, minimal external dependencies, and an intuitive Pine Script-like development experience in Python. We welcome contributions that enhance this vision.
Setting Up Your Development Environment
Prerequisites
- Python Version: 3.11 or newer (as specified in the project’s requirements)
- Git: For version control
- Virtual Environment: To isolate dependencies
Setup Steps
Clone the repository:
git clone https://github.com/PyneSys/pynecore.git cd pynecore
Create and activate a virtual environment:
python -m venv venv # On Windows: venv\Scripts\activate # On macOS/Linux: source venv/bin/activate
Install development dependencies:
# For development, install all dependencies including development tools pip install -e ".[all,dev]"
Verify your setup:
# Run the test suite to ensure everything is working python -m pytest
Project Structure
PyneCore is organized as follows:
pynecore/
├── src/ # Source code
│ └── pynecore/ # Main package
│ ├── core/ # Core functionality and runtime components
│ ├── lib/ # Pine Script compatible function library
│ ├── transformers/ # AST transformers for Pine Script syntax
│ ├── types/ # Type definitions and interfaces
│ ├── utils/ # Utility functions and helpers
│ ├── cli/ # Command-line interface
│ └── providers/ # Data providers and integrations
├── tests/ # Test suite
├── docs/ # Component-specific documentation
└── scripts/ # Utility scripts
Understanding this structure is essential for effective contribution.
Development Guidelines
Code Style
PyneCore follows these coding standards:
- PEP 8 compliance: Try to keep line length around 100 characters, with a hard limit of 120 characters as specified in the
pyproject.toml
- Type hints: Use for all function arguments and return values
- Docstrings: Use PyCharm’s default “Sphinx-style” reStructuredText format (
:param:
,:return:
, etc.) for docstrings - Naming conventions:
- Functions and variables:
snake_case
- Classes:
PascalCase
- Constants:
UPPER_CASE
- Functions and variables:
- Comments: Add explanatory comments for complex logic
Example Code Style
def calculate_moving_average(values: Series[float], length: int) -> Series[float]:
"""
Calculate a simple moving average of a series.
:param values: Input series of values
:param length: Window length for the moving average
:return: New series containing the moving average values
"""
if length <= 0:
raise ValueError("Length must be positive")
# Implementation logic
result = values.rolling_sum(length) / length
return result
Clean Code Principles
- Single Responsibility: Functions and classes should do one thing well
- DRY (Don’t Repeat Yourself): Avoid code duplication
- KISS (Keep It Simple): Prefer simple solutions over complex ones
- Early Returns: Return early to reduce nesting and improve readability
Testing
PyneCore uses a comprehensive testing system where tests themselves are often Pyne scripts. This “dogfooding” approach ensures tests run in the same environment as real user code.
Running Tests
# Run the entire test suite
python -m pytest
# Run specific test files
python -m pytest tests/path/to/test_file.py
# Run tests with coverage report
python -m pytest --cov=pynecore
Writing Tests
Tests in PyneCore follow a unique pattern where test files are also valid Pyne scripts:
"""
@pyne
"""
from pynecore.lib import script, ta, close, plot
@script.indicator(title="Test Indicator")
def main():
my_value = ta.sma(close, 10)
plot(my_value, "My SMA")
def __test_my_feature__(csv_reader, runner, dict_comparator, log):
""" Test Description """
with csv_reader('test_data.csv', subdir="data") as cr:
for i, (candle, plot) in enumerate(runner(cr).run_iter()):
dict_comparator(plot, candle.extra_fields)
if i > 100:
break
For more details, refer to the Testing System Documentation.
Working with Core Components
AST Transformers
When modifying AST transformers in pynecore/transformers/
:
- Understand the transformation pipeline and execution order
- Test with various edge cases
- Ensure backward compatibility
- Add comprehensive tests
Library Functions
When working with library functions in pynecore/lib/
:
- Match Pine Script behavior when possible (for compatibility)
- Document any differences from Pine Script
- Optimize for performance
- Add appropriate type hints
- Include examples in docstrings
Core Runtime
When modifying core runtime components in pynecore/core/
:
- Be extra cautious - these changes affect all Pyne scripts
- Consider backward compatibility
- Document performance implications
- Add thorough tests
Documentation
All code should be well-documented:
- Every function should have a reStructuredText format docstring
- Complex code should have inline comments
- Major features should have documentation files
Docstring Format Example
def function_name(param1: type, param2: type) -> return_type:
"""
Brief description of the function.
Detailed description of the function, if needed.
:param param1: Description of param1
:param param2: Description of param2
:return: Description of return value
:raises ExceptionType: When and why this exception is raised
"""
# Function implementation
This is the PyCharm’s default Sphinx-style docstring format, not the full reStructuredText syntax used for comprehensive documentation.
Contribution Workflow
Select or create an issue: Start by finding an existing issue to work on or create a new one
Create a branch:
git checkout -b feature/your-feature-name
Make your changes: Follow the coding standards and guidelines
Add tests: Ensure your changes are properly tested
Run tests locally:
python -m pytest
Commit your changes:
git commit -m "Description of changes"
Push your branch:
git push origin feature/your-feature-name
Create a pull request: Provide a clear description of your changes
Pull Request Guidelines
When submitting a pull request, please:
- Reference issues: Link to any related issues
- Describe changes: Provide a clear description of what you’ve changed
- Document impact: Note any performance, compatibility, or API impacts
- Include tests: Add appropriate tests for your changes
- Update documentation: If applicable
License
By contributing to PyneCore, you agree that your contributions will be licensed under the project’s Apache License 2.0.
Additional Resources
- Project Structure
- Testing System Overview
- AST Module Documentation
- TradingView Pine Script Documentation
Getting Help
If you have questions or need assistance, you can:
- Open an issue on GitHub
- Reach out to the maintainers
Thank you for contributing to PyneCore!