Skip to content

Commit fc0c7a0

Browse files
author
Diptorup Deb
authored
Merge pull request #422 from IntelPython/all-linter-changes
All linter changes
2 parents 8866561 + 084ba59 commit fc0c7a0

Some content is hidden

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

61 files changed

+1258
-651
lines changed

.flake8

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[flake8]
2+
filename = *.py, *.pyx
3+
max_line_length = 80
4+
max-doc-length = 80
5+
extend-ignore = E203, W503
6+
show-source = True
7+
8+
exclude =
9+
versioneer.py
10+
dpctl/_version.py
11+
build
12+
conda.recipe
13+
.git
14+
15+
per-file-ignores =
16+
dpctl/_sycl_context.pyx: E999, E225, E227
17+
dpctl/_sycl_device.pyx: E999, E225
18+
dpctl/_sycl_device_factory.pyx: E999, E225
19+
dpctl/_sycl_event.pyx: E999, E225
20+
dpctl/_sycl_platform.pyx: E999, E225
21+
dpctl/_sycl_queue.pyx: E999, E225, E226, E227
22+
dpctl/_sycl_queue_manager.pyx: E999, E225
23+
dpctl/memory/_memory.pyx: E999, E225, E226, E227
24+
dpctl/program/_program.pyx: E999, E225, E226, E227
25+
dpctl/tensor/numpy_usm_shared.py: F821
26+
examples/cython/sycl_buffer/_buffer_example.pyx: E999, E225, E402
27+
examples/cython/sycl_direct_linkage/_buffer_example.pyx: E999, E225, E402
28+
examples/cython/usm_memory/blackscholes.pyx: E999, E225, E226, E402
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is a workflow to format C/C++ sources with clang-format
2+
3+
name: C++ Code Style
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
pull_request:
9+
push:
10+
branches: [master]
11+
12+
jobs:
13+
formatting-check:
14+
name: clang-format
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v2
18+
- name: Run clang-format style check for C/C++ programs.
19+
uses: jidicula/[email protected]
20+
with:
21+
clang-format-version: '11'
22+
check-path: 'dpctl-capi'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# This is a workflow to format Python code with black formatter
2+
3+
name: Python Code Style
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the master branch
7+
on:
8+
pull_request:
9+
push:
10+
branches: [master]
11+
12+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
13+
jobs:
14+
# The isort job sorts all imports in .py, .pyx, .pxd files
15+
isort:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-python@v2
20+
- uses: jamescurtin/isort-action@master
21+
with:
22+
args: ". --check-only"
23+
24+
black:
25+
# The type of runner that the job will run on
26+
runs-on: ubuntu-latest
27+
28+
# Steps represent a sequence of tasks that will be executed as part of the job
29+
steps:
30+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
31+
- uses: actions/checkout@v2
32+
# Set up a Python environment for use in actions
33+
- uses: actions/setup-python@v2
34+
35+
# Run black code formatter
36+
- uses: psf/[email protected]
37+
with:
38+
args: ". --check"
39+
40+
flake8:
41+
runs-on: ubuntu-latest
42+
43+
strategy:
44+
matrix:
45+
python-version: [3.7]
46+
47+
steps:
48+
- uses: actions/checkout@v2
49+
- name: Set up Python ${{ matrix.python-version }}
50+
uses: actions/setup-python@v2
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
- name: Install dependencies
54+
run: |
55+
python -m pip install --upgrade pip
56+
pip install flake8
57+
- name: Lint with flake8
58+
uses: py-actions/flake8@v1

.pre-commit-config.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,32 @@ repos:
77
- id: bandit
88
pass_filenames: false
99
args: ["-r", "dpctl", "-lll"]
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v2.3.0
12+
hooks:
13+
- id: end-of-file-fixer
14+
- id: trailing-whitespace
15+
- repo: https://github.com/psf/black
16+
rev: 21.4b2
17+
hooks:
18+
- id: black
19+
exclude: "versioneer.py|dpctl/_version.py"
20+
- repo: https://github.com/pycqa/isort
21+
rev: 5.8.0
22+
hooks:
23+
- id: isort
24+
name: isort (python)
25+
- id: isort
26+
name: isort (cython)
27+
types: [cython]
28+
- id: isort
29+
name: isort (pyi)
30+
types: [pyi]
31+
- repo: https://gitlab.com/pycqa/flake8
32+
rev: 3.9.1
33+
hooks:
34+
- id: flake8
35+
- repo: https://github.com/pocc/pre-commit-hooks
36+
rev: v1.1.1
37+
hooks:
38+
- id: clang-format

