Skip to content

Commit cb76973

Browse files
authored
Python Ruby - Linting: Move SuperLinter into standalone linters (#6450)
1 parent a14ab9e commit cb76973

File tree

7 files changed

+131
-551
lines changed

7 files changed

+131
-551
lines changed

Diff for: .github/linters/.ruby-lint.yml

-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#######################
33
# Rubocop Config file #
44
#######################
5-
6-
inherit_gem:
7-
rubocop-github:
8-
- config/default.yml
95
Metrics/MethodLength:
106
Max: 25
117
Metrics/AbcSize:

Diff for: .github/workflows/python.yml

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Lint Python
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
black:
9+
name: Flake8 Linting & Black Formatting
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v2
15+
16+
- name: Get changed files
17+
id: changed-files
18+
uses: tj-actions/changed-files@v41
19+
with:
20+
files: "**.py"
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v2
24+
with:
25+
python-version: 3.9
26+
27+
- name: Install dependencies
28+
run: |
29+
pip install black pylint
30+
31+
- name: Run Black & Pylint
32+
if: steps.changed-files.outputs.any_changed == 'true'
33+
run: |
34+
changed_files=(${{steps.changed-files.outputs.all_changed_files}})
35+
black "${changed_files[@]}"
36+
pylint --rcfile .github/linters/.python-lint "${changed_files[@]}"

Diff for: .github/workflows/ruby.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Ruby Linting
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
rubocop:
9+
name: RuboCop
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Repository
14+
uses: actions/checkout@v2
15+
16+
- name: Get changed files
17+
id: changed-files
18+
uses: tj-actions/changed-files@v41
19+
with:
20+
files: "ruby/**/*.rb"
21+
22+
- name: Set up Ruby
23+
uses: ruby/setup-ruby@v1
24+
with:
25+
ruby-version: 3.0
26+
27+
- name: Install dependencies
28+
run: |
29+
gem install rubocop
30+
31+
- name: Run RuboCop
32+
if: steps.changed-files.outputs.any_changed == 'true'
33+
run: |
34+
changed_files=(${{steps.changed-files.outputs.all_changed_files}})
35+
rubocop --config .github/linters/.ruby-lint.yml "${changed_files[@]}"

Diff for: .github/workflows/super-linter.yml

-5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
sparse-checkout: |
1818
.github
1919
php
20-
python
21-
ruby
2220
kotlin
2321
- name: Lint Code Base
2422
uses: github/super-linter@v4
@@ -27,7 +25,4 @@ jobs:
2725
DEFAULT_BRANCH: main
2826
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2927
VALIDATE_PHP_PHPCS: true
30-
VALIDATE_PYTHON: true
31-
VALIDATE_PYTHON_BLACK: true
32-
VALIDATE_RUBY: true
3328
VALIDATE_KOTLIN: true

Diff for: python/README.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Install the packages for the example by running the following:
7474
python -m pip install -r requirements.txt
7575
```
7676

77-
This installs all of the packages listed in the `requirements.txt` file in the current
77+
This installs all the packages listed in the `requirements.txt` file in the current
7878
folder.
7979

8080
### Run the code
@@ -90,6 +90,44 @@ Some examples require command line arguments. In these cases, you can run the ex
9090
with a `-h` flag to get help. Each example has a README.md that describes additional
9191
specifics about how to run the example and any other prerequisites.
9292

93+
## Linting and formatting
94+
We rely on [pylint](https://pylint.pycqa.org/en/latest/) and [black](https://black.readthedocs.io/en/stable/) to keep this code consistently formatted and styled.
95+
To contribute Python code to this project, please refer to the following installation and usage steps.
96+
97+
### Using Pylint
98+
We run Pylint using [a custom configuration file](.github/linters/.python-lint) against any changed file or directory. See the [Python Github Action workflow](../.github/workflows/python.yml) for details.
99+
100+
To invoke Pylint yourself, first install it with `pip install pylint`.
101+
102+
Next, run:
103+
104+
```bash
105+
pylint --rcfile=.github/linters/.python-lint path/to/python/file_or_directory
106+
```
107+
108+
To lint all Python files in the current directory and its subdirectories, run:
109+
110+
```bash
111+
pylint --rcfile=.github/linters/.python-lint .
112+
```
113+
114+
### Using Black
115+
We run Black against any changed file or directory. See the [Python Github Action workflow](../.github/workflows/python.yml) for details.
116+
117+
To invoke Black yourself, first install it with `pip install black`.
118+
119+
Next, run:
120+
121+
```bash
122+
black path/to/python/file_or_directory
123+
```
124+
125+
To format all Python files in the current directory and its subdirectories, run:
126+
127+
```bash
128+
black .
129+
```
130+
93131
## Tests
94132

95133
All tests use Pytest, and you can find them in the `test` folder for each example.

0 commit comments

Comments
 (0)