Skip to content

All linter changes #422

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 2 commits into from
May 1, 2021
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
28 changes: 28 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[flake8]
filename = *.py, *.pyx
max_line_length = 80
max-doc-length = 80
extend-ignore = E203, W503
show-source = True

exclude =
versioneer.py
dpctl/_version.py
build
conda.recipe
.git

per-file-ignores =
dpctl/_sycl_context.pyx: E999, E225, E227
dpctl/_sycl_device.pyx: E999, E225
dpctl/_sycl_device_factory.pyx: E999, E225
dpctl/_sycl_event.pyx: E999, E225
dpctl/_sycl_platform.pyx: E999, E225
dpctl/_sycl_queue.pyx: E999, E225, E226, E227
dpctl/_sycl_queue_manager.pyx: E999, E225
dpctl/memory/_memory.pyx: E999, E225, E226, E227
dpctl/program/_program.pyx: E999, E225, E226, E227
dpctl/tensor/numpy_usm_shared.py: F821
examples/cython/sycl_buffer/_buffer_example.pyx: E999, E225, E402
examples/cython/sycl_direct_linkage/_buffer_example.pyx: E999, E225, E402
examples/cython/usm_memory/blackscholes.pyx: E999, E225, E226, E402
22 changes: 22 additions & 0 deletions .github/workflows/cpp_style_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is a workflow to format C/C++ sources with clang-format

name: C++ Code Style

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
push:
branches: [master]

jobs:
formatting-check:
name: clang-format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/[email protected]
with:
clang-format-version: '11'
check-path: 'dpctl-capi'
58 changes: 58 additions & 0 deletions .github/workflows/python_style_checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# This is a workflow to format Python code with black formatter

name: Python Code Style

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
pull_request:
push:
branches: [master]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# The isort job sorts all imports in .py, .pyx, .pxd files
isort:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: jamescurtin/isort-action@master
with:
args: ". --check-only"

black:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
# Set up a Python environment for use in actions
- uses: actions/setup-python@v2

# Run black code formatter
- uses: psf/[email protected]
with:
args: ". --check"

flake8:
runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.7]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
uses: py-actions/flake8@v1
29 changes: 29 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,32 @@ repos:
- id: bandit
pass_filenames: false
args: ["-r", "dpctl", "-lll"]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 21.4b2
hooks:
- id: black
exclude: "versioneer.py|dpctl/_version.py"
- repo: https://github.com/pycqa/isort
rev: 5.8.0
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.1
hooks:
- id: flake8
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.1.1
hooks:
- id: clang-format
64 changes: 47 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ Run before each commit: `clang-format -style=file -i dpctl-capi/include/*.h dpct

### Python code style

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

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

Run before each commit: `black .`
Please run these three tools before each commit. Although, you may choose to
do so manually, but it is much easier and preferable to automate these checks.
Refer your IDE docs to set them up in your IDE, or you can set up `pre-commit`
to add git hooks.

### Setting up pre-commit

A `.pre-commit-config.yaml` is included to run various check before you
commit your code. Here are the steps to setup `pre-commit` in your workflow:

- Install `pre-commit`: `pip install pre-commit`
- Install the git hook scripts: `pre-commit install`

That should be it!

### C/C++ File Headers

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

### Python File Headers

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

### Bandit

We use [Bandit](https://github.com/PyCQA/bandit) to find common security issues in Python code.
We use [Bandit](https://github.com/PyCQA/bandit) to find common security issues
in Python code.

Install: `pip install bandit`

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

## Code Coverage

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

### Using Code Coverage

You need to install additional packages and add an environment variable to cover:
You need to install additional packages and add an environment variable to
cover:
- conda install cmake
- conda install coverage
- conda install conda-forge::lcov
- conda install conda-forge::gtest
- export CODE_COVERAGE=ON

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.
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.
It was added for the convenience of configuring the CI in the future.

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

The coverage report will appear during the build in the console. This report contains information about c++ file coverage.
The `dpctl-c-api-coverage` folder will appear in the root folder after installation.
The folder contains a report on the coverage of c++ files in html format.
The coverage report will appear during the build in the console. This report
contains information about c++ file coverage.
The `dpctl-c-api-coverage` folder will appear in the root folder after
installation. The folder contains a report on the coverage of c++ files in html
format.

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

The required flags for the command coverage run are contained in the file `.coveragerc`.
The required flags for the command coverage run are contained in the file
`.coveragerc`.

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

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.
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.

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

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

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.
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.

Erase previously collected coverage data:
- coverage erase

### Error in the build process

An error occurs during the dcptl build with the CODE_COVERAGE environment variable:
An error occurs during the dcptl build with the CODE_COVERAGE environment
variable:
```
error: '../compat/unistd.h' file not found, did you mean 'compat/unistd.h'?
# include "../compat/unistd.h"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)

What?
====
Expand Down
6 changes: 3 additions & 3 deletions docs/conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ use_doxyrest = "@DPCTL_ENABLE_DOXYREST@"

if use_doxyrest == "ON":
# Specify the path to Doxyrest extensions for Sphinx:
import sys, os
import os
import sys

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

from sphinx.ext.autosummary import Autosummary
from sphinx.ext.autosummary import get_documenter
from docutils.parsers.rst import directives
from sphinx.ext.autosummary import Autosummary, get_documenter
from sphinx.util.inspect import safe_getattr


Expand Down
Loading