Index
ruff_sync ¶
Ruff sync package.
This package provides tools to synchronize ruff configuration across projects.
__all__
module-attribute
¶
__all__ = [
"Arguments",
"Config",
"FetchResult",
"__version__",
"check",
"fetch_upstream_config",
"get_config",
"get_ruff_config",
"get_ruff_tool_table",
"is_ruff_toml_file",
"main",
"merge_ruff_toml",
"pull",
"resolve_raw_url",
"to_git_url",
"toml_ruff_parse",
]
Arguments ¶
Bases: NamedTuple
CLI arguments for the ruff-sync tool.
Source code in src/ruff_sync/cli.py
fields
cached
classmethod
¶
Config ¶
Bases: TypedDict
Configuration schema for [tool.ruff-sync] in pyproject.toml.
Source code in src/ruff_sync/core.py
FetchResult ¶
Bases: NamedTuple
Result of fetching an upstream configuration.
Source code in src/ruff_sync/core.py
get_config
cached
¶
Read [tool.ruff-sync] configuration from pyproject.toml.
Examples:
>>> import pathlib
>>> config = get_config(pathlib.Path("."))
>>> if "upstream" in config:
... print(f"Syncing from {config['upstream']}")
Source code in src/ruff_sync/cli.py
main ¶
Run the ruff-sync CLI.
Source code in src/ruff_sync/cli.py
check
async
¶
Check if the local pyproject.toml / ruff.toml is in sync with the upstream.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
0 if in sync, 1 if out of sync. |
Examples:
>>> import asyncio
>>> from ruff_sync.cli import Arguments
>>> from httpx import URL
>>> import pathlib
>>> args = Arguments(
... command="check",
... upstream=URL("https://github.com/org/repo/blob/main/pyproject.toml"),
... to=pathlib.Path("pyproject.toml"),
... exclude=[],
... )
>>> # asyncio.run(check(args))
Source code in src/ruff_sync/core.py
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
fetch_upstream_config
async
¶
Fetch the upstream pyproject.toml either via HTTP or git clone.
Source code in src/ruff_sync/core.py
get_ruff_config ¶
Get the ruff section or document from a TOML string.
If it does not exist and it is a pyproject.toml, create it.
Source code in src/ruff_sync/core.py
is_ruff_toml_file ¶
Return True if the path or URL indicates a ruff.toml file.
This handles: - Plain paths (e.g. "ruff.toml", ".ruff.toml", "configs/ruff.toml") - URLs with query strings or fragments (e.g. "ruff.toml?ref=main", "ruff.toml#L10") by examining only the path component (or the part before any query/fragment).
Source code in src/ruff_sync/core.py
merge_ruff_toml ¶
Merge the source and upstream tool ruff config with better whitespace preservation.
Examples:
>>> from tomlkit import parse
>>> source = parse("[tool.ruff]\nline-length = 80")
>>> upstream = parse("[tool.ruff]\nline-length = 100")["tool"]["ruff"]
>>> merged = merge_ruff_toml(source, upstream)
>>> print(merged.as_string())
[tool.ruff]
line-length = 100
Source code in src/ruff_sync/core.py
pull
async
¶
Pull the upstream ruff config and apply it to the source.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
0 on success, 1 on failure. |
Examples:
>>> import asyncio
>>> from ruff_sync.cli import Arguments
>>> from httpx import URL
>>> import pathlib
>>> args = Arguments(
... command="pull",
... upstream=URL("https://github.com/org/repo/blob/main/pyproject.toml"),
... to=pathlib.Path("pyproject.toml"),
... exclude=["lint.isort"],
... init=True,
... )
>>> # asyncio.run(pull(args))
Source code in src/ruff_sync/core.py
resolve_raw_url ¶
Convert a GitHub or GitLab repository/blob URL to a raw content URL.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
URL
|
The URL to resolve. |
required |
branch
|
str
|
The default branch to use for repo URLs. |
'main'
|
path
|
str | None
|
The directory prefix for pyproject.toml. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
URL |
URL
|
The resolved raw content URL, or the original URL if no conversion applies. |
Source code in src/ruff_sync/core.py
to_git_url ¶
Attempt to convert a browser or raw URL to a git (SSH) URL.
Supports GitHub and GitLab.
Source code in src/ruff_sync/core.py
toml_ruff_parse ¶
Parse a TOML string for the tool.ruff section excluding certain ruff configs.