Skip to content

Commit 8d76e6b

Browse files
authored
Adjust configuration for autoformatting with black (NVIDIA#5168)
Temporarily disable the linter in this commit, before the whole repository is adjusted to new formatting. Add black to third party deps listing to include it in the deps update procedure. Use latest version but require only the one for given year according to the compatibility policy. Remove obsolete configs related to previous linter or exceptions related to the formatting of some parts of DALI. Keep the separate config with exceptions for autograph to limit the code changes. Signed-off-by: Krzysztof Lecki <[email protected]>
1 parent fc5b7a1 commit 8d76e6b

File tree

10 files changed

+42
-25
lines changed

10 files changed

+42
-25
lines changed

.flake8

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
color = auto
33
count = True
44
doctests = False
5-
max-doc-length = 120
65
max-line-length = 100
76
statistics = True
7+
# E203 - whitespace before ':' - PEP8 non-compliant warning in slicing expressions
8+
# W503 - Line break occurred before a binary operator, replaced by W504
9+
extend-ignore = E203,W503
10+
# W504 - Line break occurred after a binary operator
11+
extend-select = W504
812
# Filter out the AutoGraph from regular linter - it has a separate .flake8.ag config.
913
exclude = *nvidia/dali/_autograph/*,*test/python/autograph/*

.flake8.ag

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# AutoGraph uses 2 spaces, thus it requires a separate flake8 config
1+
# per-file-ignore do not work well with absolute path (or more complex paths),
2+
# so just disable them by a special config
23
[flake8]
3-
indent-size = 2
44
color = auto
55
count = True
66
doctests = False
7-
max-doc-length = 100
87
max-line-length = 100
98
statistics = True
9+
# E203 - whitespace before ':' - PEP8 non-compliant warning in slicing expressions
10+
# W503 - Line break occurred before a binary operator, replaced by W504
1011
# E741 - ambiguous variable name 'l'
1112
# E731 - do not assign a lambda expression, use a def
1213
# F401 - 'autograph.operators....' imported but unused - used to bring types into another module
13-
extend-ignore = E741,E731,F401
14+
extend-ignore = E203,E741,E731,F401
15+
# W504 - Line break occurred after a binary operator
16+
extend-select = W504

.style.yapf

Lines changed: 0 additions & 7 deletions
This file was deleted.

cmake/lint.cmake

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# Copyright (c) 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -31,15 +31,26 @@ set(AUTOGRAPH_LINT_PATHS
3131
${PROJECT_SOURCE_DIR}/dali/test/python/autograph/
3232
)
3333

34+
add_custom_target(lint-python-black
35+
COMMAND
36+
black --check --config ${PROJECT_SOURCE_DIR}/pyproject.toml ${PYTHON_LINT_PATHS} ${AUTOGRAPH_LINT_PATHS}
37+
COMMENT
38+
"Performing black Python formatting check"
39+
)
3440

35-
add_custom_target(lint-python
41+
42+
add_custom_target(lint-python-flake
3643
COMMAND
3744
flake8 --config=${PROJECT_SOURCE_DIR}/.flake8 ${PYTHON_LINT_PATHS}
3845
COMMAND
3946
flake8 --config=${PROJECT_SOURCE_DIR}/.flake8.ag ${AUTOGRAPH_LINT_PATHS}
4047
COMMENT
4148
"Performing Python linter check"
4249
)
50+
add_dependencies(lint-python-flake lint-python-black)
51+
52+
add_custom_target(lint-python)
53+
add_dependencies(lint-python lint-python-flake)
4354

4455
add_custom_target(lint)
45-
add_dependencies(lint lint-cpp lint-python)
56+
add_dependencies(lint lint-cpp)

conda/recipe/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ requirements:
7373
- astunparse >=1.6.0
7474
- gast >=0.3.3
7575
- dm-tree >=0.1.8
76-
- black
76+
- black =23.11.0
7777
host:
7878
- python
7979
- future

dali/python/nvidia/dali/_autograph/.style.yapf

Lines changed: 0 additions & 4 deletions
This file was deleted.

dali/test/python/autograph/.style.yapf

Lines changed: 0 additions & 4 deletions
This file was deleted.

docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ ENV PYVER=${PYVER} \
2020
RUN ln -s /opt/python/cp${PYV}* /opt/python/v
2121

2222
# install Python bindings and patch it to use the clang we have here
23-
RUN pip install future setuptools wheel clang==14.0 flake8 astunparse gast dm-tree black && \
23+
RUN pip install future setuptools wheel clang==14.0 flake8 astunparse gast dm-tree black==23.11.0 && \
2424
PY_CLANG_PATH=$(echo $(pip show clang) | sed 's/.*Location: \(.*\) Requires.*/\1/')/clang/cindex.py && \
2525
LIBCLANG_PATH=/usr/local/lib/libclang.so && \
2626
sed -i "s|library_file = None|library_file = \"${LIBCLANG_PATH}\"|" ${PY_CLANG_PATH} && \

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[tool.black]
2+
line-length = 100
3+
target-version = ['py38', 'py39', 'py310', 'py311']
4+
required-version = '23'
5+
workers = 32

third_party/README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This part of the repository contains extra dependencies required to build DALI,
2323
+-----------------+---------------------+---------------------+
2424
| |rapidjson|_ | |rapidjsonver|_ | |rapidjsonlic|_ |
2525
+-----------------+---------------------+---------------------+
26+
| |black|_ | |blackver|_ | |blacklic|_ |
27+
+-----------------+---------------------+---------------------+
2628

2729
.. |benchmark| replace:: Google Benchmark
2830
.. _benchmark: https://github.com/google/benchmark
@@ -86,3 +88,10 @@ This part of the repository contains extra dependencies required to build DALI,
8688
.. _rapidjsonver: https://github.com/Tencent/rapidjson/commit/f9d53419e912910fd8fa57d5705fa41425428c35
8789
.. |rapidjsonlic| replace:: MIT License, BSD 3-Clause License, JSON License
8890
.. _rapidjsonlic: https://github.com/Tencent/rapidjson/blob/master/license.txt
91+
92+
.. |black| replace:: black
93+
.. _black: https://github.com/psf/black
94+
.. |blackver| replace:: 23.11.0
95+
.. _blackver: https://pypi.org/project/black/23.11.0/
96+
.. |blacklic| replace:: MIT License
97+
.. _blacklic: https://github.com/psf/black/blob/main/LICENSE

0 commit comments

Comments
 (0)