artifact-lint-py 1.0.0__tar.gz
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.
- artifact_lint_py-1.0.0/LICENSE +201 -0
- artifact_lint_py-1.0.0/PKG-INFO +101 -0
- artifact_lint_py-1.0.0/README.md +74 -0
- artifact_lint_py-1.0.0/artifact_lint_py.egg-info/PKG-INFO +101 -0
- artifact_lint_py-1.0.0/artifact_lint_py.egg-info/SOURCES.txt +15 -0
- artifact_lint_py-1.0.0/artifact_lint_py.egg-info/dependency_links.txt +1 -0
- artifact_lint_py-1.0.0/artifact_lint_py.egg-info/requires.txt +14 -0
- artifact_lint_py-1.0.0/artifact_lint_py.egg-info/top_level.txt +1 -0
- artifact_lint_py-1.0.0/lint/__init__.py +6 -0
- artifact_lint_py-1.0.0/lint/config.py +193 -0
- artifact_lint_py-1.0.0/lint/linter.py +58 -0
- artifact_lint_py-1.0.0/lint/result.py +31 -0
- artifact_lint_py-1.0.0/lint/rule.py +39 -0
- artifact_lint_py-1.0.0/lint/status.py +49 -0
- artifact_lint_py-1.0.0/lint/typing.py +3 -0
- artifact_lint_py-1.0.0/pyproject.toml +34 -0
- artifact_lint_py-1.0.0/setup.cfg +4 -0
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: artifact-lint-py
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A python framework for developing artifact linters
|
5
|
+
Author-email: Ethan Balcik <ethanbalcik@ibm.com>
|
6
|
+
License-Expression: Apache-2.0
|
7
|
+
Project-URL: Homepage, https://github.com/whatsacomputertho/artifact-lint-py
|
8
|
+
Project-URL: Issues, https://github.com/whatsacomputertho/artifact-lint-py/issues
|
9
|
+
Keywords: artifact,lint,py,linter
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.9
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
Requires-Dist: jsonschema
|
16
|
+
Provides-Extra: test
|
17
|
+
Requires-Dist: tox; extra == "test"
|
18
|
+
Requires-Dist: pytest; extra == "test"
|
19
|
+
Requires-Dist: pytest-mock; extra == "test"
|
20
|
+
Requires-Dist: pytest-cov; extra == "test"
|
21
|
+
Provides-Extra: build
|
22
|
+
Requires-Dist: build; extra == "build"
|
23
|
+
Provides-Extra: doc
|
24
|
+
Requires-Dist: sphinx; extra == "doc"
|
25
|
+
Requires-Dist: sphinx_rtd_theme; extra == "doc"
|
26
|
+
Dynamic: license-file
|
27
|
+
|
28
|
+

