Skip to content

Commit 1f63544

Browse files
authored
Linting (#305)
* Add megalinter configuration Add exclusions to megalinter. * Force megalinter to run. * Add linter/formatter tool configuration * Fix megalinter template issues. * Add whitespace to test megalinter commits. * [Mega-Linter] Apply linters fixes Co-authored-by: TimPansino <[email protected]>
1 parent 2707fdf commit 1f63544

File tree

6 files changed

+170
-20
lines changed

6 files changed

+170
-20
lines changed

.github/workflows/mega-linter.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
---
2+
# Mega-Linter GitHub Action configuration file
3+
# More info at https://nvuillam.github.io/mega-linter
4+
name: Mega-Linter
5+
6+
on:
7+
# Trigger mega-linter at every push. Action will also be visible from Pull Requests to main
8+
# push: # Comment this line to trigger action only on pull-requests (not recommended if you don't pay for GH Actions)
9+
pull_request:
10+
branches: [main]
11+
12+
env: # Comment env block if you do not want to apply fixes
13+
# Apply linter fixes configuration
14+
APPLY_FIXES: all # When active, APPLY_FIXES must also be defined as environment variable (in github/workflows/mega-linter.yml or other CI tool)
15+
APPLY_FIXES_EVENT: pull_request # Decide which event triggers application of fixes in a commit or a PR (pull_request, push, all)
16+
APPLY_FIXES_MODE: commit # If APPLY_FIXES is used, defines if the fixes are directly committed (commit) or posted in a PR (pull_request)
17+
18+
jobs:
19+
# Cancel duplicate jobs: https://github.com/fkirc/skip-duplicate-actions#option-3-cancellation-only
20+
cancel_duplicates:
21+
name: Cancel duplicate jobs
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: fkirc/skip-duplicate-actions@master
25+
with:
26+
github_token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
27+
28+
build:
29+
name: Mega-Linter
30+
runs-on: ubuntu-latest
31+
steps:
32+
# Git Checkout
33+
- name: Checkout Code
34+
uses: actions/checkout@v2
35+
with:
36+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
37+
fetch-depth: 0
38+
39+
# Mega-Linter
40+
- name: Mega-Linter
41+
id: ml
42+
# You can override Mega-Linter flavor used to have faster performances
43+
# More info at https://nvuillam.github.io/mega-linter/flavors/
44+
uses: nvuillam/mega-linter/flavors/python@v4
45+
env:
46+
# All available variables are described in documentation
47+
# https://nvuillam.github.io/mega-linter/configuration/
48+
VALIDATE_ALL_CODEBASE: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} # Validates all source when push on main, else just the git diff with main. Set 'true' if you always want to lint all sources
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
# ADD YOUR CUSTOM ENV VARIABLES HERE TO OVERRIDE VALUES OF .mega-linter.yml AT THE ROOT OF YOUR REPOSITORY
51+
52+
# Upload Mega-Linter artifacts
53+
- name: Archive production artifacts
54+
if: ${{ success() }} || ${{ failure() }}
55+
uses: actions/upload-artifact@v2
56+
with:
57+
name: Mega-Linter reports
58+
path: |
59+
report
60+
mega-linter.log
61+
62+
# Create pull request if applicable (for now works only on PR from same repository, not from forks)
63+
- name: Create Pull Request with applied fixes
64+
id: cpr
65+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
66+
uses: peter-evans/create-pull-request@v3
67+
with:
68+
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
69+
commit-message: "[Mega-Linter] Apply linters automatic fixes"
70+
title: "[Mega-Linter] Apply linters automatic fixes"
71+
labels: bot
72+
- name: Create PR output
73+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'pull_request' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
74+
run: |
75+
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
76+
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
77+
78+
# Push new commit if applicable (for now works only on PR from same repository, not from forks)
79+
- name: Prepare commit
80+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
81+
run: sudo chown -Rc $UID .git/
82+
- name: Commit and push applied linter fixes
83+
if: steps.ml.outputs.has_updated_sources == 1 && (env.APPLY_FIXES_EVENT == 'all' || env.APPLY_FIXES_EVENT == github.event_name) && env.APPLY_FIXES_MODE == 'commit' && github.ref != 'refs/heads/main' && (github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository) && !contains(github.event.head_commit.message, 'skip fix')
84+
uses: stefanzweifel/git-auto-commit-action@v4
85+
with:
86+
branch: ${{ github.event.pull_request.head.ref || github.head_ref || github.ref }}
87+
commit_message: "[Mega-Linter] Apply linters fixes"

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Linter
2+
report/
3+
14
# Byte-compiled / optimized / DLL files
25
__pycache__/
36
*.py[cod]

