Skip to content

Commit efaf8dc

Browse files
committed
👌🏻 IMP: Review
1 parent 1602674 commit efaf8dc

23 files changed

+1559
-204
lines changed

.pre-commit-config.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-added-large-files
9+
- id: check-json
10+
- id: check-merge-conflict
11+
- id: check-toml
12+
- id: debug-statements
13+
- id: mixed-line-ending
14+
15+
- repo: https://github.com/psf/black
16+
rev: 23.12.1
17+
hooks:
18+
- id: black
19+
language_version: python3
20+
args: [--line-length=88]
21+
22+
- repo: https://github.com/pycqa/isort
23+
rev: 5.13.2
24+
hooks:
25+
- id: isort
26+
args: [--profile=black, --line-length=88]
27+
28+
- repo: https://github.com/astral-sh/ruff-pre-commit
29+
rev: v0.1.9
30+
hooks:
31+
- id: ruff
32+
args: [--fix]
33+
34+
- repo: https://github.com/pre-commit/mirrors-mypy
35+
rev: v1.8.0
36+
hooks:
37+
- id: mypy
38+
args: [--strict, --ignore-missing-imports]
39+
additional_dependencies: [types-requests>=2.28.0]
40+
exclude: ^(tests/|examples/)

CONTRIBUTING.md

Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
# Contributing to Langbase Python SDK
2+
3+
Thank you for your interest in contributing to the Langbase Python SDK! We welcome contributions from the community.
4+
5+
## Getting Started
6+
7+
### Prerequisites
8+
9+
- Python 3.7 or higher
10+
- pip package manager
11+
- git
12+
13+
### Development Setup
14+
15+
1. **Fork and clone the repository**
16+
```bash
17+
git clone https://github.com/langbase/langbase-python-sdk
18+
cd langbase-python-sdk
19+
```
20+
21+
2. **Create a virtual environment**
22+
```bash
23+
python3 -m venv .venv
24+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
25+
```
26+
27+
3. **Install the package in development mode**
28+
```bash
29+
pip install -e .
30+
```
31+
32+
4. **Install development dependencies**
33+
```bash
34+
pip install -r requirements-dev.txt
35+
```
36+
37+
5. **Install pre-commit hooks**
38+
```bash
39+
pre-commit install
40+
```
41+
42+
## Before You Commit
43+
44+
**IMPORTANT**: All code must pass quality checks before committing. Run these commands:
45+
46+
### 1. Format Your Code
47+
```bash
48+
# Auto-format with Black (required)
49+
black langbase/ tests/ examples/
50+
51+
# Sort imports with isort (required)
52+
isort langbase/ tests/ examples/
53+
```
54+
55+
### 2. Run Linting Checks
56+
```bash
57+
# Run Ruff linter (auto-fixes many issues)
58+
ruff check --fix langbase/ tests/
59+
60+
# Check without auto-fix to see what changed
61+
ruff check langbase/ tests/
62+
```
63+
64+
### 3. Type Checking
65+
```bash
66+
# Run mypy for type checking
67+
mypy langbase/ --strict
68+
```
69+
70+
### 4. Run Tests
71+
```bash
72+
# Run all tests
73+
pytest
74+
75+
# Run with coverage
76+
pytest --cov=langbase
77+
78+
# Run specific test file
79+
pytest tests/test_pipes.py
80+
81+
# Run in verbose mode
82+
pytest -v
83+
```
84+
85+
### 5. Run All Checks at Once
86+
```bash
87+
# This runs all pre-commit hooks (black, isort, ruff, mypy)
88+
pre-commit run --all-files
89+
```
90+
91+
## Quick Checklist
92+
93+
Before pushing your changes, ensure:
94+
95+
- [ ] ✅ Code is formatted with `black`
96+
- [ ] ✅ Imports are sorted with `isort`
97+
- [ ] ✅ No linting errors from `ruff`
98+
- [ ] ✅ Type checking passes with `mypy`
99+
- [ ] ✅ All tests pass with `pytest`
100+
- [ ] ✅ New features have tests
101+
- [ ] ✅ New features have type hints
102+
- [ ] ✅ Documentation is updated if needed
103+
104+
## Making Changes
105+
106+
### 1. Create a Feature Branch
107+
```bash
108+
git checkout -b feature/your-feature-name
109+
```
110+
111+
### 2. Make Your Changes
112+
- Write clean, readable code
113+
- Add type hints to all functions
114+
- Follow existing code patterns
115+
- Add docstrings to public functions
116+
117+
### 3. Add Tests
118+
- Write tests for new features
119+
- Ensure existing tests still pass
120+
- Aim for good test coverage
121+
122+
### 4. Update Documentation
123+
- Update README.md if adding new features
124+
- Update docstrings
125+
- Add examples if applicable
126+
127+
### 5. Commit Your Changes
128+
```bash
129+
# Stage your changes
130+
git add .
131+
132+
# Commit with a descriptive message
133+
git commit -m "📖 DOC: Improved contribution docs"
134+
```
135+
136+
Follow conventional commit format:
137+
- `📦 NEW:` New feature
138+
- `🐛 BUG:` Bug fix
139+
- `📖 Docs:` Documentation changes
140+
- `👌🏻 IMP:` Improvements
141+
142+
### 6. Push and Create PR
143+
```bash
144+
git push origin feature/your-feature-name
145+
```
146+
147+
Then create a Pull Request on GitHub.
148+
149+
## Code Style Guide
150+
151+
### Type Hints
152+
All functions should have type hints:
153+
```python
154+
def process_data(input_text: str, max_length: int = 100) -> Dict[str, Any]:
155+
"""Process input text and return results."""
156+
...
157+
```
158+
159+
### Docstrings
160+
Use Google-style docstrings:
161+
```python
162+
def my_function(param1: str, param2: int) -> bool:
163+
"""
164+
Brief description of function.
165+
166+
Args:
167+
param1: Description of param1
168+
param2: Description of param2
169+
170+
Returns:
171+
Description of return value
172+
173+
Raises:
174+
ValueError: When invalid input provided
175+
"""
176+
...
177+
```
178+
179+
### Error Handling
180+
Use specific exceptions and helpful error messages:
181+
```python
182+
if not api_key:
183+
raise ValueError(
184+
"API key is required. Set LANGBASE_API_KEY environment variable "
185+
"or pass api_key parameter."
186+
)
187+
```
188+
189+
## Testing Guidelines
190+
191+
### Writing Tests
192+
- Use pytest for all tests
193+
- Use descriptive test names
194+
- Test both success and error cases
195+
- Use fixtures for common setup
196+
197+
Example:
198+
```python
199+
def test_pipe_run_with_invalid_name_raises_error(langbase_client):
200+
"""Test that running a pipe with invalid name raises appropriate error."""
201+
with pytest.raises(NotFoundError) as exc_info:
202+
langbase_client.pipes.run(name="non-existent-pipe")
203+
204+
assert "404" in str(exc_info.value)
205+
```
206+
207+
## Need Help?
208+
209+
- Check existing issues and PRs
210+
- Read the [documentation](https://langbase.com/docs)
211+
- Ask in our [Discord community](https://discord.gg/langbase)
212+
- Open an issue for bugs or feature requests
213+
214+
## License
215+
216+
By contributing, you agree that your contributions will be licensed under the MIT License.

0 commit comments

Comments
 (0)