stylebook 0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
stylebook/__init__.py ADDED
@@ -0,0 +1 @@
1
+ """main"""
stylebook/__main__.py ADDED
@@ -0,0 +1,4 @@
1
+ from stylebook.cli import run
2
+
3
+ if __name__ == '__main__':
4
+ run()
stylebook/cli.py ADDED
@@ -0,0 +1,46 @@
1
+ from pathlib import Path
2
+ from sys import argv, exit, stderr
3
+
4
+ from stylebook.commands import Command, SqlfluffCommand, TaploCommand, YamllintCommand
5
+
6
+
7
+ def walk(target_path: Path) -> list[str]:
8
+ if target_path.is_file():
9
+ return [str(target_path)]
10
+ if target_path.is_dir():
11
+ results = []
12
+ for child in target_path.iterdir():
13
+ results.extend(walk(child))
14
+ return results
15
+ return []
16
+
17
+
18
+ def run() -> None:
19
+ input_args: list[str] = argv[1:]
20
+ if not input_args:
21
+ print('Need a path.', file=stderr)
22
+ exit(1)
23
+
24
+ sqlfluff_command: Command = SqlfluffCommand()
25
+ taplo_command: Command = TaploCommand()
26
+ yamllint_command: Command = YamllintCommand()
27
+ commands: dict[Command, list[str]] = {
28
+ sqlfluff_command: [],
29
+ taplo_command: [],
30
+ yamllint_command: [],
31
+ }
32
+ for target_path in [path for arg in input_args for path in walk(Path(arg))]:
33
+ match Path(target_path).suffix.lower():
34
+ case '.sql':
35
+ commands[sqlfluff_command].append(target_path)
36
+ case '.toml':
37
+ commands[taplo_command].append(target_path)
38
+ case '.yaml' | '.yml':
39
+ commands[yamllint_command].append(target_path)
40
+
41
+ exit(
42
+ min(
43
+ 1,
44
+ sum(command.execute(paths) for command, paths in commands.items() if paths),
45
+ ),
46
+ )
@@ -0,0 +1,11 @@
1
+ from stylebook.commands.command import Command
2
+ from stylebook.commands.sqlfluff import SqlfluffCommand
3
+ from stylebook.commands.taplo import TaploCommand
4
+ from stylebook.commands.yamllint import YamllintCommand
5
+
6
+ __all__: list[str] = [
7
+ 'Command',
8
+ 'SqlfluffCommand',
9
+ 'TaploCommand',
10
+ 'YamllintCommand',
11
+ ]
@@ -0,0 +1,26 @@
1
+ from abc import ABC, abstractmethod
2
+ from importlib.resources import files
3
+ from pathlib import Path
4
+ from subprocess import run
5
+
6
+
7
+ class Command(ABC):
8
+ def __init__(self, binary: str, config_file: str) -> None:
9
+ self.binary = binary
10
+ local_config_file: Path = Path.cwd() / f'.{config_file}'
11
+ self.config_file = \
12
+ str(
13
+ local_config_file
14
+ if local_config_file.exists()
15
+ else files('stylebook.resources').joinpath(config_file),
16
+ )
17
+
18
+ @abstractmethod
19
+ def get_arguments(self) -> list[str]:
20
+ pass
21
+
22
+ def execute(self, target_paths: list[str]) -> int:
23
+ return run(
24
+ [self.binary, *self.get_arguments(), *target_paths],
25
+ capture_output=False,
26
+ ).returncode
@@ -0,0 +1,9 @@
1
+ from stylebook.commands import Command
2
+
3
+
4
+ class SqlfluffCommand(Command):
5
+ def __init__(self):
6
+ super().__init__('sqlfluff', 'sqlfluff')
7
+
8
+ def get_arguments(self) -> list[str]:
9
+ return ['lint', '--config', self.config_file]
@@ -0,0 +1,9 @@
1
+ from stylebook.commands import Command
2
+
3
+
4
+ class TaploCommand(Command):
5
+ def __init__(self):
6
+ super().__init__('taplo', 'taplo.toml')
7
+
8
+ def get_arguments(self) -> list[str]:
9
+ return ['fmt', '--diff', '-c', self.config_file]
@@ -0,0 +1,9 @@
1
+ from stylebook.commands import Command
2
+
3
+
4
+ class YamllintCommand(Command):
5
+ def __init__(self) -> None:
6
+ super().__init__('yamllint', 'yamllintrc.yaml')
7
+
8
+ def get_arguments(self) -> list[str]:
9
+ return ['-c', self.config_file]
@@ -0,0 +1,30 @@
1
+ [sqlfluff]
2
+ dialect = snowflake
3
+ templater = jinja
4
+ exclude_rules = ambiguous.column_count, structure.column_order
5
+ max_line_length = 80
6
+ processes = -1
7
+
8
+ [sqlfluff:templater:dbt]
9
+ project_dir = ./
10
+
11
+ [sqlfluff:indentation]
12
+ implicit_indents = allow
13
+ tab_space_size = 2
14
+
15
+ [sqlfluff:rules:aliasing.length]
16
+ min_alias_length = 3
17
+
18
+ [sqlfluff:rules:capitalisation.keywords]
19
+ capitalisation_policy = upper
20
+ [sqlfluff:rules:capitalisation.identifiers]
21
+ extended_capitalisation_policy = lower
22
+ [sqlfluff:rules:capitalisation.functions]
23
+ extended_capitalisation_policy = lower
24
+ [sqlfluff:rules:capitalisation.literals]
25
+ capitalisation_policy = upper
26
+ [sqlfluff:rules:capitalisation.types]
27
+ extended_capitalisation_policy = upper
28
+
29
+ [sqlfluff:rules:convention.not_equal]
30
+ preferred_not_equal_style = c_style
@@ -0,0 +1,3 @@
1
+ [formatting]
2
+ allowed_blank_lines = 1
3
+ array_auto_collapse = false
@@ -0,0 +1,14 @@
1
+ extends: default
2
+
3
+ rules:
4
+ document-start: disable
5
+ empty-lines:
6
+ max: 1
7
+ empty-values: enable
8
+ indentation:
9
+ spaces: 2
10
+ indent-sequences: whatever
11
+ float-values: enable
12
+ octal-values: enable
13
+ truthy:
14
+ check-keys: false
@@ -0,0 +1,200 @@
1
+ Metadata-Version: 2.4
2
+ Name: stylebook
3
+ Version: 0.1
4
+ Summary: Permissive linter extensions for markup and data languages
5
+ Project-URL: Source Code, https://github.com/hanggrian/stylebook
6
+ Project-URL: Bug Tracker, https://github.com/hanggrian/stylebook/issues
7
+ Author-email: Hendra Anggrian <hanggrian@proton.me>
8
+ License: Apache-2.0
9
+ Keywords: lint,linter,sql,toml,yaml
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Requires-Python: >=3.10
14
+ Requires-Dist: sqlfluff==4.1.0
15
+ Requires-Dist: taplo==0.9.3
16
+ Requires-Dist: yamllint==1.38.0
17
+ Description-Content-Type: text/markdown
18
+
19
+ [![GitHub Actions](https://img.shields.io/github/actions/workflow/status/hanggrian/stylebook/code-analysis.yaml)](https://github.com/hanggrian/stylebook/actions/workflows/code-analysis.yaml)
20
+ [![Codecov](https://img.shields.io/codecov/c/gh/hanggrian/stylebook)](https://app.codecov.io/gh/hanggrian/stylebook/)
21
+ [![Renovate](https://img.shields.io/badge/dependency-mend-blue)](https://developer.mend.io/github/hanggrian/stylebook/)\
22
+ [![PyPI](https://shields.io/pypi/v/stylebook)](https://pypi.org/project/stylebook/)
23
+ [![TestPyPI](https://shields.io/pypi/v/stylebook?label=testpypi&pypiBaseUrl=https://test.pypi.org)](https://test.pypi.org/project/stylebook/)
24
+ [![Python](https://img.shields.io/badge/python-3.10+-informational)](https://docs.python.org/3.10/)\
25
+ [![NPM](https://shields.io/npm/v/@hanggrian/stylebook)](https://www.npmjs.com/package/@hanggrian/stylebook/)
26
+ [![Node](https://img.shields.io/badge/node-12+-informational)](https://nodejs.org/en/blog/release/v12.0.0/)
27
+
28
+ # Stylebook
29
+
30
+ ![The Stylebook logo.](https://github.com/hanggrian/stylebook/raw/assets/logo.svg)
31
+
32
+ Third-party linter rules and configuration for various data formats not
33
+ considered as a programming language.
34
+
35
+ <table>
36
+ <thead>
37
+ <tr>
38
+ <th>Runner</th>
39
+ <th>File type</th>
40
+ <th>Linter</th>
41
+ <th>Style</th>
42
+ </tr>
43
+ </thead>
44
+ <tbody>
45
+ <tr>
46
+ <td rowspan="3">Python</td>
47
+ <td>SQL</td>
48
+ <td>
49
+ <a href="https://github.com/sqlfluff/sqlfluff/">
50
+ SQLFluff
51
+ </a>
52
+ </td>
53
+ <td>
54
+ <a href="https://docs.telemetry.mozilla.org/concepts/sql_style/">
55
+ Mozilla SQL Style Guide
56
+ </a>
57
+ </td>
58
+ </tr>
59
+ <tr>
60
+ <td>TOML</td>
61
+ <td>
62
+ <a href="https://github.com/tamasfe/taplo/">
63
+ Taplo
64
+ </a>
65
+ </td>
66
+ <td>
67
+ <a href="https://toml.io/en/">
68
+ TOML Spec
69
+ </a>
70
+ </td>
71
+ </tr>
72
+ <tr>
73
+ <td>YAML</td>
74
+ <td>
75
+ <a href="https://github.com/adrienverge/yamllint/">
76
+ yamllint
77
+ </a>
78
+ </td>
79
+ <td>
80
+ <a href="https://yaml.org/spec/">
81
+ YAML Spec
82
+ </a>
83
+ </td>
84
+ </tr>
85
+ <tr>
86
+ <td rowspan="4">Node</td>
87
+ <td>CSS</td>
88
+ <td>
89
+ <a href="https://github.com/stylelint/stylelint/">
90
+ Stylelint
91
+ </a>
92
+ </td>
93
+ <td>
94
+ <a href="https://protocol.mozilla.org/docs/contributing/css-guide/">
95
+ Mozilla HTML Coding Guide
96
+ </a>
97
+ </td>
98
+ </tr>
99
+ <tr>
100
+ <td>HTML</td>
101
+ <td>
102
+ <a href="https://github.com/htmlhint/HTMLHint/">
103
+ HTMLHint
104
+ </a>
105
+ </td>
106
+ <td>
107
+ <a href="https://developer.mozilla.org/en-US/docs/MDN/Writing_guidelines/Code_style_guide/HTML/">
108
+ Mozilla HTML Style Guide
109
+ </a>
110
+ </td>
111
+ </tr>
112
+ <tr>
113
+ <td>JSON</td>
114
+ <td>
115
+ <a href="https://github.com/prantlf/jsonlint/">
116
+ JSON Lint
117
+ </a>
118
+ </td>
119
+ <td>
120
+ <a href="https://spec.json5.org/">
121
+ JSON5 Spec
122
+ </a>
123
+ </td>
124
+ </tr>
125
+ <tr>
126
+ <td>Markdown</td>
127
+ <td>
128
+ <a href="https://github.com/davidanson/markdownlint/">
129
+ markdownlint
130
+ </a>
131
+ </td>
132
+ <td>
133
+ <a href="https://github.github.com/gfm/">
134
+ GitHub Flavored Markdown Spec
135
+ </a>
136
+ </td>
137
+ </tr>
138
+ </tbody>
139
+ </table>
140
+
141
+ ## Download
142
+
143
+ ### PyPI
144
+
145
+ ```sh
146
+ pip install stylebook-data
147
+ ```
148
+
149
+ ### NPM
150
+
151
+ ```sh
152
+ npm install stylebook-markup \
153
+ stylelint @stylistic/stylelint-plugin stylelint-config-recommended \
154
+ @prantlf/jsonlint \
155
+ markdownlint markdownlint-cli2 --save-dev
156
+ ```
157
+
158
+ ## Usage
159
+
160
+ Insert target paths into the command. The program will recursively search for
161
+ qualifying file types and spawn the corresponding linter processes.
162
+
163
+ ```sh
164
+ npm exec stylebook some-folder/ some-file.sql
165
+ source .venv/bin/activate && stylebook **/* # or use uv run
166
+ ```
167
+
168
+ ### SQLFluff
169
+
170
+ No setup is necessary. However, to customize behaviors, a local
171
+ `.sqlfluff` is needed.
172
+
173
+ ### tomllint
174
+
175
+ No setup is necessary. However, to customize behaviors, a local
176
+ `.taplo.toml` is needed.
177
+
178
+ ### yamllint
179
+
180
+ No setup is necessary. However, to customize behaviors, a local
181
+ `.yamllintrc.json` is needed.
182
+
183
+ ### Stylelint
184
+
185
+ Create `.stylint.config.js` file in the root directory.
186
+
187
+ ### HTML Hint
188
+
189
+ No setup is necessary. However, to customize behaviors, a local
190
+ `.htmlhintrc` is needed.
191
+
192
+ ### JSON Lint
193
+
194
+ No setup is necessary. However, to customize behaviors, a local
195
+ `.jsonlintrc.config.json` is needed.
196
+
197
+ ### markdownlint
198
+
199
+ No setup is necessary. However, to customize behaviors, a local
200
+ `.markdownlint-cli2.json` is needed.
@@ -0,0 +1,15 @@
1
+ stylebook/__init__.py,sha256=GdezVuMnjMXj_Ig_uYJRxBuNTb9ghpl_klOnk2SpkG4,11
2
+ stylebook/__main__.py,sha256=yigECWPJNabtOHpiJTGnFsf5simenlscbzrNCLzYQoQ,68
3
+ stylebook/cli.py,sha256=jmBnouC5bXUYTnpuPcOW_myvPl02DYI_i3PMXKtgdgI,1394
4
+ stylebook/commands/__init__.py,sha256=Baucdvu-6dCsDHepg82oDc_nIJa-_iem3kzjClAG0i8,316
5
+ stylebook/commands/command.py,sha256=uBMOBarfkZNjytQlvEJaL9HCvqLO7D26keO1BovUmAc,790
6
+ stylebook/commands/sqlfluff.py,sha256=6vrkXuqbIRnTW43Ap7Q8EkGTY40B0QOnbvASPj67ECc,243
7
+ stylebook/commands/taplo.py,sha256=KxWcmwVkPZogPN6yitYMH2CD9uigV4ndJkZD-2m_6uE,242
8
+ stylebook/commands/yamllint.py,sha256=qSrlwQL67rUsqoYY1O_g7XuiPCuV1B1UyScq6BbtmJI,244
9
+ stylebook/resources/sqlfluff,sha256=zdEKzjjMvOKHDi-4_gZp4-rkZmWrtrCDJV6GpoEAg7E,773
10
+ stylebook/resources/taplo.toml,sha256=t-auffFTUh6Y9eqQ_uzkIrgfcpoWgnXC4fI-oI8YPuc,65
11
+ stylebook/resources/yamllintrc.yaml,sha256=tVsEVhvTMlrBnjcp9CDZKesTl2MPy4QMoFB8yhbKrKs,238
12
+ stylebook-0.1.dist-info/METADATA,sha256=1Ws8EYVpTMeSzUrzBOnvRMxyCE8iniG_kvMbem9QrHo,5304
13
+ stylebook-0.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
14
+ stylebook-0.1.dist-info/entry_points.txt,sha256=17WUzJtMFGG7U4qxDxAUbs2T932nFlaauksx46Zb_00,48
15
+ stylebook-0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ stylebook = stylebook.cli:run