.mega-linter.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Configuration file for Mega-Linter
2+
# See all available variables at https://nvuillam.github.io/mega-linter/configuration/ and in linters documentation
3+
4+
APPLY_FIXES: none # all, none, or list of linter keys
5+
DEFAULT_BRANCH: main # Usually master or main
6+
SHOW_ELAPSED_TIME: true
7+
FILEIO_REPORTER: false
8+
PRINT_ALPACA: false
9+
VALIDATE_ALL_CODEBASE: false
10+
ENABLE_LINTERS: # If you use ENABLE_LINTERS variable, all other linters will be disabled by default
11+
- MARKDOWN_MARKDOWN_LINK_CHECK
12+
- MARKDOWN_MARKDOWNLINT
13+
- PYTHON_BANDIT
14+
- PYTHON_BLACK
15+
- PYTHON_FLAKE8
16+
- PYTHON_ISORT
17+
- PYTHON_PYLINT
18+
- RST_RST_LINT
19+
- RST_RSTCHECK
20+
- RST_RSTFMT
21+
- YAML_PRETTIER
22+
- YAML_V8R
23+
- YAML_YAMLLINT
24+
# IGNORE_GITIGNORED_FILES: true # Currently broken
25+
EXCLUDED_DIRECTORIES:
26+
- "__pycache__"
27+
- ".eggs"
28+
- ".env"
29+
- ".mypy_cache"
30+
- ".nox"
31+
- ".pytest_cache"
32+
- ".pytype"
33+
- ".tox"
34+
- ".venv"
35+
- "build"
36+
- "cover"
37+
- "cython_debug"
38+
- "develop-eggs"
39+
- "dist"
40+
- "downloads"
41+
- "eggs"
42+
- "env"
43+
- "htmlcov"
44+
- "lib"
45+
- "lib64"
46+
- "parts"
47+
- "report"
48+
- "sdist"
49+
- "python-wheels"
50+
- "target"
51+
- "var"
52+
- "venv"
53+
- "wheels"

pyproject.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[tool.black]
2+
line-length = 120
3+
include = '\.pyi?$'
4+
5+
[tool.isort]
6+
profile = "black"
7+
8+
[tool.pylint.messages_control]
9+
disable = "C0330, C0326"
10+
11+
[tool.pylint.format]
12+
max-line-length = "88"

setup.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
license_files =
33
LICENSE
44
THIRD_PARTY_NOTICES.md
5+
6+
[flake8]
7+
max-line-length = 120
8+
extend-ignore = E203,E501

tests/framework_graphene/_target_application.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from graphene import (
15-
ObjectType,
16-
Field,
17-
String,
18-
Schema,
19-
Mutation as GrapheneMutation,
20-
Int,
21-
List,
22-
NonNull,
23-
Union,
24-
)
14+
from graphene import Field, Int, List
15+
from graphene import Mutation as GrapheneMutation
16+
from graphene import NonNull, ObjectType, Schema, String, Union
2517

2618

2719
class Author(ObjectType):
@@ -59,7 +51,6 @@ class Library(ObjectType):
5951
Storage = List(String)
6052

6153

62-
6354
authors = [
6455
Author(
6556
first_name="New",
@@ -120,14 +111,13 @@ class Library(ObjectType):
120111
storage = []
121112

122113

123-
124114
class StorageAdd(GrapheneMutation):
125115
class Arguments:
126116
string = String(required=True)
127117

128118
string = String()
129119

130-
def mutate(parent, info, string):
120+
def mutate(self, info, string):
131121
storage.append(string)
132122
return String(string=string)
133123

@@ -140,25 +130,25 @@ class Query(ObjectType):
140130
storage = Storage
141131
error = String()
142132

143-
def resolve_library(parent, info, index):
133+
def resolve_library(self, info, index):
144134
# returns an object that represents a Person
145135
return libraries[index]
146136

147-
def resolve_storage(parent, info):
137+
def resolve_storage(self, info):
148138
return storage
149139

150-
def resolve_search(parent, info, contains):
140+
def resolve_search(self, info, contains):
151141
search_books = [b for b in books if contains in b.name]
152142
search_magazines = [m for m in magazines if contains in m.name]
153143
return search_books + search_magazines
154144

155-
def resolve_hello(root, info):
145+
def resolve_hello(self, info):
156146
return "Hello!"
157147

158-
def resolve_echo(root, info, echo):
148+
def resolve_echo(self, info, echo):
159149
return echo
160150

161-
def resolve_error(root, info):
151+
def resolve_error(self, info):
162152
raise RuntimeError("Runtime Error!")
163153

164154
error_non_null = Field(NonNull(String), resolver=resolve_error)
@@ -167,4 +157,5 @@ def resolve_error(root, info):
167157
class Mutation(ObjectType):
168158
storage_add = StorageAdd.Field()
169159

160+
170161
_target_application = Schema(query=Query, mutation=Mutation, auto_camelcase=False)

0 commit comments

Comments
 (0)