Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Commit 6892f56

Browse files
authored
Format the ruff table (#14)
1 parent 3f740bd commit 6892f56

File tree

7 files changed

+578
-27
lines changed

7 files changed

+578
-27
lines changed

rust/src/build_system.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::helpers::array::{sort, transform};
22
use crate::helpers::pep508::{format_requirement, get_canonic_requirement_name};
33
use crate::helpers::table::{for_entries, reorder_table_keys, Tables};
44

5-
pub fn fix_build(tables: &mut Tables, keep_full_version: bool) {
5+
pub fn fix(tables: &mut Tables, keep_full_version: bool) {
66
let table_element = tables.get(&String::from("build-system"));
77
if table_element.is_none() {
88
return;
@@ -29,14 +29,14 @@ mod tests {
2929
use taplo::parser::parse;
3030
use taplo::syntax::SyntaxElement;
3131

32-
use crate::build_system::fix_build;
32+
use crate::build_system::fix;
3333
use crate::helpers::table::Tables;
3434

3535
fn evaluate(start: &str, keep_full_version: bool) -> String {
3636
let root_ast = parse(start).into_syntax().clone_for_update();
3737
let count = root_ast.children_with_tokens().count();
3838
let mut tables = Tables::from_ast(&root_ast);
39-
fix_build(&mut tables, keep_full_version);
39+
fix(&mut tables, keep_full_version);
4040
let entries = tables
4141
.table_set
4242
.iter()
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
[tool.ruff]
2+
required-version = ">=0.0.193"
3+
extend = "../pyproject.toml"
4+
target-version = "py37"
5+
line-length = 120
6+
indent-width = 2
7+
tab-size = 2
8+
builtins = [
9+
"ALPHA",
10+
"Bar",
11+
]
12+
namespace-packages = [
13+
"ALPHA",
14+
"Bar",
15+
]
16+
src = [
17+
"ALPHA",
18+
"Bar",
19+
]
20+
include = [
21+
"ALPHA",
22+
"Bar",
23+
]
24+
extend-include = [
25+
"ALPHA",
26+
"Bar",
27+
]
28+
exclude = [
29+
"ALPHA",
30+
"Bar",
31+
]
32+
extend-exclude = [
33+
"ALPHA",
34+
"Bar",
35+
]
36+
force-exclude = true
37+
respect-gitignore = false
38+
preview = true
39+
fix = true
40+
unsafe-fixes = true
41+
fix-only = true
42+
show-fixes = true
43+
show-source = true
44+
output-format = "grouped"
45+
cache-dir = "~/a"
46+
format.preview = true
47+
format.indent-style = "tab"
48+
format.quote-style = "single"
49+
format.line-ending = "lf"
50+
format.skip-magic-trailing-comma = true
51+
format.docstring-code-line-length = 60
52+
format.exclude = [
53+
"ALPHA",
54+
"Bar",
55+
]
56+
format.docstring-code-format = true
57+
format.extra = true
58+
format.more = true
59+
lint.select = [
60+
"ALPHA",
61+
"Bar",
62+
]
63+
lint.extend-select = [
64+
"ALPHA",
65+
"Bar",
66+
]
67+
lint.explicit-preview-rules = true
68+
lint.exclude = [
69+
"ALPHA",
70+
"Bar",
71+
]
72+
lint.extend-ignore = [
73+
"ALPHA",
74+
"Bar",
75+
]
76+
lint.per-file-ignores.'Magic.py' = [
77+
"ALPHA",
78+
"Bar",
79+
]
80+
lint.per-file-ignores."alpha.py" = [
81+
"ALPHA",
82+
"Bar",
83+
]
84+
lint.extend-per-file-ignores.'Magic.py' = [
85+
"ALPHA",
86+
"Bar",
87+
]
88+
lint.extend-per-file-ignores."alpha.py" = [
89+
"ALPHA",
90+
"Bar",
91+
]
92+
lint.fixable = [
93+
"ALPHA",
94+
"Bar",
95+
]
96+
lint.extend-fixable = [
97+
"ALPHA",
98+
"Bar",
99+
]
100+
lint.unfixable = [
101+
"ALPHA",
102+
"Bar",
103+
]
104+
lint.extend-safe-fixes = [
105+
"ALPHA",
106+
"Bar",
107+
]
108+
lint.extend-unsafe-fixes = [
109+
"ALPHA",
110+
"Bar",
111+
]
112+
lint.typing-modules = [
113+
"ALPHA",
114+
"Bar",
115+
]
116+
lint.allowed-confusables = [
117+
"",
118+
"",
119+
"ρ",
120+
]
121+
lint.dummy-variable-rgx = "^_$"
122+
lint.external = [
123+
"ALPHA",
124+
"Bar",
125+
]
126+
lint.task-tags = [
127+
"ALPHA",
128+
"Bar",
129+
]
130+
lint.flake8-annotations.suppress-none-returning = true
131+
lint.flake8-bandit.hardcoded-tmp-directory = [
132+
"ALPHA",
133+
"Bar",
134+
]
135+
lint.flake8-boolean-trap.extend-allowed-calls = [
136+
"ALPHA",
137+
"Bar",
138+
]
139+
lint.flake8-bugbear.extend-immutable-calls = [
140+
"ALPHA",
141+
"Bar",
142+
]
143+
lint.flake8-builtins.builtins-ignorelist = [
144+
"ALPHA",
145+
"Bar",
146+
]
147+
lint.flake8-comprehensions.allow-dict-calls-with-keyword-arguments = true
148+
lint.flake8-copyright.author = "Ruff"
149+
lint.flake8-copyright.notice-rgx = "(?i)Copyright \\(C\\) \\d{4}"
150+
lint.flake8-errmsg.max-string-length = 20
151+
lint.flake8-gettext.extend-function-names = [
152+
"ALPHA",
153+
"Bar",
154+
]
155+
lint.flake8-implicit-str-concat.allow-multiline = false
156+
lint.flake8-import-conventions.aliases.altair = "alt"
157+
lint.flake8-import-conventions.aliases.numpy = "np"
158+
lint.flake8-pytest-style.parametrize-names-type = "list"
159+
lint.flake8-pytest-style.raises-extend-require-match-for = [
160+
"ALPHA",
161+
"Bar",
162+
]
163+
lint.flake8-quotes.docstring-quotes = "single"
164+
lint.flake8-self.extend-ignore-names = [
165+
"ALPHA",
166+
"Bar",
167+
]
168+
lint.flake8-tidy-imports.banned-module-level-imports = [
169+
"ALPHA",
170+
"Bar",
171+
]
172+
lint.flake8-type-checking.exempt-modules = [
173+
"ALPHA",
174+
"Bar",
175+
]
176+
lint.flake8-unused-arguments.ignore-variadic-names = true
177+
lint.isort.section-order = [
178+
"Bar",
179+
"ALPHA",
180+
]
181+
lint.mccabe.max-complexity = 5
182+
lint.pep8-naming.classmethod-decorators = [
183+
"ALPHA",
184+
"Bar",
185+
]
186+
lint.pycodestyle.max-line-length = 100
187+
lint.pydocstyle.convention = "google"
188+
lint.pyflakes.extend-generics = [
189+
"ALPHA",
190+
"Bar",
191+
]
192+
lint.pylint.allow-dunder-method-names = [
193+
"ALPHA",
194+
"Bar",
195+
]
196+
lint.pyupgrade.keep-runtime-typing = true
197+
lint.extra.ok = 1
198+
lint.more.ok = 1
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
[tool.ruff]
2+
builtins = ['Bar', 'ALPHA']
3+
cache-dir = '~/a'
4+
exclude = ['Bar', 'ALPHA']
5+
extend = '../pyproject.toml'
6+
extend-exclude = ['Bar', 'ALPHA']
7+
extend-include = ['Bar', 'ALPHA']
8+
fix = true
9+
fix-only = true
10+
force-exclude = true
11+
include = ['Bar', 'ALPHA']
12+
indent-width = 2
13+
line-length = 120
14+
namespace-packages = ['Bar', 'ALPHA']
15+
output-format = 'grouped'
16+
preview = true
17+
required-version = '>=0.0.193'
18+
respect-gitignore = false
19+
show-fixes = true
20+
show-source = true
21+
src = ['Bar', 'ALPHA']
22+
tab-size = 2
23+
target-version = 'py37'
24+
unsafe-fixes = true
25+
[tool.ruff.format]
26+
docstring-code-format = true
27+
docstring-code-line-length = 60
28+
exclude = ['Bar', 'ALPHA']
29+
indent-style = 'tab'
30+
line-ending = 'lf'
31+
preview = true
32+
more = true
33+
extra = true
34+
quote-style = 'single'
35+
skip-magic-trailing-comma = true
36+
[tool.ruff.lint]
37+
allowed-confusables = ['', 'ρ', '']
38+
dummy-variable-rgx = '^_$'
39+
exclude = ['Bar', 'ALPHA']
40+
explicit-preview-rules = true
41+
extend-fixable = ['Bar', 'ALPHA']
42+
extend-ignore = ['Bar', 'ALPHA']
43+
extend-safe-fixes = ['Bar', 'ALPHA']
44+
extend-select = ['Bar', 'ALPHA']
45+
extend-unsafe-fixes = ['Bar', 'ALPHA']
46+
external = ['Bar', 'ALPHA']
47+
fixable = ['Bar', 'ALPHA']
48+
select = ['Bar', 'ALPHA']
49+
task-tags = ['Bar', 'ALPHA']
50+
typing-modules = ['Bar', 'ALPHA']
51+
unfixable = ['Bar', 'ALPHA']
52+
[tool.ruff.lint.extend-per-file-ignores]
53+
'Magic.py' = ['Bar', 'ALPHA']
54+
"alpha.py" = ['Bar', 'ALPHA']
55+
[tool.ruff.lint.per-file-ignores]
56+
'Magic.py' = ['Bar', 'ALPHA']
57+
"alpha.py" = ['Bar', 'ALPHA']
58+
[tool.ruff.lint.flake8-annotations]
59+
suppress-none-returning = true
60+
[tool.ruff.lint.flake8-bandit]
61+
hardcoded-tmp-directory = ['Bar', 'ALPHA']
62+
[tool.ruff.lint.flake8-boolean-trap]
63+
extend-allowed-calls = ['Bar', 'ALPHA']
64+
[tool.ruff.lint.flake8-bugbear]
65+
extend-immutable-calls = ['Bar', 'ALPHA']
66+
[tool.ruff.lint.flake8-builtins]
67+
builtins-ignorelist = ['Bar', 'ALPHA']
68+
[tool.ruff.lint.flake8-comprehensions]
69+
allow-dict-calls-with-keyword-arguments = true
70+
[tool.ruff.lint.flake8-copyright]
71+
author = 'Ruff'
72+
notice-rgx = '(?i)Copyright \\(C\\) \\d{4}'
73+
[tool.ruff.lint.flake8-errmsg]
74+
max-string-length = 20
75+
[tool.ruff.lint.flake8-gettext]
76+
extend-function-names = ['Bar', 'ALPHA']
77+
[tool.ruff.lint.flake8-implicit-str-concat]
78+
allow-multiline = false
79+
[tool.ruff.lint.flake8-import-conventions.aliases]
80+
altair = "alt"
81+
numpy = "np"
82+
[tool.ruff.lint.flake8-pytest-style]
83+
parametrize-names-type = 'list'
84+
raises-extend-require-match-for = ['Bar', 'ALPHA']
85+
[tool.ruff.lint.flake8-quotes]
86+
docstring-quotes = 'single'
87+
[tool.ruff.lint.flake8-self]
88+
extend-ignore-names = ['Bar', 'ALPHA']
89+
[tool.ruff.lint.flake8-tidy-imports]
90+
banned-module-level-imports = ['Bar', 'ALPHA']
91+
[tool.ruff.lint.flake8-type-checking]
92+
exempt-modules = ['Bar', 'ALPHA']
93+
[tool.ruff.lint.flake8-unused-arguments]
94+
ignore-variadic-names = true
95+
[tool.ruff.lint.isort]
96+
section-order = ['Bar', 'ALPHA']
97+
[tool.ruff.lint.mccabe]
98+
max-complexity = 5
99+
[tool.ruff.lint.pep8-naming]
100+
classmethod-decorators = ['Bar', 'ALPHA']
101+
[tool.ruff.lint.pycodestyle]
102+
max-line-length = 100
103+
[tool.ruff.lint.pydocstyle]
104+
convention = 'google'
105+
[tool.ruff.lint.pyflakes]
106+
extend-generics = ['Bar', 'ALPHA']
107+
[tool.ruff.lint.pylint]
108+
allow-dunder-method-names = ['Bar', 'ALPHA']
109+
[tool.ruff.lint.more]
110+
ok = 1
111+
[tool.ruff.lint.extra]
112+
ok = 1
113+
[tool.ruff.lint.pyupgrade]
114+
keep-runtime-typing = true

rust/src/helpers/table.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,32 @@ fn get_key(k: &str) -> String {
119119
}
120120

121121
pub fn reorder_table_keys(table: &mut RefMut<Vec<SyntaxElement>>, order: &[&str]) {
122-
let size = table.len();
123-
let (key_to_pos, key_set) = load_keys(table);
124-
let mut to_insert = Vec::<SyntaxElement>::new();
125-
let mut handled = HashSet::<usize>::new();
126-
for key in order {
127-
let mut parts = key_to_pos
128-
.keys()
129-
.filter(|k| {
130-
key == k || (k.starts_with(key) && k.len() > key.len() && k.chars().nth(key.len()).unwrap() == '.')
122+
let (size, mut to_insert) = (table.len(), Vec::<SyntaxElement>::new());
123+
let (key_to_position, key_set) = load_keys(table);
124+
let mut handled_positions = HashSet::<usize>::new();
125+
for current_key in order {
126+
let mut matching_keys = key_to_position
127+
.iter()
128+
.filter(|(checked_key, position)| {
129+
!handled_positions.contains(position)
130+
&& (current_key == checked_key
131+
|| (checked_key.starts_with(current_key)
132+
&& checked_key.len() > current_key.len()
133+
&& checked_key.chars().nth(current_key.len()).unwrap() == '.'))
131134
})
135+
.map(|(key, _)| key)
132136
.clone()
133137
.collect::<Vec<&String>>();
134-
parts.sort_by_key(|s| s.to_lowercase().replace('"', ""));
135-
for element in parts {
136-
let pos = key_to_pos[element];
137-
to_insert.extend(key_set[pos].clone());
138-
handled.insert(pos);
138+
matching_keys.sort_by_key(|key| key.to_lowercase().replace('"', ""));
139+
for key in matching_keys {
140+
let position = key_to_position[key];
141+
to_insert.extend(key_set[position].clone());
142+
handled_positions.insert(position);
139143
}
140144
}
141-
for (at, entry) in key_set.into_iter().enumerate() {
142-
if !handled.contains(&at) {
143-
to_insert.extend(entry);
145+
for (position, entries) in key_set.into_iter().enumerate() {
146+
if !handled_positions.contains(&position) {
147+
to_insert.extend(entries);
144148
}
145149
}
146150
table.splice(0..size, to_insert);

0 commit comments

Comments
 (0)