Use CircleCI version 2.1 at the top of your .circleci/config.yml file.
1
version: 2.1
Add the orbs
stanza below your version, invoking the orb:
1
2
orbs:
python-lint: qventus/python-lint@0.0.8
Use python-lint
elements in your existing workflows and jobs.
Opt-in to use of uncertified orbs on your organization’s Security settings page.
Usage
1
2
3
4
5
6
7
orbs:
pylint: qventus/python-lint@volatile
version: 2.1
workflows:
build:
jobs:
- pylint/lint
Lint python files
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
pyversion | Python version for executor | No | '3.10' | string |
working-directory | Directory path for this job | No | . | string |
checkout | Bool to checkout as a first step | No | true | boolean |
attach-workspace | Bool to attach to an existing workspace | No | false | boolean |
workspace-root | Workspace root path | No | . | string |
compare-to-pr-root | Use GITHUB_API_TOKEN to find where pull is getting merged into and find all changed files | No | true | boolean |
Run flake8 on files with git diff
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
working-directory | Directory path for this job | No | . | string |
checkout | Bool to checkout as a first step | No | true | boolean |
attach-workspace | Bool to attach to an existing workspace | No | false | boolean |
workspace-root | Workspace root path | No | . | string |
compare-to-pr-root | Use GITHUB_API_TOKEN to find where pull is getting merged into and find all changed files | No | true | boolean |
PARAMETER | DESCRIPTION | REQUIRED | DEFAULT | TYPE |
---|---|---|---|---|
pyversion | Python version for executor | No | '3.10' | string |
working-directory | Directory path for this job | No | . | string |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# This code is licensed from CircleCI to the user under the MIT license.
# See here for details: https://circleci.com/developer/ja/orbs/licensing
version: 2.1
description: |
Use this orb to run flake8 linting according to the settings.cfg in your repository.
Detects the changes to base of PR (or last commit if run with compare-to-pr-root: false) and run flake8 on py files.
examples:
python-lint:
description: Usage
usage:
orbs:
pylint: qventus/python-lint@volatile
version: 2.1
workflows:
build:
jobs:
- pylint/lint
commands:
lint:
description: Run flake8 on files with git diff
parameters:
working-directory: &working-directory
default: .
type: string
description: Directory path for this job
checkout: &checkout
default: true
type: boolean
description: Bool to checkout as a first step
attach-workspace: &attach-workspace
default: false
type: boolean
description: Bool to attach to an existing workspace
workspace-root: &workspace-root
default: .
type: string
description: Workspace root path
compare-to-pr-root: &compare-to-pr-root
default: true
type: boolean
description: Use GITHUB_API_TOKEN to find where pull is getting merged into and find all changed files
steps:
- when:
condition: << parameters.checkout >>
steps:
- checkout
- when:
condition: << parameters.attach-workspace >>
steps:
- attach_workspace:
at: << parameters.workspace-root >>
- when:
condition: << parameters.compare-to-pr-root >>
steps:
- run:
name: Find all files differing and then flake8
command: |
if [[ -z "${CIRCLE_PULL_REQUEST}" ]]; then
echo "No pull request. Skipping title validation."
exit 0
elif [[ -z "${GITHUB_API_TOKEN}" ]]; then
echo "ERROR: No Github API token. Must have valid token to run job."
exit 1
fi
pip install flake8==3.7.7
CIRCLE_PR_NUMBER=$(echo "import re; print(re.findall(r'\d+$','${CIRCLE_PULL_REQUEST}')[0])" | python)
URL="https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER}"
MERGE_TO_BRANCH=$(curl -s -X GET -G ${URL} -H "Authorization: token ${GITHUB_API_TOKEN}" | jq '.base.ref' | tr -d '"')
git checkout -q ${MERGE_TO_BRANCH}
git reset --hard -q origin/${MERGE_TO_BRANCH}
git checkout -q ${CIRCLE_BRANCH}
echo "checked out ${CIRCLE_BRANCH} from ${MERGE_TO_BRANCH}"
CHANGED_FILES=$(git diff --name-only ${MERGE_TO_BRANCH}..${CIRCLE_BRANCH} -- '*.py')
echo ${CHANGED_FILES}
echo ${CHANGED_FILES} | xargs --no-run-if-empty flake8
- unless:
condition: << parameters.compare-to-pr-root >>
steps:
- run:
name: Find most recent files differing and then flake8
command: |
if [[ -z "$CIRCLE_PULL_REQUEST" ]]; then
echo "ERROR: No pull request. Must have pull request associated with your code."
exit 1
fi
pip install flake8==3.7.7
CHANGED_FILES=$(git diff --name-only ${CIRCLE_BRANCH}~1 -- '*.py')
echo ${CHANGED_FILES}
echo ${CHANGED_FILES} | xargs --no-run-if-empty flake8
executors:
python-lint:
docker:
- image: cimg/python:<< parameters.pyversion >>
working_directory: << parameters.working-directory >>
parameters:
pyversion: &pyversion
default: "3.10"
description: Python version for executor
type: string
working-directory: *working-directory
resource_class: small
jobs:
lint:
description: Lint python files
parameters:
pyversion: *pyversion
working-directory: *working-directory
checkout: *checkout
attach-workspace: *attach-workspace
workspace-root: *workspace-root
compare-to-pr-root: *compare-to-pr-root
executor:
name: python-lint
pyversion: << parameters.pyversion >>
working-directory: << parameters.working-directory >>
steps:
- lint:
working-directory: <<parameters.working-directory>>
checkout: << parameters.checkout >>
attach-workspace: << parameters.attach-workspace >>
workspace-root: << parameters.workspace-root >>
compare-to-pr-root: << parameters.compare-to-pr-root >>