Index
ruff_sync ¶
Ruff sync package.
This package provides tools to synchronize ruff configuration across projects.
__all__
module-attribute
¶
__all__ = [
"Arguments",
"Config",
"FetchResult",
"OutputFormat",
"RuffConfigFileName",
"__version__",
"check",
"fetch_upstream_config",
"get_config",
"get_formatter",
"get_ruff_config",
"get_ruff_tool_table",
"inspect",
"is_ruff_toml_file",
"load_local_ruff_config",
"main",
"merge_ruff_toml",
"pull",
"resolve_raw_url",
"resolve_target_path",
"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
¶
RuffConfigFileName ¶
Bases: str, Enum
Enumeration of Ruff configuration filenames.
Source code in src/ruff_sync/config_io.py
tried_order
classmethod
¶
Return the order in which configuration files should be tried.
OutputFormat ¶
Bases: str, Enum
Output formats for the CLI.
Source code in src/ruff_sync/constants.py
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
inspect ¶
Entry point for the ruff-inspect console script.
Source code in src/ruff_sync/cli.py
main ¶
Run the ruff-sync CLI.
Source code in src/ruff_sync/cli.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 | |
is_ruff_toml_file ¶
Return True if the path or URL indicates a ruff.toml file.
This handles cases with query strings or fragments by examining only the path component.
Source code in src/ruff_sync/config_io.py
load_local_ruff_config ¶
Load the local Ruff configuration as a plain dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
Path
|
The directory or file path to load configuration from. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A plain dictionary containing the [tool.ruff] configuration. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If no configuration file is found at the target path. |
TypeError
|
If the configuration structure is invalid. |
Source code in src/ruff_sync/config_io.py
resolve_target_path ¶
Resolve the target path for configuration files.
If 'to' is a file, it's used directly. Otherwise, it looks for existing ruff/pyproject.toml in the 'to' directory. If none found, it defaults to pyproject.toml unless the first upstream is a ruff.toml.
Source code in src/ruff_sync/config_io.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
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 | |
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
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
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 | |
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.
Source code in src/ruff_sync/core.py
get_formatter ¶
Return the corresponding formatter for the given format.