Skip to content

Commit 836926d

Browse files
[STAGE] Release Candidate alpha for version v2.0.8
* stage patches v2.0.4...v2.0.7 for v2.0.8-alpha staging * stage stable...master into staging for release 1. **.ast-grep Rules**: Many YAML rules were added for validating Python code and GitHub Actions configurations, focusing on enforcing documentation, exception handling, and coding patterns. 2. **Enhanced GitHub Actions**: - New workflows for **Flake8**, **Shellcheck**, **CD-PyPi**, and **Makefile Lint**. - Updates to existing workflows for CI, testing, and code quality checks. - Improved automation for packaging, testing, and deployment. - Additional matrix configurations for Python versions and operating systems. 3. **Housekeeping and Configuration**: - Revised `.gitignore` to exclude more development artifacts. - `.coderabbit.yaml` and `.coveragerc` were updated for broader compatibility and stricter linting. - Enhanced `Makefile` with new targets (`branding`, `purge-coverage-artifacts`), dependencies management, and defaults. - **Removed Legacy Scripts**: Tools like `tool_checkmake.sh` and `tool_shlock_helper.sh` were replaced with symbolic links or moved under `.github/tools/`. - **Workflow Adjustments**: Deprecated YAML configurations were replaced or updated with streamlined and secure alternatives. - Updates to issue and pull request templates for better user guidance. - Improved **README.md** and other documentation to reflect new changes. - Added new tests for Python versions, workflows for minimal acceptance, and doctests. - New rules and workflows for linting (e.g., `flake8`, `shellcheck`, `yamllint`). These changes aim to enhance code quality, enforce best practices, and streamline CI/CD processes.
2 parents 9673941 + 8dc6418 commit 836926d

File tree

128 files changed