|
29
|
+
|
30
|
+
# artifact-lint-py
|
31
|
+
|
32
|
+
[](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/test.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/sec.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/doc.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/build.yaml)
|
33
|
+
|
34
|
+
A python framework for developing artifact linters
|
35
|
+
|
36
|
+
**Docs**: https://whatsacomputertho.github.io/artifact-lint-py/
|
37
|
+
|
38
|
+
**Contributing**: [CONTRIBUTING.md](https://github.com/whatsacomputertho/artifact-lint-py/blob/main/CONTRIBUTING.md)
|
39
|
+
|
40
|
+
## Quick Example
|
41
|
+
|
42
|
+
```python
|
43
|
+
from lint.rule import LintRule
|
44
|
+
from lint.result import LintResult
|
45
|
+
from lint.status import LintStatus
|
46
|
+
|
47
|
+
class IntegerIsEven(LintRule[int]):
|
48
|
+
def lint(self, artifact: int) -> LintResult:
|
49
|
+
if artifact % 2 == 0:
|
50
|
+
return LintResult(
|
51
|
+
status=LintStatus.INFO,
|
52
|
+
message=f"({self.name()}) Integer was even: {artifact}"
|
53
|
+
)
|
54
|
+
return LintResult(
|
55
|
+
status=LintStatus.ERROR,
|
56
|
+
message=f"({self.name()}) Integer was odd: {artifact}"
|
57
|
+
)
|
58
|
+
integer_is_even = IntegerIsEven()
|
59
|
+
|
60
|
+
# Lint an even integer
|
61
|
+
even_result = integer_is_even.lint(2)
|
62
|
+
print(even_result)
|
63
|
+
|
64
|
+
# Lint an odd integer
|
65
|
+
odd_result = integer_is_even.lint(337)
|
66
|
+
print(odd_result)
|
67
|
+
```
|
68
|
+
|
69
|
+
To run this example, simply execute the following from the root of this repository
|
70
|
+
```bash
|
71
|
+
python3 examples/quick-example.py
|
72
|
+
```
|
73
|
+
|
74
|
+
## Installation
|
75
|
+
|
76
|
+
### Using Pip
|
77
|
+
|
78
|
+
Run the following command to install the latest version of this package
|
79
|
+
```bash
|
80
|
+
pip install artifact-lint-py
|
81
|
+
```
|
82
|
+
|
83
|
+
### Local Install
|
84
|
+
|
85
|
+
1. Clone this repository
|
86
|
+
2. [Build the project from source](#build)
|
87
|
+
3. Locate the `.whl` (wheel) file in the `dist` folder
|
88
|
+
- It should be named something like so: artifact_lint_py-1.0.0-py3-none-any.whl
|
89
|
+
4. Run the following command from the root of the repository, replacing the name of the `.whl` file if necessary
|
90
|
+
```bash
|
91
|
+
pip install dist/artifact_lint_py-1.0.0-py3-none-any.whl
|
92
|
+
```
|
93
|
+
|
94
|
+
## Build
|
95
|
+
|
96
|
+
From the root of this repository, execute
|
97
|
+
```bash
|
98
|
+
make build
|
99
|
+
```
|
100
|
+
|
101
|
+
Under the hood, this will execute python3 -m build and produce a .whl (wheel) and .tgz (TAR-GZip archive) file in the dist subdirectory. For more on this project's make recipes, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
@@ -0,0 +1,74 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
# artifact-lint-py
|
4
|
+
|
5
|
+
[](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/test.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/sec.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/doc.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/build.yaml)
|
6
|
+
|
7
|
+
A python framework for developing artifact linters
|
8
|
+
|
9
|
+
**Docs**: https://whatsacomputertho.github.io/artifact-lint-py/
|
10
|
+
|
11
|
+
**Contributing**: [CONTRIBUTING.md](https://github.com/whatsacomputertho/artifact-lint-py/blob/main/CONTRIBUTING.md)
|
12
|
+
|
13
|
+
## Quick Example
|
14
|
+
|
15
|
+
```python
|
16
|
+
from lint.rule import LintRule
|
17
|
+
from lint.result import LintResult
|
18
|
+
from lint.status import LintStatus
|
19
|
+
|
20
|
+
class IntegerIsEven(LintRule[int]):
|
21
|
+
def lint(self, artifact: int) -> LintResult:
|
22
|
+
if artifact % 2 == 0:
|
23
|
+
return LintResult(
|
24
|
+
status=LintStatus.INFO,
|
25
|
+
message=f"({self.name()}) Integer was even: {artifact}"
|
26
|
+
)
|
27
|
+
return LintResult(
|
28
|
+
status=LintStatus.ERROR,
|
29
|
+
message=f"({self.name()}) Integer was odd: {artifact}"
|
30
|
+
)
|
31
|
+
integer_is_even = IntegerIsEven()
|
32
|
+
|
33
|
+
# Lint an even integer
|
34
|
+
even_result = integer_is_even.lint(2)
|
35
|
+
print(even_result)
|
36
|
+
|
37
|
+
# Lint an odd integer
|
38
|
+
odd_result = integer_is_even.lint(337)
|
39
|
+
print(odd_result)
|
40
|
+
```
|
41
|
+
|
42
|
+
To run this example, simply execute the following from the root of this repository
|
43
|
+
```bash
|
44
|
+
python3 examples/quick-example.py
|
45
|
+
```
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
|
49
|
+
### Using Pip
|
50
|
+
|
51
|
+
Run the following command to install the latest version of this package
|
52
|
+
```bash
|
53
|
+
pip install artifact-lint-py
|
54
|
+
```
|
55
|
+
|
56
|
+
### Local Install
|
57
|
+
|
58
|
+
1. Clone this repository
|
59
|
+
2. [Build the project from source](#build)
|
60
|
+
3. Locate the `.whl` (wheel) file in the `dist` folder
|
61
|
+
- It should be named something like so: artifact_lint_py-1.0.0-py3-none-any.whl
|
62
|
+
4. Run the following command from the root of the repository, replacing the name of the `.whl` file if necessary
|
63
|
+
```bash
|
64
|
+
pip install dist/artifact_lint_py-1.0.0-py3-none-any.whl
|
65
|
+
```
|
66
|
+
|
67
|
+
## Build
|
68
|
+
|
69
|
+
From the root of this repository, execute
|
70
|
+
```bash
|
71
|
+
make build
|
72
|
+
```
|
73
|
+
|
74
|
+
Under the hood, this will execute python3 -m build and produce a .whl (wheel) and .tgz (TAR-GZip archive) file in the dist subdirectory. For more on this project's make recipes, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
@@ -0,0 +1,101 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: artifact-lint-py
|
3
|
+
Version: 1.0.0
|
4
|
+
Summary: A python framework for developing artifact linters
|
5
|
+
Author-email: Ethan Balcik <ethanbalcik@ibm.com>
|
6
|
+
License-Expression: Apache-2.0
|
7
|
+
Project-URL: Homepage, https://github.com/whatsacomputertho/artifact-lint-py
|
8
|
+
Project-URL: Issues, https://github.com/whatsacomputertho/artifact-lint-py/issues
|
9
|
+
Keywords: artifact,lint,py,linter
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Operating System :: OS Independent
|
12
|
+
Requires-Python: >=3.9
|
13
|
+
Description-Content-Type: text/markdown
|
14
|
+
License-File: LICENSE
|
15
|
+
Requires-Dist: jsonschema
|
16
|
+
Provides-Extra: test
|
17
|
+
Requires-Dist: tox; extra == "test"
|
18
|
+
Requires-Dist: pytest; extra == "test"
|
19
|
+
Requires-Dist: pytest-mock; extra == "test"
|
20
|
+
Requires-Dist: pytest-cov; extra == "test"
|
21
|
+
Provides-Extra: build
|
22
|
+
Requires-Dist: build; extra == "build"
|
23
|
+
Provides-Extra: doc
|
24
|
+
Requires-Dist: sphinx; extra == "doc"
|
25
|
+
Requires-Dist: sphinx_rtd_theme; extra == "doc"
|
26
|
+
Dynamic: license-file
|
27
|
+
|
28
|
+

|
29
|
+
|
30
|
+
# artifact-lint-py
|
31
|
+
|
32
|
+
[](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/test.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/sec.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/doc.yaml) [](https://github.com/whatsacomputertho/artifact-lint-py/actions/workflows/build.yaml)
|
33
|
+
|
34
|
+
A python framework for developing artifact linters
|
35
|
+
|
36
|
+
**Docs**: https://whatsacomputertho.github.io/artifact-lint-py/
|
37
|
+
|
38
|
+
**Contributing**: [CONTRIBUTING.md](https://github.com/whatsacomputertho/artifact-lint-py/blob/main/CONTRIBUTING.md)
|
39
|
+
|
40
|
+
## Quick Example
|
41
|
+
|
42
|
+
```python
|
43
|
+
from lint.rule import LintRule
|
44
|
+
from lint.result import LintResult
|
45
|
+
from lint.status import LintStatus
|
46
|
+
|
47
|
+
class IntegerIsEven(LintRule[int]):
|
48
|
+
def lint(self, artifact: int) -> LintResult:
|
49
|
+
if artifact % 2 == 0:
|
50
|
+
return LintResult(
|
51
|
+
status=LintStatus.INFO,
|
52
|
+
message=f"({self.name()}) Integer was even: {artifact}"
|
53
|
+
)
|
54
|
+
return LintResult(
|
55
|
+
status=LintStatus.ERROR,
|
56
|
+
message=f"({self.name()}) Integer was odd: {artifact}"
|
57
|
+
)
|
58
|
+
integer_is_even = IntegerIsEven()
|
59
|
+
|
60
|
+
# Lint an even integer
|
61
|
+
even_result = integer_is_even.lint(2)
|
62
|
+
print(even_result)
|
63
|
+
|
64
|
+
# Lint an odd integer
|
65
|
+
odd_result = integer_is_even.lint(337)
|
66
|
+
print(odd_result)
|
67
|
+
```
|
68
|
+
|
69
|
+
To run this example, simply execute the following from the root of this repository
|
70
|
+
```bash
|
71
|
+
python3 examples/quick-example.py
|
72
|
+
```
|
73
|
+
|
74
|
+
## Installation
|
75
|
+
|
76
|
+
### Using Pip
|
77
|
+
|
78
|
+
Run the following command to install the latest version of this package
|
79
|
+
```bash
|
80
|
+
pip install artifact-lint-py
|
81
|
+
```
|
82
|
+
|
83
|
+
### Local Install
|
84
|
+
|
85
|
+
1. Clone this repository
|
86
|
+
2. [Build the project from source](#build)
|
87
|
+
3. Locate the `.whl` (wheel) file in the `dist` folder
|
88
|
+
- It should be named something like so: artifact_lint_py-1.0.0-py3-none-any.whl
|
89
|
+
4. Run the following command from the root of the repository, replacing the name of the `.whl` file if necessary
|
90
|
+
```bash
|
91
|
+
pip install dist/artifact_lint_py-1.0.0-py3-none-any.whl
|
92
|
+
```
|
93
|
+
|
94
|
+
## Build
|
95
|
+
|
96
|
+
From the root of this repository, execute
|
97
|
+
```bash
|
98
|
+
make build
|
99
|
+
```
|
100
|
+
|
101
|
+
Under the hood, this will execute python3 -m build and produce a .whl (wheel) and .tgz (TAR-GZip archive) file in the dist subdirectory. For more on this project's make recipes, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
@@ -0,0 +1,15 @@
|
|
1
|
+
LICENSE
|
2
|
+
README.md
|
3
|
+
pyproject.toml
|
4
|
+
artifact_lint_py.egg-info/PKG-INFO
|
5
|
+
artifact_lint_py.egg-info/SOURCES.txt
|
6
|
+
artifact_lint_py.egg-info/dependency_links.txt
|
7
|
+
artifact_lint_py.egg-info/requires.txt
|
8
|
+
artifact_lint_py.egg-info/top_level.txt
|
9
|
+
lint/__init__.py
|
10
|
+
lint/config.py
|
11
|
+
lint/linter.py
|
12
|
+
lint/result.py
|
13
|
+
lint/rule.py
|
14
|
+
lint/status.py
|
15
|
+
lint/typing.py
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
lint
|
@@ -0,0 +1,193 @@
|
|
1
|
+
from jsonschema import validate, ValidationError
|
2
|
+
from lint.typing import T
|
3
|
+
from typing import Generic, Any
|
4
|
+
|
5
|
+
DEFAULT_LINT_RULE_CONFIG_SCHEMA = {
|
6
|
+
"type": "object",
|
7
|
+
"required": [ "enabled" ],
|
8
|
+
"properties": {
|
9
|
+
"enabled": {
|
10
|
+
"type": "boolean"
|
11
|
+
}
|
12
|
+
}
|
13
|
+
}
|
14
|
+
"""
|
15
|
+
The default lint rule config schema, which enforces that lint rule config
|
16
|
+
dicts have a boolean property named enabled
|
17
|
+
"""
|
18
|
+
|
19
|
+
DEFAULT_LINTER_CONFIG_SCHEMA = {
|
20
|
+
"type": "object",
|
21
|
+
"additionalProperties": False,
|
22
|
+
"patternProperties": {
|
23
|
+
"^[A-Z][a-zA-Z0-9]*$": DEFAULT_LINT_RULE_CONFIG_SCHEMA
|
24
|
+
}
|
25
|
+
}
|
26
|
+
"""
|
27
|
+
The default schema for a linter config, which enforces that lint rule names
|
28
|
+
are PascalCase and that each lint rule config satisfies its default schema
|
29
|
+
"""
|
30
|
+
|
31
|
+
class LintRuleConfig(Generic[T]):
|
32
|
+
"""
|
33
|
+
The LintRuleConfig class represents the configuration for a lint rule
|
34
|
+
"""
|
35
|
+
@staticmethod
|
36
|
+
def validate_static(
|
37
|
+
config: dict[str, Any],
|
38
|
+
schema: dict[str, Any]=DEFAULT_LINT_RULE_CONFIG_SCHEMA
|
39
|
+
) -> tuple[bool, str]:
|
40
|
+
"""
|
41
|
+
Validates a LintRuleConfig dictionary
|
42
|
+
|
43
|
+
Args:
|
44
|
+
config (dict): The lint rule config dictionary
|
45
|
+
schema (dict): The lint rule config dictionary
|
46
|
+
|
47
|
+
Returns:
|
48
|
+
bool: Whether the lint rule config dict was valid
|
49
|
+
str: Error message if the config dict was invalid
|
50
|
+
"""
|
51
|
+
try:
|
52
|
+
validate(schema=schema, instance=config)
|
53
|
+
except ValidationError as ve:
|
54
|
+
return False, str(ve)
|
55
|
+
return True, ""
|
56
|
+
|
57
|
+
def __init__(
|
58
|
+
self,
|
59
|
+
config: dict[str, Any],
|
60
|
+
schema: dict[str, Any]=DEFAULT_LINT_RULE_CONFIG_SCHEMA
|
61
|
+
):
|
62
|
+
"""
|
63
|
+
Constructor for the LintRuleConfig class
|
64
|
+
|
65
|
+
Args:
|
66
|
+
config (dict): The lint rule config dictionary
|
67
|
+
schema (dict): The lint rule config JSON schema dictionary
|
68
|
+
|
69
|
+
Returns:
|
70
|
+
LintRuleConfig: The initialized lint rule config object
|
71
|
+
"""
|
72
|
+
# Validate the lint rule config
|
73
|
+
valid, err = LintRuleConfig.validate_static(config, schema)
|
74
|
+
if not valid:
|
75
|
+
raise ValidationError(err)
|
76
|
+
|
77
|
+
# If valid, save the config & schema as object properties
|
78
|
+
self.config = config
|
79
|
+
self.schema = schema
|
80
|
+
|
81
|
+
def validate(self) -> tuple[bool, str]:
|
82
|
+
"""
|
83
|
+
Validates a LintRuleConfig instance
|
84
|
+
|
85
|
+
Returns:
|
86
|
+
bool: Whether the config dict was valid
|
87
|
+
str: Error message if the config dict was invalid
|
88
|
+
"""
|
89
|
+
return LintRuleConfig.validate_static(self.config, self.schema)
|
90
|
+
|
91
|
+
def enabled(self) -> bool:
|
92
|
+
"""
|
93
|
+
Determines whether the lint rule is enabled
|
94
|
+
|
95
|
+
Returns:
|
96
|
+
bool: Whether the lint rule is enabled
|
97
|
+
"""
|
98
|
+
return self.config.get("enabled", False)
|
99
|
+
|
100
|
+
def __dict__(self) -> dict[str, Any]:
|
101
|
+
"""
|
102
|
+
Serialize the LintRuleConfig as a python dictionary
|
103
|
+
|
104
|
+
Returns:
|
105
|
+
dict: The lint rule config as a dict
|
106
|
+
"""
|
107
|
+
return self.config
|
108
|
+
|
109
|
+
class LinterConfig(Generic[T]):
|
110
|
+
"""
|
111
|
+
The LinterConfig class represents the configuration for a linter
|
112
|
+
"""
|
113
|
+
@staticmethod
|
114
|
+
def validate_static(
|
115
|
+
config: dict[str, Any],
|
116
|
+
schema: dict[str, Any]=DEFAULT_LINTER_CONFIG_SCHEMA
|
117
|
+
) -> tuple[bool, str]:
|
118
|
+
"""
|
119
|
+
Validates a LinterConfig dictionary
|
120
|
+
|
121
|
+
Args:
|
122
|
+
config (dict): The linter config dictionary
|
123
|
+
schema (dict): The linter config JSON schema dictionary
|
124
|
+
|
125
|
+
Returns:
|
126
|
+
bool: Whether the config dict was valid
|
127
|
+
str: Error message if the config dict was invalid
|
128
|
+
"""
|
129
|
+
try:
|
130
|
+
validate(schema=schema, instance=config)
|
131
|
+
except ValidationError as ve:
|
132
|
+
return False, str(ve)
|
133
|
+
return True, ""
|
134
|
+
|
135
|
+
def __init__(
|
136
|
+
self,
|
137
|
+
config: dict[str, Any],
|
138
|
+
schema: dict[str, Any]=DEFAULT_LINTER_CONFIG_SCHEMA
|
139
|
+
):
|
140
|
+
"""
|
141
|
+
Constructor for the LinterConfig class
|
142
|
+
|
143
|
+
Args:
|
144
|
+
config (dict): The linter config dictionary
|
145
|
+
schema (dict): The linter config JSON schema dictionary
|
146
|
+
"""
|
147
|
+
# Validate the linter config
|
148
|
+
valid, err = LinterConfig.validate_static(config, schema)
|
149
|
+
if not valid:
|
150
|
+
raise ValidationError(err)
|
151
|
+
|
152
|
+
# If valid, save the config & schema as object properties
|
153
|
+
# Convert each lint rule config to a LintRuleConfig before saving
|
154
|
+
self.config = {
|
155
|
+
key: LintRuleConfig(value) for key, value in config.items()
|
156
|
+
}
|
157
|
+
self.schema = schema
|
158
|
+
|
159
|
+
def validate(self) -> tuple[bool, str]:
|
160
|
+
"""
|
161
|
+
Validates a LinterConfig instance
|
162
|
+
|
163
|
+
Returns:
|
164
|
+
bool: Whether the config dict was valid
|
165
|
+
str: Error message if the config dict was invalid
|
166
|
+
"""
|
167
|
+
return LinterConfig.validate_static(self.__dict__(), self.schema)
|
168
|
+
|
169
|
+
def enabled(self, rule: str) -> bool:
|
170
|
+
"""
|
171
|
+
Determines whether a given lint rule is enabled in the lint config
|
172
|
+
|
173
|
+
Args:
|
174
|
+
rule (str): The name of the lint rule
|
175
|
+
|
176
|
+
Returns:
|
177
|
+
bool: Whether the lint rule is enabled
|
178
|
+
"""
|
179
|
+
for key in self.config.keys():
|
180
|
+
if rule == str(key):
|
181
|
+
return self.config.get(key).enabled()
|
182
|
+
return False
|
183
|
+
|
184
|
+
def __dict__(self) -> dict[str, Any]:
|
185
|
+
"""
|
186
|
+
Serialize the LinterConfig as a python dictionary
|
187
|
+
|
188
|
+
Returns:
|
189
|
+
dict: The linter config serialized as a dict
|
190
|
+
"""
|
191
|
+
return {
|
192
|
+
key: value.__dict__() for key, value in self.config.items()
|
193
|
+
}
|
@@ -0,0 +1,58 @@
|
|
1
|
+
from lint.config import LinterConfig
|
2
|
+
from lint.result import LintResult
|
3
|
+
from lint.rule import LintRule, DEFAULT_LINT_RULE_CONFIG
|
4
|
+
from lint.typing import T
|
5
|
+
from typing import Generic
|
6
|
+
|
7
|
+
DEFAULT_LINTER_CONFIG = LinterConfig({})
|
8
|
+
|
9
|
+
class Linter(Generic[T]):
|
10
|
+
"""
|
11
|
+
The Linter class applies potentially multiple lint rules against an
|
12
|
+
artifact, returning the list of lint results for each enforced rule
|
13
|
+
"""
|
14
|
+
def __init__(
|
15
|
+
self,
|
16
|
+
rules: list[LintRule[T]]
|
17
|
+
):
|
18
|
+
"""
|
19
|
+
Constructor for the Linter class
|
20
|
+
|
21
|
+
Args:
|
22
|
+
rules (list): The lint rules enforced by the linter
|
23
|
+
"""
|
24
|
+
self.rules = rules
|
25
|
+
|
26
|
+
def lint(
|
27
|
+
self,
|
28
|
+
artifact: T,
|
29
|
+
config: LinterConfig[T]=DEFAULT_LINTER_CONFIG,
|
30
|
+
**kwargs
|
31
|
+
) -> list[LintResult]:
|
32
|
+
"""
|
33
|
+
Applies the linter's lint rules against an artifact, returning the list
|
34
|
+
of lint results for each enforced rule
|
35
|
+
|
36
|
+
Args:
|
37
|
+
artifact (T): The artifact to lint
|
38
|
+
config (LinterConfig): The configuration for the linter
|
39
|
+
|
40
|
+
Returns:
|
41
|
+
list: The list of LintResults corresponding to each lint rule
|
42
|
+
"""
|
43
|
+
results = []
|
44
|
+
for rule in self.rules:
|
45
|
+
rule_name = rule.name()
|
46
|
+
if config.enabled(rule_name):
|
47
|
+
results.append(
|
48
|
+
rule.lint(
|
49
|
+
artifact,
|
50
|
+
config.config.get(
|
51
|
+
rule_name,
|
52
|
+
DEFAULT_LINT_RULE_CONFIG
|
53
|
+
)
|
54
|
+
)
|
55
|
+
)
|
56
|
+
else:
|
57
|
+
results.append(LintResult(message=f"{rule_name} disabled"))
|
58
|
+
return results
|
@@ -0,0 +1,31 @@
|
|
1
|
+
from lint.status import LintStatus
|
2
|
+
|
3
|
+
class LintResult:
|
4
|
+
"""
|
5
|
+
The LintResult class represents the result of a lint rule after the rule
|
6
|
+
has been enforced against an artifact. It includes a LintStatus indicating
|
7
|
+
the severity of the result, and a message represented as a string.
|
8
|
+
"""
|
9
|
+
def __init__(
|
10
|
+
self,
|
11
|
+
status: LintStatus=LintStatus.INFO,
|
12
|
+
message: str=""
|
13
|
+
):
|
14
|
+
"""
|
15
|
+
Constructor for the LintResult class
|
16
|
+
|
17
|
+
Args:
|
18
|
+
status (LintStatus): The status / severity of the lint result
|
19
|
+
message (str): A message describing the lint result
|
20
|
+
"""
|
21
|
+
self.status = status
|
22
|
+
self.message = message
|
23
|
+
|
24
|
+
def __str__(self) -> str:
|
25
|
+
"""
|
26
|
+
Formats the lint result as a string
|
27
|
+
|
28
|
+
Returns:
|
29
|
+
str: The lint result as a string
|
30
|
+
"""
|
31
|
+
return f"{str(self.status)}: {self.message}"
|
@@ -0,0 +1,39 @@
|
|
1
|
+
from lint.config import LintRuleConfig
|
2
|
+
from lint.result import LintResult
|
3
|
+
from lint.typing import T
|
4
|
+
from typing import Generic
|
5
|
+
|
6
|
+
DEFAULT_LINT_RULE_CONFIG = LintRuleConfig({"enabled": True})
|
7
|
+
|
8
|
+
class LintRule(Generic[T]):
|
9
|
+
"""
|
10
|
+
The LintRule class represents a rule that can be enforced against an
|
11
|
+
artifact. When enforced, it produces a LintResult which describes the
|
12
|
+
outcome of enforcing the rule.
|
13
|
+
"""
|
14
|
+
def name(self) -> str:
|
15
|
+
"""
|
16
|
+
Returns the name of the lint rule
|
17
|
+
|
18
|
+
Returns:
|
19
|
+
str: The name of the lint rule
|
20
|
+
"""
|
21
|
+
return type(self).__name__
|
22
|
+
|
23
|
+
def lint(
|
24
|
+
self,
|
25
|
+
artifact: T,
|
26
|
+
config: LintRuleConfig[T]=DEFAULT_LINT_RULE_CONFIG,
|
27
|
+
**kwargs
|
28
|
+
) -> LintResult:
|
29
|
+
"""
|
30
|
+
Enforces the lint rule against an artifact
|
31
|
+
|
32
|
+
Args:
|
33
|
+
artifact (T): An artifact to lint
|
34
|
+
config (LintRuleConfig): The configuration for this lint rule
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
LintResult: The lint result
|
38
|
+
"""
|
39
|
+
return LintResult(message="Not yet implemented")
|
@@ -0,0 +1,49 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
from typing import Union
|
3
|
+
|
4
|
+
class LintStatus(Enum):
|
5
|
+
"""
|
6
|
+
The LintStatus enum represents the status or severity of a lint rule's
|
7
|
+
result after the rule is enforced against an artifact.
|
8
|
+
"""
|
9
|
+
INFO = 0
|
10
|
+
WARNING = 1
|
11
|
+
ERROR = 2
|
12
|
+
|
13
|
+
@staticmethod
|
14
|
+
def try_from_name(
|
15
|
+
name: str
|
16
|
+
) -> tuple[Union["LintStatus", None], str]:
|
17
|
+
"""
|
18
|
+
Try to load a LintStatus from its name property serialized as a string
|
19
|
+
|
20
|
+
Args:
|
21
|
+
name (str): The name of the LintStatus enum
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
LintStatus: The loaded LintStatus, or None if not loaded
|
25
|
+
str: Error message if the LintStatus was not loaded successfully
|
26
|
+
"""
|
27
|
+
try:
|
28
|
+
return LintStatus[name], ""
|
29
|
+
except KeyError:
|
30
|
+
return None, f"Task status name does not exist: {name}"
|
31
|
+
|
32
|
+
@staticmethod
|
33
|
+
def try_from_value(
|
34
|
+
value: int
|
35
|
+
) -> tuple[Union["LintStatus", None], str]:
|
36
|
+
"""
|
37
|
+
Try to load a LintStatus from its value property serialized as an int
|
38
|
+
|
39
|
+
Args:
|
40
|
+
value (int): The value of the LintStatus enum
|
41
|
+
|
42
|
+
Returns:
|
43
|
+
LintStatus: The loaded LintStatus, or None if not loaded
|
44
|
+
str: Error message if the LintStatus was not loaded successfully
|
45
|
+
"""
|
46
|
+
try:
|
47
|
+
return LintStatus(value), ""
|
48
|
+
except ValueError:
|
49
|
+
return None, f"Task status value out of range: {value}"
|
@@ -0,0 +1,34 @@
|
|
1
|
+
[build-system]
|
2
|
+
requires = ["setuptools >= 77.0.3"]
|
3
|
+
build-backend = "setuptools.build_meta"
|
4
|
+
|
5
|
+
[project]
|
6
|
+
name = "artifact-lint-py"
|
7
|
+
version = "1.0.0"
|
8
|
+
authors = [
|
9
|
+
{name = "Ethan Balcik", email="ethanbalcik@ibm.com" }
|
10
|
+
]
|
11
|
+
description = "A python framework for developing artifact linters"
|
12
|
+
readme = "README.md"
|
13
|
+
requires-python = ">=3.9"
|
14
|
+
classifiers = [
|
15
|
+
"Programming Language :: Python :: 3",
|
16
|
+
"Operating System :: OS Independent",
|
17
|
+
]
|
18
|
+
keywords = ["artifact","lint","py","linter"]
|
19
|
+
license = "Apache-2.0"
|
20
|
+
license-files = [
|
21
|
+
"LICENSE"
|
22
|
+
]
|
23
|
+
dependencies = [
|
24
|
+
"jsonschema"
|
25
|
+
]
|
26
|
+
|
27
|
+
[project.urls]
|
28
|
+
Homepage = "https://github.com/whatsacomputertho/artifact-lint-py"
|
29
|
+
Issues = "https://github.com/whatsacomputertho/artifact-lint-py/issues"
|
30
|
+
|
31
|
+
[project.optional-dependencies]
|
32
|
+
test = ["tox","pytest","pytest-mock","pytest-cov"]
|
33
|
+
build = ["build"]
|
34
|
+
doc = ["sphinx","sphinx_rtd_theme"]
|