Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianDeconinck committed Mar 15, 2024
2 parents 239093c + ee17241 commit 52366f1
Show file tree
Hide file tree
Showing 252 changed files with 6,744 additions and 3,108 deletions.
139 changes: 20 additions & 119 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
default_language_version:
python: python3.10
repos:
# - repo: meta
# hooks:
# - id: check-hooks-apply
# - id: check-useless-excludes

# - repo: meta
# hooks:
# - id: check-hooks-apply
# - id: check-useless-excludes
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.6.0
hooks:
Expand All @@ -33,20 +32,6 @@ repos:
types: [python]
args: [--comment-style, "|#|", --license-filepath, ./LICENSE_HEADER.txt, --fuzzy-match-generates-todo]

# - repo: https://github.com/asottile/yesqa
# rev: v1.4.0
# hooks:
# - id: yesqa
# additional_dependencies:
# - flake8==5.0.4 # version from constraints.txt
# - darglint
# - flake8-bugbear
# - flake8-builtins
# - flake8-debugger
# - flake8-docstrings
# - flake8-eradicate
# - flake8-mutable

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
Expand All @@ -56,106 +41,21 @@ repos:
- id: check-yaml
- id: debug-statements

- repo: https://github.com/psf/black
##[[[cog
## import re
## version = re.search('black==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"rev: '{version}' # version from constraints.txt")
##]]]
rev: '24.1.1' # version from constraints.txt
##[[[end]]]
hooks:
- id: black

# - repo: https://github.com/charliermarsh/ruff-pre-commit
# ##[[[cog
# ## import re
# ## version = re.search('ruff==([0-9\.]*)', open("constraints.txt").read())[1]
# ## print(f"# rev: 'v{version}' # version from constraints.txt")
# ##]]]
# rev: 'v0.2.0' # version from constraints.txt
# ##[[[end]]]
# hooks:
# - id: ruff
# # args: [ --fix, --exit-non-zero-on-fix ]

- repo: https://github.com/PyCQA/isort
##[[[cog
## import re
## version = re.search('isort==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"rev: '{version}' # version from constraints.txt")
##]]]
rev: '5.13.2' # version from constraints.txt
##[[[end]]]
hooks:
- id: isort