+7128
-2263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+7128
-2263
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# GHA-avoid-always.yml
2+
id: gha-jobs-should-avoid-always
3+
rule:
4+
matches: gha_job_condition_map
5+
kind: block_mapping_pair
6+
has:
7+
kind: flow_node
8+
field: value
9+
has:
10+
pattern:
11+
selector: plain_scalar
12+
context: |
13+
$$$
14+
has:
15+
kind: string_scalar
16+
regex: \$\{\{.*always\(\).*\}\}
17+
fix: |
18+
if: ${{ !cancelled() }}
19+
language: YAML
20+
message: 'Condition "always()" is dangerous as it runs even when the workflow is canceled. Use "if: ${{ !cancelled() }}" instead for safer execution control.'
21+
severity: warning
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# .ast-grep/multicast-rule-check-class-has-documentation.yml
2+
id: check-has-class-documentation
3+
rule:
4+
pattern:
5+
selector: class_definition
6+
context: |
7+
class $CLASS_NAME($$$)$$$:$$$
8+
$BODY
9+
not:
10+
has:
11+
matches: block_with_docstring
12+
kind: block
13+
kind: class_definition
14+
language: python
15+
message: "Class definitions must have documentation. However $CLASS_NAME is missing a docstring."
16+
severity: warning
17+
description: |
18+
This rule ensures that all class definitions include proper documentation strings.
19+
The documentation must be a triple-quoted string (''' or """) immediately after
20+
the class definition.
21+
examples:
22+
- name: Valid class documentation examples
23+
code: |
24+
class MyClass:
25+
"""
26+
A class that demonstrates proper documentation.
27+
28+
Attributes:
29+
attr1: Description of first attribute
30+
attr2: Description of second attribute
31+
Methods:
32+
method1: Description of first method
33+
method2: Description of second method
34+
35+
Testing:
36+
>>> obj = MyClass()
37+
>>> obj.method1()
38+
True
39+
40+
"""
41+
pass
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# .ast-grep/multicast-rule-check-test-documentation.yml
2+
id: check-has-documentation
3+
rule:
4+
pattern:
5+
selector: function_definition
6+
context: |
7+
def $FUNC_NAME($PARAMS)$RET_TYPE:$$$
8+
$BODY
9+
kind: function_definition
10+
not:
11+
matches: function_docstring
12+
language: python
13+
message: "Functions should have documentation. However, $FUNC_NAME is missing a docstring."
14+
severity: warning
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# .ast-grep/multicast-rule-check-test-documentation.yml
2+
---
3+
id: check-test-documentation
4+
rule:
5+
all:
6+
- any:
7+
- matches: data_class_docstring
8+
- matches: function_docstring
9+
- matches: method_docstring
10+
- not:
11+
all:
12+
- matches: cep7_docstring_purpose
13+
- matches: cep7_docstring_arguments
14+
- any:
15+
- matches: data_class_docstring
16+
- matches: cep7_docstring_returns
17+
language: python
18+
message: "[CEP-7](https://gist.github.com/reactive-firewall/123b8a45f1bdeb064079e0524a29ec20#2-docstring-style) Documentation must include purpose, args, and returns sections."
19+
severity: hint
20+
description: |
21+
Ensures that Python docstrings are comprehensive with multiple sections as advocated by CEP-7.
22+
[CEP-7](https://gist.github.com/reactive-firewall/123b8a45f1bdeb064079e0524a29ec20#2-docstring-style)
23+
This rule helps maintain consistent documentation and style.
24+
examples:
25+
- name: Valid docstring with sections examples
26+
code: |
27+
def something():
28+
"""
29+
Demonstrate with imperative.
30+
31+
Describes the subject after a oneline gap as per PEP-257 and PEP-8 style.
32+
No line gap is needed for additional documentation.
33+
34+
Args:
35+
arg (arg type) -- indented argument detail
36+
37+
Returns:
38+
Good documentation.
39+
40+
Raises:
41+
TypeError: if arg is not an `arg type`
42+
43+
Testing:
44+
45+
1. Numbered Test description.
46+
47+
>>> indented test code
48+
Test Result followed by blank lines
49+
50+
"""
51+
- name: Invalid docstring without sections examples
52+
code: |
53+
def something():
54+
"""
55+
Terse descriptive phrase. Second sentence on same line.
56+
No gap before next line.
57+
58+
Test description
59+
60+
>>> unindented test code
61+
Test Result with no following space
62+
"""
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# .ast-grep/multicast-rule-enforce-testcase-format.yml
2+
id: enforce-testcase-format
3+
rule:
4+
pattern:
5+
selector: class_definition
6+
context: |
7+
class $CLASS_NAME($$$):$$$
8+
"""$DOCSTRING"""
9+
$$$
10+
kind: class_definition
11+
inside:
12+
kind: module
13+
has:
14+
kind: block
15+
has:
16+
kind: expression_statement
17+
has:
18+
pattern:
19+
selector: string
20+
context: |
21+
"""$DOCSTRING"""
22+
kind: string
23+
has:
24+
kind: string_content
25+
not:
26+
pattern: |
27+
*.+Testcase \d+: $DESCRIPTION
28+
.+?
29+
>>> $ASSERTION_CODE
30+
$ASSERTION_RESULT
31+
.*?
32+
language: python
33+
message: "Test cases must follow format: Testcase N: description followed by assertions"
34+
severity: hint
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#.ast-grep/multicast-rule-exception-handling-pattern.yml
2+
id: exception-handling-pattern
3+
rule:
4+
pattern:
5+
selector: try_statement
6+
context: |
7+
try:
8+
$$$
9+
except $ERR_TYPE as $ERR:
10+
raise CommandExecutionError(str($ERR))
11+
language: python
12+
message: "Ensure proper exception handling for $ERR_TYPE with CommandExecutionError"
13+
severity: warning
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .ast-grep/multicast-rule-has-module-documentation.yml
2+
id: check-has-module-documentation
3+
rule:
4+
kind: module
5+
not:
6+
has:
7+
matches: module_docstring
8+
language: python
9+
message: "Module docstring must be present and well formatted."
10+
severity: warning
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# .ast-grep/multicast-rule-require-docstring-testing.yml
2+
id: require-docstring-testing
3+
rule:
4+
kind: class_definition
5+
inside:
6+
kind: module
7+
has:
8+
kind: block
9+
has:
10+
kind: expression_statement
11+
has:
12+
pattern: |
13+
"""$DOCSTRING"""
14+
kind: string
15+
has:
16+
kind: string_content
17+
not:
18+
pattern: |
19+
.*(Minimal Acceptance |Meta-)Testing:.*
20+
language: python
21+
message: "Class must include docstring with testing examples"
22+
files:
23+
- tests{/**/,/}test_[a-z0-9_]*.py
24+
severity: hint
25+
description: |
26+
Ensures that Python classes include proper docstrings with testing examples.
27+
This rule helps maintain consistent documentation and testing practices.
28+
examples:
29+
- name: Valid class with testing examples
30+
code: |
31+
class MyClass:
32+
"""
33+
My class description.
34+
35+
Testing:
36+
>>> obj = MyClass()
37+
>>> obj.method()
38+
True
39+
"""
40+
- name: Invalid class without testing examples
41+
code: |
42+
class MyClass:
43+
"""
44+
My class description.
45+
"""
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# .ast-grep/multicast-rule-require-docstring.yml
2+
id: check-has-docstring-documentation
3+
rule:
4+
not:
5+
has:
6+
matches: block_with_docstring
7+
kind: block
8+
any:
9+
- kind: class_definition
10+
pattern:
11+
selector: class_definition
12+
context: |
13+
class $NAME($PARAMS):$$$
14+
$$$
15+
$CLASS_BODY
16+
- kind: function_definition
17+
pattern:
18+
selector: function_definition
19+
context: |
20+
def $NAME($PARAMS)$RET_TYPE:$$$
21+
$$$
22+
$FUNC_BODY
23+
language: python
24+
message: "$NAME must have documentation, add docstring."
25+
severity: warning
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# .ast-grep/multicast-rule-require-doctests-in-docstrings.yml
2+
---
3+
id: require-doctests-in-docstrings
4+
rule:
5+
all:
6+
- matches: block_docstring
7+
- not:
8+
has:
9+
matches: cep7_docstring_tests
10+
language: python
11+
message: "[CEP-7](https://gist.github.com/reactive-firewall/123b8a45f1bdeb064079e0524a29ec20#2-docstring-style) Documentation must include proper doctests."
12+
severity: warning
13+
description: |
14+
Ensures that Python docstrings are comprehensive with doctests as advocated by CEP-7.
15+
[CEP-7](https://gist.github.com/reactive-firewall/123b8a45f1bdeb064079e0524a29ec20)
16+
This rule helps maintain consistent test coverage.
17+
examples:
18+
- name: Valid docstring with sections examples
19+
code: |
20+
"""
21+
Test description
22+
23+
>>> indented test code
24+
Test Result
25+
26+
"""
27+
- name: Invalid docstring without doctests examples
28+
code: |
29+
"""
30+
Possible Test description.
31+
No actual doctest
32+
"""
33+
- name: Invalid docstring with invalid doctest examples
34+
code: |
35+
"""
36+
Test description
37+
38+
>>> unindented test code
39+
Test Result
40+
41+
"""

0 commit comments

Comments
 (0)