CONTRIBUTING.md

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ Run before each commit: `clang-format -style=file -i dpctl-capi/include/*.h dpct
1515

1616
### Python code style
1717

18-
We use [black](https://black.readthedocs.io/en/stable/) code formatter.
18+
We use the following Python code style tools:
19+
- [black](https://black.readthedocs.io/en/stable/) code formatter.
20+
- Revision: `20.8b1`.
21+
- [flake8](https://flake8.pycqa.org/en/latest/) linter.
22+
- Revision `3.9.1`.
23+
- [isort](https://pycqa.github.io/isort/) import sorter.
24+
- Revision `5.8.0`.
1925

20-
- Revision: `20.8b1`.
21-
- See configuration in `pyproject.toml`.
26+
- Refer `pyproject.toml` and `.flake8` config files for current configurations.
2227

23-
Run before each commit: `black .`
28+
Please run these three tools before each commit. Although, you may choose to
29+
do so manually, but it is much easier and preferable to automate these checks.
30+
Refer your IDE docs to set them up in your IDE, or you can set up `pre-commit`
31+
to add git hooks.
32+
33+
### Setting up pre-commit
34+
35+
A `.pre-commit-config.yaml` is included to run various check before you
36+
commit your code. Here are the steps to setup `pre-commit` in your workflow:
37+
38+
- Install `pre-commit`: `pip install pre-commit`
39+
- Install the git hook scripts: `pre-commit install`
40+
41+
That should be it!
2442

2543
### C/C++ File Headers
2644

@@ -61,8 +79,9 @@ Few things to note about this format:
6179
- The copyright year should be updated every calendar year.
6280
- Each comment line should be a max of 80 chars.
6381
- A Doxygen `\file` tag describing the contents of the file must be provided.
64-
Also note that the `\file` tag is inside a Doxygen comment block (defined by `///`
65-
comment marker instead of the `//` comment marker used in the rest of the header.
82+
Also note that the `\file` tag is inside a Doxygen comment block (
83+
defined by `///` comment marker instead of the `//` comment marker used in the
84+
rest of the header.
6685

6786
### Python File Headers
6887

@@ -91,7 +110,8 @@ The copyright year should be updated every calendar year.
91110

92111
### Bandit
93112

94-
We use [Bandit](https://github.com/PyCQA/bandit) to find common security issues in Python code.
113+
We use [Bandit](https://github.com/PyCQA/bandit) to find common security issues
114+
in Python code.
95115

96116
Install: `pip install bandit`
97117

@@ -101,18 +121,21 @@ Run before each commit: `bandit -r dpctl -lll`
101121

102122
## Code Coverage
103123

104-
Implement python, cython and c++ file coverage using `coverage` and `llvm-cov` packages on Linux.
124+
Implement python, cython and c++ file coverage using `coverage` and `llvm-cov`
125+
packages on Linux.
105126

106127
### Using Code Coverage
107128

108-
You need to install additional packages and add an environment variable to cover:
129+
You need to install additional packages and add an environment variable to
130+
cover:
109131
- conda install cmake
110132
- conda install coverage
111133
- conda install conda-forge::lcov
112134
- conda install conda-forge::gtest
113135
- export CODE_COVERAGE=ON
114136

115-
CODE_COVERAGE allows you to build a debug version of dpctl and enable string tracing, which allows you to analyze strings to create a coverage report.
137+
CODE_COVERAGE allows you to build a debug version of dpctl and enable string
138+
tracing, which allows you to analyze strings to create a coverage report.
116139
It was added for the convenience of configuring the CI in the future.
117140

118141
Installing the dpctl package:
@@ -121,34 +144,41 @@ Installing the dpctl package:
121144
It is important that there are no files of the old build in the folder.
122145
Use `git clean -xdf` to clean up the working tree.
123146

124-
The coverage report will appear during the build in the console. This report contains information about c++ file coverage.
125-
The `dpctl-c-api-coverage` folder will appear in the root folder after installation.
126-
The folder contains a report on the coverage of c++ files in html format.
147+
The coverage report will appear during the build in the console. This report
148+
contains information about c++ file coverage.
149+
The `dpctl-c-api-coverage` folder will appear in the root folder after
150+
installation. The folder contains a report on the coverage of c++ files in html
151+
format.
127152

128153
You need to run tests to cover the cython and python files:
129154
- coverage run -m unittest dpctl.tests
130155

131-
The required flags for the command coverage run are contained in the file `.coveragerc`.
156+
The required flags for the command coverage run are contained in the file
157+
`.coveragerc`.
132158

133159
The simplest reporting is a textual summary produced with report:
134160
- coverage report
135161

136-
For each module executed, the report shows the count of executable statements, the number of those statements missed, and the resulting coverage, expressed as a percentage.
162+
For each module executed, the report shows the count of executable statements,
163+
the number of those statements missed, and the resulting coverage, expressed as
164+
a percentage.
137165

138166
The `-m` flag also shows the line numbers of missing statements:
139167
- coverage report -m
140168

141169
To create an annotated HTML listings with coverage results:
142170
- coverage html
143171

144-
The `htmlcov` folder will appear in the root folder of the project. It contains reports on the coverage of python and cython files in html format.
172+
The `htmlcov` folder will appear in the root folder of the project. It contains
173+
reports on the coverage of python and cython files in html format.
145174

146175
Erase previously collected coverage data:
147176
- coverage erase
148177

149178
### Error in the build process
150179

151-
An error occurs during the dcptl build with the CODE_COVERAGE environment variable:
180+
An error occurs during the dcptl build with the CODE_COVERAGE environment
181+
variable:
152182
```
153183
error: '../compat/unistd.h' file not found, did you mean 'compat/unistd.h'?
154184
# include "../compat/unistd.h"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
2+
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
23

34
What?
45
====

docs/conf.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use_doxyrest = "@DPCTL_ENABLE_DOXYREST@"
4141

4242
if use_doxyrest == "ON":
4343
# Specify the path to Doxyrest extensions for Sphinx:
44-
import sys, os
44+
import os
45+
import sys
4546

4647
sys.path.insert(
4748
1,
@@ -168,9 +169,8 @@ class ClassMembersDocumenter(ClassDocumenter):
168169
# members and attributes.
169170
# See https://stackoverflow.com/questions/20569011/python-sphinx-autosummary-automated-listing-of-member-functions
170171

171-
from sphinx.ext.autosummary import Autosummary
172-
from sphinx.ext.autosummary import get_documenter
173172
from docutils.parsers.rst import directives
173+
from sphinx.ext.autosummary import Autosummary, get_documenter
174174
from sphinx.util.inspect import safe_getattr
175175

176176

0 commit comments

Comments
 (0)