- repo: https://github.com/PyCQA/flake8
##[[[cog
## import re
## version = re.search('flake8==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"rev: '{version}' # version from constraints.txt")
##]]]
rev: '7.0.0' # version from constraints.txt
##[[[end]]]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.2.0
hooks:
- id: flake8
additional_dependencies:
##[[[cog
## import re
## constraints = open("constraints.txt").read()
## for pkg in ["darglint", "flake8-bugbear", "flake8-builtins", "flake8-debugger", "flake8-docstrings",
## "flake8-eradicate", "flake8-mutable", "flake8-pyproject", "pygments"]:
## print(f"- {pkg}==" + str(re.search(f'\n{pkg}==([0-9\.]*)', constraints)[1]))
##]]]
- darglint==1.8.1
- flake8-bugbear==24.1.17
- flake8-builtins==2.2.0
- flake8-debugger==4.1.2
- flake8-docstrings==1.7.0
- flake8-eradicate==1.5.0
- flake8-mutable==1.2.0
- flake8-pyproject==1.2.3
- pygments==2.17.2
##[[[end]]]
# - flake8-rst-docstrings # Disabled for now due to random false positives
exclude: |
(?x)^(
setup.py |
docs/user/cartesian/conf.py |
src/gt4py/cartesian/__gtscript__.py |
src/gt4py/cartesian/__init__.py |
src/gt4py/cartesian/gtscript.py |
src/gt4py/cartesian/backend/__init__.py |
src/gt4py/cartesian/backend/pyext_builder.py |
src/gt4py/cartesian/frontend/__init__.py |
src/gt4py/cartesian/frontend/nodes.py |
src/gt4py/cartesian/frontend/node_util.py |
src/gt4py/cartesian/utils/__init__.py |
src/gt4py/cartesian/utils/base.py |
src/gt4py/cartesian/utils/attrib.py |
src/gt4py/cartesian/utils/meta.py |
src/gt4py/eve/extended_typing.py |
tests/conftest.py |
tests/cartesian_tests/integration_tests/multi_feature_tests/stencil_definitions.py |
tests/cartesian_tests/integration_tests/multi_feature_tests/test_code_generation.py |
tests/cartesian_tests/integration_tests/multi_feature_tests/utils.py |
tests/cartesian_tests/integration_tests/feature_tests/test_call_interface.py |
tests/cartesian_tests/unit_tests/frontend_tests/test_gtscript_frontend.py |
tests/next_tests/unit_tests/.* |
tests/next_tests/integration_tests/multi_feature_tests/.* |
tests/next_tests/integration_tests/feature_tests/ffront_tests/.* |
tests/next_tests/integration_tests/feature_tests/iterator_tests/.* |
tests/next_tests/integration_tests/feature_tests/otf_tests/.* |
tests/next_tests/integration_tests/feature_tests/math_builtin_test_data.py |
tests/next_tests/past_common_fixtures.py |
tests/next_tests/toy_connectivity.py |
)$
# Run the linter.
# TODO: include tests here
- id: ruff
files: ^src/
args: [--fix]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
##[[[cog
## import re
## version = re.search('mypy==([0-9\.]*)', open("constraints.txt").read())[1]
## version = re.search('mypy==([0-9\.]*)', open("constraints.txt").read())[1]
## print(f"#========= FROM constraints.txt: v{version} =========")
##]]]
#========= FROM constraints.txt: v1.8.0 =========
Expand All @@ -178,26 +78,27 @@ repos:
##]]]
- astunparse==1.6.3
- attrs==23.2.0
- black==24.1.1
- black==24.2.0
- boltons==23.1.1
- cached-property==1.5.2
- click==8.1.7
- cmake==3.28.1
- cmake==3.28.3
- cytoolz==0.12.3
- deepdiff==6.7.1
- devtools==0.12.2
- factory-boy==3.3.0
- frozendict==2.4.0
- gridtools-cpp==2.3.2
- importlib-resources==6.1.1
- importlib-resources==6.1.2
- jinja2==3.1.3
- lark==1.1.9
- mako==1.3.2
- nanobind==1.8.0
- nanobind==1.9.2
- ninja==1.11.1.1
- numpy==1.24.4
- packaging==23.2
- pybind11==2.11.1
- setuptools==69.0.3
- setuptools==69.1.1
- tabulate==0.9.0
- typing-extensions==4.5.0
- xxhash==3.0.0
Expand Down
25 changes: 17 additions & 8 deletions CODING_GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ We follow the [Google Python Style Guide][google-style-guide] with a few minor c

We deviate from the [Google Python Style Guide][google-style-guide] only in the following points:

