Skip to content

Commit b5bd10b

Browse files
AleksMatcopybara-github
authored andcommitted
Add schema support to pyink.
PiperOrigin-RevId: 671669739
1 parent 9ec49c6 commit b5bd10b

File tree

5 files changed

+200
-4
lines changed

5 files changed

+200
-4
lines changed

patches/pyink.patch

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@
10891089
classifiers = [
10901090
"Development Status :: 5 - Production/Stable",
10911091
"Environment :: Console",
1092-
@@ -70,53 +42,35 @@ dependencies = [
1092+
@@ -70,53 +42,38 @@ dependencies = [
10931093
"platformdirs>=2",
10941094
"tomli>=1.1.0; python_version < '3.11'",
10951095
"typing_extensions>=4.0.1; python_version < '3.11'",
@@ -1113,10 +1113,11 @@
11131113
[project.scripts]
11141114
-black = "black:patched_main"
11151115
-blackd = "blackd:patched_main [d]"
1116-
-
1117-
-[project.entry-points."validate_pyproject.tool_schema"]
1118-
-black = "black.schema:get_schema"
11191116
+pyink = "pyink:patched_main"
1117+
1118+
[project.entry-points."validate_pyproject.tool_schema"]
1119+
-black = "black.schema:get_schema"
1120+
+pyink = "pyink.schema:get_schema"
11201121

11211122
[project.urls]
11221123
-Documentation = "https://black.readthedocs.io/"
@@ -1195,6 +1196,27 @@
11951196
-[[tool.mypy.overrides]]
11961197
-module = ["tests.data.*"]
11971198
-ignore_errors = true
1199+
--- a/resources/pyink.schema.json
1200+
+++ b/resources/pyink.schema.json
1201+
@@ -1,7 +1,7 @@
1202+
{
1203+
"$schema": "http://json-schema.org/draft-07/schema#",
1204+
- "$id": "https://github.com/psf/black/blob/main/black/resources/black.schema.json",
1205+
- "$comment": "tool.black table in pyproject.toml",
1206+
+ "$id": "https://github.com/google/pyink/blob/pyink/src/pyink/resources/pyink.schema.json",
1207+
+ "$comment": "tool.pyink table in pyproject.toml",
1208+
"type": "object",
1209+
"additionalProperties": false,
1210+
"properties": {
1211+
@@ -12,7 +12,7 @@
1212+
"line-length": {
1213+
"type": "integer",
1214+
"description": "How many characters per line to allow.",
1215+
- "default": 88
1216+
+ "default": 80
1217+
},
1218+
"target-version": {
1219+
"type": "array",
11981220
--- a/strings.py
11991221
+++ b/strings.py
12001222
@@ -8,6 +8,7 @@ from functools import lru_cache

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ jupyter = [
5757
[project.scripts]
5858
pyink = "pyink:patched_main"
5959

60+
[project.entry-points."validate_pyproject.tool_schema"]
61+
pyink = "pyink.schema:get_schema"
62+
6063
[project.urls]
6164
Changelog = "https://github.com/google/pyink/blob/pyink/CHANGES.md"
6265
Repository = "https://github.com/google/pyink"

src/pyink/resources/__init__.py

Whitespace-only changes.

src/pyink/resources/pyink.schema.json

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$id": "https://github.com/google/pyink/blob/pyink/src/pyink/resources/pyink.schema.json",
4+
"$comment": "tool.pyink table in pyproject.toml",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"properties": {
8+
"code": {
9+
"type": "string",
10+
"description": "Format the code passed in as a string."
11+
},
12+
"line-length": {
13+
"type": "integer",
14+
"description": "How many characters per line to allow.",
15+
"default": 80
16+
},
17+
"target-version": {
18+
"type": "array",
19+
"items": {
20+
"enum": [
21+
"py33",
22+
"py34",
23+
"py35",
24+
"py36",
25+
"py37",
26+
"py38",
27+
"py39",
28+
"py310",
29+
"py311",
30+
"py312",
31+
"py313"
32+
]
33+
},
34+
"description": "Python versions that should be supported by Pyink's output. You should include all versions that your code supports. By default, Pyink will infer target versions from the project metadata in pyproject.toml. If this does not yield conclusive results, Pyink will use per-file auto-detection."
35+
},
36+
"pyi": {
37+
"type": "boolean",
38+
"description": "Format all input files like typing stubs regardless of file extension. This is useful when piping source on standard input.",
39+
"default": false
40+
},
41+
"ipynb": {
42+
"type": "boolean",
43+
"description": "Format all input files like Jupyter Notebooks regardless of file extension. This is useful when piping source on standard input.",
44+
"default": false
45+
},
46+
"python-cell-magics": {
47+
"type": "array",
48+
"items": {
49+
"type": "string"
50+
},
51+
"description": "When processing Jupyter Notebooks, add the given magic to the list of known python-magics (capture, prun, pypy, python, python3, time, timeit). Useful for formatting cells with custom python magics."
52+
},
53+
"skip-source-first-line": {
54+
"type": "boolean",
55+
"description": "Skip the first line of the source code.",
56+
"default": false
57+
},
58+
"skip-string-normalization": {
59+
"type": "boolean",
60+
"description": "Don't normalize string quotes or prefixes.",
61+
"default": false
62+
},
63+
"skip-magic-trailing-comma": {
64+
"type": "boolean",
65+
"description": "Don't use trailing commas as a reason to split lines.",
66+
"default": false
67+
},
68+
"preview": {
69+
"type": "boolean",
70+
"description": "Enable potentially disruptive style changes that may be added to Pyink's main functionality in the next major release.",
71+
"default": false
72+
},
73+
"unstable": {
74+
"type": "boolean",
75+
"description": "Enable potentially disruptive style changes that have known bugs or are not currently expected to make it into the stable style Pyink's next major release. Implies --preview.",
76+
"default": false
77+
},
78+
"enable-unstable-feature": {
79+
"type": "array",
80+
"items": {
81+
"enum": [
82+
"hex_codes_in_unicode_sequences",
83+
"string_processing",
84+
"hug_parens_with_braces_and_square_brackets",
85+
"unify_docstring_detection",
86+
"no_normalize_fmt_skip_whitespace",
87+
"wrap_long_dict_values_in_parens",
88+
"multiline_string_handling",
89+
"typed_params_trailing_comma",
90+
"is_simple_lookup_for_doublestar_expression",
91+
"docstring_check_for_newline",
92+
"remove_redundant_guard_parens",
93+
"parens_for_long_if_clauses_in_case_block"
94+
]
95+
},
96+
"description": "Enable specific features included in the `--unstable` style. Requires `--preview`. No compatibility guarantees are provided on the behavior or existence of any unstable features."
97+
},
98+
"check": {
99+
"type": "boolean",
100+
"description": "Don't write the files back, just return the status. Return code 0 means nothing would change. Return code 1 means some files would be reformatted. Return code 123 means there was an internal error.",
101+
"default": false
102+
},
103+
"diff": {
104+
"type": "boolean",
105+
"description": "Don't write the files back, just output a diff to indicate what changes Pyink would've made. They are printed to stdout so capturing them is simple.",
106+
"default": false
107+
},
108+
"color": {
109+
"type": "boolean",
110+
"description": "Show (or do not show) colored diff. Only applies when --diff is given.",
111+
"default": false
112+
},
113+
"fast": {
114+
"type": "boolean",
115+
"description": "By default, Pyink performs an AST safety check after formatting your code. The --fast flag turns off this check and the --safe flag explicitly enables it. [default: --safe]",
116+
"default": false
117+
},
118+
"required-version": {
119+
"type": "string",
120+
"description": "Require a specific version of Pyink to be running. This is useful for ensuring that all contributors to your project are using the same version, because different versions of Pyink may format code a little differently. This option can be set in a configuration file for consistent results across environments."
121+
},
122+
"exclude": {
123+
"type": "string",
124+
"description": "A regular expression that matches files and directories that should be excluded on recursive searches. An empty value means no paths are excluded. Use forward slashes for directories on all platforms (Windows, too). By default, Pyink also ignores all paths listed in .gitignore. Changing this value will override all default exclusions. [default: /(\\.direnv|\\.eggs|\\.git|\\.hg|\\.ipynb_checkpoints|\\.mypy_cache|\\.nox|\\.pytest_cache|\\.ruff_cache|\\.tox|\\.svn|\\.venv|\\.vscode|__pypackages__|_build|buck-out|build|dist|venv)/]"
125+
},
126+
"extend-exclude": {
127+
"type": "string",
128+
"description": "Like --exclude, but adds additional files and directories on top of the default values instead of overriding them."
129+
},
130+
"force-exclude": {
131+
"type": "string",
132+
"description": "Like --exclude, but files and directories matching this regex will be excluded even when they are passed explicitly as arguments. This is useful when invoking Pyink programmatically on changed files, such as in a pre-commit hook or editor plugin."
133+
},
134+
"include": {
135+
"type": "string",
136+
"description": "A regular expression that matches files and directories that should be included on recursive searches. An empty value means all files are included regardless of the name. Use forward slashes for directories on all platforms (Windows, too). Overrides all exclusions, including from .gitignore and command line options.",
137+
"default": "(\\.pyi?|\\.ipynb)$"
138+
},
139+
"workers": {
140+
"type": "integer",
141+
"description": "When Pyink formats multiple files, it may use a process pool to speed up formatting. This option controls the number of parallel workers. This can also be specified via the PYINK_NUM_WORKERS environment variable. Defaults to the number of CPUs in the system."
142+
},
143+
"quiet": {
144+
"type": "boolean",
145+
"description": "Stop emitting all non-critical output. Error messages will still be emitted (which can silenced by 2>/dev/null).",
146+
"default": false
147+
},
148+
"verbose": {
149+
"type": "boolean",
150+
"description": "Emit messages about files that were not changed or were ignored due to exclusion patterns. If Pyink is using a configuration file, a message detailing which one it is using will be emitted.",
151+
"default": false
152+
}
153+
}
154+
}

tests/test_schema.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import importlib.metadata
2+
import sys
3+
4+
5+
def test_schema_entrypoint() -> None:
6+
if sys.version_info < (3, 10):
7+
eps = importlib.metadata.entry_points()["validate_pyproject.tool_schema"]
8+
(black_ep,) = [ep for ep in eps if ep.name == "pyink"]
9+
else:
10+
(black_ep,) = importlib.metadata.entry_points(
11+
group="validate_pyproject.tool_schema", name="pyink"
12+
)
13+
14+
black_fn = black_ep.load()
15+
schema = black_fn()
16+
assert schema == black_fn("pyink")
17+
assert schema["properties"]["line-length"]["type"] == "integer"

0 commit comments

Comments
 (0)