Skip to content

Python Ruby - Linting: Move SuperLinter into standalone linters #6450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/linters/.ruby-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
#######################
# Rubocop Config file #
#######################

inherit_gem:
rubocop-github:
- config/default.yml
Metrics/MethodLength:
Max: 25
Metrics/AbcSize:
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint Python

on:
pull_request:
workflow_dispatch:

jobs:
black:
name: Flake8 Linting & Black Formatting
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: "**.py"

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
pip install black pylint

- name: Run Black & Pylint
if: steps.changed-files.outputs.any_changed == 'true'
run: |
changed_files=(${{steps.changed-files.outputs.all_changed_files}})
black "${changed_files[@]}"
pylint --rcfile .github/linters/.python-lint "${changed_files[@]}"
35 changes: 35 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Ruby Linting

on:
pull_request:
workflow_dispatch:

jobs:
rubocop:
name: RuboCop
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v41
with:
files: "ruby/**/*.rb"

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0

- name: Install dependencies
run: |
gem install rubocop

- name: Run RuboCop
if: steps.changed-files.outputs.any_changed == 'true'
run: |
changed_files=(${{steps.changed-files.outputs.all_changed_files}})
rubocop --config .github/linters/.ruby-lint.yml "${changed_files[@]}"
5 changes: 0 additions & 5 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ jobs:
sparse-checkout: |
.github
php
python
ruby
kotlin
- name: Lint Code Base
uses: github/super-linter@v4
Expand All @@ -27,7 +25,4 @@ jobs:
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_PHP_PHPCS: true
VALIDATE_PYTHON: true
VALIDATE_PYTHON_BLACK: true
VALIDATE_RUBY: true
VALIDATE_KOTLIN: true
40 changes: 39 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Install the packages for the example by running the following:
python -m pip install -r requirements.txt
```

This installs all of the packages listed in the `requirements.txt` file in the current
This installs all the packages listed in the `requirements.txt` file in the current
folder.

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

## Linting and formatting
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.
To contribute Python code to this project, please refer to the following installation and usage steps.

### Using Pylint
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.

To invoke Pylint yourself, first install it with `pip install pylint`.

Next, run:

```bash
pylint --rcfile=.github/linters/.python-lint path/to/python/file_or_directory
```

To lint all Python files in the current directory and its subdirectories, run:

```bash
pylint --rcfile=.github/linters/.python-lint .
```

### Using Black
We run Black against any changed file or directory. See the [Python Github Action workflow](../.github/workflows/python.yml) for details.

To invoke Black yourself, first install it with `pip install black`.

Next, run:

```bash
black path/to/python/file_or_directory
```

To format all Python files in the current directory and its subdirectories, run:

```bash
black .
```

## Tests

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