- We use [`flake8`][flake8] with some plugins instead of [`pylint`][pylint].
- We use [`black`][black] and [`isort`][isort] for source code and imports formatting, which may work differently than indicated by the guidelines in section [_3. Python Style Rules_](https://google.github.io/styleguide/pyguide.html#3-python-style-rules). For example, maximum line length is set to 100 instead of 79 (although docstring lines should still be limited to 79).
- We use [`ruff-linter`][ruff-linter] instead of [`pylint`][pylint].
- We use [`ruff-formatter`][ruff-formatter] for source code and imports formatting, which may work differently than indicated by the guidelines in section [_3. Python Style Rules_](https://google.github.io/styleguide/pyguide.html#3-python-style-rules). For example, maximum line length is set to 100 instead of 79 (although docstring lines should still be limited to 79).
- According to subsection [_2.19 Power Features_](https://google.github.io/styleguide/pyguide.html#219-power-features), direct use of _power features_ (e.g. custom metaclasses, import hacks, reflection) should be avoided, but standard library classes that internally use these power features are accepted. Following the same spirit, we allow the use of power features in infrastructure code with similar functionality and scope as the Python standard library.
- According to subsection [_3.19.12 Imports For Typing_](https://google.github.io/styleguide/pyguide.html#31912-imports-for-typing), symbols from `typing` and `collections.abc` modules used in type annotations _"can be imported directly to keep common annotations concise and match standard typing practices"_. Following the same spirit, we allow symbols to be imported directly from third-party or internal modules when they only contain a collection of frequently used typying definitions.

Expand Down Expand Up @@ -107,7 +107,7 @@ In general, you should structure new Python modules in the following way:
1. _shebang_ line: `#! /usr/bin/env python3` (only for **executable scripts**!).
2. License header (see `LICENSE_HEADER.txt`).
3. Module docstring.
4. Imports, alphabetically ordered within each block (fixed automatically by `isort`):
4. Imports, alphabetically ordered within each block (fixed automatically by `ruff-formatter`):
1. Block of imports from the standard library.
2. Block of imports from general third party libraries using standard shortcuts when customary (e.g. `numpy as np`).
3. Block of imports from specific modules of the project.
Expand All @@ -126,10 +126,17 @@ Consider configuration files as another type of source code and apply the same c

### Ignoring QA errors

You may occasionally need to disable checks from _quality assurance_ (QA) tools (e.g. linters, type checkers, etc.) on specific lines as some tool might not be able to fully understand why a certain piece of code is needed. This is usually done with special comments, e.g. `# type: ignore`. However, you should **only** ignore QA errors when you fully understand their source and rewriting your code to pass QA checks would make it less readable. Additionally, you should add a brief comment for future reference, e.g.:
You may occasionally need to disable checks from _quality assurance_ (QA) tools (e.g. linters, type checkers, etc.) on specific lines as some tool might not be able to fully understand why a certain piece of code is needed. This is usually done with special comments, e.g. `# noqa: F401`, `# type: ignore`. However, you should **only** ignore QA errors when you fully understand their source and rewriting your code to pass QA checks would make it less readable. Additionally, you should add a short descriptive code if possible (check [ruff rules][ruff-rules] and [mypy error codes][mypy-error-codes] for reference):

```python
f = lambda: 'empty' # noqa: E731 # assign lambda expression for testing
f = lambda: 'empty' # noqa: E731 [lambda-assignment]
```

and, if needed, a brief comment for future reference:

```python
...
return undeclared_symbol # noqa: F821 [undefined-name] on purpose to trigger black-magic
```

## Testing
Expand Down Expand Up @@ -213,13 +220,15 @@ https://testandcode.com/116

<!-- Reference links -->

[black]: https://black.readthedocs.io/en/stable/
[doctest]: https://docs.python.org/3/library/doctest.html
[flake8]: https://flake8.pycqa.org/
[google-style-guide]: https://google.github.io/styleguide/pyguide.html
[isort]: https://pycqa.github.io/isort/
[mypy]: https://mypy.readthedocs.io/
[mypy-error-codes]: https://mypy.readthedocs.io/en/stable/error_code_list.html
[pre-commit]: https://pre-commit.com/
[pylint]: https://pylint.pycqa.org/
[ruff-formatter]: https://docs.astral.sh/ruff/formatter/
[ruff-linter]: https://docs.astral.sh/ruff/linter/
[ruff-rules]: https://docs.astral.sh/ruff/rules/
[sphinx]: https://www.sphinx-doc.org
[sphinx-autodoc]: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
[sphinx-napoleon]: https://sphinxcontrib-napoleon.readthedocs.io/en/latest/index.html#
Expand Down
2 changes: 1 addition & 1 deletion ci/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ RUN pyenv update && \
ENV PATH="/root/.pyenv/shims:${PATH}"


RUN pip install --upgrade pip setuptools wheel tox cupy-cuda11x
RUN pip install --upgrade pip setuptools wheel tox cupy-cuda11x==12.3.0
Loading

0 comments on commit 52366f1

Please sign in to comment.