Skip to content

Commit e9a4142

Browse files
authored
style: embracing black formatting (#36)
* style: apply black formatting to test files Standardize code formatting across all test files using black formatter. Ensures consistent quote style, blank line spacing, and import ordering. * test: merging linting and test into ci github action * chore: embracing black for code format and adding docs for that as well * docs: updating README.md
1 parent cd630b2 commit e9a4142

File tree

21 files changed

+428
-173
lines changed

21 files changed

+428
-173
lines changed

.github/workflows/ci.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths-ignore:
7+
- '**/*.md'
8+
- '**/*.jpg'
9+
- '**/*.gif'
10+
- '**/*.png'
11+
- 'LICENSE'
12+
- 'misc/**'
13+
- '**/*.txt'
14+
- '.gitignore'
15+
- '.python-version'
16+
pull_request:
17+
branches: [ main ]
18+
paths-ignore:
19+
- '**/*.md'
20+
- '**/*.jpg'
21+
- '**/*.gif'
22+
- '**/*.png'
23+
- 'LICENSE'
24+
- 'misc/**'
25+
- '**/*.txt'
26+
- '.gitignore'
27+
- '.python-version'
28+
29+
permissions:
30+
contents: read
31+
32+
jobs:
33+
lint:
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- name: Set up Python
39+
uses: actions/setup-python@v5
40+
with:
41+
python-version: '3.10'
42+
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v5
45+
with:
46+
enable-cache: true
47+
48+
- name: Install dependencies
49+
run: uv sync
50+
51+
- name: Check code formatting with Black
52+
run: uv run black --check src/ tests/
53+
54+
test:
55+
runs-on: ubuntu-latest
56+
steps:
57+
- uses: actions/checkout@v4
58+
59+
- name: Set up Python
60+
uses: actions/setup-python@v5
61+
with:
62+
python-version: '3.10'
63+
64+
- name: Install uv
65+
uses: astral-sh/setup-uv@v5
66+
with:
67+
enable-cache: true
68+
69+
- name: Install dependencies
70+
run: uv sync --dev
71+
72+
- name: Run unit tests
73+
run: uv run pytest tests/test_unit.py -v

.github/workflows/test.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

CI.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ This document describes the GitHub workflows set up for the ollama-mcp-bridge pr
44

55
## Available Workflows
66

7-
### 1. Tests ([test.yml](.github/workflows/test.yml))
7+
### 1. Tests ([ci.yml](.github/workflows/ci.yml))
88

99
**Trigger:**
1010
- Push to `main` branch
1111
- Pull requests to `main` branch
1212
- Ignores changes to docs, images, and some config files
1313

1414
**Purpose:**
15-
Runs unit tests using `pytest` in a fresh environment managed by `uv`.
15+
Runs unit tests using `pytest` in a fresh environment managed by `uv`. And checks code formatting with `black`.
16+
1617

1718
**Key Steps:**
1819
- Checkout code

CONTRIBUTING.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Contributing to ollama-mcp-bridge
2+
3+
## Development Setup
4+
5+
```bash
6+
# Clone the repository
7+
git clone https://github.com/jonigl/ollama-mcp-bridge.git
8+
cd ollama-mcp-bridge
9+
10+
# Install dependencies (including dev tools)
11+
uv sync
12+
```
13+
14+
## Code Formatting
15+
16+
We use [Black](https://black.readthedocs.io/) for consistent code formatting with a 120-character line length.
17+
18+
```bash
19+
# Format all code
20+
black .
21+
22+
# Check formatting without changes
23+
black --check .
24+
```
25+
26+
Black is configured in `pyproject.toml` and runs automatically when installed via `uv sync`.
27+
28+
## Testing
29+
30+
```bash
31+
# Run all tests
32+
uv run pytest
33+
34+
# Run specific test file
35+
uv run pytest tests/test_unit.py -v
36+
37+
# Run tests in quiet mode
38+
uv run pytest -q
39+
40+
# Run with verbose output
41+
uv run pytest -v
42+
```
43+
44+
## Environment Variables
45+
46+
For testing timeout behavior, you can set:
47+
48+
```bash
49+
# Set custom Ollama proxy timeout (milliseconds)
50+
OLLAMA_PROXY_TIMEOUT=600000 uv run pytest
51+
52+
# Disable timeouts (useful for debugging)
53+
OLLAMA_PROXY_TIMEOUT=0 uv run pytest
54+
```
55+
56+
## Before Committing
57+
58+
1. **Format your code**: `black .`
59+
2. **Run tests**: `uv run pytest`
60+
3. **Verify all tests pass**
61+
62+
## Commit Convention
63+
64+
We follow [Conventional Commits](https://www.conventionalcommits.org/):
65+
66+
- `feat:` New features
67+
- `fix:` Bug fixes
68+
- `docs:` Documentation changes
69+
- `style:` Code formatting (no functional changes)
70+
- `refactor:` Code restructuring
71+
- `test:` Adding or updating tests
72+
- `chore:` Maintenance tasks
73+
74+
### Example Commits
75+
76+
```bash
77+
feat: add OLLAMA_PROXY_TIMEOUT environment variable for configurable HTTP timeouts
78+
79+
fix: resolve timeout issues with large models on localhost
80+
81+
docs: update README with new environment variable documentation
82+
83+
style: apply black formatting to test files
84+
85+
test: add comprehensive timeout behavior test coverage
86+
```
87+
88+
## Adding New Features
89+
90+
1. Create a feature branch: `git checkout -b feat/your-feature-name`
91+
2. Implement your changes with tests
92+
3. Format code: `black .`
93+
4. Run tests: `uv run pytest`
94+
5. Commit with conventional commit message
95+
6. Push and create a pull request
96+
97+
## Questions?
98+
99+
Open an issue on [GitHub](https://github.com/jonigl/ollama-mcp-bridge/issues) if you have questions or need help.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Ollama MCP Bridge
1010

1111
[![PyPI - Python Version](https://img.shields.io/pypi/v/ollama-mcp-bridge?label=ollama-mcp-bridge-pypi)](https://pypi.org/project/ollama-mcp-bridge/)
12-
[![Tests](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/test.yml/badge.svg)](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/test.yml)
12+
[![CI](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/ci.yml/badge.svg)](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/ci.yml)
1313
[![Test Publish](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/test-publish.yml/badge.svg)](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/test-publish.yml)
1414
[![Publish](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/publish.yml/badge.svg)](https://github.com/jonigl/ollama-mcp-bridge/actions/workflows/publish.yml)
1515
[![Python 3.10+](https://img.shields.io/badge/Python-3.10+-blue.svg)](https://www.python.org/downloads/)
@@ -37,6 +37,7 @@
3737
- [Development](#development)
3838
- [Key Dependencies](#key-dependencies)
3939
- [Testing](#testing)
40+
- [Contributing](#contributing)
4041
- [Related Projects](#related-projects)
4142
- [Inspiration and Credits](#inspiration-and-credits)
4243

@@ -419,6 +420,14 @@ curl -X POST "http://localhost:8000/api/chat" \
419420
> [!NOTE]
420421
> Tests require the server to be running on localhost:8000. Make sure to start the server before running pytest.
421422
423+
## Contributing
424+
425+
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for:
426+
- Development setup instructions
427+
- Code formatting guidelines (Black)
428+
- Testing procedures
429+
- Commit conventions
430+
422431
## Related Projects
423432

424433
- [**MCP Client for Ollama**](https://github.com/jonigl/mcp-client-for-ollama) - A text-based user interface (TUI) client for interacting with MCP servers using Ollama. Features include multi-server support, dynamic model switching, streaming responses, tool management, human-in-the-loop capabilities, thinking mode, full model parameters configuration, custom system prompt and saved preferences. Built for developers working with local LLMs.

mcp-config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"env": {
1212
"MCP_LOG_LEVEL": "ERROR"
1313
}
14+
},
15+
"jarvis": {
16+
"url": "https://jarvis-mcp-server-main.staging.ipsy.bfainfra.com/mcp"
1417
}
1518
}
1619
}

mock-weather-mcp-server/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
mcp = FastMCP("weather")
55

6+
67
@mcp.tool()
78
async def get_current_temperature(city: str) -> str:
89
"""Get current temperature for a location.
@@ -15,4 +16,4 @@ async def get_current_temperature(city: str) -> str:
1516

1617

1718
if __name__ == "__main__":
18-
mcp.run(transport='stdio')
19+
mcp.run(transport="stdio")

pyproject.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@ packages = ["src/ollama_mcp_bridge"]
4444
dev = [
4545
"pytest>=8.4.1",
4646
"requests>=2.32.4",
47+
"black>=24.0.0",
4748
]
49+
50+
[tool.black]
51+
line-length = 120
52+
target-version = ["py310"]
53+
include = '\.pyi?$'
54+
extend-exclude = '''
55+
/(
56+
\.eggs
57+
| \.git
58+
| \.hatch
59+
| \.pytest_cache
60+
| \.venv
61+
| \.vscode
62+
| __pycache__
63+
| build
64+
| dist
65+
)/
66+
'''

0 commit comments

Comments
 (0)