Skip to content

Commit 62a8bd4

Browse files
author
Revenue Holdings
committed
fix: ruff lint fixes, add ruff CI step, CONTRIBUTING.md, remove BOM from config files
1 parent 8300969 commit 62a8bd4

7 files changed

Lines changed: 57 additions & 11 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
run: |
2626
pip install -e ".[dev]"
2727
28+
- name: Lint with ruff
29+
run: pip install ruff && ruff check src/ --target-version py310
2830
- name: Run tests
2931
run: |
3032
python -m pytest tests/ -v --cov=src --cov-report=term-missing
33+

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ jobs:
5151
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
5252
run: |
5353
twine upload --repository testpypi dist/* --verbose
54+

CONTRIBUTING.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Contributing
2+
3+
Thanks for your interest in contributing!
4+
5+
## Development Setup
6+
7+
1. Fork and clone the repo
8+
2. Create a virtual environment: python -m venv .venv && source .venv/bin/activate
9+
3. Install dev dependencies: pip install -e ".[dev]"
10+
4. Run tests: pytest tests/ -v
11+
5. Lint: uff check src/
12+
13+
## Pull Requests
14+
15+
- Fork the repo and create a feature branch
16+
- Add tests for any new functionality
17+
- Ensure all existing tests pass
18+
- Run uff check src/ --fix before committing
19+
- Keep PRs focused on a single change
20+
21+
## Reporting Issues
22+
23+
- Use GitHub Issues
24+
- Include Python version, OS, and steps to reproduce
25+
- Include relevant error output
26+
27+
## Code Style
28+
29+
- Python 3.10+
30+
- Type hints where practical
31+
- Follow ruff defaults (Black-compatible formatting)
32+
33+
## License
34+
35+
By contributing, you agree your work will be licensed under the same license as this project.

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ json2sql = "json2sql.cli:app"
3535

3636
[tool.setuptools.packages.find]
3737
where = ["src"]
38+
39+
[tool.ruff]
40+
target-version = "py310"
41+
line-length = 120
42+
43+
[tool.ruff.lint]
44+
select = ["E", "F", "W", "I", "UP", "B", "SIM"]
45+
ignore = ["E501"]
46+
47+
[tool.ruff.lint.isort]
48+
known-first-party = ["*"]

src/json2sql/cli.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""CLI interface for json2sql using Typer."""
22

33
import sys
4-
from pathlib import Path
5-
from typing import Optional
6-
74
import typer
5+
from pathlib import Path
86

97
try:
108
from revenueholdings_license import require_license
@@ -23,12 +21,12 @@
2321

2422
@app.command()
2523
def convert(
26-
input_file: Optional[Path] = typer.Argument(
24+
input_file: Path | None = typer.Argument( # noqa: B008
2725
None,
2826
help="Path to JSON file. Reads from stdin if not provided.",
2927
exists=True,
3028
),
31-
dialect: Dialect = typer.Option(
29+
dialect: Dialect = typer.Option( # noqa: B008
3230
Dialect.POSTGRES,
3331
"--dialect",
3432
"-d",
@@ -40,7 +38,7 @@ def convert(
4038
"-t",
4139
help="Table name for INSERT statements.",
4240
),
43-
output: Optional[Path] = typer.Option(
41+
output: Path | None = typer.Option( # noqa: B008
4442
None,
4543
"--output",
4644
"-o",
@@ -79,7 +77,7 @@ def convert(
7977
result = converter.convert(json_text, table_name=table)
8078
except Exception as e:
8179
typer.echo(f"Error converting JSON: {e}", err=True)
82-
raise typer.Exit(code=1)
80+
raise typer.Exit(code=1) from e
8381

8482
# Write output
8583
if output:

src/json2sql/converter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
"""Core JSON-to-SQL conversion logic."""
22

33
import json
4-
from typing import Any
54

65
from .dialects import (
76
Dialect,
87
create_table_sql,
98
format_value,
109
insert_sql,
11-
quote_identifier,
1210
sql_type_for,
1311
)
1412

@@ -183,7 +181,7 @@ def _flatten_object(
183181
row: list[str],
184182
) -> None:
185183
"""Flatten a nested object into parent row with prefixed keys."""
186-
for sub_key, sub_value in nested.items():
184+
for _sub_key, sub_value in nested.items():
187185
row.append(format_value(sub_value, self.dialect))
188186

189187
def _process_flatten(self, objects: list, table_name: str) -> None:

src/json2sql/dialects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def sql_type_for(value: Any, dialect: Dialect) -> str:
4141
if value is None:
4242
return _TYPE_MAP[dialect].get(str, "TEXT")
4343
py_type = type(value)
44-
if py_type == bool: # bool must be checked before int (bool is subclass of int)
44+
if py_type is bool: # bool must be checked before int (bool is subclass of int)
4545
return _TYPE_MAP[dialect][bool]
4646
return _TYPE_MAP[dialect].get(py_type, "TEXT")
4747

0 commit comments

Comments
 (0)